2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2011 Adam <Adam@anope.org>
5 * Copyright (C) 2007, 2009 Dennis Friis <peavey@inspircd.org>
6 * Copyright (C) 2007-2008 Craig Edwards <craigedwards@brainbox.cc>
7 * Copyright (C) 2008 Eric Dietz <root@wrongway.org>
8 * Copyright (C) 2007 Burlex <???@???>
9 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
11 * This file is part of InspIRCd. InspIRCd is free software: you can
12 * redistribute it and/or modify it under the terms of the GNU General Public
13 * License as published by the Free Software Foundation, version 2.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #define _CRT_SECURE_NO_DEPRECATE
27 #define CONFIGURE_BUILD
28 #define WIN32_LEAN_AND_MEAN
36 #include "inspircd_win32wrapper.h"
42 void WriteCompileModules(const vector<string> &, const vector<string> &);
43 void WriteCompileCommands();
47 /* detects if we are running windows xp or higher (5.1) */
51 vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
53 if(vi.dwMajorVersion >= 5)
59 int get_int_option(const char * text, int def)
61 static char buffer[500];
63 printf_c("%s\n[\033[1;32m%u\033[0m] -> ", text, def);
64 fgets(buffer, sizeof(buffer), stdin);
65 if(sscanf(buffer, "%u", &ret) != 1)
72 bool get_bool_option(const char * text, bool def)
74 static char buffer[500];
76 printf_c("%s [\033[1;32m%c\033[0m] -> ", text, def ? 'y' : 'n');
77 fgets(buffer, sizeof(buffer), stdin);
78 if(sscanf(buffer, "%s", ret) != 1)
79 strcpy(ret, def ? "y" : "n");
82 return !strncmp(ret, "y", 1);
85 string get_string_option(const char * text, char * def)
88 printf_c("%s\n[\033[1;32m%s\033[0m] -> ", text, def);
90 printf_c("%s\n[] -> ", text);
92 char buffer[1000], buf[1000];
93 fgets(buffer, sizeof(buffer), stdin);
94 if (sscanf(buffer, "%s", buf) != 1)
101 // escapes a string for use in a c++ file
102 void escape_string(string &str)
107 for (unsigned i = 0; i < copy.size(); ++i)
115 string get_git_commit()
118 char *ref = NULL, *commit = NULL;
119 FILE *f = fopen("../.git/HEAD", "r");
122 if (fgets(buf, sizeof(buf), f))
124 while (isspace(buf[strlen(buf) - 1]))
125 buf[strlen(buf) - 1] = 0;
126 char *p = strchr(buf, ' ');
134 string ref_file = string("../.git/") + string(ref);
135 f = fopen(ref_file.c_str(), "r");
138 if (fgets(buf, sizeof(buf), f))
140 while (isspace(buf[strlen(buf) - 1]))
141 buf[strlen(buf) - 1] = 0;
147 return commit != NULL ? commit : "";
150 void get_machine_info(char * buffer, size_t len)
155 DWORD dwSize = sizeof(buf);
156 if (!GetComputerNameEx((COMPUTER_NAME_FORMAT)ComputerNameDnsFullyQualified, buf, &dwSize))
157 sprintf(buf, "%s", "unknown");
159 FILE * f = fopen("ver.txt.tmp", "r");
162 while (fgets(buf2, sizeof(buf2), f)) { }
164 unlink("ver.txt.tmp");
167 sprintf(buf2, "%s", "unknown");
169 sprintf(buffer, "%s ", buf);
171 char* b = buffer + strlen(buf)+1;
175 if (*b2 != 10 && *b2 != 13)
185 vector<string> get_dir_list(const string &path_list)
187 char *paths = strdup(path_list.c_str());
188 char *paths_save = paths;
190 vector<string> paths_return;
192 while ((p = strchr(paths, ';')))
195 paths_return.push_back(paths);
199 paths_return.push_back(paths);
205 int __stdcall WinMain(IN HINSTANCE hInstance, IN HINSTANCE hPrevInstance, IN LPSTR lpCmdLine, IN int nShowCmd )
207 if (!strcmp(lpCmdLine, "/rebase"))
213 FILE * j = fopen("inspircd_config.h", "r");
216 if (MessageBox(0, "inspircd_config.h already exists. Remove it and build from clean?", "Configure program", MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2) != IDYES)
223 // call before we hook console handles
224 system("ver > ver.txt.tmp");
228 // pipe standard handles to this console
229 freopen("CONIN$", "r", stdin);
230 freopen("CONOUT$", "w", stdout);
231 freopen("CONOUT$", "w", stderr);
241 printf_c("\nWelcome to the \033[1mInspIRCd\033[0m Configuration program! (\033[1minteractive mode\033[0m)\n"
242 "\033[1mPackage maintainers: Type ./configure --help for non-interactive help\033[0m\n\n");
243 printf_c("*** If you are unsure of any of these values, leave it blank for ***\n"
244 "*** standard settings that will work, and your server will run ***\n"
245 "*** using them. Please consult your IRC network admin if in doubt. ***\n\n"
246 "Press \033[1m<RETURN>\033[0m to accept the default for any option, or enter\n"
247 "a new value. Please note: You will \033[1mHAVE\033[0m to read the docs\n"
248 "dir, otherwise you won't have a config file!\n\n");
254 vector<string> extra_include_paths, extra_lib_paths;
255 string revision = get_git_commit();
257 char machine_text[MAX_PATH];
258 get_machine_info(machine_text, MAX_PATH);
261 FILE * fI = fopen("..\\src\\version.sh", "r");
264 fgets(version, sizeof(version), fI);
265 fgets(version, sizeof(version), fI);
278 strcpy(version, "InspIRCD-Unknown");
280 printf_c("Your operating system is: \033[1;32mwindows_x64 \033[0m\n");
282 printf_c("Your operating system is: \033[1;32mwindows_x32 \033[0m\n");
284 printf_c("InspIRCd revision ID: \033[1;32m%s \033[0m\n\n", !revision.empty() ? revision.c_str() : "(Non-GIT build)");
286 printf_c("\033[1mExtra modules.\033[0m\n");
287 if (get_bool_option("Do you want to compile any extra non-core modules?", false))
289 string extra_i_path = get_string_option("Extra include search paths separate by \";\"", ".");
290 string extra_l_path = get_string_option("Extra library search paths, separate by \";\"", ".");
292 extra_include_paths = get_dir_list(extra_i_path);
293 extra_lib_paths = get_dir_list(extra_l_path);
296 printf_c("\033[1mAll paths are relative to the binary directory.\033[0m\n");
297 string base_path = get_string_option("In what directory do you wish to install the InspIRCd base?", "..");
298 string config_file = get_string_option("In what directory are the configuration files?", "conf");
299 string mod_path = get_string_option("In what directory are the modules to be compiled to?", "modules");
300 string bin_dir = get_string_option("In what directory is the IRCd binary to be placed?", ".");
302 printf_c("\n\033[1;32mPre-build configuration is complete!\n\n"); sc(TNORMAL);
306 // dump all the options back out
307 printf_c("\033[0mBase install path:\033[1;32m %s\n", base_path.c_str());
308 printf_c("\033[0mConfig path:\033[1;32m %s\n", config_file.c_str());
309 printf_c("\033[0mModule path:\033[1;32m %s\n", mod_path.c_str());
310 printf_c("\033[0mSocket Engine:\033[1;32m %s\n", "select");
312 printf("\n"); sc(TNORMAL);
313 if(get_bool_option("Are these settings correct?", true) == false)
321 escape_string(config_file);
322 escape_string(mod_path);
324 printf("\nWriting inspircd_config.h...");
325 FILE * f = fopen("inspircd_config.h", "w");
326 fprintf(f, "/* Auto generated by configure, do not modify! */\n");
327 fprintf(f, "#ifndef __CONFIGURATION_AUTO__\n");
328 fprintf(f, "#define __CONFIGURATION_AUTO__\n\n");
330 fprintf(f, "#define MOD_PATH \"%s\"\n", mod_path.c_str());
331 fprintf(f, "#define SOMAXCONN_S \"128\"\n");
332 fprintf(f, "#define MAXBUF 514\n");
334 fprintf(f, "\n#include \"inspircd_win32wrapper.h\"");
335 fprintf(f, "\n#include \"inspircd_namedpipe.h\"");
336 fprintf(f, "\n#include \"threadengines/threadengine_win32.h\"\n\n");
337 fprintf(f, "#endif\n\n");
340 sc(TGREEN); printf(" done\n"); sc(TNORMAL);
341 printf("Writing inspircd_se_config.h...");
343 f = fopen("inspircd_se_config.h", "w");
344 fprintf(f, "/* Auto generated by configure, do not modify or commit to Git! */\n");
345 fprintf(f, "#ifndef __CONFIGURATION_SOCKETENGINE__\n");
346 fprintf(f, "#define __CONFIGURATION_SOCKETENGINE__\n\n");
347 fprintf(f, "#include \"socketengines/socketengine_%s.h\"\n\n", "select");
348 fprintf(f, "#endif\n\n");
351 sc(TGREEN); printf(" done\n"); sc(TNORMAL);
352 printf("Writing inspircd_version.h...");
353 f = fopen("inspircd_version.h", "w");
354 fprintf(f, "#define VERSION \"%s\"\n", version);
355 fprintf(f, "#define REVISION \"%s\"\n", revision.c_str());
356 fprintf(f, "#define SYSTEM \"%s\"\n", machine_text);
359 sc(TGREEN); printf(" done\n"); sc(TNORMAL);
360 printf("Writing command and module compilation scripts...");
361 WriteCompileCommands();
362 WriteCompileModules(extra_include_paths, extra_lib_paths);
363 sc(TGREEN); printf(" done\n"); sc(TNORMAL);
365 printf("\nconfigure is done.. exiting!\n");
368 /* Keeps files from modules/extra up to date if theyre copied into modules/ */
374 printf("\nUpdating extra modules in src/modules...\n");
377 HANDLE fh = FindFirstFile("..\\src\\modules\\extra\\*.*", &fd);
379 if(fh == INVALID_HANDLE_VALUE)
384 strcpy(dest, "..\\src\\modules\\");
385 strcat(dest, fd.cFileName);
386 strcpy(src, "..\\src\\modules\\extra\\");
387 strcat(src, fd.cFileName);
388 FILE* x = fopen(dest, "r");
392 CopyFile(src, dest, false);
393 sc(TGREEN); printf(" %s", fd.cFileName); sc(TNORMAL);
397 while (FindNextFile(fh, &fd));
413 HANDLE fh = FindFirstFile("..\\bin\\debug\\modules\\*.so", &fd);
415 HANDLE fh = FindFirstFile("..\\bin\\release\\modules\\*.so", &fd);
417 if(fh == INVALID_HANDLE_VALUE)
425 strcat(dest, " ..\\bin\\debug\\modules\\");
427 strcat(dest, " ..\\bin\\release\\modules\\");
429 strcat(dest, fd.cFileName);
431 while (FindNextFile(fh, &fd));
433 sprintf(command, "rebase.exe -v -b 11000000 -c baseaddr_modules.txt %s", dest);
434 printf("%s\n", command);
440 void WriteCompileCommands()
442 char commands[300][100];
443 int command_count = 0;
444 printf("\n Finding Command Sources...\n");
446 HANDLE fh = FindFirstFile("..\\src\\commands\\cmd_*.cpp", &fd);
447 if(fh == INVALID_HANDLE_VALUE)
448 printf_c("\033[1;32m No command sources could be found! This \033[1m*could*\033[1;32m be a bad thing.. :P\033[0m");
454 strcpy(commands[command_count], fd.cFileName);
455 commands[command_count][strlen(fd.cFileName) - 4] = 0;
456 printf(" %s\n", commands[command_count]);
458 } while(FindNextFile(fh, &fd));
462 // Write our spiffy new makefile :D
463 // I am such a lazy fucker :P
464 FILE * f = fopen("..\\src\\commands\\commands.mak", "w");
466 time_t t = time(NULL);
467 fprintf(f, "# Generated at %s\n", ctime(&t));
468 fprintf(f, "all: makedir ");
470 // dump modules.. first time :)
471 for(int i = 0; i < command_count; ++i)
472 fprintf(f, "%s.so ", commands[i]);
474 fprintf(f, "\n.cpp.obj:\n");
478 fprintf(f, " cl /nologo /LD /Od /I \".\" /I \"../../include\" /I \"../../include/modes\" /I \"../../include/commands\" /I \"../../win\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"DLL_BUILD\" /Gm /EHsc /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");
479 CreateDirectory("..\\src\\commands\\debug", NULL);
480 CreateDirectory("..\\bin\\debug\\modules", NULL);
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\" /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");
483 CreateDirectory("..\\src\\commands\\release", NULL);
484 CreateDirectory("..\\bin\\release\\modules", NULL);
488 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");
489 CreateDirectory("..\\src\\commands\\debug", NULL);
490 CreateDirectory("..\\bin\\debug\\modules", NULL);
492 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");
493 CreateDirectory("..\\src\\commands\\release", NULL);
494 CreateDirectory("..\\bin\\release\\modules", NULL);
498 fprintf(f, "makedir:\n");
500 fprintf(f, " if not exist ..\\..\\bin\\debug mkdir ..\\..\\bin\\debug\n");
501 fprintf(f, " if not exist ..\\..\\bin\\debug\\modules mkdir ..\\..\\bin\\debug\\modules\n");
502 fprintf(f, " if not exist ..\\..\\bin\\debug\\data mkdir ..\\..\\bin\\debug\\data\n");
503 fprintf(f, " if not exist ..\\..\\bin\\debug\\logs mkdir ..\\..\\bin\\debug\\logs\n");
505 fprintf(f, " if not exist ..\\..\\bin\\release mkdir ..\\..\\bin\\release\n");
506 fprintf(f, " if not exist ..\\..\\bin\\release\\modules mkdir ..\\..\\bin\\release\\modules\n");
507 fprintf(f, " if not exist ..\\..\\bin\\release\\data mkdir ..\\..\\bin\\release\\data\n");
508 fprintf(f, " if not exist ..\\..\\bin\\release\\logs mkdir ..\\..\\bin\\release\\logs\n");
511 // dump modules.. again the second and last time :)
512 for(int i = 0; i < command_count; ++i)
513 fprintf(f, "%s.so : %s.obj\n", commands[i], commands[i]);
519 void WriteCompileModules(const vector<string> &includes, const vector<string> &libs)
521 char modules[300][100];
522 int module_count = 0;
524 printf("Finding Modules...\n");
526 HANDLE fh = FindFirstFile("..\\src\\modules\\m_*.cpp", &fd);
527 if(fh == INVALID_HANDLE_VALUE)
528 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");
534 strcpy(modules[module_count], fd.cFileName);
535 modules[module_count][strlen(fd.cFileName) - 4] = 0;
536 printf(" %s\n", modules[module_count]);
538 } while(FindNextFile(fh, &fd));
542 string extra_include, extra_lib;
543 for (unsigned i = 0; i < includes.size(); ++i)
544 extra_include += " /I \"" + includes[i] + "\" ";
545 for (unsigned i = 0; i < libs.size(); ++i)
546 extra_lib += " /LIBPATH:\"" + libs[i] + "\" ";
548 // Write our spiffy new makefile :D
549 // I am such a lazy fucker :P
550 FILE * f = fopen("..\\src\\modules\\modules.mak", "w");
552 time_t t = time(NULL);
553 fprintf(f, "# Generated at %s\n", ctime(&t));
554 fprintf(f, "all: makedir ");
556 // dump modules.. first time :)
557 for(int i = 0; i < module_count; ++i)
558 fprintf(f, "%s.so ", modules[i]);
560 fprintf(f, "\n.cpp.obj:\n");
564 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());
565 CreateDirectory("..\\src\\modules\\debug_x64", NULL);
567 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());
568 CreateDirectory("..\\src\\modules\\release_x64", NULL);
572 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());
573 CreateDirectory("..\\src\\modules\\debug", NULL);
575 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());
576 CreateDirectory("..\\src\\modules\\release", NULL);
581 fprintf(f, "makedir:\n if not exist debug mkdir debug\n\n");
583 fprintf(f, "makedir:\n if not exist release mkdir release\n\n");
586 // dump modules.. again the second and last time :)
587 for(int i = 0; i < module_count; ++i)
588 fprintf(f, "%s.so : %s.obj\n", modules[i], modules[i]);