(svn r4102) -Backported 3673, 3674, 3675, 3679, 3682, 3882, 3884 [all OSX] 0.4
authorbjarni
Sat, 25 Mar 2006 08:45:30 +0000
branch0.4
changeset 9965 40a3a784609a
parent 9964 d4a7ce61b6e9
child 9966 a4da286111df
(svn r4102) -Backported 3673, 3674, 3675, 3679, 3682, 3882, 3884 [all OSX]
added support for G5 (ppc970) optimised code
added support for triple binaries (ppc, ppc970, i386)
updated the makefile to handle building of universal and triple in a more automated way (way less flags to set)
now it's no longer needed to spent minutes setting up flags when releasing. It works out of the box :)
note: even though it looks like it's a lot of commits, it really is that there changes were introduced in small pieces in the trunk
Makefile
makefiledir/Makefile.config_writer
os/macosx/G5_detector.c
os/macosx/Makefile
os/macosx/Makefile.setup
--- a/Makefile	Sat Mar 25 07:40:02 2006 +0000
+++ b/Makefile	Sat Mar 25 08:45:30 2006 +0000
@@ -109,7 +109,8 @@
 #
 # Special for crosscompiling there are some commands available:
 #
-# FAT_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)
 #
 # 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
@@ -132,7 +133,7 @@
 
 # Makefile version tag
 # it checks if the version tag in Makefile.config is the same and force update outdated config files
-MAKEFILE_VERSION:=8
+MAKEFILE_VERSION:=9
 
 # CONFIG_WRITER has to be found even for manual configuration
 CONFIG_WRITER=makefiledir/Makefile.config_writer
@@ -340,6 +341,11 @@
 ifdef OSX
 # 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
+ifdef IS_G5
+ifndef UNIVERSAL_BINARY
+BASECFLAGS += $(G5_FLAGS)
+endif
+endif
 else
 ifdef MORPHOS
 BASECFLAGS += -I/gg/os-include -O2 -noixemul -fstrict-aliasing -fexpensive-optimizations
@@ -994,17 +1000,21 @@
 	$(Q)$(CC) $(OBJCFLAGS) $(CDEFS) -MM $< | sed 's#^$(@F:%.d=%.o):#$@ $(@:.deps/%.d=%.o):#' > $@
 
 
+ifndef TRIPLE_BINARY
+# building tripple binary object files is handled in os/macosx/Makefile
+# TARGET_CPU_FLAGS is used to set target CPUs in OSX universal binaries. It's empty for all other builds
 %.o: %.c $(MAKE_CONFIG)
 	@echo '===> Compiling $<'
-	$(Q)$(CC) $(CFLAGS) $(CDEFS) -c -o $@ $<
+	$(Q)$(CC) $(TARGET_CPU_FLAGS) $(CFLAGS) $(CDEFS) -c -o $@ $<
 
 %.o: %.cpp  $(MAKE_CONFIG)
 	@echo '===> Compiling $<'
-	$(Q)$(CXX) $(CFLAGS) $(CDEFS) -c -o $@ $<
+	$(Q)$(CXX) $(TARGET_CPU_FLAGS) $(CFLAGS) $(CDEFS) -c -o $@ $<
 
 %.o: %.m  $(MAKE_CONFIG)
 	@echo '===> Compiling $<'
-	$(Q)$(CC) $(CFLAGS) $(CDEFS) -c -o $@ $<
+	$(Q)$(CC) $(TARGET_CPU_FLAGS) $(CFLAGS) $(CDEFS) -c -o $@ $<
+endif
 
 %.o: %.rc
 	@echo '===> Compiling resource $<'
--- a/makefiledir/Makefile.config_writer	Sat Mar 25 07:40:02 2006 +0000
+++ b/makefiledir/Makefile.config_writer	Sat Mar 25 08:45:30 2006 +0000
@@ -87,25 +87,13 @@
 
 	$(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,SDL_PPC_CONFIG:=$(SDL_PPC_CONFIG))
