1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 #define _CRT_SECURE_NO_DEPRECATE
16 #include <windows.h>
\r
20 #include "colours.h"
\r
25 void WriteCompileModules();
26 void WriteCompileCommands();
28 /* detects if we are running windows xp or higher (5.1) */
32 vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
34 if(vi.dwMajorVersion >= 5)
40 int get_int_option(const char * text, int def)
42 static char buffer[500];
44 printf_c("%s\n[\033[1;32m%u\033[0m] -> ", text, def);
45 fgets(buffer, 500, stdin);
46 if(sscanf(buffer, "%u", &ret) != 1)
53 bool get_bool_option(const char * text, bool def)
55 static char buffer[500];
57 printf_c("%s [\033[1;32m%c\033[0m] -> ", text, def ? 'y' : 'n');
58 fgets(buffer, 500, stdin);
59 if(sscanf(buffer, "%s", ret) != 1)
60 strcpy(ret, def ? "y" : "n");
63 return !strncmp(ret, "y", 1);
66 void get_string_option(const char * text, char * def, char * buf)
68 static char buffer[500];
69 printf_c("%s\n[\033[1;32m%s\033[0m] -> ", text, def);
70 fgets(buffer, 500, stdin);
71 if(sscanf(buffer, "%s", buf) != 1)
77 // escapes a string for use in a c++ file
78 bool escape_string(char * str, size_t size)
80 size_t len = strlen(str);
81 char * d_str = (char*)malloc(len * 2);
112 /* gets the svn revision */
113 int get_svn_revision(char * buffer, size_t len)
115 /* again.. I am lazy :p cbf to pipe output of svn info to us, so i'll just read the file */
123 FILE * f = fopen("..\\.svn\\entries", "r");
126 if(!fgets(buf, 1000, f)) goto bad_rev;
127 if(!fgets(buf, 1000, f)) goto bad_rev;
128 if(!fgets(buf, 1000, f)) goto bad_rev;
129 if(!fgets(buf, 1000, f)) goto bad_rev;
131 if(rev == 0) goto bad_rev;
132 sprintf(buffer, "%u", rev);
137 strcpy(buffer, "non-svn");
142 int __stdcall WinMain(IN HINSTANCE hInstance, IN HINSTANCE hPrevInstance, IN LPSTR lpCmdLine, IN int nShowCmd )
144 FILE * j = fopen("inspircd_config.h", "r");
147 if (MessageBox(0, "inspircd_config.h already exists. Remove it and build from clean?", "Configure program", MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2) != IDYES)
156 // pipe standard handles to this console
157 freopen("CONIN$", "r", stdin);
158 freopen("CONOUT$", "w", stdout);
159 freopen("CONOUT$", "w", stderr);
163 WriteCompileCommands();
164 WriteCompileModules();
171 printf_c("\nWelcome to the \033[1mInspIRCd\033[0m Configuration program! (\033[1minteractive mode\033[0m)\n"
172 "\033[1mPackage maintainers: Type ./configure --help for non-interactive help\033[0m\n\n");
173 printf_c("*** If you are unsure of any of these values, leave it blank for ***\n"
174 "*** standard settings that will work, and your server will run ***\n"
175 "*** using them. Please consult your IRC network admin if in doubt. ***\n\n"
176 "Press \033[1m<RETURN>\033[0m to accept the default for any option, or enter\n"
177 "a new value. Please note: You will \033[1mHAVE\033[0m to read the docs\n"
178 "dir, otherwise you won't have a config file!\n\n");
185 bool use_iocp = false;
186 bool support_ip6links = false;
187 char mod_path[MAX_PATH];
188 char config_file[MAX_PATH];
189 char library_dir[MAX_PATH];
190 char base_path[MAX_PATH];
191 char bin_dir[MAX_PATH];
192 char revision_text[MAX_PATH];
194 int max_clients = 1024;
197 int modechanges = 20;
204 int revision = get_svn_revision(revision_text, MAX_PATH);
208 FILE * fI = fopen("..\\src\\version.sh", "r");
211 fgets(version, 514, fI);
212 fgets(version, 514, fI);
225 strcpy(version, "InspIRCD-Unknown");
227 printf_c("Your operating system is: \033[1;32mwindows_x64 \033[0m\n");
229 printf_c("Your operating system is: \033[1;32mwindows_x32 \033[0m\n");
231 printf_c("InspIRCd revision ID: \033[1;32m%s \033[0m\n\n", revision ? revision_text : "(Non-SVN build)");
233 max_fd = get_int_option("What is the maximum file descriptor count you would like to allow?", 1024);
238 printf_c("You are running Windows 2000 or above, and IOCP support is most likely available.\n"
239 "This removes the socket number limitation of select and is much more efficent.\n"
240 "If you are unsure, answer yes.\n\n");
242 use_iocp = get_bool_option("Do you want to use the IOCP implementation?", true);
245 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)",
248 printf_c("\033[1mAll paths are relative to the binary directory.\033[0m\n");
249 get_string_option("In what directory do you wish to install the InspIRCd base?", "..", base_path);
250 get_string_option("In what directory are the configuration files?", "../conf", config_file);
251 get_string_option("In what directory are the modules to be compiled to?", "../modules", mod_path);
252 get_string_option("In what directory is the IRCd binary to be placed?", ".", bin_dir);
253 get_string_option("In what directory are the IRCd libraries to be placed?", "../lib", library_dir);
255 printf_c("The following questions will ask you for various figures relating\n"
256 "To your IRCd install. Please note that these should usually be left\n"
257 "as defaults unless you have a real reason to change them. If they\n"
258 "changed, then the values must be identical on all servers on your\n"
259 "network, or malfunctions and/or crashes may occur, with the exception\n"
260 "of the 'maximum number of clients' setting which may be different on\n"
261 "different servers on the network.\n\n");
264 max_clients = get_int_option("Please enter the maximum number of clients at any one time?", 1024);
265 nicklen = get_int_option("Please enter the maximum length of nicknames?", 31);
266 chanlen = get_int_option("Please enter the maximum length of channel names?", 64);
267 modechanges = get_int_option("Please enter the maximum number of mode changes in one line?", 20);
268 identlen = get_int_option("Please enter the maximum length of an ident (username)?", 12);
269 quitlen = get_int_option("Please enter the maximum length of a quit message?", 255);
270 topiclen = get_int_option("Please enter the maximum length of a channel topic?", 307);
271 kicklen = get_int_option("Please enter the maximum length of a kick message?", 255);
272 rllen = get_int_option("Please enter the maximum length of a GECOS (real name)?", 128);
273 awaylen = get_int_option("Please enter the maximum length of an away message?", 200);
275 printf_c("\n\033[1;32mPre-build configuration is complete!\n\n"); sc(TNORMAL);
277 // dump all the options back out
278 printf_c("\033[0mBase install path:\033[1;32m %s\n", base_path);
279 printf_c("\033[0mConfig path:\033[1;32m %s\n", config_file);
280 printf_c("\033[0mModule path:\033[1;32m %s\n", mod_path);
281 printf_c("\033[0mLibrary path:\033[1;32m %s\n", library_dir);
282 printf_c("\033[0mSocket Engine:\033[1;32m %s\n", use_iocp ? "iocp" : "select");
283 printf_c("\033[0mMax file descriptors:\033[1;32m %u\n", max_fd);
284 printf_c("\033[0mMax connections:\033[1;32m %u\n", max_clients);
285 printf_c("\033[0mMax nickname length:\033[1;32m %u\n", nicklen);
286 printf_c("\033[0mMax channel length:\033[1;32m %u\n", chanlen);
287 printf_c("\033[0mMax mode length:\033[1;32m %u\n", modechanges);
288 printf_c("\033[0mMax ident length:\033[1;32m %u\n", identlen);
289 printf_c("\033[0mMax quit length:\033[1;32m %u\n", quitlen);
290 printf_c("\033[0mMax topic length:\033[1;32m %u\n", topiclen);
291 printf_c("\033[0mMax kick length:\033[1;32m %u\n", kicklen);
292 printf_c("\033[0mMax name length:\033[1;32m %u\n", rllen);
293 printf_c("\033[0mMax away length:\033[1;32m %u\n", awaylen);
294 printf("\n"); sc(TNORMAL);
295 if(get_bool_option("Are these settings correct?", true) == false)
303 escape_string(config_file, MAX_PATH);
304 escape_string(mod_path, MAX_PATH);
305 escape_string(library_dir, MAX_PATH);
307 printf("\nWriting inspircd_config.h...");
308 FILE * f = fopen("inspircd_config.h", "w");
309 fprintf(f, "/* Auto generated by configure, do not modify! */\n");
310 fprintf(f, "#ifndef __CONFIGURATION_AUTO__\n");
311 fprintf(f, "#define __CONFIGURATION_AUTO__\n\n");
313 fprintf(f, "#define CONFIG_USE_IOCP 1\n\n");
315 fprintf(f, "#define CONFIG_FILE \"%s/inspircd.conf\"\n", config_file);
316 fprintf(f, "#define MOD_PATH \"%s\"\n", mod_path);
317 fprintf(f, "#define MAX_DESCRIPTORS %u\n", max_fd);
318 fprintf(f, "#define MAXCLIENTS %u\n", max_clients);
319 fprintf(f, "#define MAXCLIENTS_S \"%u\"\n", max_clients);
320 fprintf(f, "#define SOMAXCONN_S \"128\"\n");
321 fprintf(f, "#define NICKMAX %u\n", nicklen+1);
322 fprintf(f, "#define CHANMAX %u\n", chanlen+1);
323 fprintf(f, "#define MAXMODES %u\n", modechanges);
324 fprintf(f, "#define IDENTMAX %u\n", identlen);
325 fprintf(f, "#define MAXQUIT %u\n", quitlen);
326 fprintf(f, "#define MAXTOPIC %u\n", topiclen);
327 fprintf(f, "#define MAXKICK %u\n", kicklen);
328 fprintf(f, "#define MAXGECOS %u\n", rllen);
329 fprintf(f, "#define MAXAWAY %u\n", awaylen);
330 fprintf(f, "#define LIBRARYDIR \"%s\"\n", library_dir);
331 fprintf(f, "#define VERSION \"%s\"\n", version);
332 fprintf(f, "#define REVISION \"%s\"\n", revision_text);
334 fprintf(f, "#define SUPPORT_IP6LINKS 1\n");
337 vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
340 fprintf(f, "#define SYSTEM \"Windows_x64 %u.%u.%u %s\"\n", vi.dwMajorVersion, vi.dwMinorVersion, vi.dwBuildNumber, vi.szCSDVersion);
342 fprintf(f, "#define SYSTEM \"Windows_x32 %u.%u.%u %s\"\n", vi.dwMajorVersion, vi.dwMinorVersion, vi.dwBuildNumber, vi.szCSDVersion);
344 fprintf(f, "#define MAXBUF 514\n");
346 fprintf(f, "\n#include \"inspircd_win32wrapper.h\"\n\n");
347 fprintf(f, "#endif\n\n");
350 sc(TGREEN); printf(" done\n"); sc(TNORMAL);
351 printf("Writing inspircd_se_config.h...");
353 f = fopen("inspircd_se_config.h", "w");
354 fprintf(f, "/* Auto generated by configure, do not modify or commit to svn! */\n");
355 fprintf(f, "#ifndef __CONFIGURATION_SOCKETENGINE__\n");
356 fprintf(f, "#define __CONFIGURATION_SOCKETENGINE__\n\n");
357 fprintf(f, "#include \"socketengine_%s.h\"\n\n", use_iocp ? "iocp" : "select");
358 fprintf(f, "#endif\n\n");
361 sc(TGREEN); printf(" done\n"); sc(TNORMAL);
362 printf("Writing command and module compilation scripts...");
363 WriteCompileCommands();
364 WriteCompileModules();
365 sc(TGREEN); printf(" done\n"); sc(TNORMAL);
367 printf("\nconfigure is done.. exiting!\n");
370 void WriteCompileCommands()
372 char commands[300][100];
373 int command_count = 0;
374 printf("\n Finding Command Sources...\n");
376 HANDLE fh = FindFirstFile("..\\src\\cmd_*.cpp", &fd);
377 if(fh == INVALID_HANDLE_VALUE)
378 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");
384 strcpy(commands[command_count], fd.cFileName);
385 commands[command_count][strlen(fd.cFileName) - 4] = 0;
386 printf(" %s\n", commands[command_count]);
388 } while(FindNextFile(fh, &fd));
392 // Write our spiffy new makefile :D
393 // I am such a lazy fucker :P
394 FILE * f = fopen("..\\src\\commands.mak", "w");
396 time_t t = time(NULL);
397 fprintf(f, "# Generated at %s\n", ctime(&t));
398 fprintf(f, "all: makedir ");
400 // dump modules.. first time :)
401 for(int i = 0; i < command_count; ++i)
402 fprintf(f, "%s.so ", commands[i]);
404 fprintf(f, "\n.cpp.obj:\n");
408 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 /MTd /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");
409 CreateDirectory("..\\src\\debug", NULL);
410 CreateDirectory("..\\bin\\debug\\bin", NULL);
411 CreateDirectory("..\\bin\\debug\\lib", NULL);
412 CreateDirectory("..\\bin\\debug\\modules", NULL);
414 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 /MT /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");
415 CreateDirectory("..\\src\\release", NULL);
416 CreateDirectory("..\\bin\\release\\bin", NULL);
417 CreateDirectory("..\\bin\\release\\lib", NULL);
418 CreateDirectory("..\\bin\\release\\modules", NULL);
422 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 /MTd /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");
423 CreateDirectory("..\\src\\debug", NULL);
424 CreateDirectory("..\\bin\\debug\\bin", NULL);
425 CreateDirectory("..\\bin\\debug\\lib", NULL);
426 CreateDirectory("..\\bin\\debug\\modules", NULL);
428 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 /MT /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");
429 CreateDirectory("..\\src\\release", NULL);
430 CreateDirectory("..\\bin\\release\\bin", NULL);
431 CreateDirectory("..\\bin\\release\\lib", NULL);
432 CreateDirectory("..\\bin\\release\\modules", NULL);
436 fprintf(f, "makedir:\n if not exist debug mkdir debug\n\n");
438 // dump modules.. again the second and last time :)
439 for(int i = 0; i < command_count; ++i)
440 fprintf(f, "%s.so : %s.obj\n", commands[i], commands[i]);
446 void WriteCompileModules()
448 char modules[300][100];
449 int module_count = 0;
451 printf("Finding Modules...\n");
453 HANDLE fh = FindFirstFile("..\\src\\modules\\m_*.cpp", &fd);
454 if(fh == INVALID_HANDLE_VALUE)
455 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");
461 strcpy(modules[module_count], fd.cFileName);
462 modules[module_count][strlen(fd.cFileName) - 4] = 0;
463 printf(" %s\n", modules[module_count]);
465 } while(FindNextFile(fh, &fd));
469 // Write our spiffy new makefile :D
470 // I am such a lazy fucker :P
471 FILE * f = fopen("..\\src\\modules\\modules.mak", "w");
473 time_t t = time(NULL);
474 fprintf(f, "# Generated at %s\n", ctime(&t));
475 fprintf(f, "all: makedir ");
477 // dump modules.. first time :)
478 for(int i = 0; i < module_count; ++i)
479 fprintf(f, "%s.so ", modules[i]);
481 fprintf(f, "\n.cpp.obj:\n");
485 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 /MTd /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");
486 CreateDirectory("..\\src\\modules\\debug_x64", NULL);
488 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 /MT /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");
489 CreateDirectory("..\\src\\modules\\release_x64", NULL);
493 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 /MTd /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");
494 CreateDirectory("..\\src\\modules\\debug", NULL);
496 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 /MT /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");
497 CreateDirectory("..\\src\\modules\\release", NULL);
501 fprintf(f, "makedir:\n if not exist debug mkdir debug\n\n");
503 // dump modules.. again the second and last time :)
504 for(int i = 0; i < module_count; ++i)
505 fprintf(f, "%s.so : %s.obj\n", modules[i], modules[i]);