| 1 |
# -*- makefile -*- |
| 2 |
|
| 3 |
ifeq ($(OS),) |
| 4 |
BUILD_OS := $(shell uname -s | tr '[:upper:]' '[:lower:]') |
| 5 |
OS := $(BUILD_OS) |
| 6 |
endif |
| 7 |
|
| 8 |
ifeq ($(CPU),) |
| 9 |
CPU := $(shell uname -m | sed -e 's/i[345678]86/i386/') |
| 10 |
endif |
| 11 |
|
| 12 |
PLATFORM = $(CPU)-$(OS) |
| 13 |
|
| 14 |
ifeq ($(OS), sunos) |
| 15 |
OS = solaris |
| 16 |
endif |
| 17 |
|
| 18 |
SRC_DIR = . |
| 19 |
BUILD_DIR ?= . |
| 20 |
TEST_BUILD_DIR = . |
| 21 |
# Set defaults to unix (linux/solaris/bsd) |
| 22 |
PREFIX = lib |
| 23 |
LIBEXT ?= so |
| 24 |
LIBNAME = $(PREFIX)test.$(LIBEXT) |
| 25 |
|
| 26 |
CCACHE := $(strip $(realpath $(shell which ccache 2> /dev/null))) |
| 27 |
|
| 28 |
TEST_SRCS = $(wildcard $(SRC_DIR)/*.c) |
| 29 |
TEST_OBJS := $(patsubst $(SRC_DIR)/%.c, $(TEST_BUILD_DIR)/%.o, $(TEST_SRCS)) |
| 30 |
|
| 31 |
# |
| 32 |
# Compiler/linker flags from: |
| 33 |
# http://weblogs.java.net/blog/kellyohair/archive/2006/01/compilation_of_1.html |
| 34 |
JFLAGS = -fno-omit-frame-pointer -fno-strict-aliasing |
| 35 |
OFLAGS = -O2 $(JFLAGS) |
| 36 |
WFLAGS = -W -Wall -Wno-unused -Wno-unused-parameter -Wno-parentheses |
| 37 |
PICFLAGS = -fPIC |
| 38 |
SOFLAGS = -shared |
| 39 |
LDFLAGS += $(SOFLAGS) |
| 40 |
|
| 41 |
IFLAGS = -I"$(BUILD_DIR)" |
| 42 |
CFLAGS = $(OFLAGS) $(WFLAGS) $(IFLAGS) $(PICFLAGS) -D_REENTRANT |
| 43 |
|
| 44 |
ifneq ($(strip $(findstring $(OS), win32, mingw, cygwin)),) |
| 45 |
# For cygwin => win32-native builds, strip out cygwin deps |
| 46 |
ifneq ($(findstring cygwin, $(BUILD_OS)),) |
| 47 |
CC += -mno-cygwin -mwin32 |
| 48 |
LDFLAGS += -mno-cygwin -Wl,--add-stdcall-alias |
| 49 |
endif |
| 50 |
PICFLAGS= |
| 51 |
LIBEXT=dll |
| 52 |
CC = gcc |
| 53 |
endif |
| 54 |
|
| 55 |
ifeq ($(OS), darwin) |
| 56 |
ifneq ($(findstring $(CPU),ppc),) |
| 57 |
ARCHFLAGS += -arch ppc |
| 58 |
endif |
| 59 |
CFLAGS += $(ARCHFLAGS) -DTARGET_RT_MAC_CFM=0 |
| 60 |
CFLAGS += -fno-common |
| 61 |
LDFLAGS = $(ARCHFLAGS) -dynamiclib |
| 62 |
# link against the universal libraries on ppc machines |
| 63 |
LDFLAGS += -L$(MACSDK)/usr/lib |
| 64 |
LIBEXT = dylib |
| 65 |
FFI_CFLAGS += -isysroot $(MACSDK) |
| 66 |
PICFLAGS = |
| 67 |
SOFLAGS = |
| 68 |
endif |
| 69 |
|
| 70 |
ifeq ($(OS), linux) |
| 71 |
SOFLAGS += -Wl,-soname,$(LIBNAME) |
| 72 |
endif |
| 73 |
|
| 74 |
ifeq ($(OS), solaris) |
| 75 |
CC = /usr/sfw/bin/gcc -std=c99 |
| 76 |
LD = /usr/ccs/bin/ld |
| 77 |
SOFLAGS = -shared -static-libgcc |
| 78 |
endif |
| 79 |
|
| 80 |
ifeq ($(OS), aix) |
| 81 |
LIBEXT = a |
| 82 |
SOFLAGS = -shared -static-libgcc |
| 83 |
PICFLAGS += -pthread |
| 84 |
endif |
| 85 |
|
| 86 |
ifneq ($(findstring bsd, $(OS)),) |
| 87 |
SOFLAGS = -shared -static-libgcc |
| 88 |
CFLAGS += -pthread |
| 89 |
LDFLAGS += -pthread |
| 90 |
endif |
| 91 |
|
| 92 |
ifeq ($(CPU), i386) |
| 93 |
MODEL = 32 |
| 94 |
endif |
| 95 |
|
| 96 |
ifeq ($(CPU), sparcv9) |
| 97 |
MODEL = 64 |
| 98 |
endif |
| 99 |
|
| 100 |
ifeq ($(CPU), amd64) |
| 101 |
MODEL = 64 |
| 102 |
endif |
| 103 |
|
| 104 |
ifeq ($(CPU), x86_64) |
| 105 |
MODEL = 64 |
| 106 |
endif |
| 107 |
|
| 108 |
ifeq ($(CPU), ppc64) |
| 109 |
MODEL = 64 |
| 110 |
endif |
| 111 |
|
| 112 |
ifeq ($(CPU), powerpc64) |
| 113 |
MODEL = 64 |
| 114 |
endif |
| 115 |
|
| 116 |
MODELFLAG = |
| 117 |
ifneq ($(MODEL),) |
| 118 |
MODELFLAG = -m$(MODEL) |
| 119 |
endif |
| 120 |
|
| 121 |
# On platforms (linux, solaris) that support both 32bit and 64bit, force building for one or the other |
| 122 |
ifneq ($(or $(findstring linux, $(OS)), $(findstring solaris, $(OS))),) |
| 123 |
# Change the CC/LD instead of CFLAGS/LDFLAGS, incase other things in the flags |
| 124 |
# makes the libffi build choke |
| 125 |
CC += $(MODELFLAG) |
| 126 |
LD += $(MODELFLAG) |
| 127 |
endif |
| 128 |
|
| 129 |
LIBTEST = $(LIBNAME) |
| 130 |
|
| 131 |
all: $(LIBTEST) |
| 132 |
|
| 133 |
$(TEST_BUILD_DIR)/%.o : $(SRC_DIR)/%.c |
| 134 |
@mkdir -p $(@D) |
| 135 |
$(CCACHE) $(CC) $(CFLAGS) -c $< -o $@ |
| 136 |
|
| 137 |
$(LIBTEST): $(TEST_OBJS) |
| 138 |
$(CC) -o $@ $(LDFLAGS) $(TEST_OBJS) -lm |
| 139 |
|
| 140 |
clean:: |
| 141 |
# nothing to do - ant will delete the build dir |
| 142 |
|
| 143 |
debug:: |
| 144 |
@echo "SRCS=$(TEST_SRCS)" |