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