summaryrefslogtreecommitdiff
path: root/os/macosx
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-03-29 16:28:41 +0000
committerbjarni <bjarni@openttd.org>2006-03-29 16:28:41 +0000
commitf6662e056ddbf15463827b524a343b67dd5a3440 (patch)
tree1e4688cde558014e598671f4a0d212ecd112c4ce /os/macosx
parentc2bb4a052efad837d80adff0211c8a1df15ca7db (diff)
downloadopenttd-f6662e056ddbf15463827b524a343b67dd5a3440.tar.xz
(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
Diffstat (limited to 'os/macosx')
-rw-r--r--os/macosx/Makefile96
-rw-r--r--os/macosx/Makefile.setup86
2 files changed, 134 insertions, 48 deletions
diff --git a/os/macosx/Makefile b/os/macosx/Makefile
index a9c0d6c3a..a8c276362 100644
--- a/os/macosx/Makefile
+++ b/os/macosx/Makefile
@@ -2,29 +2,79 @@
# This makefile is not a standalone makefile, but is called from the general one
# it contains targets specific to MacOS X
-ifdef TRIPLE_BINARY
-# this is to add G5_FLAGS to ppc970 builds only. If the ability to add flags to a single arch only shows up in the future
-# we can get rid of this. Xcode supports arch dependant flags, but we can't do it in the makefile (yet?)
-%.o: %.c $(MAKE_CONFIG)
- @echo '===> Compiling $<'
- $(Q)$(CC) $(CFLAGS) $(CDEFS) -arch ppc -c -arch i386 -o $@.uni $<
- $(Q)$(CC) $(CFLAGS) $(CDEFS) $(G5_FLAGS) -arch ppc970 -c -o $@.ppc970 $<
- $(Q)lipo -create -output $@ $@.uni $@.ppc970
- $(Q)rm $@.uni $@.ppc970
-
-%.o: %.cpp $(MAKE_CONFIG)
- @echo '===> Compiling $<'
- $(Q)$(CXX) $(CFLAGS) $(CDEFS) -arch ppc -arch i386 -c -o $@.uni $<
- $(Q)$(CXX) $(CFLAGS) $(CDEFS) $(G5_FLAGS) -arch ppc970 -c -o $@.ppc970 $<
- $(Q)lipo -create -output $@ $@.uni $@.ppc970
- $(Q)rm $@.uni $@.ppc970
-
-%.o: %.m $(MAKE_CONFIG)
- @echo '===> Compiling $<'
- $(Q)$(CC) $(CFLAGS) $(CDEFS) -arch ppc -arch i386 -c -o $@.uni $<
- $(Q)$(CC) $(CFLAGS) $(CDEFS) -arch ppc970 $(G5_FLAGS) -c -o $@.ppc970 $<
- $(Q)lipo -create -output $@ $@.uni $@.ppc970
- $(Q)rm $@.uni $@.ppc970
+ifdef NATIVE_OSX
+
+DEPS_MAGIC := $(shell mkdir -p $(sort $(dir $(OBJS:%.o=.OSX/%))))
+
+ifdef OTTD_PPC
+OTTD_PPC :=.OSX/openttd.ppc
+OBJS_ppc := $(OBJS:%.o=.OSX/%.o.ppc)
+endif
+
+ifdef OTTD_i386
+OTTD_i386 :=.OSX/openttd.i386
+OBJS_i386 := $(OBJS:%.o=.OSX/%.o.i386)
+endif
+
+ifdef OTTD_PPC970
+OTTD_PPC970 :=.OSX/openttd.ppc970
+OBJS_ppc970 := $(OBJS:%.o=.OSX/%.o.ppc970)
+endif
+
+# targets to link OpenTTD
+$(TTD): $(OTTD_PPC) $(OTTD_i386) $(OTTD_PPC970)
+ @echo '===> Linking $@ into a single file'
+ $(Q)lipo -create -output $@ $(OTTD_PPC) $(OTTD_i386) $(OTTD_PPC970)
+
+$(OTTD_PPC): $(MAKE_CONFIG) $(OBJS_ppc)
+ @echo '[PowerPC] Linking $(TTD)'
+ $(Q)$(CC) $(LDFLAGS) $(TTDLDFLAGS) $(OBJS_ppc) $(LIBS) $(LDFLAGS_PPC) -arch ppc -o $@
+
+$(OTTD_i386): $(MAKE_CONFIG) $(OBJS_i386)
+ @echo '[i386] Linking $(TTD)'
+ $(Q)$(CC) $(LDFLAGS) $(TTDLDFLAGS) $(OBJS_i386) $(LIBS) $(LDFLAGS_i386) -arch i386 -o $@
+
+$(OTTD_PPC970): $(MAKE_CONFIG) $(OBJS_ppc970)
+ @echo '[PowerPC G5] Linking $(TTD)'
+ $(Q)$(CC) $(LDFLAGS) $(TTDLDFLAGS) $(OBJS_ppc970) $(LIBS) $(LDFLAGS_PPC) $(G5_FLAGS) -arch ppc970 -o $@
+
+# targets to compile each c, m and cpp file
+.OSX/%.o.ppc: %.c .deps/%.d
+ @echo '[PowerPC] Compiling $<'
+ $(Q)$(CC) $(CFLAGS) $(CFLAGS_PPC) $(CDEFS) -arch ppc -c -o $@ $<
+
+.OSX/%.o.ppc: %.cpp .deps/%.d
+ @echo '[PowerPC] Compiling $<'
+ $(Q)$(CPP) $(CFLAGS) $(CFLAGS_PPC) $(CDEFS) -arch ppc -c -o $@ $<
+
+.OSX/%.o.ppc: %.m .deps/%.d
+ @echo '[PowerPC] Compiling $<'
+ $(Q)$(CC) $(CFLAGS) $(CFLAGS_PPC) $(CDEFS) -arch ppc -c -o $@ $<
+
+.OSX/%.o.i386: %.c .deps/%.d
+ @echo '[i386] Compiling $<'
+ $(Q)$(CC) $(CFLAGS) $(CFLAGS_i386) $(CDEFS) -arch i386 -c -o $@ $<
+
+.OSX/%.o.i386: %.cpp .deps/%.d
+ @echo '[i386] Compiling $<'
+ $(Q)$(CPP) $(CFLAGS) $(CFLAGS_i386) $(CDEFS) -arch i386 -c -o $@ $<
+
+.OSX/%.o.i386: %.m .deps/%.d
+ @echo '[i386] Compiling $<'
+ $(Q)$(CC) $(CFLAGS) $(CFLAGS_i386) $(CDEFS) -arch i386 -c -o $@ $<
+
+.OSX/%.o.ppc970: %.c .deps/%.d
+ @echo '[PowerPC G5] Compiling $<'
+ $(Q)$(CC) $(CFLAGS) $(CFLAGS_PPC) $(G5_FLAGS) $(CDEFS) -arch ppc970 -c -o $@ $<
+
+.OSX/%.o.ppc970: %.cpp .deps/%.d
+ @echo '[PowerPC G5] Compiling $<'
+ $(Q)$(CPP) $(CFLAGS) $(CFLAGS_PPC) $(G5_FLAGS) $(CDEFS) -arch ppc970 -c -o $@ $<
+
+.OSX/%.o.ppc970: %.m .deps/%.d
+ @echo '[PowerPC G5] Compiling $<'
+ $(Q)$(CC) $(CFLAGS) $(CFLAGS_PPC) $(G5_FLAGS) $(CDEFS) -arch ppc970 -c -o $@ $<
+
endif
ifdef JAGUAR
diff --git a/os/macosx/Makefile.setup b/os/macosx/Makefile.setup
index 159bf0aa5..252eb8b60 100644
--- a/os/macosx/Makefile.setup
+++ b/os/macosx/Makefile.setup
@@ -18,7 +18,7 @@ endif
ifdef TRIPLE_BINARY
ifdef DEBUG
-$(error no G5 optimisation is made in debug builds, so tripple binaries aren't possible. Use UNIVERSAL_BINARY instead if you really want a universal debug build)
+$(error no G5 optimisation is made in debug builds, so triple binaries aren't possible. Use UNIVERSAL_BINARY instead if you really want a universal debug build)
endif
UNIVERSAL_BINARY:=1
endif
@@ -36,24 +36,16 @@ $(warning Compiling a release build, that is a debug build)
endif
endif
-# setup flags if none are defined
-ifndef CFLAGS_JAGUAR
- CFLAGS_JAGUAR:= -isysroot /Developer/SDKs/MacOSX10.2.8.sdk
-endif
-ifndef LDFLAGS_JAGUAR
- LDFLAGS_JAGUAR:= -Wl,-syslibroot,/Developer/SDKs/MacOSX10.2.8.sdk
+ifeq ($(shell uname), Darwin)
+ # it's a hardware mac, not crosscompiling
+ NATIVE_OSX:=1
endif
-ifndef CFLAGS_UNIVERSAL
- CFLAGS_UNIVERSAL:= -isysroot /Developer/SDKs/MacOSX10.4u.sdk
+ifndef PPC_OSX_TARGET
+PPC_OSX_TARGET:=10.3.9
endif
-ifndef LDFLAGS_UNIVERSAL
- LDFLAGS_UNIVERSAL:= -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk
-endif
-
-ifdef JAGUAR
- CFLAGS:= $(CFLAGS_JAGUAR) -arch ppc
- LDFLAGS:= $(LDFLAGS_JAGUAR)
+ifndef i386_OSX_TARGET
+i386_OSX_TARGET:=10.4u
endif
ifndef G5_FLAGS
@@ -61,26 +53,70 @@ G5_FLAGS := -mtune=970 -mcpu=970 -mpowerpc-gpopt
endif
ifdef UNIVERSAL_BINARY
-TARGET_CPU_FLAGS:= -arch ppc -arch i386
-LDFLAGS := $(LDFLAGS_UNIVERSAL) -arch ppc -arch i386
-CFLAGS += $(CFLAGS_UNIVERSAL)
-ifdef TRIPLE_BINARY
-LDFLAGS += -arch ppc970
+ OTTD_PPC:=1
+ OTTD_i386:=1
+ ifdef TRIPLE_BINARY
+ OTTD_PPC970:=1
+ endif
+endif
+
+# if any targets have been defined by now, we are crosscompiling and we will set up paths accordingly
+ifdef OTTD_PPC
+ CFLAGS_PPC += -isysroot /Developer/SDKs/MacOSX$(PPC_OSX_TARGET).sdk
+ LDFLAGS_PPC += -Wl,-syslibroot,/Developer/SDKs/MacOSX$(PPC_OSX_TARGET).sdk
+endif
+
+ifdef OTTD_i386
+ CFLAGS_i386 += -isysroot /Developer/SDKs/MacOSX$(i386_OSX_TARGET).sdk
+ LDFLAGS_i386 += -Wl,-syslibroot,/Developer/SDKs/MacOSX$(i386_OSX_TARGET).sdk
endif
+
+ifdef OTTD_PPC970
+ ifndef OTTD_PPC
+ CFLAGS_PPC += -isysroot /Developer/SDKs/MacOSX$(PPC_OSX_TARGET).sdk
+ LDFLAGS_PPC += -Wl,-syslibroot,/Developer/SDKs/MacOSX$(PPC_OSX_TARGET).sdk
+ endif
+endif
+
+ifdef JAGUAR
+ CFLAGS += -isysroot /Developer/SDKs/MacOSX10.2.8.sdk
+ LDFLAGS += -Wl,-syslibroot,/Developer/SDKs/MacOSX10.2.8.sdk
+ OTTD_PPC:=1
endif
# setting up flags to make a binary, that fits the system it builds on
-ifndef UNIVERSAL_BINARY
- ifndef JAGUAR
- ifeq ($(shell uname), Darwin)
- # it's a hardware mac, not crosscompiling
+ifdef NATIVE_OSX
+ ifndef UNIVERSAL_BINARY
+ # we are not crosscompiling for other macs
+ ifndef JAGUAR
# the next line fails if it got whitespace in front of it
$(shell $(CC) os/macosx/G5_detector.c -o os/macosx/G5_detector)
IS_G5:=$(shell os/macosx/G5_detector)
ifeq ($(shell uname -r), 6.8)
# OSX 10.2.8 uses Darwin 6.8, so we better set JAGUAR so we avoid the stuff that was added in 10.3 or later
JAGUAR:=1
+ OTTD_PPC:=1
endif
endif
endif
endif
+
+ifdef NATIVE_OSX
+ ifndef OTTD_PPC
+ ifndef OTTD_i386
+ ifndef OTTD_PPC970
+ # no flags have been set for target versions of OSX, so we will set it to compile for the current host
+ ifeq ($(shell uname -p), powerpc)
+ ifdef IS_G5
+ OTTD_PPC970:=1
+ else
+ OTTD_PPC:=1
+ endif
+ else
+ # we are not using a PowerPC CPU, so we assume that it's an Intel mac
+ OTTD_i386:=1
+ endif
+ endif
+ endif
+ endif
+endif \ No newline at end of file