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
32 #include "../include/consolecolors.h"
34 WORD g_wOriginalColors;
35 WORD g_wBackgroundColor;
42 #include "inspircd_win32wrapper.h"
47 void WriteCompileModules(const vector<string> &, const vector<string> &);
48 void WriteCompileCommands();
54 #define OUTFOLDER "debug_x64"
56 #define OUTFOLDER "release_x64"
60 #define OUTFOLDER "debug"
62 #define OUTFOLDER "release"
66 int get_int_option(const char * text, int def)
68 static char buffer[500];
70 std::cout << text << std::endl << " [" << con_green << def << con_reset << "] -> ";
71 fgets(buffer, sizeof(buffer), stdin);
72 if(sscanf(buffer, "%u", &ret) != 1)
75 std::cout << std::endl;
79 bool get_bool_option(const char * text, bool def)
81 static char buffer[500];
83 std::cout << text << " [" << con_green << (def ? 'y' : 'n') << con_reset << "] -> ";
84 fgets(buffer, sizeof(buffer), stdin);
85 if(sscanf(buffer, "%s", ret) != 1)
86 strcpy(ret, def ? "y" : "n");
88 std::cout << std::endl;
89 return !strnicmp(ret, "y", 1);
92 string get_string_option(const char * text, char * def)
95 std::cout << text << std::endl << "[" << con_green << def << con_reset << "] -> ";
97 std::cout << text << std::endl << "[] -> ";
99 char buffer[1000], buf[1000];
100 fgets(buffer, sizeof(buffer), stdin);
101 if (sscanf(buffer, "%s", buf) != 1)
104 std::cout << std::endl;
108 // escapes a string for use in a c++ file
109 void escape_string(string &str)
114 for (unsigned i = 0; i < copy.size(); ++i)
122 string get_git_commit()
125 char *ref = NULL, *commit = NULL;
126 FILE *f = fopen("../.git/HEAD", "r");
129 if (fgets(buf, sizeof(buf), f))
131 while (isspace(buf[strlen(buf) - 1]))
132 buf[strlen(buf) - 1] = 0;
133 char *p = strchr(buf, ' ');
141 string ref_file = string("../.git/") + string(ref);
142 f = fopen(ref_file.c_str(), "r");
145 if (fgets(buf, sizeof(buf), f))
147 while (isspace(buf[strlen(buf) - 1]))
148 buf[strlen(buf) - 1] = 0;
154 return commit != NULL ? commit : "0";
157 void get_machine_info(char * buffer, size_t len)
162 DWORD dwSize = sizeof(buf);
163 if (!GetComputerNameExA((COMPUTER_NAME_FORMAT)ComputerNameDnsFullyQualified, buf, &dwSize))
164 sprintf(buf, "%s", "unknown");
166 FILE * f = fopen("ver.txt.tmp", "r");
169 while (fgets(buf2, sizeof(buf2), f)) { }
171 _unlink("ver.txt.tmp");
174 sprintf(buf2, "%s", "unknown");
176 sprintf(buffer, "%s ", buf);
178 char* b = buffer + strlen(buf)+1;
182 if (*b2 != 10 && *b2 != 13)
192 vector<string> get_dir_list(const string &path_list)
194 char *paths = _strdup(path_list.c_str());
195 char *paths_save = paths;
197 vector<string> paths_return;
199 while ((p = strchr(paths, ';')))
202 paths_return.push_back(paths);
206 paths_return.push_back(paths);
212 int __stdcall WinMain(IN HINSTANCE hInstance, IN HINSTANCE hPrevInstance, IN LPSTR lpCmdLine, IN int nShowCmd )
214 FILE * j = fopen("..\\include\\inspircd_config.h", "r");
217 if (MessageBoxA(0, "inspircd_config.h already exists. Remove it and build from clean?", "Configure program", MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2) != IDYES)
224 // call before we hook console handles
225 system("ver > ver.txt.tmp");
229 // pipe standard handles to this console
230 freopen("CONIN$", "r", stdin);
231 freopen("CONOUT$", "w", stdout);
232 freopen("CONOUT$", "w", stderr);
234 // Initialize the console values
235 g_hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
236 CONSOLE_SCREEN_BUFFER_INFO bufinf;
237 if(GetConsoleScreenBufferInfo(g_hStdout, &bufinf))
239 g_wOriginalColors = bufinf.wAttributes & 0x00FF;
240 g_wBackgroundColor = bufinf.wAttributes & 0x00F0;
244 g_wOriginalColors = FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN;
245 g_wBackgroundColor = 0;
256 std::cout << std::endl << "Welcome to the " << con_white_bright << "InspIRCd" << con_reset << " Configuration program! (" << con_white_bright << "interactive mode" << con_reset << ")" << std::endl
257 << con_white_bright << "Package maintainers: Type ./configure --help for non-interactive help" << con_reset << std::endl << std::endl
258 << "*** If you are unsure of any of these values, leave it blank for ***" << std::endl
259 << "*** standard settings that will work, and your server will run ***" << std::endl
260 << "*** using them. Please consult your IRC network admin if in doubt. ***" << std::endl << std::endl
261 << "Press " << con_white_bright << "<RETURN>" << con_reset << " to accept the default for any option, or enter" << std::endl
262 << "a new value. Please note: You will " << con_white_bright << "HAVE" << con_reset << " to read the docs" << std::endl
263 << "dir, otherwise you won't have a config file!" << std::endl << std::endl;
269 vector<string> extra_include_paths, extra_lib_paths;
270 string revision = get_git_commit();
272 char machine_text[MAX_PATH];
273 get_machine_info(machine_text, MAX_PATH);
276 FILE * fI = fopen("..\\src\\version.sh", "r");
279 fgets(version, sizeof(version), fI);
280 fgets(version, sizeof(version), fI);
293 strcpy(version, "InspIRCd-0.0.0");
295 string branch(version);
296 branch.erase(branch.find_last_of('.'));
298 std::cout << "Your operating system is: " << con_green << "Windows " <<
304 << con_reset << std::endl << "InspIRCd revision ID: " << con_green << ( (!revision.empty() && revision != "0") ? revision : "(Non-GIT build)" ) << con_reset << std::endl << std::endl
305 << con_white_bright << "Extra modules." << con_reset << std::endl;
306 if (get_bool_option("Do you want to compile any extra non-core modules?", false))
308 string extra_i_path = get_string_option("Extra include search paths separate by \";\"", ".");
309 string extra_l_path = get_string_option("Extra library search paths, separate by \";\"", ".");
311 extra_include_paths = get_dir_list(extra_i_path);
312 extra_lib_paths = get_dir_list(extra_l_path);
315 std::cout << con_white_bright << "All paths are relative to the binary directory." << con_reset << std::endl;
316 string base_path = get_string_option("In what directory do you wish to install the InspIRCd base?", "..");
317 string config_path = get_string_option("In what directory are the configuration files?", "conf");
318 string mod_path = get_string_option("In what directory are the modules to be compiled to?", "modules");
319 string data_path = get_string_option("In what directory is the variable data to be placed in?", "data");
320 string log_path = get_string_option("In what directory is the logs to be placed in?", "logs");
321 string bin_dir = get_string_option("In what directory is the IRCd binary to be placed?", ".");
323 std::cout << std::endl << con_green << "Pre-build configuration is complete!" << std::endl << std::endl;
327 // dump all the options back out
328 std::cout << con_reset << "Base install path:\t" << con_green << base_path << std::endl
329 << con_reset << "Config path:\t" << con_green << config_path << std::endl
330 << con_reset << "Module path:\t" << con_green << mod_path << std::endl
331 << con_reset << "Data path:\t"<< con_green << data_path << std::endl
332 << con_reset << "Log path:\t" << con_green << log_path << std::endl
333 << con_reset << "Socket Engine:\t" << con_green << "select" << con_reset << std::endl;
335 if(get_bool_option("Are these settings correct?", true) == false)
340 std::cout << std::endl;
343 escape_string(data_path);
344 escape_string(log_path);
345 escape_string(config_path);
346 escape_string(mod_path);
348 printf("\nWriting inspircd_config.h...");
349 FILE * f = fopen("..\\include\\inspircd_config.h", "w");
350 fprintf(f, "/* Auto generated by configure, do not modify! */\n");
351 fprintf(f, "#ifndef __CONFIGURATION_AUTO__\n");
352 fprintf(f, "#define __CONFIGURATION_AUTO__\n\n");
354 fprintf(f, "#define CONFIG_PATH \"%s\"\n", config_path.c_str());
355 fprintf(f, "#define MOD_PATH \"%s\"\n", mod_path.c_str());
356 fprintf(f, "#define DATA_PATH \"%s\"\n", data_path.c_str());
357 fprintf(f, "#define LOG_PATH \"%s\"\n", log_path.c_str());
358 fprintf(f, "#define SOMAXCONN_S \"128\"\n");
359 fprintf(f, "#define MAXBUF 514\n");
361 fprintf(f, "\n#include \"inspircd_win32wrapper.h\"");
362 fprintf(f, "\n#include \"threadengines/threadengine_win32.h\"\n\n");
363 fprintf(f, "#endif\n\n");
366 std::cout << con_green << "done" << con_reset << std::endl;
367 printf("Writing inspircd_version.h...");
368 f = fopen("..\\include\\inspircd_version.h", "w");
369 fprintf(f, "#define BRANCH \"%s\"\n", branch.c_str());
370 fprintf(f, "#define VERSION \"%s\"\n", version);
371 fprintf(f, "#define REVISION \"%s\"\n", revision.c_str());
372 fprintf(f, "#define SYSTEM \"%s\"\n", machine_text);
375 std::cout << con_green << "done" << con_reset << std::endl;
376 printf("Writing command and module compilation scripts...");
377 WriteCompileCommands();
378 WriteCompileModules(extra_include_paths, extra_lib_paths);
379 std::cout << con_green << "done" << con_reset << std::endl;
381 printf("\nconfigure is done.. exiting!\n");
384 /* Keeps files from modules/extra up to date if theyre copied into modules/ */
390 printf("\nUpdating extra modules in src/modules...\n");
393 HANDLE fh = FindFirstFileA("..\\src\\modules\\extra\\*.*", &fd);
395 if(fh == INVALID_HANDLE_VALUE)
400 strcpy(dest, "..\\src\\modules\\");
401 strcat(dest, fd.cFileName);
402 strcpy(src, "..\\src\\modules\\extra\\");
403 strcat(src, fd.cFileName);
404 FILE* x = fopen(dest, "r");
408 CopyFileA(src, dest, false);
409 std::cout << con_green << "\t" << fd.cFileName << con_reset << "..." << std::endl;
412 while (FindNextFileA(fh, &fd));
419 void WriteCompileCommands()
421 char commands[300][100];
422 int command_count = 0;
423 printf("\n Finding Command Sources...\n");
425 HANDLE fh = FindFirstFileA("..\\src\\commands\\cmd_*.cpp", &fd);
426 if(fh == INVALID_HANDLE_VALUE)
427 std::cout << con_green << " No command sources could be found! This *could* be a bad thing.. :P" << con_reset << std::endl;
430 std::cout << con_green;
433 strcpy(commands[command_count], fd.cFileName);
434 commands[command_count][strlen(fd.cFileName) - 4] = 0;
435 printf(" %s\n", commands[command_count]);
437 } while(FindNextFileA(fh, &fd));
438 std::cout << con_reset;
441 // Write our spiffy new makefile :D
442 // I am such a lazy fucker :P
443 FILE * f = fopen("..\\src\\commands\\commands.mak", "w");
445 time_t t = time(NULL);
446 fprintf(f, "# Generated at %s\n", ctime(&t));
447 fprintf(f, "all: makedir ");
449 // dump modules.. first time :)
450 for(int i = 0; i < command_count; ++i)
451 fprintf(f, "%s.so ", commands[i]);
453 fprintf(f, "\n.cpp.obj:\n");
457 fprintf(f, " cl /nologo /LD /Od /I \".\" /I \"../../include\" /I \"../../include/modes\" /I \"../../include/commands\" /I \"../../win\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"DLL_BUILD\" /Gm /EHsc /RTC1 /MDd /Fo\"Debug_x64/\" /Fd\"Debug_x64/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");
459 fprintf(f, " cl /nologo /LD /O2 /I \".\" /I \"../../include\" /I \"../../include/modes\" /I \"../../include/commands\" /I \"../../win\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"DLL_BUILD\" /Gm /EHsc /GL /MD /Fo\"Release_x64/\" /Fd\"Release_x64/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");
463 fprintf(f, " cl /nologo /LD /Od /I \".\" /I \"../../include\" /I \"../../include/modes\" /I \"../../include/commands\" /I \"../../win\" /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");
465 fprintf(f, " cl /nologo /LD /O2 /I \".\" /I \"../../include\" /I \"../../include/modes\" /I \"../../include/commands\" /I \"../../win\" /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");
469 fprintf(f, "makedir:\n");
471 CreateDirectoryA("..\\src\\commands\\" OUTFOLDER, NULL);
472 CreateDirectoryA("..\\bin\\" OUTFOLDER "\\modules", NULL);
473 fprintf(f, " if not exist ..\\..\\bin\\" OUTFOLDER "\\modules mkdir ..\\..\\bin\\" OUTFOLDER "\\modules\n");
474 fprintf(f, " if not exist ..\\..\\bin\\" OUTFOLDER "\\data mkdir ..\\..\\bin\\" OUTFOLDER "\\data\n");
475 fprintf(f, " if not exist ..\\..\\bin\\" OUTFOLDER "\\logs mkdir ..\\..\\bin\\" OUTFOLDER "\\logs\n");
477 // dump modules.. again the second and last time :)
478 for(int i = 0; i < command_count; ++i)
479 fprintf(f, "%s.so : %s.obj\n", commands[i], commands[i]);
485 void WriteCompileModules(const vector<string> &includes, const vector<string> &libs)
487 char modules[300][100];
488 int module_count = 0;
490 printf("Finding Modules...\n");
492 HANDLE fh = FindFirstFileA("..\\src\\modules\\m_*.cpp", &fd);
493 if(fh == INVALID_HANDLE_VALUE)
494 std::cout << con_green << " No module sources could be found! This *could* be a bad thing.. :P" << con_reset << std::endl;
497 std::cout << con_green;
500 strcpy(modules[module_count], fd.cFileName);
501 modules[module_count][strlen(fd.cFileName) - 4] = 0;
502 printf(" %s\n", modules[module_count]);
504 } while(FindNextFileA(fh, &fd));
505 std::cout << con_reset;
508 string extra_include, extra_lib;
509 for (unsigned i = 0; i < includes.size(); ++i)
510 extra_include += " /I \"" + includes[i] + "\" ";
511 for (unsigned i = 0; i < libs.size(); ++i)
512 extra_lib += " /LIBPATH:\"" + libs[i] + "\" ";
514 // Write our spiffy new makefile :D
515 // I am such a lazy fucker :P
516 FILE * f = fopen("..\\src\\modules\\modules.mak", "w");
518 time_t t = time(NULL);
519 fprintf(f, "# Generated at %s\n", ctime(&t));
520 fprintf(f, "all: makedir ");
522 // dump modules.. first time :)
523 for(int i = 0; i < module_count; ++i)
524 fprintf(f, "%s.so ", modules[i]);
526 fprintf(f, "\n.cpp.obj:\n");
530 fprintf(f, " cl /nologo /LD /Od /I \".\" /I \"../../include\" /I \"../../include/modes\" /I \"../../include/modules\" /I \"../../win\" %s /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"DLL_BUILD\" /Gm /EHsc /RTC1 /MDd /Fo\"Debug_x64/\" /Fd\"Debug_x64/vc90.pdb\" /W2 /Zi /TP $*.cpp ..\\..\\win\\inspircd_memory_functions.cpp /link %s ..\\..\\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", extra_include.c_str(), extra_lib.c_str());
532 fprintf(f, " cl /nologo /LD /O2 /I \".\" /I \"../../include\" /I \"../../include/modes\" /I \"../../include/modules\" /I \"../../win\" %s /D \"_CONSOLE\" /D \"_MBCS\" /D \"DLL_BUILD\" /Gm /EHsc /GL /MD /Fo\"Release_x64/\" /Fd\"Release_x64/vc90.pdb\" /W2 /Zi /TP $*.cpp ..\\..\\win\\inspircd_memory_functions.cpp /link %s ..\\..\\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", extra_include.c_str(), extra_lib.c_str());
536 fprintf(f, " cl /nologo /LD /Od /I \".\" /I \"../../include\" /I \"../../include/modes\" /I \"../../include/modules\" /I \"../../win\" %s /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 /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());
538 fprintf(f, " cl /nologo /LD /O2 /I \".\" /I \"../../include\" /I \"../../include/modes\" /I \"../../include/modules\" /I \"../../win\" %s /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 /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());
542 CreateDirectoryA("..\\src\\modules\\" OUTFOLDER, NULL);
545 fprintf(f, "makedir:\n if not exist debug mkdir debug\n\n");
547 fprintf(f, "makedir:\n if not exist release mkdir release\n\n");
550 // dump modules.. again the second and last time :)
551 for(int i = 0; i < module_count; ++i)
552 fprintf(f, "%s.so : %s.obj\n", modules[i], modules[i]);