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