2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * doconfig.c: Generates the gamesdef.h file used to build the game, and
29 * the various make include files needed to build correctly.
31 * Known contributors to this file:
32 * Steve McClure, 1996-2000
36 #include <sys/types.h>
46 #define mkdir(dir,perm) _mkdir(dir)
50 static void wrmakesrc(char *pathname);
51 static void wripglob(char *filename);
52 static void wrauth(char *filename);
53 static void wrgamesdef(char *filename);
55 char *copyright_header =
57 " * Empire - A multi-player, client/server Internet based war game.\n"
58 " * Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,\n"
59 " * Ken Stevens, Steve McClure\n"
61 " * This program is free software; you can redistribute it and/or modify\n"
62 " * it under the terms of the GNU General Public License as published by\n"
63 " * the Free Software Foundation; either version 2 of the License, or\n"
64 " * (at your option) any later version.\n"
66 " * This program is distributed in the hope that it will be useful,\n"
67 " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
68 " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
69 " * GNU General Public License for more details.\n"
71 " * You should have received a copy of the GNU General Public License\n"
72 " * along with this program; if not, write to the Free Software\n"
73 " * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n"
77 " * See the \"LEGAL\", \"LICENSE\", \"CREDITS\" and \"README\" files for all the\n"
78 " * related information and legal notices. It is expected that any future\n"
79 " * projects/authors will amend these files as needed.\n"
85 " * Known contributors to this file:\n"
86 " * Automatically generated by doconfig.c\n"
89 #if defined(__GLIBC__) || defined(FBSD) || defined(__APPLE_) || defined(_WIN32)
90 #define safe_getcwd() getcwd(NULL, 0)
98 char *buf = malloc(size);
101 if (getcwd (buf, size))
118 if ((pathname = safe_getcwd()) == NULL) {
119 printf("Can't get current path!\n");
123 cp = strrchr(pathname, '/');
125 cp = strrchr(pathname, '/');
128 cp = strrchr(pathname, '\\');
130 cp = strrchr(pathname, '\\');
133 printf("Configuring...\n");
135 sprintf(buf, "%s/include/gamesdef.h", pathname);
137 sprintf(buf, "%s/src/client/ipglob.c", pathname);
141 printf("making directory %s\n", EP);
142 if (mkdir(EP, 0755)) {
143 printf("mkdir failed on %s, exiting.\n", EP);
147 sprintf(buf, "%s/data", EP);
148 if (access(buf, 0)) {
149 printf("making directory %s\n", buf);
150 if (mkdir(buf, 0755)) {
151 printf("mkdir failed on %s, exiting.\n", buf);
155 sprintf(buf, "%s/data/auth", EP);
161 wrmakesrc(char *pathname)
166 sprintf(buf, "%s/src/make.src", pathname);
167 if ((fp = fopen(buf, "wb")) == NULL) {
168 printf("Cannot open %s for writing, exiting.\n", buf);
172 "# make.src: Source tree absolute pathname - auto generated.\n\n");
173 fprintf(fp, "SRCDIR = %s\n", pathname);
178 wripglob(char *filename)
182 printf("Writing %s\n", filename);
183 if ((fp = fopen(filename, "wb")) == NULL) {
184 printf("Cannot open %s for writing, exiting.\n", filename);
187 fprintf(fp, copyright_header,
188 strrchr(filename, '/')+1, "IP globals.");
189 fprintf(fp, "char empirehost[] = \"%s\";\n", HN);
190 fprintf(fp, "char empireport[] = \"%d\";\n", PN);
195 wrauth(char *filename)
199 printf("Writing %s\n", filename);
200 if ((fp = fopen(filename, "w")) == NULL) {
201 printf("Cannot open %s for writing, exiting.\n", filename);
206 "# %s: Empire Authorization File\n"
207 "# Users listed will be allowed to log in as deities.\n#\n",
208 strrchr(filename, '/')+1);
209 fprintf(fp, "# Format is:\n");
210 fprintf(fp, "# hostname that authorized user uses on a line\n");
211 fprintf(fp, "# username that authorized user uses on a line\n#\n");
212 fprintf(fp, "# REMEMBER TO USE PAIRS OF LINES!\n#\n");
213 fprintf(fp, "# Example:\n#\n");
214 fprintf(fp, "#nowhere.land.edu\n#nowhereman\n");
215 fprintf(fp, "%s\n%s\n", HN, UN);
216 fprintf(fp, "%s\n%s\n", IP, UN);
217 fprintf(fp, "127.0.0.1\n%s\n", UN);
222 wrgamesdef(char *filename)
233 for (i = 0; i < strlen(EP); i++) {
242 c = buf[strlen(buf) - 1];
243 if (strchr("dhm", c) && strlen(buf) > 0) {
247 (((double)s_p_etu * 60.0 * 60.0 * 24.0) / (double)ET);
249 s_p_etu = (((double)s_p_etu * 60.0 * 60.0) / (double)ET);
251 s_p_etu = (((double)s_p_etu * 60.0) / (double)ET);
253 printf("ETU frequency is bad - using 10 minutes.\n");
257 printf("Writing %s\n", filename);
258 if ((fp = fopen(filename, "wb")) == NULL) {
259 printf("Cannot open %s for writing, exiting.\n", filename);
262 fprintf(fp, copyright_header,
263 strrchr(filename,'/')+1, "Server compile-time configuration");
264 fprintf(fp, "/*\n * Feel free to change these, but if you rerun doconfig this file will\n");
265 fprintf(fp, " * be overwritten again.\n");
266 fprintf(fp, " */\n\n");
267 fprintf(fp, "#ifndef _GAMESDEF_H_\n");
268 fprintf(fp, "#define _GAMESDEF_H_\n\n");
269 fprintf(fp, "#define EMPDIR \"%s\"\n", EP);
270 fprintf(fp, "#define PRVNAM \"%s\"\n", PV);
271 fprintf(fp, "#define PRVLOG \"%s\"\n", EM);
272 fprintf(fp, "#define GET_SOURCE \"using:\\n http://www.wolfpackempire.com/\"\n");
273 fprintf(fp, "#define EMP_HOST \"%s\"\n", IP);
274 fprintf(fp, "#define EMP_PORT \"%d\"\n\n", PN);
275 fprintf(fp, "#define MAXNOC %d\n\n", MC);
276 fprintf(fp, "#define DEF_WORLD_X %d\n", WX);
277 fprintf(fp, "#define DEF_WORLD_Y %d\n\n", WY);
278 fprintf(fp, "#define DEF_S_P_ETU %d\n", s_p_etu);
279 fprintf(fp, "#define ETUS %d\n\n", ET);
281 fprintf(fp, "#define BLITZ 1\n\n");
282 fprintf(fp, "#endif /* _GAMESDEF_H_ */\n");