]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - win/configure.cpp
eddbfd4404b10faba6f47465d5d87c74e7c8828b
[user/henk/code/inspircd.git] / win / configure.cpp
1 /*       +------------------------------------+\r
2  *       | Inspire Internet Relay Chat Daemon |\r
3  *       +------------------------------------+\r
4  *\r
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team\r
6  * See: http://www.inspircd.org/wiki/index.php/Credits\r
7  *\r
8  * This program is free but copyrighted software; see\r
9  *            the file COPYING for details.\r
10  *\r
11  * ---------------------------------------------------\r
12  */\r
13 \r
14 #define _CRT_SECURE_NO_DEPRECATE\r
15 \r
16 #include <time.h>\r
17 #include "inspircd_win32wrapper.h"\r
18 \r
19 using namespace std;\r
20 void Run();\r
21 void Banner();\r
22 void WriteCompileModules();\r
23 void WriteCompileCommands();\r
24 \r
25 /* detects if we are running windows xp or higher (5.1) */\r
26 bool iswinxp()\r
27 {\r
28         OSVERSIONINFO vi;\r
29         vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);\r
30         GetVersionEx(&vi);\r
31         if(vi.dwMajorVersion >= 5)\r
32                 return true;\r
33         \r
34         return false;\r
35 }\r
36 \r
37 int get_int_option(const char * text, int def)\r
38 {\r
39         static char buffer[500];\r
40         int ret;\r
41         printf_c("%s\n[\033[1;32m%u\033[0m] -> ", text, def);\r
42         fgets(buffer, 500, stdin);\r
43         if(sscanf(buffer, "%u", &ret) != 1)\r
44                 ret = def;\r
45 \r
46         printf("\n");\r
47         return ret;\r
48 }\r
49 \r
50 bool get_bool_option(const char * text, bool def)\r
51 {\r
52         static char buffer[500];\r
53         char ret[100];\r
54         printf_c("%s [\033[1;32m%c\033[0m] -> ", text, def ? 'y' : 'n');\r
55         fgets(buffer, 500, stdin);\r
56         if(sscanf(buffer, "%s", ret) != 1)\r
57                 strcpy(ret, def ? "y" : "n");\r
58 \r
59         printf("\n");\r
60         return !strncmp(ret, "y", 1);\r
61 }\r
62 \r
63 void get_string_option(const char * text, char * def, char * buf)\r
64 {\r
65         static char buffer[500];\r
66         printf_c("%s\n[\033[1;32m%s\033[0m] -> ", text, def);\r
67         fgets(buffer, 500, stdin);\r
68         if(sscanf(buffer, "%s", buf) != 1)\r
69                 strcpy(buf, def);\r
70 \r
71         printf("\n");\r
72 }\r
73 \r
74 // escapes a string for use in a c++ file\r
75 bool escape_string(char * str, size_t size)\r
76 {\r
77         size_t len = strlen(str);\r
78         char * d_str = (char*)malloc(len * 2);\r
79     \r
80         size_t i = 0;\r
81         size_t j = 0;\r
82 \r
83         for(; i < len; ++i)\r
84         {\r
85                 if(str[i] == '\\')\r
86                 {\r
87                         d_str[j++] = '\\';\r
88                         d_str[j++] = '\\';\r
89                 }\r
90                 else\r
91                 {\r
92                         d_str[j++] = str[i];\r
93                 }\r
94         }\r
95 \r
96         d_str[j++] = 0;\r
97 \r
98     if(j > size)\r
99         {\r
100                 free(d_str);\r
101                 return false;\r
102         }\r
103 \r
104         strcpy(str, d_str);\r
105         free(d_str);\r
106         return true;\r
107 }\r
108 \r
109 /* gets the svn revision */\r
110 int get_svn_revision(char * buffer, size_t len)\r
111 {\r
112         /* again.. I am lazy :p cbf to pipe output of svn info to us, so i'll just read the file */\r
113         /*\r
114         8\r
115 \r
116         dir\r
117         7033\r
118         */\r
119         char buf[1000];\r
120         FILE * f = fopen("..\\.svn\\entries", "r");\r
121         if(!f) goto bad_rev;\r
122     \r
123         if(!fgets(buf, 1000, f)) goto bad_rev;\r
124         if(!fgets(buf, 1000, f)) goto bad_rev;\r
125         if(!fgets(buf, 1000, f)) goto bad_rev;\r
126         if(!fgets(buf, 1000, f)) goto bad_rev;\r
127         int rev = atoi(buf);\r
128         if(rev == 0) goto bad_rev;\r
129         sprintf(buffer, "%u", rev);\r
130         fclose(f);\r
131         return rev;\r
132         \r
133 bad_rev:\r
134         strcpy(buffer, "non-svn");\r
135         if(f) fclose(f);\r
136         return 0;\r
137 }\r
138 \r
139 int __stdcall WinMain(IN HINSTANCE hInstance, IN HINSTANCE hPrevInstance, IN LPSTR lpCmdLine, IN int nShowCmd )\r
140 {\r
141         FILE * j = fopen("inspircd_config.h", "r");\r
142         if (j)\r
143         {\r
144                 if (MessageBox(0, "inspircd_config.h already exists. Remove it and build from clean?", "Configure program", MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2) != IDYES)\r
145                 {\r
146                         fclose(j);\r
147                         exit(0);\r
148                 }\r
149         }\r
150 \r
151         AllocConsole();\r
152 \r
153         // pipe standard handles to this console\r
154         freopen("CONIN$", "r", stdin);\r
155         freopen("CONOUT$", "w", stdout);\r
156         freopen("CONOUT$", "w", stderr);\r
157 \r
158         Banner();\r
159         Run();\r
160         WriteCompileCommands();\r
161         WriteCompileModules();\r
162         FreeConsole();\r
163         return 0;\r
164 }\r
165 \r
166 void Banner()\r
167 {\r
168         printf_c("\nWelcome to the \033[1mInspIRCd\033[0m Configuration program! (\033[1minteractive mode\033[0m)\n"\r
169                          "\033[1mPackage maintainers: Type ./configure --help for non-interactive help\033[0m\n\n");\r
170         printf_c("*** If you are unsure of any of these values, leave it blank for    ***\n"\r
171                          "*** standard settings that will work, and your server will run      ***\n"\r
172                          "*** using them. Please consult your IRC network admin if in doubt.  ***\n\n"\r
173                          "Press \033[1m<RETURN>\033[0m to accept the default for any option, or enter\n"\r
174                          "a new value. Please note: You will \033[1mHAVE\033[0m to read the docs\n"\r
175                          "dir, otherwise you won't have a config file!\n\n");\r
176 \r
177 }\r
178 \r
179 void Run()\r
180 {\r
181         int max_fd = 1024;\r
182         bool use_iocp = false;\r
183         bool support_ip6links = false;\r
184         char mod_path[MAX_PATH];\r
185         char config_file[MAX_PATH];\r
186         char library_dir[MAX_PATH];\r
187         char base_path[MAX_PATH];\r
188         char bin_dir[MAX_PATH];\r
189         char revision_text[MAX_PATH];\r
190 \r
191         int max_clients = 1024;\r
192         int nicklen = 31;\r
193         int chanlen = 64;\r
194         int modechanges = 20;\r
195         int identlen = 12;\r
196         int quitlen = 255;\r
197         int topiclen = 500;\r
198         int kicklen = 255;\r
199         int rllen = 128;\r
200         int awaylen = 200;\r
201         int revision = get_svn_revision(revision_text, MAX_PATH);\r
202         char version[514];\r
203 \r
204         // grab version\r
205         FILE * fI = fopen("..\\src\\version.sh", "r");\r
206         if(fI)\r
207         {\r
208                 fgets(version, 514, fI);\r
209                 fgets(version, 514, fI);\r
210                 char * p2 = version;\r
211                 while(*p2 != '\"')\r
212                         ++p2;\r
213                 ++p2;\r
214                 strcpy(version, p2);\r
215                 p2 = version;\r
216                 while(*p2 != '\"')\r
217                         ++p2;\r
218                 *p2 = 0;\r
219                 fclose(fI);\r
220         }\r
221         else\r
222                 strcpy(version, "InspIRCD-Unknown");\r
223 #ifdef WIN64\r
224         printf_c("Your operating system is: \033[1;32mwindows_x64 \033[0m\n");\r
225 #else\r
226         printf_c("Your operating system is: \033[1;32mwindows_x32 \033[0m\n");\r
227 #endif\r
228         printf_c("InspIRCd revision ID: \033[1;32m%s \033[0m\n\n", revision ? revision_text : "(Non-SVN build)");\r
229 \r
230         max_fd = get_int_option("What is the maximum file descriptor count you would like to allow?", 1024);\r
231 \r
232         // detect windows\r
233         if(iswinxp())\r
234         {\r
235                 printf_c("You are running Windows 2000 or above, and IOCP support is most likely available.\n"\r
236                              "This removes the socket number limitation of select and is much more efficent.\n"\r
237                                  "If you are unsure, answer yes.\n\n");\r
238 \r
239                 use_iocp = get_bool_option("Do you want to use the IOCP implementation?", true);\r
240         }\r
241 \r
242         support_ip6links = get_bool_option("\nYou have chosen to build an \033[1;32mIPV4-only\033[0m server.\nWould you like to enable support for linking to IPV6-enabled InspIRCd servers?\nIf you are using a recent operating system and are unsure, answer yes.\nIf you answer 'no' here, your InspIRCd server will be unable\nto parse IPV6 addresses (e.g. for CIDR bans)", \r
243                 true);\r
244         \r
245         printf_c("\033[1mAll paths are relative to the binary directory.\033[0m\n");\r
246         get_string_option("In what directory do you wish to install the InspIRCd base?", "..", base_path);\r
247         get_string_option("In what directory are the configuration files?", "../conf", config_file);\r
248         get_string_option("In what directory are the modules to be compiled to?", "../modules", mod_path);\r
249         get_string_option("In what directory is the IRCd binary to be placed?", ".", bin_dir);\r
250         get_string_option("In what directory are the IRCd libraries to be placed?", "../lib", library_dir);\r
251 \r
252         printf_c("The following questions will ask you for various figures relating\n"\r
253                 "To your IRCd install. Please note that these should usually be left\n"\r
254                 "as defaults unless you have a real reason to change them. If they\n"\r
255                 "changed, then the values must be identical on all servers on your\n"\r
256                 "network, or malfunctions and/or crashes may occur, with the exception\n"\r
257                 "of the 'maximum number of clients' setting which may be different on\n"\r
258                 "different servers on the network.\n\n");\r
259 \r
260     \r
261         max_clients = get_int_option("Please enter the maximum number of clients at any one time?", 1024);\r
262         nicklen = get_int_option("Please enter the maximum length of nicknames?", 31);\r
263         chanlen = get_int_option("Please enter the maximum length of channel names?", 64);\r
264         modechanges = get_int_option("Please enter the maximum number of mode changes in one line?", 20);\r
265         identlen = get_int_option("Please enter the maximum length of an ident (username)?", 12);\r
266         quitlen = get_int_option("Please enter the maximum length of a quit message?", 255);\r
267         topiclen = get_int_option("Please enter the maximum length of a channel topic?", 307);\r
268         kicklen = get_int_option("Please enter the maximum length of a kick message?", 255);\r
269         rllen = get_int_option("Please enter the maximum length of a GECOS (real name)?", 128);\r
270         awaylen = get_int_option("Please enter the maximum length of an away message?", 200);\r
271 \r
272         printf_c("\n\033[1;32mPre-build configuration is complete!\n\n");       sc(TNORMAL);\r
273 \r
274         // dump all the options back out\r
275         printf_c("\033[0mBase install path:\033[1;32m        %s\n", base_path);\r
276         printf_c("\033[0mConfig path:\033[1;32m              %s\n", config_file);\r
277         printf_c("\033[0mModule path:\033[1;32m              %s\n", mod_path);\r
278         printf_c("\033[0mLibrary path:\033[1;32m             %s\n", library_dir);\r
279         printf_c("\033[0mSocket Engine:\033[1;32m            %s\n", use_iocp ? "iocp" : "select");\r
280         printf_c("\033[0mMax file descriptors:\033[1;32m     %u\n", max_fd);\r
281         printf_c("\033[0mMax connections:\033[1;32m          %u\n", max_clients);\r
282         printf_c("\033[0mMax nickname length:\033[1;32m      %u\n", nicklen);\r
283         printf_c("\033[0mMax channel length:\033[1;32m       %u\n", chanlen);\r
284         printf_c("\033[0mMax mode length:\033[1;32m          %u\n", modechanges);\r
285         printf_c("\033[0mMax ident length:\033[1;32m         %u\n", identlen);\r
286         printf_c("\033[0mMax quit length:\033[1;32m          %u\n", quitlen);\r
287         printf_c("\033[0mMax topic length:\033[1;32m         %u\n", topiclen);\r
288         printf_c("\033[0mMax kick length:\033[1;32m          %u\n", kicklen);\r
289         printf_c("\033[0mMax name length:\033[1;32m          %u\n", rllen);\r
290         printf_c("\033[0mMax away length:\033[1;32m          %u\n", awaylen);\r
291         printf("\n"); sc(TNORMAL);\r
292         if(get_bool_option("Are these settings correct?", true) == false)\r
293         {\r
294                 Run();\r
295                 return;\r
296         }\r
297         printf("\n");\r
298 \r
299         // escape the pathes\r
300         escape_string(config_file, MAX_PATH);\r
301         escape_string(mod_path, MAX_PATH);\r
302         escape_string(library_dir, MAX_PATH);\r
303 \r
304         printf("\nWriting inspircd_config.h...");\r
305         FILE * f = fopen("inspircd_config.h", "w");\r
306         fprintf(f, "/* Auto generated by configure, do not modify! */\n");\r
307         fprintf(f, "#ifndef __CONFIGURATION_AUTO__\n");\r
308         fprintf(f, "#define __CONFIGURATION_AUTO__\n\n");\r
309         if(use_iocp)\r
310                 fprintf(f, "#define CONFIG_USE_IOCP 1\n\n");\r
311 \r
312         fprintf(f, "#define CONFIG_FILE \"%s/inspircd.conf\"\n", config_file);\r
313         fprintf(f, "#define MOD_PATH \"%s\"\n", mod_path);\r
314         fprintf(f, "#define MAX_DESCRIPTORS %u\n", max_fd);\r
315         fprintf(f, "#define MAXCLIENTS %u\n", max_clients);\r
316         fprintf(f, "#define MAXCLIENTS_S \"%u\"\n", max_clients);\r
317         fprintf(f, "#define SOMAXCONN_S \"128\"\n");\r
318         fprintf(f, "#define NICKMAX %u\n", nicklen+1);\r
319         fprintf(f, "#define CHANMAX %u\n", chanlen+1);\r
320         fprintf(f, "#define MAXMODES %u\n", modechanges);\r
321         fprintf(f, "#define IDENTMAX %u\n", identlen);\r
322         fprintf(f, "#define MAXQUIT %u\n", quitlen);\r
323         fprintf(f, "#define MAXTOPIC %u\n", topiclen);\r
324         fprintf(f, "#define MAXKICK %u\n", kicklen);\r
325         fprintf(f, "#define MAXGECOS %u\n", rllen);\r
326         fprintf(f, "#define MAXAWAY %u\n", awaylen);\r
327         fprintf(f, "#define LIBRARYDIR \"%s\"\n", library_dir);\r
328         fprintf(f, "#define VERSION \"%s\"\n", version);\r
329         fprintf(f, "#define REVISION \"%s\"\n", revision_text);\r
330         if(support_ip6links)\r
331                 fprintf(f, "#define SUPPORT_IP6LINKS 1\n");\r
332 \r
333         OSVERSIONINFO vi;\r
334         vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);\r
335         GetVersionEx(&vi);\r
336 #ifdef WIN64\r
337         fprintf(f, "#define SYSTEM \"Windows_x64 %u.%u.%u %s\"\n", vi.dwMajorVersion, vi.dwMinorVersion, vi.dwBuildNumber, vi.szCSDVersion);\r
338 #else\r
339         fprintf(f, "#define SYSTEM \"Windows_x32 %u.%u.%u %s\"\n", vi.dwMajorVersion, vi.dwMinorVersion, vi.dwBuildNumber, vi.szCSDVersion);\r
340 #endif\r
341         fprintf(f, "#define MAXBUF 514\n");\r
342 \r
343         fprintf(f, "\n#include \"inspircd_win32wrapper.h\"\n\n");\r
344         fprintf(f, "#endif\n\n");\r
345         fclose(f);\r
346 \r
347         sc(TGREEN); printf(" done\n"); sc(TNORMAL);\r
348         printf("Writing inspircd_se_config.h...");\r
349 \r
350         f = fopen("inspircd_se_config.h", "w");\r
351         fprintf(f, "/* Auto generated by configure, do not modify or commit to svn! */\n");\r
352         fprintf(f, "#ifndef __CONFIGURATION_SOCKETENGINE__\n");\r
353         fprintf(f, "#define __CONFIGURATION_SOCKETENGINE__\n\n");\r
354         fprintf(f, "#include \"socketengine_%s.h\"\n\n", use_iocp ? "iocp" : "select");\r
355         fprintf(f, "#endif\n\n");\r
356         fclose(f);\r
357 \r
358         sc(TGREEN); printf(" done\n"); sc(TNORMAL);\r
359         printf("Writing command and module compilation scripts...");\r
360         WriteCompileCommands();\r
361         WriteCompileModules();\r
362         sc(TGREEN); printf(" done\n"); sc(TNORMAL);\r
363 \r
364         printf("\nconfigure is done.. exiting!\n");\r
365 }\r
366 \r
367 void WriteCompileCommands()\r
368 {\r
369         char commands[300][100];\r
370         int command_count = 0;\r
371         printf("\n  Finding Command Sources...\n");\r
372         WIN32_FIND_DATA fd;\r
373         HANDLE fh = FindFirstFile("..\\src\\cmd_*.cpp", &fd);\r
374         if(fh == INVALID_HANDLE_VALUE)\r
375                 printf_c("\033[1;32m  No command sources could be found! This \033[1m*could*\033[1;32m be a bad thing.. :P\033[0m");\r
376         else\r
377         {\r
378                 sc(TGREEN);\r
379                 do \r
380                 {\r
381                         strcpy(commands[command_count], fd.cFileName);\r
382                         commands[command_count][strlen(fd.cFileName) - 4] = 0;\r
383                         printf("    %s\n", commands[command_count]);\r
384                         ++command_count;\r
385                 } while(FindNextFile(fh, &fd));\r
386                 sc(TNORMAL);\r
387         }\r
388     \r
389         // Write our spiffy new makefile :D\r
390         // I am such a lazy fucker :P\r
391         FILE * f = fopen("..\\src\\commands.mak", "w");\r
392 \r
393         time_t t = time(NULL);\r
394         fprintf(f, "# Generated at %s\n", ctime(&t));\r
395         fprintf(f, "all: makedir ");\r
396 \r
397         // dump modules.. first time :)\r
398         for(int i = 0; i < command_count; ++i)\r
399                 fprintf(f, "%s.so ", commands[i]);\r
400 \r
401         fprintf(f, "\n.cpp.obj:\n");\r
402 #ifdef WIN64\r
403         // /MACHINE:X64\r
404         #ifdef _DEBUG\r
405                 fprintf(f, "  cl /nologo /LD /Od /I \".\" /I \"../include\" /I \"../include/modes\" /I \"../include/commands\" /I \"../win\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"DLL_BUILD\" /Gm /EHsc /Gm /RTC1 /MTd /Fo\"Debug/\" /Fd\"Debug/vc70.pdb\" /W2 /Wp64 /Zi /TP $*.cpp ..\\win\\inspircd_memory_functions.cpp /link ..\\bin\\debug_x64\\bin\\inspircd.lib /OUT:\"..\\bin\\debug_x64\\lib\\$*.so\" /PDB:\"..\\bin\\debug_x64\\lib\\$*.pdb\" /MACHINE:X64 /IMPLIB:\"..\\bin\\debug_x64\\lib\\$*.lib\"\n\n");\r
406                 CreateDirectory("..\\src\\debug", NULL);\r
407                 CreateDirectory("..\\bin\\debug\\bin", NULL);\r
408                 CreateDirectory("..\\bin\\debug\\lib", NULL);\r
409                 CreateDirectory("..\\bin\\debug\\modules", NULL);\r
410         #else\r
411                 fprintf(f, "  cl /nologo /LD /Od /I \".\" /I \"../include\" /I \"../include/modes\" /I \"../include/commands\" /I \"../win\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"DLL_BUILD\" /EHsc /Gm /MT /Fo\"Release/\" /Fd\"Release/vc70.pdb\" /W2 /Wp64 /Zi /TP $*.cpp ..\\win\\inspircd_memory_functions.cpp /link ..\\bin\\release_x64\\bin\\inspircd.lib /OUT:\"..\\bin\\release_x64\\lib\\$*.so\" /PDB:\"..\\bin\\release_x64\\lib\\$*.pdb\" /MACHINE:X64 /IMPLIB:\"..\\bin\\release_x64\\lib\\$*.lib\"\n\n");\r
412                 CreateDirectory("..\\src\\release", NULL);\r
413                 CreateDirectory("..\\bin\\release\\bin", NULL);\r
414                 CreateDirectory("..\\bin\\release\\lib", NULL);\r
415                 CreateDirectory("..\\bin\\release\\modules", NULL);\r
416         #endif\r
417 #else\r
418         #ifdef _DEBUG\r
419                 fprintf(f, "  cl /nologo /LD /Od /I \".\" /I \"../include\" /I \"../include/modes\" /I \"../include/commands\" /I \"../win\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"DLL_BUILD\" /Gm /EHsc /Gm /RTC1 /MTd /Fo\"Debug/\" /Fd\"Debug/vc70.pdb\" /W2 /Wp64 /Zi /TP $*.cpp ..\\win\\inspircd_memory_functions.cpp /link ..\\bin\\debug\\bin\\inspircd.lib /OUT:\"..\\bin\\debug\\lib\\$*.so\" /PDB:\"..\\bin\\debug\\lib\\$*.pdb\" /IMPLIB:\"..\\bin\\debug\\lib\\$*.lib\"\n\n");\r
420                 CreateDirectory("..\\src\\debug", NULL);\r
421                 CreateDirectory("..\\bin\\debug\\bin", NULL);\r
422                 CreateDirectory("..\\bin\\debug\\lib", NULL);\r
423                 CreateDirectory("..\\bin\\debug\\modules", NULL);\r
424         #else\r
425                 fprintf(f, "  cl /nologo /LD /Od /I \".\" /I \"../include\" /I \"../include/modes\" /I \"../include/commands\" /I \"../win\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"DLL_BUILD\" /EHsc /Gm /MT /Fo\"Release/\" /Fd\"Release/vc70.pdb\" /W2 /Wp64 /Zi /TP $*.cpp ..\\win\\inspircd_memory_functions.cpp /link ..\\bin\\release\\bin\\inspircd.lib /OUT:\"..\\bin\\release\\lib\\$*.so\" /PDB:\"..\\bin\\release\\lib\\$*.pdb\" /IMPLIB:\"..\\bin\\release\\lib\\$*.lib\"\n\n");\r
426                 CreateDirectory("..\\src\\release", NULL);\r
427                 CreateDirectory("..\\bin\\release\\bin", NULL);\r
428                 CreateDirectory("..\\bin\\release\\lib", NULL);\r
429                 CreateDirectory("..\\bin\\release\\modules", NULL);\r
430         #endif\r
431 #endif\r
432 \r
433         fprintf(f, "makedir:\n  if not exist debug mkdir debug\n\n");\r
434         \r
435         // dump modules.. again the second and last time :)\r
436         for(int i = 0; i < command_count; ++i)\r
437                 fprintf(f, "%s.so : %s.obj\n", commands[i], commands[i]);\r
438 \r
439         fprintf(f, "\n");\r
440         fclose(f);\r
441 }\r
442 \r
443 void WriteCompileModules()\r
444 {\r
445         char modules[300][100];\r
446         int module_count = 0;\r
447 \r
448         printf("Finding Modules...\n");\r
449         WIN32_FIND_DATA fd;\r
450         HANDLE fh = FindFirstFile("..\\src\\modules\\m_*.cpp", &fd);\r
451         if(fh == INVALID_HANDLE_VALUE)\r
452                 printf_c("\033[1;32m  No module sources could be found! This \033[1m*could*\033[1;32m be a bad thing.. :P\033[0m");\r
453         else\r
454         {\r
455                 sc(TGREEN);\r
456                 do \r
457                 {\r
458                         strcpy(modules[module_count], fd.cFileName);\r
459                         modules[module_count][strlen(fd.cFileName) - 4] = 0;\r
460                         printf("  %s\n", modules[module_count]);\r
461                         ++module_count;\r
462                 } while(FindNextFile(fh, &fd));\r
463                 sc(TNORMAL);\r
464         }\r
465 \r
466         // Write our spiffy new makefile :D\r
467         // I am such a lazy fucker :P\r
468         FILE * f = fopen("..\\src\\modules\\modules.mak", "w");\r
469 \r
470         time_t t = time(NULL);\r
471         fprintf(f, "# Generated at %s\n", ctime(&t));\r
472         fprintf(f, "all: makedir ");\r
473 \r
474         // dump modules.. first time :)\r
475         for(int i = 0; i < module_count; ++i)\r
476                 fprintf(f, "%s.so ", modules[i]);\r
477 \r
478         fprintf(f, "\n.cpp.obj:\n");\r
479 #ifdef WIN64\r
480         // /MACHINE:X64\r
481         #ifdef _DEBUG\r
482                 fprintf(f, "  cl /nologo /LD /Od /I \".\" /I \"../../include\" /I \"../../include/modes\" /I \"../../include/modules\" /I \"../../win\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"DLL_BUILD\" /Gm /EHsc /Gm /RTC1 /MTd /Fo\"Debug/\" /Fd\"Debug/vc70.pdb\" /W2 /Wp64 /Zi /TP $*.cpp ..\\..\\win\\inspircd_memory_functions.cpp /link ..\\..\\bin\\debug_x64\\bin\\inspircd.lib ws2_32.lib /OUT:\"..\\..\\bin\\debug_x64\\modules\\$*.so\" /PDB:\"..\\..\\bin\\debug_x64\\modules\\$*.pdb\" /MACHINE:X64 /IMPLIB:\"..\\..\\bin\\debug_x64\\modules\\$*.lib\"\n\n");\r
483                 CreateDirectory("..\\src\\modules\\debug_x64", NULL);\r
484         #else\r
485                 fprintf(f, "  cl /nologo /LD /Od /I \".\" /I \"../../include\" /I \"../../include/modes\" /I \"../../include/modules\" /I \"../../win\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"DLL_BUILD\" /EHsc /Gm /MT /Fo\"Release/\" /Fd\"Release/vc70.pdb\" /W2 /Wp64 /Zi /TP $*.cpp ..\\..\\win\\inspircd_memory_functions.cpp /link ..\\..\\bin\\release_x64\\bin\\inspircd.lib ws2_32.lib /OUT:\"..\\..\\bin\\release_x64\\modules\\$*.so\" /PDB:\"..\\..\\bin\\release_x64\\modules\\$*.pdb\" /MACHINE:X64 /IMPLIB:\"..\\..\\bin\\release_x64\\modules\\$*.lib\"\n\n");\r
486                 CreateDirectory("..\\src\\modules\\release_x64", NULL);\r
487         #endif\r
488 #else\r
489         #ifdef _DEBUG\r
490                 fprintf(f, "  cl /nologo -Dssize_t=long /LD /Od /I \".\" /I \"../../include\" /I \"../../include/modes\" /I \"../../include/modules\" /I \"../../win\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"DLL_BUILD\" /Gm /EHsc /Gm /RTC1 /MTd /Fo\"Debug/\" /Fd\"Debug/vc70.pdb\" /W2 /Wp64 /Zi /TP $*.cpp ..\\..\\win\\inspircd_memory_functions.cpp /link ..\\..\\bin\\debug\\bin\\inspircd.lib ws2_32.lib /OUT:\"..\\..\\bin\\debug\\modules\\$*.so\" /PDB:\"..\\..\\bin\\debug\\modules\\$*.pdb\" /IMPLIB:\"..\\..\\bin\\debug\\modules\\$*.lib\"\n\n");\r
491                 CreateDirectory("..\\src\\modules\\debug", NULL);\r
492         #else\r
493                 fprintf(f, "  cl /nologo -Dssize_t=long /LD /Od /I \".\" /I \"../../include\" /I \"../../include/modes\" /I \"../../include/modules\" /I \"../../win\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"DLL_BUILD\" /EHsc /Gm /MT /Fo\"Release/\" /Fd\"Release/vc70.pdb\" /W2 /Wp64 /Zi /TP $*.cpp ..\\..\\win\\inspircd_memory_functions.cpp /link ..\\..\\bin\\release\\bin\\inspircd.lib ws2_32.lib /OUT:\"..\\..\\bin\\release\\modules\\$*.so\" /PDB:\"..\\..\\bin\\release\\modules\\$*.pdb\" /IMPLIB:\"..\\..\\bin\\release\\modules\\$*.lib\"\n\n");\r
494                 CreateDirectory("..\\src\\modules\\release", NULL);\r
495         #endif\r
496 #endif\r
497         \r
498         fprintf(f, "makedir:\n  if not exist debug mkdir debug\n\n");\r
499 \r
500         // dump modules.. again the second and last time :)\r
501         for(int i = 0; i < module_count; ++i)\r
502                 fprintf(f, "%s.so : %s.obj\n", modules[i], modules[i]);\r
503 \r
504         fprintf(f, "\n");\r
505         fclose(f);\r
506 }\r