diff options
author | Wayne Meissner <wmeissner@gmail.com> | 2009-10-03 19:39:23 +1000 |
---|---|---|
committer | Wayne Meissner <wmeissner@gmail.com> | 2009-10-03 19:39:23 +1000 |
commit | e582d1cfc8bfc6610eb0aee58fe0267704f027ab (patch) | |
tree | b8f93109fdcb867bd2ea0c715e1d1f3fae9db78b | |
parent | 41e15d930abe4d4eda6a0bf3cdeb12879f22769f (diff) | |
download | ffi-e582d1cfc8bfc6610eb0aee58fe0267704f027ab.tar.gz |
Tweak OS/CPU detection for libtest based on rbconfig
-rw-r--r-- | Rakefile | 50 | ||||
-rw-r--r-- | libtest/GNUmakefile | 42 |
2 files changed, 67 insertions, 25 deletions
@@ -23,8 +23,52 @@ rescue LoadError end end -LIBEXT = Config::CONFIG['host_os'].downcase =~ /darwin/ ? "dylib" : "so" -GMAKE = Config::CONFIG['host_os'].downcase =~ /bsd/ ? "gmake" : "make" +LIBEXT = case Config::CONFIG['host_os'].downcase + when /darwin/ + "dylib" + when /mswin|mingw/ + "dll" + else + Config::CONFIG['DLEXT'] + end + +CPU = case Config::CONFIG['host_cpu'].downcase + when /i[3456]86/ + # Darwin always reports i686, even when running in 64bit mode + if Config::CONFIG['host_os'] =~ /darwin/ && 0xfee1deadbeef.is_a?(Fixnum) + "x86_64" + else + "i386" + end + when /amd64|x86_64/ + "x86_64" + when /ppc|powerpc/ + "powerpc" + else + Config::CONFIG['host_cpu'] + end + +OS = case Config::CONFIG['host_os'].downcase + when /linux/ + "linux" + when /darwin/ + "darwin" + when /freebsd/ + "freebsd" + when /openbsd/ + "openbsd" + when /sunos|solaris/ + "solaris" + when /mswin|mingw/ + "win32" + else + Config::CONFIG['host_os'].downcase + end + +CC=ENV['CC'] || Config::CONFIG['CC'] || "gcc" + +GMAKE = Config::CONFIG['host_os'].downcase =~ /bsd|solaris/ ? "gmake" : "make" + LIBTEST = "build/libtest.#{LIBEXT}" BUILD_DIR = "build" BUILD_EXT_DIR = File.join(BUILD_DIR, "#{Config::CONFIG['arch']}", 'ffi_c', RUBY_VERSION) @@ -112,7 +156,7 @@ end desc "Build the native test lib" task "build/libtest.#{LIBEXT}" do - sh %{#{GMAKE} -f libtest/GNUmakefile CPU=#{Config::CONFIG['host_cpu']}} + sh %{#{GMAKE} -f libtest/GNUmakefile CPU=#{CPU} OS=#{OS} CC="#{CC}" } end diff --git a/libtest/GNUmakefile b/libtest/GNUmakefile index 05e6193..f8bb047 100644 --- a/libtest/GNUmakefile +++ b/libtest/GNUmakefile @@ -1,10 +1,18 @@ # -*- makefile -*- -BUILD_OS := $(shell uname -s | tr '[:upper:]' '[:lower:]') -OS ?= $(BUILD_OS) -CPU ?= $(shell uname -m) -override CPU := $(shell echo $(CPU) | sed -e 's/i[345678]86/i386/') + +ifeq ($(OS),) + BUILD_OS := $(shell uname -s | tr '[:upper:]' '[:lower:]') + OS := $(BUILD_OS) +endif + +ifeq ($(CPU),) + CPU := $(shell uname -m | sed -e 's/i[345678]86/i386/') +endif + MODEL = 32 # Default to 32bit compiles + PLATFORM = $(CPU)-$(OS) + ifeq ($(OS), sunos) OS = solaris endif @@ -14,14 +22,12 @@ BUILD_DIR ?= build TEST_BUILD_DIR = $(BUILD_DIR)/libtest # Set defaults to unix (linux/solaris/bsd) PREFIX = lib -LIBEXT = so +LIBEXT ?= so LIBNAME = $(PREFIX)test.$(LIBEXT) export MACOSX_DEPLOYMENT_TARGET=10.4 -ifeq ($(OS),linux) -CCACHE := $(shell /usr/bin/which ccache) -endif +CCACHE := $(strip $(realpath $(shell which ccache 2> /dev/null))) TEST_SRCS = $(wildcard $(SRC_DIR)/*.c) TEST_OBJS := $(patsubst $(SRC_DIR)/%.c, $(TEST_BUILD_DIR)/%.o, $(TEST_SRCS)) @@ -39,7 +45,7 @@ LDFLAGS += $(SOFLAGS) IFLAGS = -I"$(BUILD_DIR)" CFLAGS = $(OFLAGS) $(WFLAGS) $(IFLAGS) $(PICFLAGS) -D_REENTRANT -ifeq ($(OS), win32) +ifneq ($(strip $(findstring $(OS), win32, mingw, cygwin)),) # For cygwin => win32-native builds, strip out cygwin deps ifneq ($(findstring cygwin, $(BUILD_OS)),) CC += -mno-cygwin -mwin32 @@ -48,6 +54,7 @@ ifeq ($(OS), win32) PICFLAGS= LIBEXT=dll endif + ifeq ($(OS), darwin) ARCHFLAGS = -arch ppc ifeq ($(CPU),i386) @@ -55,11 +62,12 @@ ifeq ($(OS), darwin) endif CFLAGS += $(ARCHFLAGS) -DTARGET_RT_MAC_CFM=0 CFLAGS += -fno-common - LDFLAGS = $(ARCHFLAGS) -dynamiclib -Wl,-syslibroot,$(SDKROOT) -mmacosx-version-min=10.4 + MACSDK = /Developer/SDKs/MacOSX10.4u.sdk + LDFLAGS = $(ARCHFLAGS) -dynamiclib -Wl,-syslibroot,$(MACSDK) -mmacosx-version-min=10.4 # link against the universal libraries on ppc machines - LDFLAGS += -L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib + LDFLAGS += -L$(MACSDK)/usr/lib LIBEXT = dylib - FFI_CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk + FFI_CFLAGS += -isysroot $(MACSDK) PICFLAGS = SOFLAGS = endif @@ -86,16 +94,6 @@ ifneq ($(findstring bsd, $(OS)),) LDFLAGS += -pthread endif -ifneq ($(findstring cygwin, $(OS)),) - CFLAGS += -mno-cygwin -mwin32 - LIBEXT = dll -# PREFIX = - PICFLAGS= -endif -ifneq ($(findstring mingw, $(OS)),) - LIBEXT = dll - PICFLAGS= -endif ifeq ($(CPU), sparcv9) MODEL = 64 endif |