]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - win/configure.cpp
fix a warning. I am on a warning zapping crusade today.
[user/henk/code/inspircd.git] / win / configure.cpp
1 /*         +------------------------------------+
2  *         | Inspire Internet Relay Chat Daemon |
3  *         +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *                      the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #define _CRT_SECURE_NO_DEPRECATE
15
16 #define CONFIGURE_BUILD
17 #define WIN32_LEAN_AND_MEAN
18 #include <windows.h>
19 #include <stdio.h>
20 #include <string>
21 #include <time.h>
22 #include "inspircd_win32wrapper.h"
23 #include "colours.h"
24
25 using namespace std;
26 void Run();
27 void Banner();
28 void WriteCompileModules();
29 void WriteCompileCommands();
30 void Rebase();
31
32 /* detects if we are running windows xp or higher (5.1) */
33 bool iswinxp()
34 {
35         OSVERSIONINFO vi;
36         vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
37         GetVersionEx(&vi);
38         if(vi.dwMajorVersion >= 5)
39                 return true;
40         
41         return false;
42 }
43
44 int get_int_option(const char * text, int def)
45 {
46         static char buffer[500];
47         int ret;
48         printf_c("%s\n[\033[1;32m%u\033[0m] -> ", text, def);
49         fgets(buffer, 500, stdin);
50         if(sscanf(buffer, "%u", &ret) != 1)
51                 ret = def;
52
53         printf("\n");
54         return ret;
55 }
56
57 bool get_bool_option(const char * text, bool def)
58 {
59         static char buffer[500];
60         char ret[100];
61         printf_c("%s [\033[1;32m%c\033[0m] -> ", text, def ? 'y' : 'n');
62         fgets(buffer, 500, stdin);
63         if(sscanf(buffer, "%s", ret) != 1)
64                 strcpy(ret, def ? "y" : "n");
65
66         printf("\n");
67         return !strncmp(ret, "y", 1);
68 }
69
70 void get_string_option(const char * text, char * def, char * buf)
71 {
72         static char buffer[500];
73         if (*def)
74                 printf_c("%s\n[\033[1;32m%s\033[0m] -> ", text, def);
75         else
76                 printf_c("%s\n[] -> ", text);
77         fgets(buffer, 500, stdin);
78         if(sscanf(buffer, "%s", buf) != 1)
79                 strcpy(buf, def);
80
81         printf("\n");
82 }
83
84 // escapes a string for use in a c++ file
85 bool escape_string(char * str, size_t size)
86 {
87         size_t len = strlen(str);
88         char * d_str = (char*)malloc(len * 2);
89         
90         size_t i = 0;
91         size_t j = 0;
92
93         for(; i < len; ++i)
94         {
95                 if(str[i] == '\\')
96                 {
97                         d_str[j++] = '\\';
98                         d_str[j++] = '\\';
99                 }
100                 else
101                 {
102                         d_str[j++] = str[i];
103                 }
104         }
105
106         d_str[j++] = 0;
107
108         if(j > size)
109         {
110                 free(d_str);
111                 return false;
112         }
113
114         strcpy(str, d_str);
115         free(d_str);
116         return true;
117 }
118
119 /* gets the svn revision */
120 int get_svn_revision(char * buffer, size_t len)
121 {
122         /* again.. I am lazy :p cbf to pipe output of svn info to us, so i'll just read the file */
123         /*
124         8
125
126         dir
127         7033
128         */
129         char buf[1000];
130         int rev = 0;
131         
132         FILE * f = fopen("..\\.svn\\entries", "r");
133         if (f)
134         {
135                 for (int q = 0; q < 4; ++q)
136                         fgets(buf, 1000, f);
137
138                 rev = atoi(buf);
139                 sprintf(buffer, "%u", rev);
140                 fclose(f);
141         }
142         
143         return rev;
144 }
145
146 int __stdcall WinMain(IN HINSTANCE hInstance, IN HINSTANCE hPrevInstance, IN LPSTR lpCmdLine, IN int nShowCmd )
147 {
148         if (!strcmp(lpCmdLine, "/rebase"))
149         {
150                 Rebase();
151                 return 0;
152         }
153         FILE * j = fopen("inspircd_config.h", "r");
154         if (j)
155         {
156                 if (MessageBox(0, "inspircd_config.h already exists. Remove it and build from clean?", "Configure program", MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2) != IDYES)
157                 {
158                         fclose(j);
159                         exit(0);
160                 }
161         }
162
163         AllocConsole();
164
165         // pipe standard handles to this console
166         freopen("CONIN$", "r", stdin);
167         freopen("CONOUT$", "w", stdout);
168         freopen("CONOUT$", "w", stderr);
169
170         Banner();
171         Run();
172         FreeConsole();
173         return 0;
174 }
175
176 void Banner()
177 {
178         printf_c("\nWelcome to the \033[1mInspIRCd\033[0m Configuration program! (\033[1minteractive mode\033[0m)\n"
179                          "\033[1mPackage maintainers: Type ./configure --help for non-interactive help\033[0m\n\n");
180         printf_c("*** If you are unsure of any of these values, leave it blank for      ***\n"
181                          "*** standard settings that will work, and your server will run          ***\n"
182                          "*** using them. Please consult your IRC network admin if in doubt.  ***\n\n"
183                          "Press \033[1m<RETURN>\033[0m to accept the default for any option, or enter\n"
184                          "a new value. Please note: You will \033[1mHAVE\033[0m to read the docs\n"
185                          "dir, otherwise you won't have a config file!\n\n");
186
187 }
188
189 void Run()
190 {
191         bool use_iocp = false;
192         bool support_ip6links = true;
193         bool use_openssl = false;
194         bool ipv6 = true;
195         char mod_path[MAX_PATH];
196         char config_file[MAX_PATH];
197         char library_dir[MAX_PATH];
198         char base_path[MAX_PATH];
199         char bin_dir[MAX_PATH];
200         char revision_text[MAX_PATH];
201         char openssl_inc_path[MAX_PATH];
202         char openssl_lib_path[MAX_PATH];
203         int revision = get_svn_revision(revision_text, MAX_PATH);
204         char version[514];
205
206         // grab version
207         FILE * fI = fopen("..\\src\\version.sh", "r");
208         if(fI)
209         {
210                 fgets(version, 514, fI);
211                 fgets(version, 514, fI);
212                 char * p2 = version;
213                 while(*p2 != '\"')
214                         ++p2;
215                 ++p2;
216                 strcpy(version, p2);
217                 p2 = version;
218                 while(*p2 != '\"')
219                         ++p2;
220                 *p2 = 0;
221                 fclose(fI);
222         }
223         else
224                 strcpy(version, "InspIRCD-Unknown");
225 #ifdef WIN64
226         printf_c("Your operating system is: \033[1;32mwindows_x64 \033[0m\n");
227 #else
228         printf_c("Your operating system is: \033[1;32mwindows_x32 \033[0m\n");
229 #endif
230         printf_c("InspIRCd revision ID: \033[1;32m%s \033[0m\n\n", revision ? revision_text : "(Non-SVN build)");
231
232         // detect windows
233         if(iswinxp())
234         {
235                 printf_c("You are running Windows 2000 or above, and IOCP support is most likely available.\n"
236                                  "Thisis much more efficent but is currently EXPERIMENTAL and UNSUPPORTED.\n"
237                                  "If you are unsure, answer no.\n\n");
238
239                 use_iocp = get_bool_option("Do you want to use the IOCP implementation?", false);
240         }
241
242         ipv6 = get_bool_option("Do you want to enable IPv6?", false);
243
244         if (!ipv6)
245                 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)", true);
246         else
247                 support_ip6links = true;
248         
249         printf_c("\033[1mAll paths are relative to the binary directory.\033[0m\n");
250         get_string_option("In what directory do you wish to install the InspIRCd base?", "..", base_path);
251         get_string_option("In what directory are the configuration files?", "../conf", config_file);
252         get_string_option("In what directory are the modules to be compiled to?", "../modules", mod_path);
253         get_string_option("In what directory is the IRCd binary to be placed?", ".", bin_dir);
254         get_string_option("In what directory are the IRCd libraries to be placed?", "../lib", library_dir);
255
256         // NOTE: this may seem hackish (generating a batch build script), but it assures the user knows
257         // what they're doing, and we don't have to mess with copying files and changing around modules.mak
258         // for the extra libraries. --fez
259         // in case it exists, remove old m_ssl_openssl.cpp
260         remove("..\\src\\modules\\m_ssl_openssl.cpp");
261         printf_c("You can compile InspIRCd modules that add OpenSSL or GnuTLS support for SSL functionality.\n"
262                 "To do so you will need the appropriate link libraries and header files on your system.\n");
263         use_openssl = get_bool_option("Would you like to compile the IRCd with OpenSSL support?", false);
264         if (use_openssl)
265         {
266                 get_string_option("Please enter the full path to your OpenSSL include directory\n"
267                         "(e.g., C:\\openssl\\include, but NOT the openssl subdirectory under include\\)\n"
268                         "(also, path should not end in '\\')",
269                         "C:\\openssl\\include", openssl_inc_path);
270
271                 // NOTE: if inspircd ever changes so that it compiles with /MT instead of the /MTd switch, then
272                 // the dependency on libeay32mtd.lib and ssleay32mtd.lib will change to just libeay32.lib and
273                 // ssleay32.lib. --fez
274
275                 get_string_option("Please enter the full path to your OpenSSL library directory\n"
276                         "(e.g., C:\\openssl\\lib, which should contain libeay32mtd.lib and ssleay32mtd.lib)",
277                         "C:\\openssl\\lib", openssl_lib_path);
278
279                 // write batch file
280                 FILE *fp = fopen("compile_openssl.bat", "w");
281                 fprintf(fp, "@echo off\n");
282                 fprintf(fp, "echo This batch script compiles m_ssl_openssl for InspIRCd.\n");
283                 fprintf(fp, "echo NOTE: this batch file should be invoked from the Visual Studio Command Prompt (vsvars32.bat)\n");
284                 fprintf(fp, "set OPENSSL_INC_PATH=\"%s\"\n", openssl_inc_path);
285                 fprintf(fp, "set OPENSSL_LIB_PATH=\"%s\"\n", openssl_lib_path);
286                 fprintf(fp, "set COMPILE=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 /I %%OPENSSL_INC_PATH%% m_ssl_openssl.cpp ..\\..\\win\\inspircd_memory_functions.cpp %%OPENSSL_INC_PATH%%\\openssl\\applink.c /link /LIBPATH:%%OPENSSL_LIB_PATH%% ..\\..\\bin\\release\\bin\\inspircd.lib ws2_32.lib /OUT:\"..\\..\\bin\\release\\modules\\m_ssl_openssl.so\" /PDB:\"..\\..\\bin\\release\\modules\\m_ssl_openssl.pdb\" /IMPLIB:\"..\\..\\bin\\release\\modules\\m_ssl_openssl.lib\"\n");
287                 fprintf(fp, "cd ..\\src\\modules\n");
288                 fprintf(fp, "copy extra\\m_ssl_openssl.cpp .\n");
289                 fprintf(fp, "echo \t%%COMPILE%%\n");
290                 fprintf(fp, "%%COMPILE%%\n");
291                 fprintf(fp, "cd ..\\..\\win\n");
292                 fprintf(fp, "echo done... now check for errors.\n");
293                 fclose(fp);
294
295                 printf_c("\033[1;32m!!!NOTICE!!! The file 'compile_openssl.bat' has been written to your 'win' directory.  Launch it\n"
296                         "!!! from the Visual Studio Command Prompt !!! to compile the m_ssl_openssl module.\n"
297                         "Wait until after compiling inspircd to run it.\n"
298                         "Also, ssleay32.dll and libeay32.dll will be required for the IRCd to run.\033[0m\n");
299         }
300
301         printf_c("\n\033[1;32mPre-build configuration is complete!\n\n");       sc(TNORMAL);
302
303         // dump all the options back out
304         printf_c("\033[0mBase install path:\033[1;32m        %s\n", base_path);
305         printf_c("\033[0mConfig path:\033[1;32m              %s\n", config_file);
306         printf_c("\033[0mModule path:\033[1;32m              %s\n", mod_path);
307         printf_c("\033[0mLibrary path:\033[1;32m             %s\n", library_dir);
308         printf_c("\033[0mSocket Engine:\033[1;32m            %s\n", use_iocp ? "iocp" : "select");
309
310         printf("\n"); sc(TNORMAL);
311         if(get_bool_option("Are these settings correct?", true) == false)
312         {
313                 Run();
314                 return;
315         }
316         printf("\n");
317
318         // escape the pathes
319         escape_string(config_file, MAX_PATH);
320         escape_string(mod_path, MAX_PATH);
321         escape_string(library_dir, MAX_PATH);
322
323         printf("\nWriting inspircd_config.h...");
324         FILE * f = fopen("inspircd_config.h", "w");
325         fprintf(f, "/* Auto generated by configure, do not modify! */\n");
326         fprintf(f, "#ifndef __CONFIGURATION_AUTO__\n");
327         fprintf(f, "#define __CONFIGURATION_AUTO__\n\n");
328         if(use_iocp)
329                 fprintf(f, "#define CONFIG_USE_IOCP 1\n\n");
330         if (ipv6)
331                 fprintf(f, "#define IPV6 1\n\n");
332
333         fprintf(f, "#define CONFIG_FILE \"%s/inspircd.conf\"\n", config_file);
334         fprintf(f, "#define MOD_PATH \"%s\"\n", mod_path);
335         fprintf(f, "#define SOMAXCONN_S \"128\"\n");
336         fprintf(f, "#define LIBRARYDIR \"%s\"\n", library_dir);
337         fprintf(f, "#define VERSION \"%s\"\n", version);
338         fprintf(f, "#define REVISION \"%s\"\n", revision_text);
339         if(support_ip6links)
340                 fprintf(f, "#define SUPPORT_IP6LINKS 1\n");
341
342         OSVERSIONINFO vi;
343         vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
344         GetVersionEx(&vi);
345 #ifdef WIN64
346         fprintf(f, "#define SYSTEM \"Windows_x64 %u.%u.%u %s\"\n", vi.dwMajorVersion, vi.dwMinorVersion, vi.dwBuildNumber, vi.szCSDVersion);
347 #else
348         fprintf(f, "#define SYSTEM \"Windows_x32 %u.%u.%u %s\"\n", vi.dwMajorVersion, vi.dwMinorVersion, vi.dwBuildNumber, vi.szCSDVersion);
349 #endif
350         fprintf(f, "#define MAXBUF 514\n");
351
352         fprintf(f, "\n#include \"inspircd_win32wrapper.h\"");
353         fprintf(f, "\n#include \"inspircd_namedpipe.h\"");
354         fprintf(f, "\n#include \"threadengines/threadengine_win32.h\"\n\n");
355         fprintf(f, "#endif\n\n");
356         fclose(f);
357
358         sc(TGREEN); printf(" done\n"); sc(TNORMAL);
359         printf("Writing inspircd_se_config.h...");
360
361         f = fopen("inspircd_se_config.h", "w");
362         fprintf(f, "/* Auto generated by configure, do not modify or commit to svn! */\n");
363         fprintf(f, "#ifndef __CONFIGURATION_SOCKETENGINE__\n");
364         fprintf(f, "#define __CONFIGURATION_SOCKETENGINE__\n\n");
365         fprintf(f, "#include \"socketengines/socketengine_%s.h\"\n\n", use_iocp ? "iocp" : "select");
366         fprintf(f, "#endif\n\n");
367         fclose(f);
368
369         sc(TGREEN); printf(" done\n"); sc(TNORMAL);
370         printf("Writing command and module compilation scripts...");
371         WriteCompileCommands();
372         WriteCompileModules();
373         sc(TGREEN); printf(" done\n"); sc(TNORMAL);
374
375         printf("\nconfigure is done.. exiting!\n");
376 }
377
378 void Rebase()
379 {
380         char dest[65535];
381         char command[65535];
382
383         *dest = 0;
384
385         WIN32_FIND_DATA fd;
386 #ifdef _DEBUG
387         HANDLE fh = FindFirstFile("..\\bin\\debug\\lib\\*.so", &fd);
388 #else
389         HANDLE fh = FindFirstFile("..\\bin\\release\\lib\\*.so", &fd);
390 #endif
391         if(fh == INVALID_HANDLE_VALUE)
392                 return;
393
394         do
395         {
396 #ifdef _DEBUG
397                 strcat(dest, " ..\\bin\\debug\\lib\\");
398 #else
399                 strcat(dest, " ..\\bin\\release\\lib\\");
400 #endif
401                 strcat(dest, fd.cFileName);
402         }
403         while (FindNextFile(fh, &fd));
404
405         FindClose(fh);
406
407         sprintf(command, "rebase.exe -v -b 10000000 -c baseaddr_commands.txt %s", dest);
408         printf("%s\n", command);
409         system(command);
410
411 #ifdef _DEBUG
412         fh = FindFirstFile("..\\bin\\debug\\modules\\*.so", &fd);
413 #else
414         fh = FindFirstFile("..\\bin\\release\\modules\\*.so", &fd);
415 #endif
416         if(fh == INVALID_HANDLE_VALUE)
417                 return;
418
419         *dest = 0;
420
421         do
422         {
423 #ifdef _DEBUG
424                 strcat(dest, " ..\\bin\\debug\\modules\\");
425 #else
426                 strcat(dest, " ..\\bin\\release\\modules\\");
427 #endif
428                 strcat(dest, fd.cFileName);
429         }
430         while (FindNextFile(fh, &fd));
431
432         sprintf(command, "rebase.exe -v -b 11000000 -c baseaddr_modules.txt %s", dest);
433         printf("%s\n", command);
434         system(command);
435
436         FindClose(fh);
437
438 }
439
440 void WriteCompileCommands()
441 {
442         char commands[300][100];
443         int command_count = 0;
444         printf("\n  Finding Command Sources...\n");
445         WIN32_FIND_DATA fd;
446         HANDLE fh = FindFirstFile("..\\src\\commands\\cmd_*.cpp", &fd);
447         if(fh == INVALID_HANDLE_VALUE)
448                 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");
449         else
450         {
451                 sc(TGREEN);
452                 do 
453                 {
454                         strcpy(commands[command_count], fd.cFileName);
455                         commands[command_count][strlen(fd.cFileName) - 4] = 0;
456                         printf("        %s\n", commands[command_count]);
457                         ++command_count;
458                 } while(FindNextFile(fh, &fd));
459                 sc(TNORMAL);
460         }
461         
462         // Write our spiffy new makefile :D
463         // I am such a lazy fucker :P
464         FILE * f = fopen("..\\src\\commands\\commands.mak", "w");
465
466         time_t t = time(NULL);
467         fprintf(f, "# Generated at %s\n", ctime(&t));
468         fprintf(f, "all: makedir ");
469
470         // dump modules.. first time :)
471         for(int i = 0; i < command_count; ++i)
472                 fprintf(f, "%s.so ", commands[i]);
473
474         fprintf(f, "\n.cpp.obj:\n");
475 #ifdef WIN64
476         // /MACHINE:X64
477         #ifdef _DEBUG
478                 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 /MDd /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");
479                 CreateDirectory("..\\src\\debug", NULL);
480                 CreateDirectory("..\\bin\\debug\\bin", NULL);
481                 CreateDirectory("..\\bin\\debug\\lib", NULL);
482                 CreateDirectory("..\\bin\\debug\\modules", NULL);
483         #else
484                 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 /GL /MD /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");
485                 CreateDirectory("..\\src\\release", NULL);
486                 CreateDirectory("..\\bin\\release\\bin", NULL);
487                 CreateDirectory("..\\bin\\release\\lib", NULL);
488                 CreateDirectory("..\\bin\\release\\modules", NULL);
489         #endif
490 #else
491         #ifdef _DEBUG
492                 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 /MDd /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");
493                 CreateDirectory("..\\src\\debug", NULL);
494                 CreateDirectory("..\\bin\\debug\\bin", NULL);
495                 CreateDirectory("..\\bin\\debug\\lib", NULL);
496                 CreateDirectory("..\\bin\\debug\\modules", NULL);
497         #else
498                 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 /GL /MD /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");
499                 CreateDirectory("..\\src\\release", NULL);
500                 CreateDirectory("..\\bin\\release\\bin", NULL);
501                 CreateDirectory("..\\bin\\release\\lib", NULL);
502                 CreateDirectory("..\\bin\\release\\modules", NULL);
503         #endif
504 #endif
505
506 #ifdef _DEBUG
507         fprintf(f, "makedir:\n  if not exist debug mkdir debug\n  if not exist ..\\..\\bin\\debug\\lib mkdir ..\\..\\bin\\debug\\lib\n\n");
508 #else
509         fprintf(f, "makedir:\n  if not exist release mkdir release\n  if not exist ..\\..\\bin\\release\\lib mkdir ..\\..\\bin\\release\\lib\n\n");
510 #endif
511         
512         // dump modules.. again the second and last time :)
513         for(int i = 0; i < command_count; ++i)
514                 fprintf(f, "%s.so : %s.obj\n", commands[i], commands[i]);
515
516         fprintf(f, "\n");
517         fclose(f);
518 }
519
520 void WriteCompileModules()
521 {
522         char modules[300][100];
523         int module_count = 0;
524
525         printf("Finding Modules...\n");
526         WIN32_FIND_DATA fd;
527         HANDLE fh = FindFirstFile("..\\src\\modules\\m_*.cpp", &fd);
528         if(fh == INVALID_HANDLE_VALUE)
529                 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");
530         else
531         {
532                 sc(TGREEN);
533                 do 
534                 {
535                         strcpy(modules[module_count], fd.cFileName);
536                         modules[module_count][strlen(fd.cFileName) - 4] = 0;
537                         printf("  %s\n", modules[module_count]);
538                         ++module_count;
539                 } while(FindNextFile(fh, &fd));
540                 sc(TNORMAL);
541         }
542
543         // Write our spiffy new makefile :D
544         // I am such a lazy fucker :P
545         FILE * f = fopen("..\\src\\modules\\modules.mak", "w");
546
547         time_t t = time(NULL);
548         fprintf(f, "# Generated at %s\n", ctime(&t));
549         fprintf(f, "all: makedir ");
550
551         // dump modules.. first time :)
552         for(int i = 0; i < module_count; ++i)
553                 fprintf(f, "%s.so ", modules[i]);
554
555         fprintf(f, "\n.cpp.obj:\n");
556 #ifdef WIN64
557         // /MACHINE:X64
558         #ifdef _DEBUG
559                 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 /MDd /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");
560                 CreateDirectory("..\\src\\modules\\debug_x64", NULL);
561         #else
562                 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 /GL /MD /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");
563                 CreateDirectory("..\\src\\modules\\release_x64", NULL);
564         #endif
565 #else
566         #ifdef _DEBUG
567                 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 /MDd /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");
568                 CreateDirectory("..\\src\\modules\\debug", NULL);
569                 CreateDirectory("..\\src\\modules\\debug\\lib", NULL);
570                 CreateDirectory("..\\src\\modules\\debug\\modules", NULL);
571                 CreateDirectory("..\\src\\modules\\debug\\bin", NULL);
572         #else
573                 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 /GL /MD /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");
574                 CreateDirectory("..\\src\\modules\\release", NULL);
575                 CreateDirectory("..\\src\\modules\\release\\lib", NULL);
576                 CreateDirectory("..\\src\\modules\\release\\modules", NULL);
577                 CreateDirectory("..\\src\\modules\\release\\bin", NULL);
578         #endif
579 #endif
580         
581 #ifdef _DEBUG
582         fprintf(f, "makedir:\n  if not exist debug mkdir debug\n  if not exist ..\\..\\bin\\debug\\modules mkdir ..\\..\\bin\\debug\\modules\n\n");
583 #else
584         fprintf(f, "makedir:\n  if not exist release mkdir release\n  if not exist ..\\..\\bin\\release\\modules mkdir ..\\..\\bin\\release\\modules\n\n");
585 #endif
586
587         // dump modules.. again the second and last time :)
588         for(int i = 0; i < module_count; ++i)
589                 fprintf(f, "%s.so : %s.obj\n", modules[i], modules[i]);
590
591         fprintf(f, "\n");
592         fclose(f);
593 }