Makefiles: Tweaks for Debian
[sdk] / include.mk
1 # HOST PLATFORM DETECTION
2 ifeq "$(OS)" "Windows_NT"
3    WINDOWS = defined
4 else
5 ifeq "$(OSTYPE)" "FreeBSD"
6    BSD = defined
7 else
8 ifeq "$(shell uname)" "Darwin"
9    OSX = defined
10 else
11    LINUX = defined
12 endif
13 endif
14 endif
15
16 # PLATFORM (TARGET)
17 ifndef PLATFORM
18 ifdef WINDOWS
19    PLATFORM := win32
20 else
21 ifdef OSX
22    PLATFORM := apple
23 else
24    PLATFORM := linux
25 endif
26 endif
27 endif
28
29 # MISC STRING TOOLS
30 empty :=
31 space := $(empty) $(empty)
32 escspace = $(subst $(space),\$(space),$(subst \$(space),$(space),$1))
33 hidspace = $(subst $(space),\7f,$(subst \$(space),\7f,$1))
34 shwspace = $(subst \7f,\$(space),$1)
35
36 # PATH SEPARATOR STRING TOOLS
37 ifdef WINDOWS
38 ifndef MSYSCON
39    WIN_PS_TOOLS := defined
40 endif
41 endif
42 ifdef WIN_PS_TOOLS
43    fixps = $(subst \,/,$(1))
44    psep = $(subst \\,/,$(subst /,\,$(1)))
45    PS := $(strip \)
46 else
47    fixps = $(1)
48    PS := $(strip /)
49    psep = $(1)
50 endif
51
52 # PREFIXES AND EXTENSIONS
53 .SUFFIXES: .c .ec .sym .imp .bowl .o .a
54 S := .sym
55 I := .imp
56 B := .bowl
57 C := .c
58 O := .o
59 A := .a
60 ifeq "$(PLATFORM)" "win32"
61    E := .exe
62 ifeq "$(TARGET_TYPE)" "staticlib"
63    LP := lib
64 else
65    LP :=
66 endif
67    SO := .dll
68 else
69 ifeq "$(PLATFORM)" "apple"
70    E :=
71    LP := lib
72    SO := .dylib
73 else
74    E :=
75    LP := lib
76    SO := .so
77 endif
78 endif
79
80 # SUPER TOOLS
81 ifdef CCACHE
82    CCACHE_COMPILE := ccache
83 ifdef DISTCC
84    DISTCC_COMPILE := distcc
85 endif
86 else
87 ifdef DISTCC
88    DISTCC_COMPILE := distcc
89 endif
90 endif
91
92 # TOOLCHAIN
93 export CC      = $(CCACHE_COMPILE) $(DISTCC_COMPILE) gcc
94 export CPP     = $(CCACHE_COMPILE) $(DISTCC_COMPILE) cpp
95 export ECP     = ecp
96 export ECC     = ecc
97 export ECS     = ecs
98 export EAR     = ear
99 export AS      = as
100 export LD      = ld
101 export AR      = ar
102 export STRIP   = strip
103 UPX := upx
104
105 # SHELL COMMANDS
106 ifdef WINDOWS
107 ifndef MSYSCON
108    WIN_SHELL_COMMANDS := defined
109 endif
110 endif
111 ifdef WIN_SHELL_COMMANDS
112    echo = $(if $(1),echo $(1))
113    cpq = $(if $(1),@cmd /c for %%I in ($(call psep,$(1))) do @copy /y %%I $(call psep,$(2)) > nul 2>&1)
114    rmq = $(if $(1),-@del /f /q $(call psep,$(1)) > nul 2>&1)
115    rmrq = $(if $(1),-@rmdir /q /s $(call psep,$(1)) > nul 2>&1)
116    mkdirq = $(if $(1),-@mkdir $(call psep,$(1)) > nul 2>&1)
117    rmdirq = $(if $(1),-@rmdir /q $(call psep,$(1)) > nul 2>&1)
118 else
119    echo = $(if $(1),echo "$(1)")
120    cpq = $(if $(1),@cp $(1) $(2))
121    rmq = $(if $(1),-@rm -f $(1))
122    rmrq = $(if $(1),-@rm -f -r $(1))
123    mkdirq = $(if $(1),-@mkdir -p $(1))
124    rmdirq = $(if $(1),-@rmdir $(1))
125 endif
126
127 # COMPILER OPTIONS
128 ifeq "$(TARGET_TYPE)" "sharedlib"
129    ECSLIBOPT := -dynamiclib
130 else
131 ifeq "$(TARGET_TYPE)" "staticlib"
132    ECSLIBOPT := -staticlib
133 else
134    ECSLIBOPT :=
135 endif
136 endif
137 ifdef WINDOWS
138    FVISIBILITY :=
139    FPIC :=
140 ifeq "$(TARGET_TYPE)" "executable"
141    EXECUTABLE := $(CONSOLE)
142 else
143    EXECUTABLE :=
144 endif
145 else
146    FVISIBILITY := -fvisibility=hidden
147    FPIC := -fPIC
148    EXECUTABLE :=
149 endif
150 ifdef OSX
151 ifeq "$(TARGET_TYPE)" "sharedlib"
152    INSTALLNAME := -install_name $(LP)$(MODULE)$(SO)
153 else
154    INSTALLNAME :=
155 endif
156 else
157    INSTALLNAME :=
158 endif
159
160 # DEBIAN
161 ifdef DEBIAN_PACKAGE
162 CFLAGS += $(CPPFLAGS)
163 OFLAGS += $(LDFLAGS)
164 endif
165
166 # LINKER OPTIONS
167 ifdef OSX
168 ifeq "$(TARGET_TYPE)" "sharedlib"
169    SHAREDLIB := -dynamiclib -single_module -multiply_defined suppress
170    LINKOPT :=
171 else
172    SHAREDLIB :=
173    LINKOPT :=
174 endif
175 ifeq "$(TARGET_TYPE)" "sharedlib"
176    STRIPOPT := -x
177 else
178    STRIPOPT := -u -r
179 endif
180 else
181 ifeq "$(TARGET_TYPE)" "sharedlib"
182    SHAREDLIB := -shared
183 else
184    SHAREDLIB :=
185 endif
186    LINKOPT :=
187    STRIPOPT := -x --strip-unneeded --remove-section=.comment --remove-section=.note
188 endif
189 ifdef WINDOWS
190    SODESTDIR := obj/$(PLATFORM)/bin/
191 else
192    SODESTDIR := obj/$(PLATFORM)/lib/
193 endif
194
195 # COMMON LIBRARIES DETECTION
196
197 ifdef WINDOWS
198
199 ifdef OPENSSL_CONF
200 _OPENSSL_CONF = $(call hidspace,$(call fixps,$(OPENSSL_CONF)))
201 OPENSSL_INCLUDE_DIR = $(call shwspace,$(subst /bin/openssl.cfg,/include,$(_OPENSSL_CONF)))
202 OPENSSL_LIB_DIR = $(call shwspace,$(subst /bin/openssl.cfg,/lib,$(_OPENSSL_CONF)))
203 OPENSSL_BIN_DIR = $(call shwspace,$(subst /bin/openssl.cfg,/bin,$(_OPENSSL_CONF)))
204 endif
205
206 endif