ecere/gui/Window: Prevent uninitialized values if base Window methods not overridden...
[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 # On Windows/32 bit systems, pass -m32 as TDM-GCC packaged with the installer produces 64 bit executables by default
139 # Disable this if your compiler does not accept -m32
140 ifndef ARCH
141  ifeq ($(HOST_PLATFORM),win32)
142   ifeq ($(TARGET_PLATFORM),win32)
143    ifndef ProgramFiles(x86)
144     ARCH := x32
145     TARGET_ARCH := i386
146     ARCH_FLAGS := -m32
147    endif
148   endif
149  endif
150 endif
151
152 # DEBUG SUFFIX
153 ifdef DEBUG
154 DEBUG_SUFFIX := .debug
155 endif
156
157 # COMPILER SUFFIX
158 COMPILER_SUFFIX = $(ARCH_SUFFIX)
159 ifdef COMPILER
160 ifneq ($(COMPILER),default)
161 COMPILER_SUFFIX = .$(COMPILER)$(ARCH_SUFFIX)
162 endif
163 endif
164
165 # STRING TOOLS
166 empty :=
167 esc := $(empty)\7f$(empty)
168 space := $(empty) $(empty)
169 comma := ,
170 quote := "
171 slash := $(empty)/$(empty)
172 backslash := $(empty)\$(empty)
173 escspace = $(subst $(space),$(backslash)$(space),$(subst $(backslash)$(space),$(space),$(1)))
174 hidspace = $(subst $(space),$(esc),$(subst $(backslash)$(space),$(esc),$(1)))
175 shwspace = $(subst $(esc),$(backslash)$(space),$(1))
176 unescp_all = $(subst $(esc),$(backslash),$(subst $(backslash),,$(subst $(backslash)$(backslash),$(esc),$(1))))
177
178 # HIDDEN SPACE STRING TOOLS
179 temporaty_token := _+;:;+_:;+;:_:+;+:_
180 hidden_space := $(empty)\7f$(empty)
181 hs_hide = $(subst $(space),$(hidden_space),$(1))
182 hs_unhide = $(subst $(hidden_space),$(space),$(1))
183 hs_escape = $(subst $(hidden_space),$(backslash)$(space),$(1))
184 hs_process = $(subst $(space),$(hidden_space),$(subst $(backslash)$(space),$(hidden_space),$(1)))
185 hs_quote_all = $(foreach item,$(1),"$(call hs_unhide,$(item))")
186 hs_quote_each = $(foreach item,$(1),$(if $(findstring $(esc),$(item)),"$(call hs_unhide,$(item))",$(item)))
187
188 # FILE PATH TOOLS
189 fp_unquote = $(subst $(quote),,$(1))
190 fp_opt_quotes = $(if $(findstring $(space),$(1)),"$(1)",$(1))
191 fp_no_parent_dir = $(foreach item,$(1),$(if $(findstring ..,$(item)),,$(item)))
192
193 # FILE SYSTEM TOOLS
194 # hs_ls doc
195 #     usage: $(hs_ls) | $(hs_ls_dir) | $(hs_ls_files)
196 #     result:
197 #      -      for hs_ls: a list of files and directories in the current dir
198 #                        i.e.: fileA dir1/ fileB fileC dir2/ dir3/
199 #      -  for hs_ls_dir: a list of directories in the current dir
200 #                        i.e.: dir1 dir2 dir3
201 #      - for hs_ls_file: a list of files in the current dir
202 #                        i.e.: fileA fileB fileC
203 #     notes:
204 #      - hs_ls* functions work in current dir, you can't specify a directory
205 #      - hs_ls* functions do not report hidden files and directories because wildcard doesn't
206 #        you would never get such a list: .fileA .dir1/
207 hs_ls = $(subst $(temporaty_token),$(space),$(subst ./,,$(call hs_hide,$(subst $(space)./,$(temporaty_token),$(wildcard ./*/)))))
208 hs_ls_dir = $(subst /,,$(foreach item,$(hs_ls),$(if $(findstring /,$(item)),$(item),)))
209 hs_ls_file = $(foreach item,$(hs_ls),$(if $(findstring /,$(item)),,$(item)))
210
211 # CONTROL FLOW TOOLS
212 # hs_crossloop usage: $(call hs_crossloop,<list>,<command_function>)
213 #                     hs_crossloop will call <command_function> with the item as first parameter ($(1))
214 hs_crossloop = $(call hs_unsafe_crossloop,$(call fp_no_parent_dir,$(1)),$(2))
215
216 # PATH SEPARATOR STRING TOOLS
217 ifdef WINDOWS_HOST
218    ifneq ($(TERM),cygwin)
219       ifndef MSYSCON
220          WIN_PS_TOOLS := defined
221       endif
222    endif
223 endif
224 slash_path = $(subst $(backslash),$(slash),$(1))
225 ifdef WIN_PS_TOOLS
226    psep := $(backslash)
227    sys_path = $(subst $(backslash)$(backslash),$(slash),$(subst $(slash),$(backslash),$(1)))
228    quote_path = "$(call sys_path,$(call unescp_all,$(1)))"
229    each_path_quote = $(if $(findstring $(esc),$(path)),"$(call unescp_all,$(call shwspace,$(path)))",$(call unescp_all,$(path)))
230    sys_path_list = $(foreach path,$(1),$(each_path_quote))
231 else
232    psep := $(slash)
233    sys_path = $(1)
234    quote_path = $(1)
235 endif
236
237 # PREFIXES AND EXTENSIONS
238 EC := .ec
239 S := .sym
240 I := .imp
241 B := .bowl
242 C := .c
243 ifndef O
244 O := .o
245 endif
246 A := .a
247 E := $(if $(WINDOWS_TARGET),.exe,)
248 SO := $(if $(WINDOWS_TARGET),.dll,$(if $(OSX_TARGET),.dylib,.so))
249 LP := $(if $(WINDOWS_TARGET),$(if $(STATIC_LIBRARY_TARGET),lib,),lib)
250 HOST_E := $(if $(WINDOWS_HOST),.exe,)
251 HOST_SO := $(if $(WINDOWS_HOST),.dll,$(if $(OSX_HOST),.dylib,.so))
252 HOST_LP := $(if $(WINDOWS_HOST),$(if $(STATIC_LIBRARY_TARGET),lib,),lib)
253 .SUFFIXES: .c .ec .sym .imp .bowl $(O) $(A)
254
255 # TARGET VERSION
256 VER := $(if $(LINUX_TARGET),$(if $(LINUX_HOST),$(if $(VERSION),.$(VERSION),),),)
257
258 # SUPER TOOLS
259 ifdef CCACHE
260    CCACHE_COMPILE := ccache$(space)
261 ifdef DISTCC
262    DISTCC_COMPILE := distcc$(space)
263 endif
264 else
265 ifdef DISTCC
266    DISTCC_COMPILE := distcc$(space)
267 endif
268 endif
269
270 _CPP = $(if $(findstring $(space),$(CPP)),"$(CPP)",$(CPP))
271
272 _SYSROOT = $(if $(SYSROOT),$(space)--sysroot=$(SYSROOT),)
273
274 _MAKE = $(call fp_opt_quotes,$(MAKE))
275
276 # SHELL COMMANDS
277 ifdef WINDOWS_HOST
278    ifneq ($(TERM),cygwin)
279       ifndef MSYSCON
280          WIN_SHELL_COMMANDS := defined
281       endif
282    endif
283 endif
284 ifneq ($(V),1)
285    SILENT_IS_ON := defined
286 endif
287 ifeq ($(D),1)
288    DEBUG_IS_ON := defined
289 endif
290 addtolistfile = $(if $(1),@$(call echo,$(1)) >> $(2),)
291 ifdef WIN_SHELL_COMMANDS
292    cd = @cd
293    nullerror = 2>NUL
294    echo = $(if $(1),echo $(1))
295    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%%)")
296    cp = $(if $(1),@cmd /c "for %%I in ($(call sys_path,$(1))) do copy /by %%I $(call sys_path,$(2))"$(if $(SILENT_IS_ON), > nul,))
297    cpr = $(if $(1),xcopy /y /i /e$(if $(SILENT_IS_ON), /q,) $(call sys_path,$(call sys_path_list,$(1))) $(call sys_path,$(2))$(if $(SILENT_IS_ON), > nul,))
298    rm = $(if $(1),-del /f$(if $(SILENT_IS_ON), /q,) $(call sys_path,$(call sys_path_list,$(1)))$(if $(SILENT_IS_ON), > nul,)$(if $(DEBUG_IS_ON),, 2>&1))
299    rmr = $(if $(1),-rmdir /s$(if $(SILENT_IS_ON), /q,) $(call sys_path,$(1))$(if $(SILENT_IS_ON), > nul,))
300    mkdir = $(if $(1),-mkdir $(call sys_path,$(1))$(if $(SILENT_IS_ON), > nul,)$(if $(DEBUG_IS_ON),, 2>&1))
301    rmdir = $(if $(1),-rmdir$(if $(SILENT_IS_ON), /q,) $(call sys_path,$(1))$(if $(SILENT_IS_ON), > nul,))
302    hs_unsafe_crossloop = ${if $(1),${if $(2),@cmd /c "for %%I in (${call hs_quote_each,$(1)}) do ${call $(2),%%I}",},}
303 else
304    cd = cd
305    nullerror = 2>/dev/null
306    echo = $(if $(1),echo "$(1)")
307    touch = $(if $(1),touch $(1))
308    cp = $(if $(1),cp -P$(if $(SILENT_IS_ON),,v) $(1) $(2))
309    cpr = $(if $(1),cp -PR$(if $(SILENT_IS_ON),,v) $(1) $(2))
310    rm = $(if $(1),-rm -f$(if $(SILENT_IS_ON),,v) $(1))
311    rmr = $(if $(1),-rm -fr$(if $(SILENT_IS_ON),,v) $(1))
312    mkdir = $(if $(1),-mkdir -p$(if $(SILENT_IS_ON),,v) $(1))
313    rmdir = $(if $(1),-rmdir$(if $(SILENT_IS_ON),, -v) $(1))
314    hs_unsafe_crossloop = ${if $(1),${if $(2),for item in ${call hs_quote_each,$(1)}; do ${call $(2),"$$item"}; done,},}
315 endif
316
317 # potential common use variables
318 numbers := 0 1 2 3 4 5 6 7 8 9
319
320 # potential common use functions
321 reverselist = $(if $(1),$(call reverselist,$(strip $(wordlist 2,$(words $(1)),$(1))))) $(firstword $(1))
322 dirlistfromlocation = $(strip $(subst $(slash),$(space),$(subst $(backslash),$(space),$(1))))
323 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)))))))))))
324 hasnumbers = $(if $(filter $(numbers),$(call spacenumbers,$(1))),$(1),)
325 isanumber = $(if $(filter-out $(numbers),$(call spacenumbers,$(1))),,$(1))
326
327 # location version utility functions (lv_*)
328 lv_issimplever = $(if $(call isanumber,$(firstword $(call spacenumbers,$(subst .,,$(1))))),$(1),)
329 lv_isversionver = $(if $(call lv_issimplever,$(1:v%=%)),$(1),$(if $(call lv_issimplever,$(1:ver%=%)),$(1),$(if $(call lv_issimplever,$(1:version%=%)),$(1),)))
330 lv_isreleasever = $(if $(call lv_issimplever,$(1:r%=%)),$(1),$(if $(call lv_issimplever,$(1:rel%=%)),$(1),$(if $(call lv_issimplever,$(1:release%=%)),$(1),)))
331 lv_isbuildver = $(if $(call lv_issimplever,$(1:b%=%)),$(1),$(if $(call lv_issimplever,$(1:bld%=%)),$(1),$(if $(call lv_issimplever,$(1:build%=%)),$(1),)))
332 lv_iscomplexver = $(if $(call lv_isversionver,$(1)),$(1),$(if $(call lv_isreleasever,$(1)),$(1),$(if $(call lv_isbuildver,$(1)),$(1),)))
333 lv_isver = $(if $(call lv_issimplever,$(1)),$(1),$(if $(call lv_iscomplexver,$(1)),$(1),))
334 lv_possibleverorver = $(if $(findstring -,$(1)),$(if $(call hasnumbers,$(1)),$(1),),$(if $(call lv_isver,$(1)),$(1),))
335 lv_termslistfromdir = $(strip $(subst -,$(space),$(1)))
336 lv_verfromtermlist = $(if $(1)$(2),$(if $(1),$(1)$(if $(2),-,),)$(call lv_verfromtermlist,$(firstword $(2)),$(wordlist 2,$(words $(2)),$(2))),)
337 lv_termwalker = $(if $(firstword $(1)),$(if $(call lv_isver,$(firstword $(1))),$(call lv_verfromtermlist,,$(1)),$(call lv_termwalker,$(wordlist 2,$(words $(1)),$(1)))),)
338 lv_version = $(if $(call lv_possibleverorver,$(1)),$(call lv_termwalker,$(call lv_termslistfromdir,$(1))),)
339 lv_dirwalker = $(if $(firstword $(1)),$(if $(call lv_version,$(firstword $(1))),$(call lv_version,$(firstword $(1))),$(call lv_dirwalker,$(wordlist 2,$(words $(1)),$(1)))),)
340 locationversion = $(call shwspace,$(call lv_dirwalker,$(call reverselist,$(subst $(space)$(space),$(space),$(call dirlistfromlocation,$(call hidspace,$(1)))))))
341
342 # SOURCE CODE REPOSITORY VERSION
343 ifndef REPOSITORY_VER
344    # TODO: support other VCS
345    ifndef GIT_REPOSITORY
346       ifndef GIT
347          GIT := git
348       endif
349       ifeq ($(shell $(GIT) --version $(nullerror)),)
350          export GIT_NA := $(GIT)NotAvailable
351       else
352          ifneq ($(shell $(GIT) log -n 1 --format="%%%%" $(nullerror)),)
353             export GIT_REPOSITORY := yes
354             export REPOSITORY_VER := $(shell $(GIT) describe --tags --dirty=" (dirty)" --always)
355          endif
356       endif
357    endif
358    ifndef REPOSITORY_VER
359       DIR_VER := $(call locationversion,$(CURDIR))
360       ifneq ($(DIR_VER),)
361          export REPOSITORY_VER := $(DIR_VER)
362       endif
363    endif
364    ifndef REPOSITORY_VER
365       export REPOSITORY_VER := unknown
366    endif
367 endif
368
369 # COMPILER OPTIONS
370 ECSLIBOPT := $(if $(STATIC_LIBRARY_TARGET),-staticlib,$(if $(SHARED_LIBRARY_TARGET),-dynamiclib,))
371 FVISIBILITY := $(if $(WINDOWS_TARGET),,-fvisibility=hidden)
372 FPIC := $(if $(WINDOWS_TARGET),,-fPIC)
373 EXECUTABLE := $(if $(WINDOWS_TARGET),$(if $(EXECUTABLE_TARGET),$(CONSOLE),),)
374 INSTALLNAME := $(if $(OSX_TARGET),$(if $(SHARED_LIBRARY_TARGET),-install_name $(LP)$(MODULE)$(SO),),)
375
376 # LINKER OPTIONS
377 SHAREDLIB := $(if $(SHARED_LIBRARY_TARGET),$(if $(OSX_TARGET),-dynamiclib -single_module -multiply_defined suppress,-shared),)
378 LINKOPT :=
379 STRIPOPT := $(if $(OSX_TARGET),$(if $(SHARED_LIBRARY_TARGET),-x, -u -r), -x --strip-unneeded --remove-section=.comment --remove-section=.note)
380 HOST_SODESTDIR := $(if $(WINDOWS_HOST),obj/$(HOST_PLATFORM)$(COMPILER_SUFFIX)$(DEBUG_SUFFIX)/bin/,obj/$(HOST_PLATFORM)$(COMPILER_SUFFIX)$(DEBUG_SUFFIX)/lib/)
381 SODESTDIR := $(if $(WINDOWS_TARGET),obj/$(TARGET_PLATFORM)$(COMPILER_SUFFIX)$(DEBUG_SUFFIX)/bin/,obj/$(TARGET_PLATFORM)$(COMPILER_SUFFIX)$(DEBUG_SUFFIX)/lib/)
382
383 # EXCLUDED_LIBS TOOL
384 _L = $(if $(filter $(1),$(EXCLUDED_LIBS)),,-l$(1))
385
386 # DEBIAN
387 ifdef DEBIAN_PACKAGE
388 CFLAGS += $(CPPFLAGS)
389 endif
390
391 ifdef DEBUG
392 CFLAGS += -D_DEBUG
393 endif
394
395 # COMMON LIBRARIES DETECTION
396 ifdef WINDOWS_TARGET
397  ifdef OPENSSL_CONF
398   _OPENSSL_CONF = $(call hidspace,$(call slash_path,$(OPENSSL_CONF)))
399   OPENSSL_INCLUDE_DIR = $(call shwspace,$(subst /bin/openssl.cfg,/include,$(_OPENSSL_CONF)))
400   OPENSSL_LIB_DIR = $(call shwspace,$(subst /bin/openssl.cfg,/lib,$(_OPENSSL_CONF)))
401   OPENSSL_BIN_DIR = $(call shwspace,$(subst /bin/openssl.cfg,/bin,$(_OPENSSL_CONF)))
402  else
403 # to avoid issues with empty -L/-I
404   OPENSSL_INCLUDE_DIR = .
405   OPENSSL_LIB_DIR = .
406   OPENSSL_BIN_DIR = .
407  endif
408 endif