]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - win/configure.cpp
Fix to use dll in debug build
[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                 AllocConsole();
150                 // pipe standard handles to this console
151                 freopen("CONIN$", "r", stdin);
152                 freopen("CONOUT$", "w", stdout);
153                 freopen("CONOUT$", "w", stderr);
154                 Rebase();
155                 FreeConsole();
156                 return 0;
157         }
158         FILE * j = fopen("inspircd_config.h", "r");
159         if (j)
160         {
161                 if (MessageBox(0, "inspircd_config.h already exists. Remove it and build from clean?", "Configure program", MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2) != IDYES)
162                 {
163                         fclose(j);
164                         exit(0);
165                 }
166         }
167
168         AllocConsole();
169
170         // pipe standard handles to this console
171         freopen("CONIN$", "r", stdin);
172         freopen("CONOUT$", "w", stdout);
173         freopen("CONOUT$", "w", stderr);
174
175         Banner();
176         Run();
177         FreeConsole();
178         return 0;
179 }
180
181 void Banner()
182 {
183         printf_c("\nWelcome to the \033[1mInspIRCd\033[0m Configuration program! (\033[1minteractive mode\033[0m)\n"
184                          "\033[1mPackage maintainers: Type ./configure --help for non-interactive help\033[0m\n\n");
185         printf_c("*** If you are unsure of any of these values, leave it blank for      ***\n"
186                          "*** standard settings that will work, and your server will run          ***\n"
187                          "*** using them. Please consult your IRC network admin if in doubt.  ***\n\n"
188                          "Press \033[1m<RETURN>\033[0m to accept the default for any option, or enter\n"
189                          "a new value. Please note: You will \033[1mHAVE\033[0m to read the docs\n"
190                          "dir, otherwise you won't have a config file!\n\n");
191
192 }
193
194 void Run()
195 {
196         bool use_iocp = false;
197         bool support_ip6links = true;
198         bool use_openssl = false;
199         bool ipv6 = true;
200         char mod_path[MAX_PATH];
201         char config_file[MAX_PATH];
202         char library_dir[MAX_PATH];
203         char base_path[MAX_PATH];
204         char bin_dir[MAX_PATH];
205         char revision_text[MAX_PATH];
206         char openssl_inc_path[MAX_PATH];
207         char openssl_lib_path[MAX_PATH];
208
209         int nicklen = 31;
210         int chanlen = 64;
211         int modechanges = 20;
212         int identlen = 12;
213         int quitlen = 255;
214         int topiclen = 500;
215         int kicklen = 255;
216         int rllen = 128;
217         int awaylen = 200;
218         int revision = get_svn_revision(revision_text, MAX_PATH);
219         char version[514];
220
221         // grab version
222         FILE * fI = fopen("..\\src\\version.sh", "r");
223         if(fI)
224         {
225                 fgets(version, 514, fI);
226                 fgets(version, 514, fI);
227                 char * p2 = version;
228                 while(*p2 != '\"')
229                         ++p2;
230                 ++p2;
231                 strcpy(version, p2);
232                 p2 = version;
233                 while(*p2 != '\"')
234                         ++p2;
235                 *p2 = 0;
236                 fclose(fI);
237         }
238         else
239                 strcpy(version, "InspIRCD-Unknown");
240 #ifdef WIN64
241         printf_c("Your operating system is: \033[1;32mwindows_x64 \033[0m\n");
242 #else
243         printf_c("Your operating system is: \033[1;32mwindows_x32 \033[0m\n");
244 #endif
245         printf_c("InspIRCd revision ID: \033[1;32m%s \033[0m\n\n", revision ? revision_text : "(Non-SVN build)");
246
247         // detect windows
248         if(iswinxp())
249         {
250                 printf_c("You are running Windows 2000 or above, and IOCP support is most likely available.\n"
251                                  "Thisis much more efficent but is currently EXPERIMENTAL and UNSUPPORTED.\n"
252                                  "If you are unsure, answer no.\n\n");
253
254                 use_iocp = get_bool_option("Do you want to use the IOCP implementation?", false);
255         }
256
257         ipv6 = get_bool_option("Do you want to enable IPv6?", false);
258
259         if (!ipv6)
260                 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);
261         else
262                 support_ip6links = true;
263         
264         printf_c("\033[1mAll paths are relative to the binary directory.\033[0m\n");
265         get_string_option("In what directory do you wish to install the InspIRCd base?", "..", base_path);
266         get_string_option("In what directory are the configuration files?", "../conf", config_file);
267         get_string_option("In what directory are the modules to be compiled to?", "../modules", mod_path);
268         get_string_option("In what directory is the IRCd binary to be placed?", ".", bin_dir);
269         get_string_option("In what directory are the IRCd libraries to be placed?", "../lib", library_dir);
270
271         printf_c("The following questions will ask you for various figures relating\n"
272                 "To your IRCd install. Please note that these should usually be left\n"
273                 "as defaults unless you have a real reason to change them. If they\n"
274                 "changed, then the values must be identical on all servers on your\n"
275                 "network, or malfunctions and/or crashes may occur, with the exception\n"
276                 "of the 'maximum number of clients' setting which may be different on\n"
277                 "different servers on the network.\n\n");
278
279         nicklen = get_int_option("Please enter the maximum length of nicknames?", 31);
280         chanlen = get_int_option("Please enter the maximum length of channel names?", 64);
281         modechanges = get_int_option("Please enter the maximum number of mode changes in one line?", 20);
282         identlen = get_int_option("Please enter the maximum length of an ident (username)?", 12);
283         quitlen = get_int_option("Please enter the maximum length of a quit message?", 255);
284         topiclen = get_int_option("Please enter the maximum length of a channel topic?", 307);
285         kicklen = get_int_option("Please enter the maximum length of a kick message?", 255);
286         rllen = get_int_option("Please enter the maximum length of a GECOS (real name)?", 128);
287         awaylen = get_int_option("Please enter the maximum length of an away message?", 200);
288
289         // NOTE: this may seem hackish (generating a batch build script), but it assures the user knows
290         // what they're doing, and we don't have to mess with copying files and changing around modules.mak
291         // for the extra libraries. --fez
292         // in case it exists, remove old m_ssl_openssl.cpp
293         remove("..\\src\\modules\\m_ssl_openssl.cpp");
294         printf_c("You can compile InspIRCd modules that add OpenSSL or GnuTLS support for SSL functionality.\n"
295                 "To do so you will need the appropriate link libraries and header files on your system.\n");
296         use_openssl = get_bool_option("Would you like to compile the IRCd with OpenSSL support?", false);
297         if (use_openssl)
298         {
299                 get_string_option("Please enter the full path to your OpenSSL include directory\n"
300                         "(e.g., C:\\openssl\\include, but NOT the openssl subdirectory under include\\)\n"
301                         "(also, path should not end in '\\')",
302                         "C:\\openssl\\include", openssl_inc_path);
303
304                 // NOTE: if inspircd ever changes so that it compiles with /MT instead of the /MTd switch, then
305                 // the dependency on libeay32mtd.lib and ssleay32mtd.lib will change to just libeay32.lib and
306                 // ssleay32.lib. --fez
307
308                 get_string_option("Please enter the full path to your OpenSSL library directory\n"
309                         "(e.g., C:\\openssl\\lib, which should contain libeay32mtd.lib and ssleay32mtd.lib)",
310                         "C:\\openssl\\lib", openssl_lib_path);
311
312                 // write batch file
313                 FILE *fp = fopen("compile_openssl.bat", "w");
314                 fprintf(fp, "@echo off\n");
315                 fprintf(fp, "echo This batch script compiles m_ssl_openssl for InspIRCd.\n");
316                 fprintf(fp, "echo NOTE: this batch file should be invoked from the Visual Studio Command Prompt (vsvars32.bat)\n");
317                 fprintf(fp, "set OPENSSL_INC_PATH=\"%s\"\n", openssl_inc_path);
318                 fprintf(fp, "set OPENSSL_LIB_PATH=\"%s\"\n", openssl_lib_path);
319                 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");
320                 fprintf(fp, "cd ..\\src\\modules\n");
321                 fprintf(fp, "copy extra\\m_ssl_openssl.cpp .\n");
322                 fprintf(fp, "echo \t%%COMPILE%%\n");
323                 fprintf(fp, "%%COMPILE%%\n");
324                 fprintf(fp, "cd ..\\..\\win\n");
325                 fprintf(fp, "echo done... now check for errors.\n");
326                 fclose(fp);
327
328                 printf_c("\033[1;32m!!!NOTICE!!! The file 'compile_openssl.bat' has been written to your 'win' directory.  Launch it\n"
329                         "!!! from the Visual Studio Command Prompt !!! to compile the m_ssl_openssl module.\n"
330                         "Wait until after compiling inspircd to run it.\n"
331                         "Also, ssleay32.dll and libeay32.dll will be required for the IRCd to run.\033[0m\n");
332         }
333
334         printf_c("\n\033[1;32mPre-build configuration is complete!\n\n");       sc(TNORMAL);
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[0mLibrary path:\033[1;32m             %s\n", library_dir);
341         printf_c("\033[0mSocket Engine:\033[1;32m            %s\n", use_iocp ? "iocp" : "select");
342         printf_c("\033[0mMax nickname length:\033[1;32m      %u\n", nicklen);
343         printf_c("\033[0mMax channel length:\033[1;32m       %u\n", chanlen);
344         printf_c("\033[0mMax mode length:\033[1;32m          %u\n", modechanges);
345         printf_c("\033[0mMax ident length:\033[1;32m         %u\n", identlen);
346         printf_c("\033[0mMax quit length:\033[1;32m          %u\n", quitlen);
347         printf_c("\033[0mMax topic length:\033[1;32m         %u\n", topiclen);
348         printf_c("\033[0mMax kick length:\033[1;32m          %u\n", kicklen);
349         printf_c("\033[0mMax name length:\033[1;32m          %u\n", rllen);
350         printf_c("\033[0mMax away length:\033[1;32m          %u\n", awaylen);
351         printf("\n"); sc(TNORMAL);
352         if(get_bool_option("Are these settings correct?", true) == false)
353         {
354                 Run();
355                 return;
356         }
357         printf("\n");
358
359         // escape the pathes
360         escape_string(config_file, MAX_PATH);
361         escape_string(mod_path, MAX_PATH);
362         escape_string(library_dir, MAX_PATH);
363
364         printf("\nWriting inspircd_config.h...");
365         FILE * f = fopen("inspircd_config.h", "w");
366         fprintf(f, "/* Auto generated by configure, do not modify! */\n");
367         fprintf(f, "#ifndef __CONFIGURATION_AUTO__\n");
368         fprintf(f, "#define __CONFIGURATION_AUTO__\n\n");
369         if(use_iocp)
370                 fprintf(f, "#define CONFIG_USE_IOCP 1\n\n");
371         if (ipv6)
372                 fprintf(f, "#define IPV6 1\n\n");
373
374         fprintf(f, "#define CONFIG_FILE \"%s/inspircd.conf\"\n", config_file);
375         fprintf(f, "#define MOD_PATH \"%s\"\n", mod_path);
376         fprintf(f, "#define SOMAXCONN_S \"128\"\n");
377         fprintf(f, "#define NICKMAX %u\n", nicklen+1);
378         fprintf(f, "#define CHANMAX %u\n", chanlen+1);
379         fprintf(f, "#define MAXMODES %u\n", modechanges);
380         fprintf(f, "#define IDENTMAX %u\n", identlen);
381         fprintf(f, "#define MAXQUIT %u\n", quitlen);
382         fprintf(f, "#define MAXTOPIC %u\n", topiclen);
383         fprintf(f, "#define MAXKICK %u\n", kicklen);
384         fprintf(f, "#define MAXGECOS %u\n", rllen);
385         fprintf(f, "#define MAXAWAY %u\n", awaylen);
386         fprintf(f, "#define LIBRARYDIR \"%s\"\n", library_dir);
387         fprintf(f, "#define VERSION \"%s\"\n", version);
388         fprintf(f, "#define REVISION \"%s\"\n", revision_text);
389         if(support_ip6links)
390                 fprintf(f, "#define SUPPORT_IP6LINKS 1\n");
391
392         OSVERSIONINFO vi;
393         vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
394         GetVersionEx(&vi);
395 #ifdef WIN64
396         fprintf(f, "#define SYSTEM \"Windows_x64 %u.%u.%u %s\"\n", vi.dwMajorVersion, vi.dwMinorVersion, vi.dwBuildNumber, vi.szCSDVersion);
397 #else
398         fprintf(f, "#define SYSTEM \"Windows_x32 %u.%u.%u %s\"\n", vi.dwMajorVersion, vi.dwMinorVersion, vi.dwBuildNumber, vi.szCSDVersion);
399 #endif
400         fprintf(f, "#define MAXBUF 514\n");
401
402         fprintf(f, "\n#include \"inspircd_win32wrapper.h\"\n\n");
403         fprintf(f, "#include \"threadengines/threadengine_win32.h\"\n\n");
404         fprintf(f, "#endif\n\n");
405         fclose(f);
406
407         sc(TGREEN); printf(" done\n"); sc(TNORMAL);
408         printf("Writing inspircd_se_config.h...");
409
410         f = fopen("inspircd_se_config.h", "w");
411         fprintf(f, "/* Auto generated by configure, do not modify or commit to svn! */\n");
412         fprintf(f, "#ifndef __CONFIGURATION_SOCKETENGINE__\n");
413         fprintf(f, "#define __CONFIGURATION_SOCKETENGINE__\n\n");
414         fprintf(f, "#include \"socketengines/socketengine_%s.h\"\n\n", use_iocp ? "iocp" : "select");
415         fprintf(f, "#endif\n\n");
416         fclose(f);
417
418         sc(TGREEN); printf(" done\n"); sc(TNORMAL);
419         printf("Writing command and module compilation scripts...");
420         WriteCompileCommands();
421         WriteCompileModules();
422         sc(TGREEN); printf(" done\n"); sc(TNORMAL);
423
424         printf("\nconfigure is done.. exiting!\n");
425 }
426
427 void Rebase()
428 {
429         char dest[65535];
430         char command[65535];
431
432         *dest = 0;
433
434         WIN32_FIND_DATA fd;
435 #ifdef _DEBUG
436         HANDLE fh = FindFirstFile("..\\bin\\debug\\lib\\*.so", &fd);
437 #else
438         HANDLE fh = FindFirstFile("..\\bin\\release\\lib\\*.so", &fd);
439 #endif
440         if(fh == INVALID_HANDLE_VALUE)
441                 return;
442
443         do
444         {
445 #ifdef _DEBUG
446                 strcat(dest, " ..\\bin\\debug\\lib\\");
447 #else
448                 strcat(dest, " ..\\bin\\release\\lib\\");
449 #endif
450                 strcat(dest, fd.cFileName);
451         }
452         while (FindNextFile(fh, &fd));
453
454         FindClose(fh);
455
456         sprintf(command, "rebase.exe -v -b 10000000 -c baseaddr_commands.txt %s", dest);
457         printf("%s\n", command);
458         system(command);
459
460 #ifdef _DEBUG
461         fh = FindFirstFile("..\\bin\\debug\\modules\\*.so", &fd);
462 #else
463         fh = FindFirstFile("..\\bin\\release\\modules\\*.so", &fd);
464 #endif
465         if(fh == INVALID_HANDLE_VALUE)
466                 return;
467
468         *dest = 0;
469
470         do
471         {
472 #ifdef _DEBUG
473                 strcat(dest, " ..\\bin\\debug\\modules\\");
474 #else
475                 strcat(dest, " ..\\bin\\release\\modules\\");
476 #endif
477                 strcat(dest, fd.cFileName);
478         }
479         while (FindNextFile(fh, &fd));
480
481         sprintf(command, "rebase.exe -v -b 11000000 -c baseaddr_modules.txt %s", dest);
482         printf("%s\n", command);
483         system(command);
484
485         FindClose(fh);
486
487 }
488
489 void WriteCompileCommands()
490 {
491         char commands[300][100];
492         int command_count = 0;
493         printf("\n  Finding Command Sources...\n");
494         WIN32_FIND_DATA fd;
495         HANDLE fh = FindFirstFile("..\\src\\commands\\cmd_*.cpp", &fd);
496         if(fh == INVALID_HANDLE_VALUE)
497                 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");
498         else
499         {
500                 sc(TGREEN);
501                 do 
502                 {
503                         strcpy(commands[command_count], fd.cFileName);
504                         commands[command_count][strlen(fd.cFileName) - 4] = 0;
505                         printf("        %s\n", commands[command_count]);
506                         ++command_count;
507                 } while(FindNextFile(fh, &fd));
508                 sc(TNORMAL);
509         }
510         
511         // Write our spiffy new makefile :D
512         // I am such a lazy fucker :P
513         FILE * f = fopen("..\\src\\commands\\commands.mak", "w");
514
515         time_t t = time(NULL);
516         fprintf(f, "# Generated at %s\n", ctime(&t));
517         fprintf(f, "all: makedir ");
518
519         // dump modules.. first time :)
520         for(int i = 0; i < command_count; ++i)
521                 fprintf(f, "%s.so ", commands[i]);
522
523         fprintf(f, "\n.cpp.obj:\n");
524 #ifdef WIN64
525         // /MACHINE:X64
526         #ifdef _DEBUG
527                 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");
528                 CreateDirectory("..\\src\\debug", NULL);
529                 CreateDirectory("..\\bin\\debug\\bin", NULL);
530                 CreateDirectory("..\\bin\\debug\\lib", NULL);
531                 CreateDirectory("..\\bin\\debug\\modules", NULL);
532         #else
533                 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");
534                 CreateDirectory("..\\src\\release", NULL);
535                 CreateDirectory("..\\bin\\release\\bin", NULL);
536                 CreateDirectory("..\\bin\\release\\lib", NULL);
537                 CreateDirectory("..\\bin\\release\\modules", NULL);
538         #endif
539 #else
540         #ifdef _DEBUG
541                 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");
542                 CreateDirectory("..\\src\\debug", NULL);
543                 CreateDirectory("..\\bin\\debug\\bin", NULL);
544                 CreateDirectory("..\\bin\\debug\\lib", NULL);
545                 CreateDirectory("..\\bin\\debug\\modules", NULL);
546         #else
547                 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");
548                 CreateDirectory("..\\src\\release", NULL);
549                 CreateDirectory("..\\bin\\release\\bin", NULL);
550                 CreateDirectory("..\\bin\\release\\lib", NULL);
551                 CreateDirectory("..\\bin\\release\\modules", NULL);
552         #endif
553 #endif
554
555 #ifdef _DEBUG
556         fprintf(f, "makedir:\n  if not exist debug mkdir debug\n  if not exist ..\\..\\bin\\debug\\lib mkdir ..\\..\\bin\\debug\\lib\n\n");
557 #else
558         fprintf(f, "makedir:\n  if not exist release mkdir release\n  if not exist ..\\..\\bin\\release\\lib mkdir ..\\..\\bin\\release\\lib\n\n");
559 #endif
560         
561         // dump modules.. again the second and last time :)
562         for(int i = 0; i < command_count; ++i)
563                 fprintf(f, "%s.so : %s.obj\n", commands[i], commands[i]);
564
565         fprintf(f, "\n");
566         fclose(f);
567 }
568
569 void WriteCompileModules()
570 {
571         char modules[300][100];
572         int module_count = 0;
573
574         printf("Finding Modules...\n");
575         WIN32_FIND_DATA fd;
576         HANDLE fh = FindFirstFile("..\\src\\modules\\m_*.cpp", &fd);
577         if(fh == INVALID_HANDLE_VALUE)
578                 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");
579         else
580         {
581                 sc(TGREEN);
582                 do 
583                 {
584                         strcpy(modules[module_count], fd.cFileName);
585                         modules[module_count][strlen(fd.cFileName) - 4] = 0;
586                         printf("  %s\n", modules[module_count]);
587                         ++module_count;
588                 } while(FindNextFile(fh, &fd));
589                 sc(TNORMAL);
590         }
591
592         // Write our spiffy new makefile :D
593         // I am such a lazy fucker :P
594         FILE * f = fopen("..\\src\\modules\\modules.mak", "w");
595
596         time_t t = time(NULL);
597         fprintf(f, "# Generated at %s\n", ctime(&t));
598         fprintf(f, "all: makedir ");
599
600         // dump modules.. first time :)
601         for(int i = 0; i < module_count; ++i)
602                 fprintf(f, "%s.so ", modules[i]);
603
604         fprintf(f, "\n.cpp.obj:\n");
605 #ifdef WIN64
606         // /MACHINE:X64
607         #ifdef _DEBUG
608                 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");
609                 CreateDirectory("..\\src\\modules\\debug_x64", NULL);
610         #else
611                 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");
612                 CreateDirectory("..\\src\\modules\\release_x64", NULL);
613         #endif
614 #else
615         #ifdef _DEBUG
616                 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");
617                 CreateDirectory("..\\src\\modules\\debug", NULL);
618                 CreateDirectory("..\\src\\modules\\debug\\lib", NULL);
619                 CreateDirectory("..\\src\\modules\\debug\\modules", NULL);
620                 CreateDirectory("..\\src\\modules\\debug\\bin", NULL);
621         #else
622                 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");
623                 CreateDirectory("..\\src\\modules\\release", NULL);
624                 CreateDirectory("..\\src\\modules\\release\\lib", NULL);
625                 CreateDirectory("..\\src\\modules\\release\\modules", NULL);
626                 CreateDirectory("..\\src\\modules\\release\\bin", NULL);
627         #endif
628 #endif
629         
630 #ifdef _DEBUG
631         fprintf(f, "makedir:\n  if not exist debug mkdir debug\n  if not exist ..\\..\\bin\\debug\\modules mkdir ..\\..\\bin\\debug\\modules\n\n");
632 #else
633         fprintf(f, "makedir:\n  if not exist release mkdir release\n  if not exist ..\\..\\bin\\release\\modules mkdir ..\\..\\bin\\release\\modules\n\n");
634 #endif
635
636         // dump modules.. again the second and last time :)
637         for(int i = 0; i < module_count; ++i)
638                 fprintf(f, "%s.so : %s.obj\n", modules[i], modules[i]);
639
640         fprintf(f, "\n");
641         fclose(f);
642 }