1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2011 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 #define _CRT_SECURE_NO_DEPRECATE
16 #define CONFIGURE_BUILD
17 #define WIN32_LEAN_AND_MEAN
25 #include "inspircd_win32wrapper.h"
31 void WriteCompileModules(const vector<string> &, const vector<string> &);
32 void WriteCompileCommands();
36 /* detects if we are running windows xp or higher (5.1) */
40 vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
42 if(vi.dwMajorVersion >= 5)
48 int get_int_option(const char * text, int def)
50 static char buffer[500];
52 printf_c("%s\n[\033[1;32m%u\033[0m] -> ", text, def);
53 fgets(buffer, 500, stdin);
54 if(sscanf(buffer, "%u", &ret) != 1)
61 bool get_bool_option(const char * text, bool def)
63 static char buffer[500];
65 printf_c("%s [\033[1;32m%c\033[0m] -> ", text, def ? 'y' : 'n');
66 fgets(buffer, 500, stdin);
67 if(sscanf(buffer, "%s", ret) != 1)
68 strcpy(ret, def ? "y" : "n");
71 return !strncmp(ret, "y", 1);
74 string get_string_option(const char * text, char * def)
77 printf_c("%s\n[\033[1;32m%s\033[0m] -> ", text, def);
79 printf_c("%s\n[] -> ", text);
81 char buffer[1000], buf[1000];
82 fgets(buffer, sizeof(buffer), stdin);
83 if (sscanf(buffer, "%s", buf) != 1)
90 // escapes a string for use in a c++ file
91 void escape_string(string &str)
96 for (unsigned i = 0; i < copy.size(); ++i)
104 string get_git_commit()
107 char *ref = NULL, *commit = NULL;
108 FILE *f = fopen("../.git/HEAD", "r");
111 if (fgets(buf, sizeof(buf), f))
113 while (isspace(buf[strlen(buf) - 1]))
114 buf[strlen(buf) - 1] = 0;
115 char *p = strchr(buf, ' ');
123 string ref_file = string("../.git/") + string(ref);
124 f = fopen(ref_file.c_str(), "r");
127 if (fgets(buf, sizeof(buf), f))
129 while (isspace(buf[strlen(buf) - 1]))
130 buf[strlen(buf) - 1] = 0;
136 return commit != NULL ? commit : "";
139 void get_machine_info(char * buffer, size_t len)
144 DWORD dwSize = sizeof(buf);
145 if (!GetComputerNameEx((COMPUTER_NAME_FORMAT)ComputerNameDnsFullyQualified, buf, &dwSize))
146 sprintf(buf, "%s", "unknown");
148 FILE * f = fopen("ver.txt.tmp", "r");
151 while (fgets(buf2, 500, f)) { }
153 unlink("ver.txt.tmp");
156 sprintf(buf2, "%s", "unknown");
158 sprintf(buffer, "%s ", buf);
160 char* b = buffer + strlen(buf)+1;
164 if (*b2 != 10 && *b2 != 13)
174 vector<string> get_dir_list(const string &path_list)
176 char *paths = strdup(path_list.c_str());
177 char *paths_save = paths;
179 vector<string> paths_return;
181 while ((p = strchr(paths, ';')))
184 paths_return.push_back(paths);
188 paths_return.push_back(paths);
194 int __stdcall WinMain(IN HINSTANCE hInstance, IN HINSTANCE hPrevInstance, IN LPSTR lpCmdLine, IN int nShowCmd )
196 if (!strcmp(lpCmdLine, "/rebase"))
202 FILE * j = fopen("inspircd_config.h", "r");
205 if (MessageBox(0, "inspircd_config.h already exists. Remove it and build from clean?", "Configure program", MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2) != IDYES)
212 // call before we hook console handles
213 system("ver > ver.txt.tmp");
217 // pipe standard handles to this console
218 freopen("CONIN$", "r", stdin);
219 freopen("CONOUT$", "w", stdout);
220 freopen("CONOUT$", "w", stderr);
230 printf_c("\nWelcome to the \033[1mInspIRCd\033[0m Configuration program! (\033[1minteractive mode\033[0m)\n"
231 "\033[1mPackage maintainers: Type ./configure --help for non-interactive help\033[0m\n\n");
232 printf_c("*** If you are unsure of any of these values, leave it blank for ***\n"
233 "*** standard settings that will work, and your server will run ***\n"
234 "*** using them. Please consult your IRC network admin if in doubt. ***\n\n"
235 "Press \033[1m<RETURN>\033[0m to accept the default for any option, or enter\n"
236 "a new value. Please note: You will \033[1mHAVE\033[0m to read the docs\n"
237 "dir, otherwise you won't have a config file!\n\n");
243 vector<string> extra_include_paths, extra_lib_paths;
244 string revision = get_git_commit();
246 char machine_text[MAX_PATH];
247 get_machine_info(machine_text, MAX_PATH);
250 FILE * fI = fopen("..\\src\\version.sh", "r");
253 fgets(version, 514, fI);
254 fgets(version, 514, fI);
267 strcpy(version, "InspIRCD-Unknown");
269 printf_c("Your operating system is: \033[1;32mwindows_x64 \033[0m\n");
271 printf_c("Your operating system is: \033[1;32mwindows_x32 \033[0m\n");
273 printf_c("InspIRCd revision ID: \033[1;32m%s \033[0m\n\n", !revision.empty() ? revision.c_str() : "(Non-GIT build)");
275 printf_c("\033[1mExtra modules.\033[0m\n");
276 if (get_bool_option("Do you want to compile any extra non-core modules?", false))
278 string extra_i_path = get_string_option("Extra include search paths separate by \";\"", ".");
279 string extra_l_path = get_string_option("Extra library search paths, separate by \";\"", ".");
281 extra_include_paths = get_dir_list(extra_i_path);
282 extra_lib_paths = get_dir_list(extra_l_path);
285 printf_c("\033[1mAll paths are relative to the binary directory.\033[0m\n");
286 string base_path = get_string_option("In what directory do you wish to install the InspIRCd base?", "..");
287 string config_file = get_string_option("In what directory are the configuration files?", "conf");
288 string mod_path = get_string_option("In what directory are the modules to be compiled to?", "modules");
289 string bin_dir = get_string_option("In what directory is the IRCd binary to be placed?", ".");
291 printf_c("\n\033[1;32mPre-build configuration is complete!\n\n"); sc(TNORMAL);
295 // dump all the options back out
296 printf_c("\033[0mBase install path:\033[1;32m %s\n", base_path.c_str());
297 printf_c("\033[0mConfig path:\033[1;32m %s\n", config_file.c_str());
298 printf_c("\033[0mModule path:\033[1;32m %s\n", mod_path.c_str());
299 printf_c("\033[0mSocket Engine:\033[1;32m %s\n", "select");
301 printf("\n"); sc(TNORMAL);
302 if(get_bool_option("Are these settings correct?", true) == false)
310 escape_string(config_file);
311 escape_string(mod_path);
313 printf("\nWriting inspircd_config.h...");
314 FILE * f = fopen("inspircd_config.h", "w");
315 fprintf(f, "/* Auto generated by configure, do not modify! */\n");
316 fprintf(f, "#ifndef __CONFIGURATION_AUTO__\n");
317 fprintf(f, "#define __CONFIGURATION_AUTO__\n\n");
319 fprintf(f, "#define MOD_PATH \"%s\"\n", mod_path.c_str());
320 fprintf(f, "#define SOMAXCONN_S \"128\"\n");
321 fprintf(f, "#define MAXBUF 514\n");
323 fprintf(f, "\n#include \"inspircd_win32wrapper.h\"");
324 fprintf(f, "\n#include \"inspircd_namedpipe.h\"");
325 fprintf(f, "\n#include \"threadengines/threadengine_win32.h\"\n\n");
326 fprintf(f, "#endif\n\n");
329 sc(TGREEN); printf(" done\n"); sc(TNORMAL);
330 printf("Writing inspircd_se_config.h...");
332 f = fopen("inspircd_se_config.h", "w");
333 fprintf(f, "/* Auto generated by configure, do not modify or commit to Git! */\n");
334 fprintf(f, "#ifndef __CONFIGURATION_SOCKETENGINE__\n");
335 fprintf(f, "#define __CONFIGURATION_SOCKETENGINE__\n\n");
336 fprintf(f, "#include \"socketengines/socketengine_%s.h\"\n\n", "select");
337 fprintf(f, "#endif\n\n");
340 sc(TGREEN); printf(" done\n"); sc(TNORMAL);
341 printf("Writing inspircd_version.h...");
342 f = fopen("inspircd_version.h", "w");
343 fprintf(f, "#define VERSION \"%s\"\n", version);
344 fprintf(f, "#define REVISION \"%s\"\n", revision.c_str());
345 fprintf(f, "#define SYSTEM \"%s\"\n", machine_text);
348 sc(TGREEN); printf(" done\n"); sc(TNORMAL);
349 printf("Writing command and module compilation scripts...");
350 WriteCompileCommands();
351 WriteCompileModules(extra_include_paths, extra_lib_paths);
352 sc(TGREEN); printf(" done\n"); sc(TNORMAL);
354 printf("\nconfigure is done.. exiting!\n");
357 /* Keeps files from modules/extra up to date if theyre copied into modules/ */
363 printf("\nUpdating extra modules in src/modules...\n");
366 HANDLE fh = FindFirstFile("..\\src\\modules\\extra\\*.*", &fd);
368 if(fh == INVALID_HANDLE_VALUE)
373 strcpy(dest, "..\\src\\modules\\");
374 strcat(dest, fd.cFileName);
375 strcpy(src, "..\\src\\modules\\extra\\");
376 strcat(src, fd.cFileName);
377 FILE* x = fopen(dest, "r");
381 CopyFile(src, dest, false);
382 sc(TGREEN); printf(" %s", fd.cFileName); sc(TNORMAL);
386 while (FindNextFile(fh, &fd));
402 HANDLE fh = FindFirstFile("..\\bin\\debug\\modules\\*.so", &fd);
404 HANDLE fh = FindFirstFile("..\\bin\\release\\modules\\*.so", &fd);
406 if(fh == INVALID_HANDLE_VALUE)
414 strcat(dest, " ..\\bin\\debug\\modules\\");
416 strcat(dest, " ..\\bin\\release\\modules\\");
418 strcat(dest, fd.cFileName);
420 while (FindNextFile(fh, &fd));
422 sprintf(command, "rebase.exe -v -b 11000000 -c baseaddr_modules.txt %s", dest);
423 printf("%s\n", command);
429 void WriteCompileCommands()
431 char commands[300][100];
432 int command_count = 0;
433 printf("\n Finding Command Sources...\n");
435 HANDLE fh = FindFirstFile("..\\src\\commands\\cmd_*.cpp", &fd);
436 if(fh == INVALID_HANDLE_VALUE)
437 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");
443 strcpy(commands[command_count], fd.cFileName);
444 commands[command_count][strlen(fd.cFileName) - 4] = 0;
445 printf(" %s\n", commands[command_count]);
447 } while(FindNextFile(fh, &fd));
451 // Write our spiffy new makefile :D
452 // I am such a lazy fucker :P
453 FILE * f = fopen("..\\src\\commands\\commands.mak", "w");
455 time_t t = time(NULL);
456 fprintf(f, "# Generated at %s\n", ctime(&t));
457 fprintf(f, "all: makedir ");
459 // dump modules.. first time :)
460 for(int i = 0; i < command_count; ++i)
461 fprintf(f, "%s.so ", commands[i]);
463 fprintf(f, "\n.cpp.obj:\n");
467 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\\inspircd.lib /OUT:\"..\\..\\bin\\debug_x64\\modules\\$*.so\" /PDB:\"..\\..\\bin\\debug_x64\\modules\\$*.pdb\" /MACHINE:X64 /IMPLIB:\"..\\..\\bin\\debug_x64\\modules\\$*.lib\"\n\n");
468 CreateDirectory("..\\src\\commands\\debug", NULL);
469 CreateDirectory("..\\bin\\debug\\modules", NULL);
471 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\\inspircd.lib /OUT:\"..\\..\\bin\\release_x64\\modules\\$*.so\" /PDB:\"..\\..\\bin\\release_x64\\modules\\$*.pdb\" /MACHINE:X64 /IMPLIB:\"..\\..\\bin\\release_x64\\modules\\$*.lib\"\n\n");
472 CreateDirectory("..\\src\\commands\\release", NULL);
473 CreateDirectory("..\\bin\\release\\modules", NULL);
477 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\\inspircd.lib /OUT:\"..\\..\\bin\\debug\\modules\\$*.so\" /PDB:\"..\\..\\bin\\debug\\modules\\$*.pdb\" /IMPLIB:\"..\\..\\bin\\debug\\modules\\$*.lib\"\n\n");
478 CreateDirectory("..\\src\\commands\\debug", NULL);
479 CreateDirectory("..\\bin\\debug\\modules", NULL);
481 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\\inspircd.lib /OUT:\"..\\..\\bin\\release\\modules\\$*.so\" /PDB:\"..\\..\\bin\\release\\modules\\$*.pdb\" /IMPLIB:\"..\\..\\bin\\release\\modules\\$*.lib\"\n\n");
482 CreateDirectory("..\\src\\commands\\release", NULL);
483 CreateDirectory("..\\bin\\release\\modules", NULL);
487 fprintf(f, "makedir:\n");
489 fprintf(f, " if not exist ..\\..\\bin\\debug mkdir ..\\..\\bin\\debug\n");
490 fprintf(f, " if not exist ..\\..\\bin\\debug\\modules mkdir ..\\..\\bin\\debug\\modules\n");
491 fprintf(f, " if not exist ..\\..\\bin\\debug\\data mkdir ..\\..\\bin\\debug\\data\n");
492 fprintf(f, " if not exist ..\\..\\bin\\debug\\logs mkdir ..\\..\\bin\\debug\\logs\n");
494 fprintf(f, " if not exist ..\\..\\bin\\release mkdir ..\\..\\bin\\release\n");
495 fprintf(f, " if not exist ..\\..\\bin\\release\\modules mkdir ..\\..\\bin\\release\\modules\n");
496 fprintf(f, " if not exist ..\\..\\bin\\release\\data mkdir ..\\..\\bin\\release\\data\n");
497 fprintf(f, " if not exist ..\\..\\bin\\release\\logs mkdir ..\\..\\bin\\release\\logs\n");
500 // dump modules.. again the second and last time :)
501 for(int i = 0; i < command_count; ++i)
502 fprintf(f, "%s.so : %s.obj\n", commands[i], commands[i]);
508 void WriteCompileModules(const vector<string> &includes, const vector<string> &libs)
510 char modules[300][100];
511 int module_count = 0;
513 printf("Finding Modules...\n");
515 HANDLE fh = FindFirstFile("..\\src\\modules\\m_*.cpp", &fd);
516 if(fh == INVALID_HANDLE_VALUE)
517 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");
523 strcpy(modules[module_count], fd.cFileName);
524 modules[module_count][strlen(fd.cFileName) - 4] = 0;
525 printf(" %s\n", modules[module_count]);
527 } while(FindNextFile(fh, &fd));
531 string extra_include, extra_lib;
532 for (unsigned i = 0; i < includes.size(); ++i)
533 extra_include += " /I \"" + includes[i] + "\" ";
534 for (unsigned i = 0; i < libs.size(); ++i)
535 extra_lib += " /LIBPATH:\"" + libs[i] + "\" ";
537 // Write our spiffy new makefile :D
538 // I am such a lazy fucker :P
539 FILE * f = fopen("..\\src\\modules\\modules.mak", "w");
541 time_t t = time(NULL);
542 fprintf(f, "# Generated at %s\n", ctime(&t));
543 fprintf(f, "all: makedir ");
545 // dump modules.. first time :)
546 for(int i = 0; i < module_count; ++i)
547 fprintf(f, "%s.so ", modules[i]);
549 fprintf(f, "\n.cpp.obj:\n");
553 fprintf(f, " cl /nologo /LD /Od /I \".\" /I \"../../include\" /I \"../../include/modes\" /I \"../../include/modules\" /I \"../../win\" %s /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 %s ..\\..\\bin\\debug_x64\\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", extra_include.c_str(), extra_lib.c_str());
554 CreateDirectory("..\\src\\modules\\debug_x64", NULL);
556 fprintf(f, " cl /nologo /LD /Od /I \".\" /I \"../../include\" /I \"../../include/modes\" /I \"../../include/modules\" /I \"../../win\" %s /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 %s ..\\..\\bin\\release_x64\\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", extra_include.c_str(), extra_lib.c_str());
557 CreateDirectory("..\\src\\modules\\release_x64", NULL);
561 fprintf(f, " cl /nologo /LD /Od /I \".\" /I \"../../include\" /I \"../../include/modes\" /I \"../../include/modules\" /I \"../../win\" %s /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 %s ..\\..\\bin\\debug\\inspircd.lib ws2_32.lib /OUT:\"..\\..\\bin\\debug\\modules\\$*.so\" /PDB:\"..\\..\\bin\\debug\\modules\\$*.pdb\" /IMPLIB:\"..\\..\\bin\\debug\\modules\\$*.lib\"\n\n", extra_include.c_str(), extra_lib.c_str());
562 CreateDirectory("..\\src\\modules\\debug", NULL);
564 fprintf(f, " cl /nologo /LD /Od /I \".\" /I \"../../include\" /I \"../../include/modes\" /I \"../../include/modules\" /I \"../../win\" %s /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 %s ..\\..\\bin\\release\\inspircd.lib ws2_32.lib /OUT:\"..\\..\\bin\\release\\modules\\$*.so\" /PDB:\"..\\..\\bin\\release\\modules\\$*.pdb\" /IMPLIB:\"..\\..\\bin\\release\\modules\\$*.lib\"\n\n", extra_include.c_str(), extra_lib.c_str());
565 CreateDirectory("..\\src\\modules\\release", NULL);
570 fprintf(f, "makedir:\n if not exist debug mkdir debug\n\n");
572 fprintf(f, "makedir:\n if not exist release mkdir release\n\n");
575 // dump modules.. again the second and last time :)
576 for(int i = 0; i < module_count; ++i)
577 fprintf(f, "%s.so : %s.obj\n", modules[i], modules[i]);