(svn r3258) -Feature: [OSX] added support for universal binaries

it needs both PPC and x86 libs to compile
	due to this fact, compilation with libPNG or SDL is not tested (dedicated servers only)
	only PPC part is tested as I don't have x86 OSX
replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
bjarni 19 years ago
parent 8277a0651e
commit 961b71f434

@ -106,6 +106,8 @@
#
# Special for crosscompiling there are some commands available:
#
# BUILD_UNIVERSAL_BINARY: builds a universal binary for OSX. Make sure you got both PPC and x86 libs
#
# ENDIAN_FORCE: forces the endian-check to give a certain result. Can be either BE or LE.
# WINDRES: the location of your windres
# CC_HOST: the gcc of your localhost if you are making a target that produces incompatible executables
@ -165,6 +167,18 @@ ifndef SDL-CONFIG
CONFIG_INCLUDED:=
endif
ifdef UNIVERSAL_OTHER_HALF
ifndef CC_HOST
# we are crosscompiling, so we should remember what compiler we should use for strgen
CC_HOST = $(CC)
endif
CC_TARGET = $(CC_UNI)
CFLAGS = $(CFLAGS_UNI)
LDFLAGS = $(LDFLAGS_UNI)
SDL-CONFIG = $(SDL-CONFIG_UNI)
LIBPNG-CONFIG = $(LIBPNG-CONFIG_UNI)
endif
# this is used if there aren't any Makefile.config
ifndef CONFIG_INCLUDED
# sets network on by default if there aren't any config file
@ -325,7 +339,7 @@ endif
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 -mpowerpc-gpopt -force_cpusubtype_ALL
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
else
ifdef MORPHOS
BASECFLAGS += -I/gg/os-include -O2 -noixemul -fstrict-aliasing -fexpensive-optimizations
@ -587,6 +601,9 @@ endif
### Sources
# clean up C_SOURCES first. Needed since building universal binaries on OSX calls the makefile recursively (just one time)
C_SOURCES:=
C_SOURCES += aircraft_cmd.c
C_SOURCES += aircraft_gui.c
C_SOURCES += airport.c
@ -777,8 +794,9 @@ endif
ifdef OSX
# needs to be before all
OSX:=OSX
OSX_MIDI_PLAYER_FILE:=os/macos/OpenTTDMidi.class
-include os/macosx/Makefile
endif
@ -801,10 +819,6 @@ $(TTD): $(OBJS) $(MAKE_CONFIG)
@echo '===> Linking $@'
$(Q)$(CC) $(LDFLAGS) $(TTDLDFLAGS) $(OBJS) $(LIBS) -o $@
ifdef OSX
-include os/macosx/Makefile
endif
$(STRGEN): strgen/strgen.c endian_host.h
@echo '===> Compiling and Linking $@'
$(Q)$(CC_HOST) $(CFLAGS_HOST) $(CDEFS) $< -o $@

@ -11,22 +11,39 @@
// care of the real writing to the file.
int main (int argc, char *argv[]) {
unsigned char EndianTest[2] = { 1, 0 };
int force_BE = 0, force_LE = 0;
if (argc > 1 && strcmp(argv[1], "BE") == 0)
force_BE = 1;
if (argc > 1 && strcmp(argv[1], "LE") == 0)
force_LE = 1;
printf("#ifndef ENDIAN_H\n#define ENDIAN_H\n");
if ( (*(short *) EndianTest == 1 && force_BE != 1) || force_LE == 1)
printf("#define TTD_LITTLE_ENDIAN\n");
else
printf("#define TTD_BIG_ENDIAN\n");
printf("#endif\n");
return 0;
unsigned char EndianTest[2] = { 1, 0 };
int force_BE = 0, force_LE = 0;
if (argc > 1 && strcmp(argv[1], "BE") == 0)
force_BE = 1;
if (argc > 1 && strcmp(argv[1], "LE") == 0)
force_LE = 1;
printf("#ifndef ENDIAN_H\n#define ENDIAN_H\n");
if (force_LE == 1) {
printf("#define TTD_LITTLE_ENDIAN\n");
} else {
if (force_BE == 1) {
printf("#define TTD_BIG_ENDIAN\n");
} else {
#ifdef __APPLE__
// adding support for universal binaries on OSX
// Universal binaries supports both PPC and x86
printf("#ifdef __BIG_ENDIAN__\n");
printf("#define TTD_BIG_ENDIAN\n");
printf("#else\n");
printf("#define TTD_LITTLE_ENDIAN\n");
printf("#endif\n");
#else
if ( *(short *) EndianTest == 1 )
printf("#define TTD_LITTLE_ENDIAN\n");
else
printf("#define TTD_BIG_ENDIAN\n");
#endif
}
}
printf("#endif\n");
return 0;
}

