Debian Codegraph @

libtest/GNUmakefile

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