-	$(call CONFIG_LINE,SDL_x86_CONFIG:=$(SDL_x86_CONFIG))
-
-	$(call CONFIG_LINE,\# if you got a fat libpng you should not need to change this. It is recommended to get a fat libpng lib)
-	$(call CONFIG_LINE,LIBPNG_PPC_CONFIG:=$(LIBPNG_PPC_CONFIG))
-	$(call CONFIG_LINE,LIBPNG_x86_CONFIG:=$(LIBPNG_x86_CONFIG))
+	$(call CONFIG_LINE,CFLAGS_UNIVERSAL:=$(CFLAGS_UNIVERSAL))
+	$(call CONFIG_LINE,LDFLAGS_UNIVERSAL:=$(LDFLAGS_UNIVERSAL))
 
-	$(call CONFIG_LINE,\# autodetected SDL lib path, but it is not detected in a reliable way, so verify it. It needs to be the x86 lib)
-	$(call CONFIG_LINE,x86_SDL_LIB:=$(x86_SDL_LIB))
-
-	$(call CONFIG_LINE,\# default values should be good enough for the rest of the universal binary flags, but check them anyway)
-	$(call CONFIG_LINE,SKIP_LIB_TEST:=$(SKIP_LIB_TEST))
-	$(call CONFIG_LINE,PPC_CC:=$(PPC_CC))
-	$(call CONFIG_LINE,CFLAGS_PPC:=$(CFLAGS_PPC))
-	$(call CONFIG_LINE,LDFLAGS_PPC:=$(LDFLAGS_PPC))
-
-	$(call CONFIG_LINE,x86_CC:=$(x86_CC))
-	$(call CONFIG_LINE,CFLAGS_x86:=$(CFLAGS_x86))
-	$(call CONFIG_LINE,LDFLAGS_x86:=$(LDFLAGS_x86))
+	$(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)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/os/macosx/G5_detector.c	Sat Mar 25 08:45:30 2006 +0000
@@ -0,0 +1,29 @@
+/* $Id$ */
+
+#include <mach/mach.h>
+#include <mach/mach_host.h>
+#include <mach/host_info.h>
+#include <mach/machine.h>
+#include <stdio.h>
+
+
+#ifndef CPU_SUBTYPE_POWERPC_970
+#define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
+#endif
+
+// this function is a lightly modified version of some code from Apple's developer homepage to detect G5 CPUs at runtime
+main()
+{
+	host_basic_info_data_t hostInfo;
+	mach_msg_type_number_t infoCount;
+	boolean_t is_G5;
+
+	infoCount = HOST_BASIC_INFO_COUNT;
+	host_info(mach_host_self(), HOST_BASIC_INFO,
+			  (host_info_t)&hostInfo, &infoCount);
+
+	 is_G5 = ((hostInfo.cpu_type == CPU_TYPE_POWERPC) &&
+			(hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970));
+	 if (is_G5)
+		 printf("1");
+}
--- a/os/macosx/Makefile	Sat Mar 25 07:40:02 2006 +0000
+++ b/os/macosx/Makefile	Sat Mar 25 08:45:30 2006 +0000
@@ -2,31 +2,38 @@
 # This makefile is not a standalone makefile, but is called from the general one
 # it contains targets specific to MacOS X
 
-ifdef FAT_BINARY
-FAT_BINARY:=build_universal_binary
+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
 endif
 
-ifdef UNIVERSAL_x86_PART
+ifdef UNIVERSAL_PPC_PART
 # the bundle is build by the PPC compile when making universal binaries
 BUILD_OSX_BUNDLE:=
 else
 BUILD_OSX_BUNDLE:=build_OSX_bundle
 endif
 
-# building an universal binary
-# since we can only compile for PPC or x86 at any one time, we compile one and then
-# we make clean and compile the other one. In the end we use lipo to join them together
-# when this is done, we can continue with the targets from the first run, which is build_OSX_bundle
-
-$(FAT_BINARY): $(TTD)
-	$(Q)mkdir -p temp_binary_dir
-	$(Q)cp $(TTD) temp_binary_dir/$(TTD)_a
-	$(Q)rm -rf $(TTD) $(OBJS) # delete all .o files so we can compile for a new endian
-	$(Q)make UNIVERSAL_x86_PART:=1
-	$(Q)cp $(TTD) temp_binary_dir/$(TTD)_b
-	@echo '===> Joining the PPC and x86 binaries into one universal one'
-	$(Q)lipo temp_binary_dir/$(TTD)_a temp_binary_dir/$(TTD)_b -create -output $(TTD)
-	$(Q)rm -rf temp_binary_dir
 
 ifdef JAGUAR
 JAGUAR_POSTFIX := -jaguar
@@ -35,7 +42,7 @@
 # build the bundle. OSX wants to keep apps in bundles, so we will give it one
 # the good thing about bundles is that you can keep extra files in them, so we keep lng files and a data dir in it
 
-$(BUILD_OSX_BUNDLE): $(TTD) $(FAT_BINARY)
+$(BUILD_OSX_BUNDLE): $(TTD)
 	@echo '===> Building application bundle'
 	$(Q)rm -fr "$(OSXAPP)"
 	$(Q)mkdir -p "$(OSXAPP)"/Contents/MacOS
@@ -71,4 +78,4 @@
 
 $(OSX): $(TTD) $(BUILD_OSX_BUNDLE)
 
-.PHONY: release $(BUILD_OSX_BUNDLE) $(FAT_BINARY)
+.PHONY: release $(BUILD_OSX_BUNDLE) $(UNIVERSAL_BINARY)
--- a/os/macosx/Makefile.setup	Sat Mar 25 07:40:02 2006 +0000
+++ b/os/macosx/Makefile.setup	Sat Mar 25 08:45:30 2006 +0000
@@ -11,12 +11,29 @@
 endif
 
 ifdef RELEASE
-ifndef FAT_BINARY
+ifndef UNIVERSAL_BINARY
 $(warning Compiling a release build, that is not a universal binary)
 endif
 endif
 
-ifdef FAT_BINARY
+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)
+endif
+UNIVERSAL_BINARY:=1
+endif
+
+ifndef UNIVERSAL_BINARY
+ifndef JAGUAR
+ifeq ($(shell uname), Darwin)
+# it's a hardware mac, not crosscompiling
+$(shell $(CC) os/macosx/G5_detector.c -o os/macosx/G5_detector)
+IS_G5:=$(shell os/macosx/G5_detector)
+endif
+endif
+endif
+
+ifdef UNIVERSAL_BINARY
 ifndef STATIC
 $(warning Compiling a universal binary, that is not static. Adding static flag)
 STATIC:=1
@@ -30,83 +47,36 @@
 endif
 
 # setup flags if none are defined
-ifndef CFLAGS_PPC
-	CFLAGS_PPC:= -isysroot /Developer/SDKs/MacOSX10.2.8.sdk
-endif
-ifndef LDFLAGS_PPC
-	LDFLAGS_PPC:= -Wl,-syslibroot,/Developer/SDKs/MacOSX10.2.8.sdk
-endif
-ifndef PPC_CC
-	PPC_CC:=powerpc-apple-darwin8-gcc-4.0.0
-endif
-ifndef CFLAGS_x86
-	CFLAGS_x86:= -isysroot /Developer/SDKs/MacOSX10.4u.sdk
-endif
-ifndef LDFLAGS_x86
-	LDFLAGS_x86:= -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk
-endif
-ifndef x86_CC
-	x86_CC:=i686-apple-darwin8-gcc-4.0.0
+ifndef CFLAGS_JAGUAR
+	CFLAGS_JAGUAR:= -isysroot /Developer/SDKs/MacOSX10.2.8.sdk
 endif
-ifdef WITH_PNG
-	ifndef LIBPNG_PPC_CONFIG
-		LIBPNG_PPC_CONFIG:=$(LIBPNG-CONFIG)
-	endif
-	ifndef LIBPNG_x86_CONFIG
-		LIBPNG_x86_CONFIG:=$(LIBPNG-CONFIG)
-	endif
+ifndef LDFLAGS_JAGUAR
+	LDFLAGS_JAGUAR:= -Wl,-syslibroot,/Developer/SDKs/MacOSX10.2.8.sdk
 endif
-ifdef WITH_SDL
-	ifndef SDL_PPC_CONFIG
-		SDL_PPC_CONFIG:=$(SDL-CONFIG)
-	endif
-	ifndef SDL_x86_CONFIG
-		SDL_x86_CONFIG:=$(SDL-CONFIG)
-	endif
-	ifndef x86_SDL_LIB
-		x86_SDL_LIB:=$(shell echo "`$(SDL_x86_CONFIG) --prefix`/lib/libSDL-1.2.0.dylib")
-	endif
+
+ifndef CFLAGS_UNIVERSAL
+	CFLAGS_UNIVERSAL:= -isysroot /Developer/SDKs/MacOSX10.4u.sdk
+endif
+ifndef LDFLAGS_UNIVERSAL
+	LDFLAGS_UNIVERSAL:= -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk
 endif
 
 ifdef JAGUAR
-	LIBPNG-CONFIG:=$(LIBPNG_PPC_CONFIG)
-	SDL-CONFIG:=$(SDL_PPC_CONFIG)
-	CC_TARGET:=$(PPC_CC)
-	CFLAGS:= $(CFLAGS_PPC) -arch ppc
-	LDFLAGS:= $(LDFLAGS_PPC)
+	CFLAGS:= $(CFLAGS_JAGUAR) -arch ppc
+	LDFLAGS:= $(LDFLAGS_JAGUAR)
 endif
 
-ifdef FAT_BINARY
-	# set up config files
-	ifndef SKIP_LIB_TEST
-		ifdef WITH_PNG
-			TEST:=$(shell lipo -info `$(LIBPNG_PPC_CONFIG) --prefix`/lib/libpng.a | xargs -n 1 | grep "ppc"))
-			ifndef TEST
-$(error no PPC libpng found)
-			endif
-			TEST:=$(shell lipo -info `$(LIBPNG_x86_CONFIG) --prefix`/lib/libpng.a | xargs -n 1 | grep "i386"))
-			ifndef TEST
-$(error no x86 libpng found)
-			endif
-		endif
-	endif
+ifndef G5_FLAGS
+G5_FLAGS := -mtune=970 -mcpu=970 -mpowerpc-gpopt
+endif
 
-	ifdef UNIVERSAL_x86_PART
-		LIBPNG-CONFIG:=$(LIBPNG_x86_CONFIG)
-		SDL-CONFIG:=$(SDL_x86_CONFIG)
-		CC_TARGET:=$(x86_CC)
-		# clear the cached list of PPC libs
-		LIBS:=
-		OBJS:=
-		CFLAGS:= $(CFLAGS_x86) -arch i386
-		LDFLAGS:= $(LDFLAGS_x86)
-	else
-		LIBPNG-CONFIG:=$(LIBPNG_PPC_CONFIG)
-		SDL-CONFIG:=$(SDL_PPC_CONFIG)
-		CC_TARGET:=$(PPC_CC)
-		CFLAGS:= $(CFLAGS_PPC) -arch ppc
-		LDFLAGS:= $(LDFLAGS_PPC)
-	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
+endif
 endif
 
 # setting up flags to make a binary, that fits the system it builds on