ecere/gui/drivers/XInterface: Fixed requesting frame extents on null window
[sdk] / crossplatform.mk
1 # HOST PLATFORM DETECTION
2 ifeq "$(OS)" "Windows_NT"
3    HOST_PLATFORM := win32
4    WINDOWS_HOST := defined
5 else
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
11     BSD_HOST := defined
12     HOST_PLATFORM := linux
13     LINUX_HOST := defined
14  else
15   ifeq "$(_UNAME)" "Darwin"
16      HOST_PLATFORM := apple
17      OSX_HOST := defined
18   else
19      HOST_PLATFORM := linux
20      LINUX_HOST := defined
21   endif
22  endif
23  HOST_ARCH := $(UNAME_P)
24 endif
25
26 # TARGET_PLATFORM
27 ifndef TARGET_PLATFORM
28 ifdef PLATFORM
29    TARGET_PLATFORM := $(PLATFORM)
30 endif
31 endif
32 ifndef TARGET_PLATFORM
33 ifdef WINDOWS_HOST
34    TARGET_PLATFORM := win32
35 else
36 ifdef OSX_HOST
37    TARGET_PLATFORM := apple
38 else
39 #ifdef BSD_HOST
40 #   TARGET_PLATFORM := bsd
41 #else
42    TARGET_PLATFORM := linux
43 ifdef BSD_HOST
44    BSD_TARGET := defined
45 endif
46 #endif
47 endif
48 endif
49 endif
50 ifndef PLATFORM
51    PLATFORM := $(TARGET_PLATFORM)
52 endif
53 ifeq "$(TARGET_PLATFORM)" "win32"
54    WINDOWS_TARGET := defined
55 else
56 ifeq "$(TARGET_PLATFORM)" "apple"
57    OSX_TARGET := defined
58 else
59 #ifeq "$(TARGET_PLATFORM)" "bsd"
60 #   BSD_TARGET := defined
61 #else
62    LINUX_TARGET := defined
63 #endif
64 endif
65 endif
66
67 # CROSS_TARGET
68 ifneq "$(TARGET_PLATFORM)" "$(HOST_PLATFORM)"
69    CROSS_TARGET := defined
70 endif
71
72 # TARGET_TYPE
73 ifeq "$(TARGET_TYPE)" "staticlib"
74    STATIC_LIBRARY_TARGET := defined
75 else
76 ifeq "$(TARGET_TYPE)" "sharedlib"
77    SHARED_LIBRARY_TARGET := defined
78 else
79 ifeq "$(TARGET_TYPE)" "executable"
80    EXECUTABLE_TARGET := defined
81 endif
82 endif
83 endif
84
85 ifeq "$(GCC_PREFIX)" "i586-mingw32msvc-"
86 export ARCH
87 ARCH := x32
88 endif
89
90 ifeq "$(GCC_PREFIX)" "i686-w64-mingw32-"
91 export ARCH
92 ARCH := x32
93 endif
94
95 # Accept different things for ARCH but standardize on x32/x64
96 # This will be used for object directories
97 ifdef ARCH
98  ifeq "$(ARCH)" "32"
99   override ARCH := x32
100  endif
101  ifeq "$(ARCH)" "x86"
102   override ARCH := x32
103  endif
104  ifeq "$(ARCH)" "i386"
105   override ARCH := x32
106  endif
107  ifeq "$(ARCH)" "i686"
108   override ARCH := x32
109  endif
110  ifeq "$(ARCH)" "64"
111   override ARCH := x64
112  endif
113  ifeq "$(ARCH)" "amd64"
114   override ARCH := x64
115  endif
116  ifeq "$(ARCH)" "x86_64"
117   override ARCH := x64
118  endif
119
120  # Set ARCH_FLAGS only if ARCH is set
121  ifeq "$(ARCH)" "x64"
122   TARGET_ARCH := x86_64
123   ARCH_FLAGS := -m64
124  endif
125  ifeq "$(ARCH)" "x32"
126   TARGET_ARCH := i386
127   ARCH_FLAGS := -m32
128  endif
129
130  ARCH_SUFFIX := .$(ARCH)
131
132  ifdef LINUX_TARGET
133   TARGET_ARCH := $(TARGET_ARCH)-linux-gnu
134  endif
135
136 endif
137
138 # DEBUG SUFFIX
139 ifdef DEBUG
140 DEBUG_SUFFIX := .debug
141 endif
142
143 # COMPILER SUFFIX
144 COMPILER_SUFFIX = $(ARCH_SUFFIX)
145 ifdef COMPILER
146 ifneq "$(COMPILER)" "default"
147 COMPILER_SUFFIX = .$(COMPILER)$(ARCH_SUFFIX)
148 endif
149 endif
150
151 # MISC STRING TOOLS
152 empty :=
153 esc := $(empty)\7f$(empty)
154 space := $(empty) $(empty)
155 comma := ,
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))))
162
163 # PATH SEPARATOR STRING TOOLS
164 ifdef WINDOWS_HOST
165 ifndef MSYSCON
166    WIN_PS_TOOLS := defined
167 endif
168 endif
169 ifdef WIN_PS_TOOLS
170    psep := $(backslash)
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))
176 else
177    psep := $(slash)
178    slash_path = $(1)
179    sys_path = $(1)
180    quote_path = $(1)
181 endif
182
183 # PREFIXES AND EXTENSIONS
184 .SUFFIXES: .c .ec .sym .imp .bowl .o .a
185 EC := .ec
186 S := .sym
187 I := .imp
188 B := .bowl
189 C := .c
190 O := .o
191 A := .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)
198
199 # TARGET VERSION
200 VER := $(if $(LINUX_TARGET),$(if $(LINUX_HOST),$(if $(VERSION),.$(VERSION),),),)
201
202 # SUPER TOOLS
203 ifdef CCACHE
204    CCACHE_COMPILE := ccache$(space)
205 ifdef DISTCC
206    DISTCC_COMPILE := distcc$(space)
207 endif
208 else
209 ifdef DISTCC
210    DISTCC_COMPILE := distcc$(space)
211 endif
212 endif
213
214 _CPP = $(if $(findstring $(space),$(CPP)),"$(CPP)",$(CPP))
215
216 _SYSROOT = $(if $(SYSROOT),$(space)--sysroot=$(SYSROOT),)
217
218 # SHELL COMMANDS
219 ifdef WINDOWS_HOST
220 ifndef MSYSCON
221    WIN_SHELL_COMMANDS := defined
222 endif
223 endif
224 ifdef WIN_SHELL_COMMANDS
225    nullerror = 2>NUL
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)
233 else
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))
242 endif
243
244 # potential common use variables
245 numbers := 0 1 2 3 4 5 6 7 8 9
246
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))
253
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)))))))
268
269 # SOURCE CODE REPOSITORY VERSION
270 ifndef REPOSITORY_VER
271    # TODO: support other VCS
272    ifndef GIT_REPOSITORY
273       ifndef GIT
274          GIT := git
275       endif
276       ifeq ($(shell $(GIT) --version $(nullerror)),)
277          export GIT_NA := $(GIT)NotAvailable
278       else
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)
282          endif
283       endif
284    endif
285    ifndef REPOSITORY_VER
286       DIR_VER := $(call locationversion,$(CURDIR))
287       ifneq ($(DIR_VER),)
288          export REPOSITORY_VER := $(DIR_VER)
289       endif
290    endif
291    ifndef REPOSITORY_VER
292       export REPOSITORY_VER := unknown
293    endif
294 endif
295
296 # COMPILER OPTIONS
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),),)
302
303 # LINKER OPTIONS
304 SHAREDLIB := $(if $(SHARED_LIBRARY_TARGET),$(if $(OSX_TARGET),-dynamiclib -single_module -multiply_defined suppress,-shared),)
305 LINKOPT :=
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/)
309
310 # EXCLUDED_LIBS TOOL
311 _L = $(if $(filter $(1),$(EXCLUDED_LIBS)),,-l$(1))
312
313 # DEBIAN
314 ifdef DEBIAN_PACKAGE
315 CFLAGS += $(CPPFLAGS)
316 endif
317
318 ifdef DEBUG
319 CFLAGS += -D_DEBUG
320 endif
321
322 # COMMON LIBRARIES DETECTION
323 ifdef WINDOWS_TARGET
324  ifdef OPENSSL_CONF
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)))
329  else
330 # to avoid issues with empty -L/-I
331   OPENSSL_INCLUDE_DIR = .
332   OPENSSL_LIB_DIR = .
333   OPENSSL_BIN_DIR = .
334  endif
335 endif