@ -92,6 +92,14 @@ $(MAKE_CONFIG):
$(call CONFIG_LINE,MINGW:=$(MINGW))
$(call CONFIG_LINE,)
$(call CONFIG_LINE,\# Universal binary setup)
$(call CONFIG_LINE,\# use these settings for the CPU type, that is not covered by the other settings)
$(call CONFIG_LINE,CC_UNI:=$(CC_UNI))
$(call CONFIG_LINE,CFLAGS_UNI:=$(CFLAGS_UNI))
$(call CONFIG_LINE,LDFLAGS_UNI:=$(LDFLAGS_UNI))
$(call CONFIG_LINE,SDL-CONFIG_UNI:=$(SDL-CONFIG_UNI))
$(call CONFIG_LINE,LIBPNG-CONFIG_UNI:=$(LIBPNG-CONFIG_UNI))
$(call CONFIG_LINE,\# For cross-compiling)
$(call CONFIG_LINE,CC_TARGET:=$(CC_TARGET))
$(call CONFIG_LINE,CC_HOST:=$(CC_HOST))

@ -2,10 +2,54 @@
# This makefile is not a standalone makefile, but is called from the general one
# it contains targets specific to MacOS X
ifdef UNIVERSAL_OTHER_HALF
# don't call anything in this file if it is building the 2nd half of an universal binary
# all that needs to be done will be done with the first call
OSX:=
else
ifdef BUILD_UNIVERSAL_BINARY
BUILD_UNIVERSAL_BINARY:=build_universal_binary
endif
# setting the default vars for making universal binaries
# this can be overwritten in Makefile.config
# default values are for PPC host and commends are for x86 hosts (so you know what to put in)
# the absolute path is the one Apple uses in Xcode 2.1
ifndef CC_UNI
# powerpc-apple-darwin8-gcc-4.0.0
CC_UNI:=i686-apple-darwin8-gcc-4.0.0
endif
ifndef CFLAGS_UNI
# -arch ppc
CFLAGS_UNI:= -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386
endif
ifndef LDFLAGS_UNI
LDFLAGS_UNI:= -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk
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
$(BUILD_UNIVERSAL_BINARY): $(TTD)
$(Q)mkdir -p temp_binary_dir
$(Q)cp $(TTD) temp_binary_dir/$(TTD)_a
@echo '===> Cleaning up to build for the other architecture'
$(Q)make clean
$(Q)make UNIVERSAL_OTHER_HALF:=1
$(Q)cp $(TTD) temp_binary_dir/$(TTD)_b
@echo '===> Joining 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
# 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)
build_OSX_bundle: $(TTD) $(BUILD_UNIVERSAL_BINARY)
$(Q)rm -fr "$(OSXAPP)"
$(Q)mkdir -p "$(OSXAPP)"/Contents/MacOS
$(Q)mkdir -p "$(OSXAPP)"/Contents/Resources
@ -39,4 +83,6 @@ release: all
$(OSX): $(TTD) build_OSX_bundle
.PHONY: release build_OSX_bundle
.PHONY: release build_OSX_bundle $(BUILD_UNIVERSAL_BINARY)
endif

Loading…
Cancel
Save