1 # HOST PLATFORM DETECTION
2 ifeq "$(OS)" "Windows_NT"
4 WINDOWS_HOST := defined
6 _UNAME := $(shell uname)
7 UNAME_P := $(shell uname -p)
8 ifeq "$(_UNAME)" "FreeBSD"
9 # Using Linux platform for Unix OSes for now
10 # HOST_PLATFORM := bsd
12 HOST_PLATFORM := linux
15 ifeq "$(_UNAME)" "Darwin"
16 HOST_PLATFORM := apple
19 HOST_PLATFORM := linux
23 HOST_ARCH := $(UNAME_P)
27 ifndef TARGET_PLATFORM
29 TARGET_PLATFORM := $(PLATFORM)
32 ifndef TARGET_PLATFORM
34 TARGET_PLATFORM := win32
37 TARGET_PLATFORM := apple
40 # TARGET_PLATFORM := bsd
42 TARGET_PLATFORM := linux
51 PLATFORM := $(TARGET_PLATFORM)
53 ifeq "$(TARGET_PLATFORM)" "win32"
54 WINDOWS_TARGET := defined
56 ifeq "$(TARGET_PLATFORM)" "apple"
59 #ifeq "$(TARGET_PLATFORM)" "bsd"
60 # BSD_TARGET := defined
62 LINUX_TARGET := defined
68 ifneq "$(TARGET_PLATFORM)" "$(HOST_PLATFORM)"
69 CROSS_TARGET := defined
73 ifeq "$(TARGET_TYPE)" "staticlib"
74 STATIC_LIBRARY_TARGET := defined
76 ifeq "$(TARGET_TYPE)" "sharedlib"
77 SHARED_LIBRARY_TARGET := defined
79 ifeq "$(TARGET_TYPE)" "executable"
80 EXECUTABLE_TARGET := defined
85 ifeq "$(GCC_PREFIX)" "i586-mingw32msvc-"
90 ifeq "$(GCC_PREFIX)" "i686-w64-mingw32-"
95 # Accept different things for ARCH but standardize on x32/x64
96 # This will be used for object directories
104 ifeq "$(ARCH)" "i386"
107 ifeq "$(ARCH)" "i686"
113 ifeq "$(ARCH)" "amd64"
116 ifeq "$(ARCH)" "x86_64"
120 # Set ARCH_FLAGS only if ARCH is set
122 TARGET_ARCH := x86_64
130 ARCH_SUFFIX := .$(ARCH)
133 TARGET_ARCH := $(TARGET_ARCH)-linux-gnu
140 DEBUG_SUFFIX := .debug
144 COMPILER_SUFFIX = $(ARCH_SUFFIX)
146 ifneq "$(COMPILER)" "default"
147 COMPILER_SUFFIX = .$(COMPILER)$(ARCH_SUFFIX)
153 esc := $(empty)
\7f$(empty)
154 space := $(empty) $(empty)
156 slash := $(empty)/$(empty)
157 backslash := $(empty)\$(empty)
158 escspace = $(subst $(space),$(backslash)$(space),$(subst $(backslash)$(space),$(space),$(1)))
159 hidspace = $(subst $(space),$(esc),$(subst $(backslash)$(space),$(esc),$(1)))
160 shwspace = $(subst $(esc),$(backslash)$(space),$(1))
161 unescp_all = $(subst $(esc),$(backslash),$(subst $(backslash),,$(subst $(backslash)$(backslash),$(esc),$(1))))
163 # PATH SEPARATOR STRING TOOLS
166 WIN_PS_TOOLS := defined
171 slash_path = $(subst $(backslash),$(slash),$(1))
172 sys_path = $(subst $(backslash)$(backslash),$(slash),$(subst $(slash),$(backslash),$(1)))
173 quote_path = "$(call sys_path,$(call unescp_all,$(1)))"
174 each_path_quote = $(if $(findstring $(esc),$(path)),"$(call unescp_all,$(call shwspace,$(path)))",$(call unescp_all,$(path)))
175 sys_path_list = $(foreach path,$(1),$(each_path_quote))
183 # PREFIXES AND EXTENSIONS
184 .SUFFIXES: .c .ec .sym .imp .bowl .o .a
192 E := $(if $(WINDOWS_TARGET),.exe,)
193 SO := $(if $(WINDOWS_TARGET),.dll,$(if $(OSX_TARGET),.dylib,.so))
194 LP := $(if $(WINDOWS_TARGET),$(if $(STATIC_LIBRARY_TARGET),lib,),lib)
195 HOST_E := $(if $(WINDOWS_HOST),.exe,)
196 HOST_SO := $(if $(WINDOWS_HOST),.dll,$(if $(OSX_HOST),.dylib,.so))
197 HOST_LP := $(if $(WINDOWS_HOST),$(if $(STATIC_LIBRARY_TARGET),lib,),lib)
200 VER := $(if $(LINUX_TARGET),$(if $(LINUX_HOST),$(if $(VERSION),.$(VERSION),),),)
204 CCACHE_COMPILE := ccache$(space)
206 DISTCC_COMPILE := distcc$(space)
210 DISTCC_COMPILE := distcc$(space)
214 _CPP = $(if $(findstring $(space),$(CPP)),"$(CPP)",$(CPP))
216 _SYSROOT = $(if $(SYSROOT),$(space)--sysroot=$(SYSROOT),)
221 WIN_SHELL_COMMANDS := defined
224 ifdef WIN_SHELL_COMMANDS
226 echo = $(if $(1),echo $(1))
227 touch = $(if $(1),@cmd /c "for %%I in ($(call sys_path,$(1))) do @(cd %%~pI && type nul >> %%~nxI && copy /by %%~nxI+,, > nul 2>&1 && cd %%cd%%)")
228 cpq = $(if $(1),@cmd /c "for %%I in ($(call sys_path,$(1))) do copy /by %%I $(call sys_path,$(2))" > nul 2>&1)
229 rmq = $(if $(1),-del /f /q $(call sys_path,$(call sys_path_list,$(1))) > nul 2>&1)
230 rmrq = $(if $(1),-rmdir /q /s $(call sys_path,$(1)) > nul 2>&1)
231 mkdirq = $(if $(1),-mkdir $(call sys_path,$(1)) > nul 2>&1)
232 rmdirq = $(if $(1),-rmdir /q $(call sys_path,$(1)) > nul 2>&1)
234 nullerror = 2>/dev/null
235 echo = $(if $(1),echo "$(1)")
236 touch = $(if $(1),touch $(1))
237 cpq = $(if $(1),cp $(1) $(2))
238 rmq = $(if $(1),-rm -f $(1))
239 rmrq = $(if $(1),-rm -f -r $(1))
240 mkdirq = $(if $(1),-mkdir -p $(1))
241 rmdirq = $(if $(1),-rmdir $(1))
244 # potential common use variables
245 numbers := 0 1 2 3 4 5 6 7 8 9
247 # potential common use functions
248 reverselist = $(if $(1),$(call reverselist,$(strip $(wordlist 2,$(words $(1)),$(1))))) $(firstword $(1))
249 dirlistfromlocation = $(strip $(subst $(slash),$(space),$(subst $(backslash),$(space),$(1))))
250 spacenumbers = $(subst 0,$(space)0$(space),$(subst 1,$(space)1$(space),$(subst 2,$(space)2$(space),$(subst 3,$(space)3$(space),$(subst 4,$(space)4$(space),$(subst 5,$(space)5$(space),$(subst 6,$(space)6$(space),$(subst 7,$(space)7$(space),$(subst 8,$(space)8$(space),$(subst 9,$(space)9$(space),$(1)))))))))))
251 hasnumbers = $(if $(filter $(numbers),$(call spacenumbers,$(1))),$(1),)
252 isanumber = $(if $(filter-out $(numbers),$(call spacenumbers,$(1))),,$(1))
254 # location version utility functions (lv_*)
255 lv_issimplever = $(if $(call isanumber,$(firstword $(call spacenumbers,$(subst .,,$(1))))),$(1),)
256 lv_isversionver = $(if $(call lv_issimplever,$(1:v%=%)),$(1),$(if $(call lv_issimplever,$(1:ver%=%)),$(1),$(if $(call lv_issimplever,$(1:version%=%)),$(1),)))
257 lv_isreleasever = $(if $(call lv_issimplever,$(1:r%=%)),$(1),$(if $(call lv_issimplever,$(1:rel%=%)),$(1),$(if $(call lv_issimplever,$(1:release%=%)),$(1),)))
258 lv_isbuildver = $(if $(call lv_issimplever,$(1:b%=%)),$(1),$(if $(call lv_issimplever,$(1:bld%=%)),$(1),$(if $(call lv_issimplever,$(1:build%=%)),$(1),)))
259 lv_iscomplexver = $(if $(call lv_isversionver,$(1)),$(1),$(if $(call lv_isreleasever,$(1)),$(1),$(if $(call lv_isbuildver,$(1)),$(1),)))
260 lv_isver = $(if $(call lv_issimplever,$(1)),$(1),$(if $(call lv_iscomplexver,$(1)),$(1),))
261 lv_possibleverorver = $(if $(findstring -,$(1)),$(if $(call hasnumbers,$(1)),$(1),),$(if $(call lv_isver,$(1)),$(1),))
262 lv_termslistfromdir = $(strip $(subst -,$(space),$(1)))
263 lv_verfromtermlist = $(if $(1)$(2),$(if $(1),$(1)$(if $(2),-,),)$(call lv_verfromtermlist,$(firstword $(2)),$(wordlist 2,$(words $(2)),$(2))),)
264 lv_termwalker = $(if $(firstword $(1)),$(if $(call lv_isver,$(firstword $(1))),$(call lv_verfromtermlist,,$(1)),$(call lv_termwalker,$(wordlist 2,$(words $(1)),$(1)))),)
265 lv_version = $(if $(call lv_possibleverorver,$(1)),$(call lv_termwalker,$(call lv_termslistfromdir,$(1))),)
266 lv_dirwalker = $(if $(firstword $(1)),$(if $(call lv_version,$(firstword $(1))),$(call lv_version,$(firstword $(1))),$(call lv_dirwalker,$(wordlist 2,$(words $(1)),$(1)))),)
267 locationversion = $(call shwspace,$(call lv_dirwalker,$(call reverselist,$(subst $(space)$(space),$(space),$(call dirlistfromlocation,$(call hidspace,$(1)))))))
269 # SOURCE CODE REPOSITORY VERSION
270 ifndef REPOSITORY_VER
271 # TODO: support other VCS
272 ifndef GIT_REPOSITORY
276 ifeq ($(shell $(GIT) --version $(nullerror)),)
277 export GIT_NA := $(GIT)NotAvailable
279 ifneq ($(shell $(GIT) log -n 1 --format="%%%%" $(nullerror)),)
280 export GIT_REPOSITORY := yes
281 export REPOSITORY_VER := $(shell $(GIT) describe --tags --dirty="\ (dirty)" --always)
285 ifndef REPOSITORY_VER
286 DIR_VER := $(call locationversion,$(CURDIR))
288 export REPOSITORY_VER := $(DIR_VER)
291 ifndef REPOSITORY_VER
292 export REPOSITORY_VER := unknown
297 ECSLIBOPT := $(if $(STATIC_LIBRARY_TARGET),-staticlib,$(if $(SHARED_LIBRARY_TARGET),-dynamiclib,))
298 FVISIBILITY := $(if $(WINDOWS_TARGET),,-fvisibility=hidden)
299 FPIC := $(if $(WINDOWS_TARGET),,-fPIC)
300 EXECUTABLE := $(if $(WINDOWS_TARGET),$(if $(EXECUTABLE_TARGET),$(CONSOLE),),)
301 INSTALLNAME := $(if $(OSX_TARGET),$(if $(STATIC_LIBRARY_TARGET),-install_name $(LP)$(MODULE)$(SO),),)
304 SHAREDLIB := $(if $(SHARED_LIBRARY_TARGET),$(if $(OSX_TARGET),-dynamiclib -single_module -multiply_defined suppress,-shared),)
306 STRIPOPT := $(if $(OSX_TARGET),$(if $(SHARED_LIBRARY_TARGET),-x, -u -r), -x --strip-unneeded --remove-section=.comment --remove-section=.note)
307 HOST_SODESTDIR := $(if $(WINDOWS_HOST),obj/$(HOST_PLATFORM)$(COMPILER_SUFFIX)$(DEBUG_SUFFIX)/bin/,obj/$(HOST_PLATFORM)$(COMPILER_SUFFIX)$(DEBUG_SUFFIX)/lib/)
308 SODESTDIR := $(if $(WINDOWS_TARGET),obj/$(TARGET_PLATFORM)$(COMPILER_SUFFIX)$(DEBUG_SUFFIX)/bin/,obj/$(TARGET_PLATFORM)$(COMPILER_SUFFIX)$(DEBUG_SUFFIX)/lib/)
311 _L = $(if $(filter $(1),$(EXCLUDED_LIBS)),,-l$(1))
315 CFLAGS += $(CPPFLAGS)
322 # COMMON LIBRARIES DETECTION
325 _OPENSSL_CONF = $(call hidspace,$(call slash_path,$(OPENSSL_CONF)))
326 OPENSSL_INCLUDE_DIR = $(call shwspace,$(subst /bin/openssl.cfg,/include,$(_OPENSSL_CONF)))
327 OPENSSL_LIB_DIR = $(call shwspace,$(subst /bin/openssl.cfg,/lib,$(_OPENSSL_CONF)))
328 OPENSSL_BIN_DIR = $(call shwspace,$(subst /bin/openssl.cfg,/bin,$(_OPENSSL_CONF)))
330 # to avoid issues with empty -L/-I
331 OPENSSL_INCLUDE_DIR = .