dedicated.c
author bjarni
Wed, 29 Mar 2006 16:28:41 +0000
changeset 3354 88222b8dafef
parent 2294 a938c5ecb1c4
permissions -rw-r--r--
(svn r4149) -Codechange: [OSX] rewrite of how universal binaries are compiled
Now OSX stores object files in .OSX and instead of making FAT object files, there are one for each architecture
Each architecture got their own targets to make a non-FAT binary and in the end, lipo will merge them into one binary

It's now possible to select which architectures you want to support by defining OTTD_PPC, OTTD_PPC970 (G5) and/or OTTD_i386
All combos are supported. UNIVERSAL_BINARY and TRIPLE_BINARY can still be used even though it's possible to gain the same result by using the new flags
Making a universal build when you already got part of it compiled (say the PPC part), it will reuse it and only compile the i386 part to save time
Note: in some cases when you switch flags, you risk that openttd is not updated. Delete it and try again. The Makefile can't solve this except if it forces linking each time

This fixes: FS#87 universal binary building borked in 0.4.7
Now universal binaries work on OSX 10.3.9 again

Building universal binaries no longer needs to store flags in Makefile.config as the new design makes it possible to figure everything out automatically
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2177
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2177
diff changeset
     2
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     3
#include "stdafx.h"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     4
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     5
#ifdef ENABLE_NETWORK
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     6
2195
8960c86bf103 (svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents: 2186
diff changeset
     7
#if defined(UNIX) && !defined(__MORPHOS__)
8960c86bf103 (svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents: 2186
diff changeset
     8
8960c86bf103 (svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents: 2186
diff changeset
     9
#include "openttd.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 1959
diff changeset
    10
#include "variables.h"
781
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    11
2195
8960c86bf103 (svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents: 2186
diff changeset
    12
#include <sys/types.h>
8960c86bf103 (svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents: 2186
diff changeset
    13
#include <unistd.h>
2177
73d67828ea5e (svn r2691) Separate dedicated video driver and fix bemidi declarations
tron
parents: 2163
diff changeset
    14
774
258c11431acb (svn r1240) -Fix: OpenTTD once again compiles if ENABLE_NETWORK is disabled.
darkvater
parents: 770
diff changeset
    15
void DedicatedFork(void)
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    16
{
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    17
	/* Fork the program */
1406
2d5baabe4046 (svn r1910) Move two variables out of variables.h which are only used locally
tron
parents: 1301
diff changeset
    18
	pid_t pid = fork();
2d5baabe4046 (svn r1910) Move two variables out of variables.h which are only used locally
tron
parents: 1301
diff changeset
    19
	switch (pid) {
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    20
		case -1:
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    21
			perror("Unable to fork");
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    22
			exit(1);
2294
a938c5ecb1c4 (svn r2818) Don't tell the world about a local variable which is only used once
tron
parents: 2195
diff changeset
    23
a938c5ecb1c4 (svn r2818) Don't tell the world about a local variable which is only used once
tron
parents: 2195
diff changeset
    24
		case 0: { // We're the child
a938c5ecb1c4 (svn r2818) Don't tell the world about a local variable which is only used once
tron
parents: 2195
diff changeset
    25
			FILE* f;
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    26
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    27
			/* Open the log-file to log all stuff too */
2294
a938c5ecb1c4 (svn r2818) Don't tell the world about a local variable which is only used once
tron
parents: 2195
diff changeset
    28
			f = fopen(_log_file, "a");
a938c5ecb1c4 (svn r2818) Don't tell the world about a local variable which is only used once
tron
parents: 2195
diff changeset
    29
			if (f == NULL) {
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    30
				perror("Unable to open logfile");
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    31
				exit(1);
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    32
			}
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    33
			/* Redirect stdout and stderr to log-file */
2294
a938c5ecb1c4 (svn r2818) Don't tell the world about a local variable which is only used once
tron
parents: 2195
diff changeset
    34
			if (dup2(fileno(f), fileno(stdout)) == -1) {
1626
6429294a2009 (svn r2130) Various spelling fixes in messages.
pasky
parents: 1614
diff changeset
    35
				perror("Rerouting stdout");
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    36
				exit(1);
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    37
			}
2294
a938c5ecb1c4 (svn r2818) Don't tell the world about a local variable which is only used once
tron
parents: 2195
diff changeset
    38
			if (dup2(fileno(f), fileno(stderr)) == -1) {
1626
6429294a2009 (svn r2130) Various spelling fixes in messages.
pasky
parents: 1614
diff changeset
    39
				perror("Rerouting stderr");
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    40
				exit(1);
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    41
			}
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    42
			break;
2294
a938c5ecb1c4 (svn r2818) Don't tell the world about a local variable which is only used once
tron
parents: 2195
diff changeset
    43
		}
a938c5ecb1c4 (svn r2818) Don't tell the world about a local variable which is only used once
tron
parents: 2195
diff changeset
    44
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    45
		default:
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    46
			// We're the parent
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    47
			printf("Loading dedicated server...\n");
1406
2d5baabe4046 (svn r1910) Move two variables out of variables.h which are only used locally
tron
parents: 1301
diff changeset
    48
			printf("  - Forked to background with pid %d\n", pid);
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    49
			exit(0);
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    50
	}
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    51
}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    52
#endif
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    53
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    54
#else
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    55
774
258c11431acb (svn r1240) -Fix: OpenTTD once again compiles if ENABLE_NETWORK is disabled.
darkvater
parents: 770
diff changeset
    56
void DedicatedFork(void) {}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    57
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    58
#endif /* ENABLE_NETWORK */