Replace the use of uname to get the build output.

Using uname has a couple of problems, especially when cross compiling. Instead
check the defines set by the preprocessor to figure the type of binaries it
produces. This improves support for cross compiling as it allows to (1) select
the correct default target and (2) makes it possible to use separate build
folders for different targets.

Change-Id: I69a32904dab97755034f2f0d63f8402309d479d2
This commit is contained in:
Dominik Riebeling 2013-04-05 19:49:04 +02:00
parent 891351db60
commit ea0bfe7520
2 changed files with 15 additions and 12 deletions

View file

@ -27,10 +27,8 @@ BOOTSRC = ipod1g2g.c ipod3g.c ipod4g.c ipodcolor.c ipodmini1g.c \
CFLAGS += -DWITH_BOOTOBJS CFLAGS += -DWITH_BOOTOBJS
endif endif
ifeq ($(findstring Darwin,$(shell uname)),Darwin)
# additional frameworks to link on on OS X # additional frameworks to link on on OS X
LDOPTS += -framework CoreFoundation -framework IOKit LDOPTS_OSX += -framework CoreFoundation -framework IOKit
endif
LIBSOURCES = ipodpatcher.c fat32format.c arc4.c \ LIBSOURCES = ipodpatcher.c fat32format.c arc4.c \
ipodio-posix.c ipodio-win32-scsi.c ipodio-win32.c ipodio-posix.c ipodio-win32-scsi.c ipodio-win32.c

View file

@ -25,31 +25,37 @@ TOP := $(dir $(lastword $(MAKEFILE_LIST)))
# overwrite for releases # overwrite for releases
APPVERSION ?= $(shell $(TOP)/../tools/version.sh $(TOP)/..) APPVERSION ?= $(shell $(TOP)/../tools/version.sh $(TOP)/..)
CFLAGS += -DVERSION=\""$(APPVERSION)"\" CFLAGS += -DVERSION=\""$(APPVERSION)"\"
TARGET_DIR ?= $(shell pwd)/ TARGET_DIR ?= $(abspath .)/
CPPDEFINES=$(shell echo foo | $(CROSS)$(CC) -dM -E -)
# use POSIX/C99 printf on windows # use POSIX/C99 printf on windows
CFLAGS += -D__USE_MINGW_ANSI_STDIO=1 CFLAGS += -D__USE_MINGW_ANSI_STDIO=1
BINARY = $(OUTPUT) BINARY = $(OUTPUT)
# when building a Windows binary add the correct file suffix # when building a Windows binary add the correct file suffix
ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN) ifeq ($(findstring CYGWIN,$(CPPDEFINES)),CYGWIN)
BINARY = $(OUTPUT).exe BINARY = $(OUTPUT).exe
CFLAGS+=-mno-cygwin CFLAGS+=-mno-cygwin
COMPILETARGET = cygwin
else else
ifeq ($(findstring MINGW,$(shell uname)),MINGW) ifeq ($(findstring MINGW,$(CPPDEFINES)),MINGW)
BINARY = $(OUTPUT).exe BINARY = $(OUTPUT).exe
COMPILETARGET = mingw
else else
ifeq ($(findstring mingw,$(CROSS)$(CC)),mingw) ifeq ($(findstring APPLE,$(CPPDEFINES)),APPLE)
BINARY = $(OUTPUT).exe COMPILETARGET = darwin
LDOPTS += $(LDFLAGS_OSX)
else
COMPILETARGET = posix
endif endif
endif endif
endif endif
$(info Compiler creates $(COMPILETARGET) binaries)
NATIVECC ?= gcc NATIVECC ?= gcc
CC ?= gcc CC ?= gcc
# OS X specifics. Needs to consider cross compiling for Windows. # OS X specifics. Needs to consider cross compiling for Windows.
ifeq ($(findstring Darwin,$(shell uname)),Darwin) ifeq ($(findstring APPLE,$(CPPDEFINES)),APPLE)
ifneq ($(findstring mingw,$(CROSS)$(CC)),mingw)
# when building libs for OS X build for both i386 and ppc at the same time. # when building libs for OS X build for both i386 and ppc at the same time.
# This creates fat objects, and ar can only create the archive but not operate # This creates fat objects, and ar can only create the archive but not operate
# on it. As a result the ar call must NOT use the u (update) flag. # on it. As a result the ar call must NOT use the u (update) flag.
@ -60,10 +66,9 @@ CC ?= gcc-4.0
CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4
NATIVECC ?= gcc-4.0 NATIVECC ?= gcc-4.0
endif endif
endif
WINDRES = windres WINDRES = windres
BUILD_DIR ?= $(TARGET_DIR)build BUILD_DIR ?= $(TARGET_DIR)build$(COMPILETARGET)
OBJDIR = $(abspath $(BUILD_DIR)/$(RBARCH))/ OBJDIR = $(abspath $(BUILD_DIR)/$(RBARCH))/
ifdef RBARCH ifdef RBARCH