(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
This commit is contained in:
bjarni 2006-03-29 16:28:41 +00:00
parent c2bb4a052e
commit f6662e056d
4 changed files with 144 additions and 70 deletions

View File

@ -108,6 +108,8 @@
# #
# UNIVERSAL_BINARY: builds a universal binary for OSX. Make sure you got both PPC and x86 libs. Only works with GCC 4 or newer # UNIVERSAL_BINARY: builds a universal binary for OSX. Make sure you got both PPC and x86 libs. Only works with GCC 4 or newer
# TRIPLE_BINARY: builds a universal binary with the addition of code optimised for G5 (which means a total of 3 binaries in one file) # TRIPLE_BINARY: builds a universal binary with the addition of code optimised for G5 (which means a total of 3 binaries in one file)
# OTTD_PPC, OTTD_PPC970, OTTD_i386: compile for target architecture.
# Multiple flags can be used so OTTD_PPC:=1 OTTD_i386:=1 produces the same result as UNIVERSAL_BINARY
# #
# JAGUAR: Crosscompiling for OSX 1.2.8 (codenamed Jaguar). Only works if OSX is defined too. Only works with GCC 4 or newer # JAGUAR: Crosscompiling for OSX 1.2.8 (codenamed Jaguar). Only works if OSX is defined too. Only works with GCC 4 or newer
# This can be changed to any PPC version of OSX by changing the ppc flags in Makefile.config # This can be changed to any PPC version of OSX by changing the ppc flags in Makefile.config
@ -130,7 +132,7 @@
# Makefile version tag # Makefile version tag
# it checks if the version tag in Makefile.config is the same and force update outdated config files # it checks if the version tag in Makefile.config is the same and force update outdated config files
MAKEFILE_VERSION:=9 MAKEFILE_VERSION:=10
# CONFIG_WRITER has to be found even for manual configuration # CONFIG_WRITER has to be found even for manual configuration
CONFIG_WRITER=makefiledir/Makefile.config_writer CONFIG_WRITER=makefiledir/Makefile.config_writer
@ -345,11 +347,6 @@ endif
ifdef OSX ifdef OSX
# these compilerflags makes the app run as fast as possible without making the app unstable. It works on G3 or newer # these compilerflags makes the app run as fast as possible without making the app unstable. It works on G3 or newer
BASECFLAGS += -O3 -funroll-loops -fsched-interblock -falign-loops=16 -falign-jumps=16 -falign-functions=16 -falign-jumps-max-skip=15 -falign-loops-max-skip=15 -mdynamic-no-pic BASECFLAGS += -O3 -funroll-loops -fsched-interblock -falign-loops=16 -falign-jumps=16 -falign-functions=16 -falign-jumps-max-skip=15 -falign-loops-max-skip=15 -mdynamic-no-pic
ifdef IS_G5
ifndef UNIVERSAL_BINARY
BASECFLAGS += $(G5_FLAGS)
endif
endif
else else
ifdef MORPHOS ifdef MORPHOS
BASECFLAGS += -I/gg/os-include -O2 -noixemul -fstrict-aliasing -fexpensive-optimizations BASECFLAGS += -I/gg/os-include -O2 -noixemul -fstrict-aliasing -fexpensive-optimizations
@ -830,9 +827,12 @@ $(ENDIAN_CHECK): endian_check.c
$(Q)$(CC_HOST) $(CFLAGS_HOST) $(CDEFS) $< -o $@ $(Q)$(CC_HOST) $(CFLAGS_HOST) $(CDEFS) $< -o $@
ifndef NATIVE_OSX
# OSX links in os/macosx/Makefile to handle universal binaries better
$(TTD): $(OBJS) $(MAKE_CONFIG) $(TTD): $(OBJS) $(MAKE_CONFIG)
@echo '===> Linking $@' @echo '===> Linking $@'
$(Q)$(CC) $(LDFLAGS) $(TTDLDFLAGS) $(OBJS) $(LIBS) -o $@ $(Q)$(CC) $(LDFLAGS) $(TTDLDFLAGS) $(OBJS) $(LIBS) -o $@
endif
$(STRGEN): strgen/strgen.c endian_host.h $(STRGEN): strgen/strgen.c endian_host.h
@echo '===> Compiling and Linking $@' @echo '===> Compiling and Linking $@'
@ -899,7 +899,7 @@ FORCE:
clean: clean:
@echo '===> Cleaning up' @echo '===> Cleaning up'
# endian.h is out-dated and no longer in use, so it can be removed soon # endian.h is out-dated and no longer in use, so it can be removed soon
$(Q)rm -rf .deps *~ $(TTD) $(STRGEN) core table/strings.h $(LANGS) $(OBJS) $(OSX_MIDI_PLAYER_FILE) endian.h endian_host.h endian_target.h $(ENDIAN_CHECK) $(Q)rm -rf .deps *~ $(TTD) $(STRGEN) core table/strings.h $(LANGS) $(OBJS) $(OSX_MIDI_PLAYER_FILE) endian.h endian_host.h endian_target.h $(ENDIAN_CHECK) .OSX
mrproper: clean mrproper: clean
$(Q)rm -rf $(MAKE_CONFIG) $(Q)rm -rf $(MAKE_CONFIG)
@ -1006,20 +1006,19 @@ endif
$(Q)$(CC) $(OBJCFLAGS) $(CDEFS) -MM $< | sed 's#^$(@F:%.d=%.o):#$@ $(@:.deps/%.d=%.o):#' > $@ $(Q)$(CC) $(OBJCFLAGS) $(CDEFS) -MM $< | sed 's#^$(@F:%.d=%.o):#$@ $(@:.deps/%.d=%.o):#' > $@
ifndef TRIPLE_BINARY ifndef NATIVE_OSX
# building tripple binary object files is handled in os/macosx/Makefile # OSX uses os/macosx/Makefile to compile files
# TARGET_CPU_FLAGS is used to set target CPUs in OSX universal binaries. It's empty for all other builds
%.o: %.c $(MAKE_CONFIG) %.o: %.c $(MAKE_CONFIG)
@echo '===> Compiling $<' @echo '===> Compiling $<'
$(Q)$(CC) $(TARGET_CPU_FLAGS) $(CFLAGS) $(CDEFS) -c -o $@ $< $(Q)$(CC) $(CFLAGS) $(CDEFS) -c -o $@ $<
%.o: %.cpp $(MAKE_CONFIG) %.o: %.cpp $(MAKE_CONFIG)
@echo '===> Compiling $<' @echo '===> Compiling $<'
$(Q)$(CXX) $(TARGET_CPU_FLAGS) $(CFLAGS) $(CDEFS) -c -o $@ $< $(Q)$(CXX) $(CFLAGS) $(CDEFS) -c -o $@ $<
%.o: %.m $(MAKE_CONFIG) %.o: %.m $(MAKE_CONFIG)
@echo '===> Compiling $<' @echo '===> Compiling $<'
$(Q)$(CC) $(TARGET_CPU_FLAGS) $(CFLAGS) $(CDEFS) -c -o $@ $< $(Q)$(CC) $(CFLAGS) $(CDEFS) -c -o $@ $<
endif endif
%.o: %.rc %.o: %.rc

View File

@ -83,17 +83,6 @@ $(MAKE_CONFIG):
$(call CONFIG_LINE,MINGW:=$(MINGW)) $(call CONFIG_LINE,MINGW:=$(MINGW))
$(call CONFIG_LINE,) $(call CONFIG_LINE,)
$(call CONFIG_LINE,\# Universal binary setup)
$(call CONFIG_LINE,\# use these settings for building universal binaries. Most systems should work with the default settings)
$(call CONFIG_LINE,CFLAGS_UNIVERSAL:=$(CFLAGS_UNIVERSAL))
$(call CONFIG_LINE,LDFLAGS_UNIVERSAL:=$(LDFLAGS_UNIVERSAL))
$(call CONFIG_LINE,CFLAGS_JAGUAR:=$(CFLAGS_JAGUAR))
$(call CONFIG_LINE,LDFLAGS_JAGUAR:=$(LDFLAGS_JAGUAR))
$(call CONFIG_LINE,)
$(call CONFIG_LINE,G5_FLAGS:=$(G5_FLAGS))
$(call CONFIG_LINE,)
$(call CONFIG_LINE,\# For cross-compiling) $(call CONFIG_LINE,\# For cross-compiling)
$(call CONFIG_LINE,CC_TARGET:=$(CC_TARGET)) $(call CONFIG_LINE,CC_TARGET:=$(CC_TARGET))
$(call CONFIG_LINE,CC_HOST:=$(CC_HOST)) $(call CONFIG_LINE,CC_HOST:=$(CC_HOST))

View File

@ -2,29 +2,79 @@
# This makefile is not a standalone makefile, but is called from the general one # This makefile is not a standalone makefile, but is called from the general one
# it contains targets specific to MacOS X # it contains targets specific to MacOS X
ifdef TRIPLE_BINARY ifdef NATIVE_OSX
# 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) DEPS_MAGIC := $(shell mkdir -p $(sort $(dir $(OBJS:%.o=.OSX/%))))
@echo '===> Compiling $<'
$(Q)$(CXX) $(CFLAGS) $(CDEFS) -arch ppc -arch i386 -c -o $@.uni $< ifdef OTTD_PPC
$(Q)$(CXX) $(CFLAGS) $(CDEFS) $(G5_FLAGS) -arch ppc970 -c -o $@.ppc970 $< OTTD_PPC :=.OSX/openttd.ppc
$(Q)lipo -create -output $@ $@.uni $@.ppc970 OBJS_ppc := $(OBJS:%.o=.OSX/%.o.ppc)
$(Q)rm $@.uni $@.ppc970 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 $@ $<
%.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
endif endif
ifdef JAGUAR ifdef JAGUAR

View File

@ -18,7 +18,7 @@ endif
ifdef TRIPLE_BINARY ifdef TRIPLE_BINARY
ifdef DEBUG 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 endif
UNIVERSAL_BINARY:=1 UNIVERSAL_BINARY:=1
endif endif
@ -36,24 +36,16 @@ $(warning Compiling a release build, that is a debug build)
endif endif
endif endif
# setup flags if none are defined ifeq ($(shell uname), Darwin)
ifndef CFLAGS_JAGUAR # it's a hardware mac, not crosscompiling
CFLAGS_JAGUAR:= -isysroot /Developer/SDKs/MacOSX10.2.8.sdk NATIVE_OSX:=1
endif
ifndef LDFLAGS_JAGUAR
LDFLAGS_JAGUAR:= -Wl,-syslibroot,/Developer/SDKs/MacOSX10.2.8.sdk
endif endif
ifndef CFLAGS_UNIVERSAL ifndef PPC_OSX_TARGET
CFLAGS_UNIVERSAL:= -isysroot /Developer/SDKs/MacOSX10.4u.sdk PPC_OSX_TARGET:=10.3.9
endif endif
ifndef LDFLAGS_UNIVERSAL ifndef i386_OSX_TARGET
LDFLAGS_UNIVERSAL:= -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk i386_OSX_TARGET:=10.4u
endif
ifdef JAGUAR
CFLAGS:= $(CFLAGS_JAGUAR) -arch ppc
LDFLAGS:= $(LDFLAGS_JAGUAR)
endif endif
ifndef G5_FLAGS ifndef G5_FLAGS
@ -61,25 +53,69 @@ G5_FLAGS := -mtune=970 -mcpu=970 -mpowerpc-gpopt
endif endif
ifdef UNIVERSAL_BINARY ifdef UNIVERSAL_BINARY
TARGET_CPU_FLAGS:= -arch ppc -arch i386 OTTD_PPC:=1
LDFLAGS := $(LDFLAGS_UNIVERSAL) -arch ppc -arch i386 OTTD_i386:=1
CFLAGS += $(CFLAGS_UNIVERSAL) ifdef TRIPLE_BINARY
ifdef TRIPLE_BINARY OTTD_PPC970:=1
LDFLAGS += -arch ppc970 endif
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 endif
# setting up flags to make a binary, that fits the system it builds on # setting up flags to make a binary, that fits the system it builds on
ifndef UNIVERSAL_BINARY ifdef NATIVE_OSX
ifndef UNIVERSAL_BINARY
# we are not crosscompiling for other macs
ifndef JAGUAR ifndef JAGUAR
ifeq ($(shell uname), Darwin)
# it's a hardware mac, not crosscompiling
# the next line fails if it got whitespace in front of it # the next line fails if it got whitespace in front of it
$(shell $(CC) os/macosx/G5_detector.c -o os/macosx/G5_detector) $(shell $(CC) os/macosx/G5_detector.c -o os/macosx/G5_detector)
IS_G5:=$(shell os/macosx/G5_detector) IS_G5:=$(shell os/macosx/G5_detector)
ifeq ($(shell uname -r), 6.8) 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 # 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 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
endif endif