ecere: gui/Window: tweak to update normalAnchor and normalSizeAnchor for gui config.
[sdk] / crossplatform.mk
1 # HOST PLATFORM DETECTION
2 ifeq ($(OS),Windows_NT)
3    HOST_PLATFORM := win32
4    WINDOWS_HOST := defined
5    # IA64 / AMD64 / x86   #HKEY_LOCAL_MACHINE
6    #_PROCESSOR_ARCHITECTURE := $(shell reg Query "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v PROCESSOR_ARCHITECTURE)
7    #ifneq ($(findstring AMD64,$(_PROCESSOR_ARCHITECTURE)),)
8    #   HOST_ARCH := amd64
9    #   HOST_BITS := 64
10    #else
11    #   ifneq ($(findstring IA64,$(_PROCESSOR_ARCHITECTURE)),)
12    #      HOST_ARCH := ia64
13    #      HOST_BITS := 64
14    #   else
15    #      ifneq ($(findstring x86,$(_PROCESSOR_ARCHITECTURE)),)
16    #         HOST_ARCH := x86
17    #         HOST_BITS := 32
18    #      else
19    #         HOST_ARCH := unknown
20    #         HOST_BITS := unknown
21    #      endif
22    #   endif
23    #endif
24    #ifdef ProgramFiles(x86)
25    #   HOST_BITS := 64
26    #else
27    #   HOST_BITS := 32
28    #endif
29 else
30  _UNAME := $(shell uname)
31  UNAME_P := $(shell uname -p)
32  ifeq ($(_UNAME),FreeBSD)
33  # Using Linux platform for Unix OSes for now 
34  #   HOST_PLATFORM := bsd
35     BSD_HOST := defined
36     HOST_PLATFORM := linux
37     LINUX_HOST := defined
38  else
39   ifeq ($(_UNAME),Darwin)
40      HOST_PLATFORM := apple
41      OSX_HOST := defined
42   else
43      HOST_PLATFORM := linux
44      LINUX_HOST := defined
45   endif
46  endif
47  HOST_ARCH := $(UNAME_P)
48 endif
49
50 # TARGET_PLATFORM
51 ifndef TARGET_PLATFORM
52 ifdef PLATFORM
53    TARGET_PLATFORM := $(PLATFORM)
54 endif
55 endif
56 ifndef TARGET_PLATFORM
57 ifdef WINDOWS_HOST
58    TARGET_PLATFORM := win32
59 else
60 ifdef OSX_HOST
61    TARGET_PLATFORM := apple
62 else
63 #ifdef BSD_HOST
64 #   TARGET_PLATFORM := bsd
65 #else
66    TARGET_PLATFORM := linux
67 ifdef BSD_HOST
68    BSD_TARGET := defined
69 endif
70 #endif
71 endif
72 endif
73 endif
74 ifndef PLATFORM
75    PLATFORM := $(TARGET_PLATFORM)
76 endif
77 ifeq ($(TARGET_PLATFORM),win32)
78    WINDOWS_TARGET := defined
79 else
80 ifeq ($(TARGET_PLATFORM),apple)
81    OSX_TARGET := defined
82 else
83 #ifeq ($(TARGET_PLATFORM),bsd)
84 #   BSD_TARGET := defined
85 #else
86    LINUX_TARGET := defined
87 #endif
88 endif
89 endif
90
91 # CROSS_TARGET
92 ifneq ($(TARGET_PLATFORM),$(HOST_PLATFORM))
93    CROSS_TARGET := defined
94 endif
95
96 # TARGET_TYPE
97 ifeq ($(TARGET_TYPE),staticlib)
98    STATIC_LIBRARY_TARGET := defined
99 else
100 ifeq ($(TARGET_TYPE),sharedlib)
101    SHARED_LIBRARY_TARGET := defined
102 else
103 ifeq ($(TARGET_TYPE),executable)
104    EXECUTABLE_TARGET := defined
105 endif
106 endif
107 endif
108
109 ifeq ($(GCC_PREFIX),i586-mingw32msvc-)
110 export ARCH
111 ARCH := x32
112 endif
113
114 ifeq ($(GCC_PREFIX),i686-w64-mingw32-)
115 export ARCH
116 ARCH := x32
117 endif
118
119 # Accept different things for ARCH but standardize on x32/x64
120 # This will be used for object directories
121 ifdef ARCH
122  ifeq ($(ARCH),32)
123   override ARCH := x32
124  endif
125  ifeq ($(ARCH),x86)
126   override ARCH := x32
127  endif
128  ifeq ($(ARCH),i386)
129   override ARCH := x32
130  endif
131  ifeq ($(ARCH),i686)
132   override ARCH := x32
133  endif
134  ifeq ($(ARCH),64)
135   override ARCH := x64
136  endif
137  ifeq ($(ARCH),amd64)
138   override ARCH := x64
139  endif
140  ifeq ($(ARCH),x86_64)
141   override ARCH := x64
142  endif
143
144  # Set ARCH_FLAGS only if ARCH is set
145  ifeq ($(ARCH),x64)
146   TARGET_ARCH := x86_64
147   ARCH_FLAGS := -m64
148  endif
149  ifeq ($(ARCH),x32)
150   TARGET_ARCH := i386
151   ARCH_FLAGS := -m32
152  endif
153
154  ARCH_SUFFIX := .$(ARCH)
155
156  ifdef LINUX_TARGET
157   TARGET_ARCH := $(TARGET_ARCH)-linux-gnu
158  endif
159
160 endif
161
162 # On Windows/32 bit systems, pass -m32 as TDM-GCC packaged with the installer produces 64 bit executables by default
163 # Disable this if your compiler does not accept -m32
164 ifndef ARCH
165  ifeq ($(HOST_PLATFORM),win32)
166   ifeq ($(TARGET_PLATFORM),win32)
167    #ifeq ($(HOST_BITS),32)
168    ifndef ProgramFiles(x86)
169     ARCH := x32
170     TARGET_ARCH := i386
171     ARCH_FLAGS := -m32
172    endif
173   endif
174  endif
175 endif
176
177 # DEBUG SUFFIX
178 ifdef DEBUG
179 DEBUG_SUFFIX := .debug
180 endif
181
182 # COMPILER SUFFIX
183 COMPILER_SUFFIX = $(ARCH_SUFFIX)
184 ifdef COMPILER
185 ifneq ($(COMPILER),default)
186 COMPILER_SUFFIX = .$(COMPILER)$(ARCH_SUFFIX)
187 endif
188 endif
189
190 # MISC STRING TOOLS
191 empty :=
192 esc := $(empty)\7f$(empty)
193 space := $(empty) $(empty)
194 comma := ,
195 openpar := (
196 clospar := )
197 slash := $(empty)/$(empty)
198 backslash := $(empty)\$(empty)
199 escspace = $(subst $(space),$(backslash)$(space),$(subst $(backslash)$(space),$(space),$(1)))
200 hidspace = $(subst $(space),$(esc),$(subst $(backslash)$(space),$(esc),$(1)))
201 hidescspace = $(subst $(backslash)$(space),$(esc),$(1))
202 shwspace = $(subst $(esc),$(backslash)$(space),$(1))
203 shwspacequoted = $(subst $(esc),"$(space)",$(subst \$(space),$(esc),$(1)))
204 unescp_all = $(subst $(esc),$(backslash),$(subst $(backslash),,$(subst $(backslash)$(backslash),$(esc),$(1))))
205 for_list = $(call sys_path,$(call unescp_all,$(call shwspacequoted,$(subst $(space),$(comma),$(subst $(space)$(space),$(space),$(call hidescspace,$(1)))))))
206 lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))
207
208 # PATH SEPARATOR STRING TOOLS
209 ifdef WINDOWS_HOST
210 ifndef MSYSCON
211    WIN_PS_TOOLS := defined
212 endif
213 endif
214 ifdef WIN_PS_TOOLS
215    psep := $(backslash)
216    slash_path = $(subst $(backslash),$(slash),$(1))
217    esc_ampersand = $(subst &,^&,$(subst ^&,&,$(1)))
218    sys_path = $(call esc_ampersand,$(subst $(backslash)$(backslash),$(slash),$(subst $(slash),$(backslash),$(1))))
219    each_quote_path = $(call quote_path,$(path))
220    quote_path = "$(call sys_path,$(call unescp_all,$(1)))"
221 #   each_path_quote = $(if $(findstring $(esc),$(path)),"$(call sys_path,$(call unescp_all,$(call shwspace,$(path))))",$(call sys_path,$(call unescp_all,$(path))))
222    each_path_quote = $(if $(findstring $(esc),$(path)),"$(call unescp_all,$(call shwspace,$(path)))",$(call unescp_all,$(path)))
223 #   sys_path_list
224    sys_path_list = $(foreach path,$(1),$(each_path_quote))
225 else
226    psep := $(slash)
227    slash_path = $(1)
228    sys_path = $(1)
229    quote_path = $(1)
230 endif
231
232 # PREFIXES AND EXTENSIONS
233 EC := .ec
234 S := .sym
235 I := .imp
236 B := .bowl
237 C := .c
238 ifndef O
239 O := .o
240 endif
241 A := .a
242 E := $(if $(WINDOWS_TARGET),.exe,)
243 SO := $(if $(WINDOWS_TARGET),.dll,$(if $(OSX_TARGET),.dylib,.so))
244 LP := $(if $(WINDOWS_TARGET),$(if $(STATIC_LIBRARY_TARGET),lib,),lib)
245 HOST_E := $(if $(WINDOWS_HOST),.exe,)
246 HOST_SO := $(if $(WINDOWS_HOST),.dll,$(if $(OSX_HOST),.dylib,.so))
247 HOST_LP := $(if $(WINDOWS_HOST),$(if $(STATIC_LIBRARY_TARGET),lib,),lib)
248 .SUFFIXES: .c .ec .sym .imp .bowl $(O) $(A)
249
250 # TARGET VERSION
251 VER := $(if $(LINUX_TARGET),$(if $(LINUX_HOST),$(if $(VERSION),.$(VERSION),),),)
252
253 # SUPER TOOLS
254 ifdef CCACHE
255    CCACHE_COMPILE := ccache$(space)
256 ifdef DISTCC
257    DISTCC_COMPILE := distcc$(space)
258 endif
259 else
260 ifdef DISTCC
261    DISTCC_COMPILE := distcc$(space)
262 endif
263 endif
264
265 _CPP = $(if $(findstring $(space),$(CPP)),"$(CPP)",$(CPP))
266
267 _SYSROOT = $(if $(SYSROOT),$(space)--sysroot=$(SYSROOT),)
268
269 # SHELL COMMANDS
270 ifdef WINDOWS_HOST
271 ifndef MSYSCON
272    WIN_SHELL_COMMANDS := defined
273 endif
274 endif
275 ifdef WIN_SHELL_COMMANDS
276    nullerror = 2>NUL
277    echo = $(if $(1),echo $(1),echo.)
278    cat = $(if $(1),type $(1))
279    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%%)")
280 #   cpq = $(if $(1),@cmd /c "for %%I in ($(call sys_path,$(1))) do copy /by %%I $(call sys_path,$(2))" > nul 2>&1)
281    cpq = $(if $(1),@cmd /c "for %%I in ($(call for_list,$(1))) do copy /by %%I $(call sys_path,$(2))" > nul 2>&1)
282 #   cpv = $(if $(1),@cmd /c "for %%I in ($(call sys_path,$(1))) do copy /by %%I $(call sys_path,$(2))")
283    cpv = $(if $(1),@cmd /c "for %%I in ($(call for_list,$(1))) do copy /by %%I $(call sys_path,$(2))")
284 #   rmq = $(if $(1),-del /f /q $(1) > nul 2>&1)
285 #   rmq = $(if $(1),-del /f /q $(call sys_path,$(1)) > nul 2>&1)
286    rmq = $(if $(1),-del /f /q $(call sys_path,$(call sys_path_list,$(1))) > nul 2>&1)
287 #   rmq = $(if $(1),-del /f /q $(foreach path,$(1),$(each_quote_path)) $(call sys_path,$(1)) > nul 2>&1)
288    rmrq = $(if $(1),-rmdir /q /s $(call sys_path,$(1)) > nul 2>&1)
289    mkdirq = $(if $(1),-mkdir $(call sys_path,$(1)) > nul 2>&1)
290    rmdirq = $(if $(1),-rmdir /q $(call sys_path,$(1)) > nul 2>&1)
291 else
292    nullerror = 2>/dev/null
293    echo = $(if $(1),echo "$(1)",echo)
294    cat = $(if $(1),cat $(1))
295    touch = $(if $(1),touch $(1))
296    cpq = $(if $(1),cp $(1) $(2))
297    cpv = cp $(1) $(2)
298    rmq = $(if $(1),-rm -f $(1))
299    rmrq = $(if $(1),-rm -f -r $(1))
300    mkdirq = $(if $(1),-mkdir -p $(1))
301    rmdirq = $(if $(1),-rmdir $(1))
302 endif
303
304 # potential common use variables
305 numbers := 0 1 2 3 4 5 6 7 8 9
306
307 # potential common use functions
308 reverselist = $(if $(1),$(call reverselist,$(strip $(wordlist 2,$(words $(1)),$(1))))) $(firstword $(1))
309 dirlistfromlocation = $(strip $(subst $(slash),$(space),$(subst $(backslash),$(space),$(1))))
310 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)))))))))))
311 hasnumbers = $(if $(filter $(numbers),$(call spacenumbers,$(1))),$(1),)
312 isanumber = $(if $(filter-out $(numbers),$(call spacenumbers,$(1))),,$(1))
313
314 # location version utility functions (lv_*)
315 lv_issimplever = $(if $(call isanumber,$(firstword $(call spacenumbers,$(subst .,,$(1))))),$(1),)
316 lv_isversionver = $(if $(call lv_issimplever,$(1:v%=%)),$(1),$(if $(call lv_issimplever,$(1:ver%=%)),$(1),$(if $(call lv_issimplever,$(1:version%=%)),$(1),)))
317 lv_isreleasever = $(if $(call lv_issimplever,$(1:r%=%)),$(1),$(if $(call lv_issimplever,$(1:rel%=%)),$(1),$(if $(call lv_issimplever,$(1:release%=%)),$(1),)))
318 lv_isbuildver = $(if $(call lv_issimplever,$(1:b%=%)),$(1),$(if $(call lv_issimplever,$(1:bld%=%)),$(1),$(if $(call lv_issimplever,$(1:build%=%)),$(1),)))
319 lv_iscomplexver = $(if $(call lv_isversionver,$(1)),$(1),$(if $(call lv_isreleasever,$(1)),$(1),$(if $(call lv_isbuildver,$(1)),$(1),)))
320 lv_isver = $(if $(call lv_issimplever,$(1)),$(1),$(if $(call lv_iscomplexver,$(1)),$(1),))
321 lv_possibleverorver = $(if $(findstring -,$(1)),$(if $(call hasnumbers,$(1)),$(1),),$(if $(call lv_isver,$(1)),$(1),))
322 lv_termslistfromdir = $(strip $(subst -,$(space),$(1)))
323 lv_verfromtermlist = $(if $(1)$(2),$(if $(1),$(1)$(if $(2),-,),)$(call lv_verfromtermlist,$(firstword $(2)),$(wordlist 2,$(words $(2)),$(2))),)
324 lv_termwalker = $(if $(firstword $(1)),$(if $(call lv_isver,$(firstword $(1))),$(call lv_verfromtermlist,,$(1)),$(call lv_termwalker,$(wordlist 2,$(words $(1)),$(1)))),)
325 lv_version = $(if $(call lv_possibleverorver,$(1)),$(call lv_termwalker,$(call lv_termslistfromdir,$(1))),)
326 lv_dirwalker = $(if $(firstword $(1)),$(if $(call lv_version,$(firstword $(1))),$(call lv_version,$(firstword $(1))),$(call lv_dirwalker,$(wordlist 2,$(words $(1)),$(1)))),)
327 locationversion = $(call shwspace,$(call lv_dirwalker,$(call reverselist,$(subst $(space)$(space),$(space),$(call dirlistfromlocation,$(call hidspace,$(1)))))))
328
329 # SOURCE CODE REPOSITORY VERSION
330 ifndef REPOSITORY_VER
331    # TODO: support other VCS
332    ifndef GIT_REPOSITORY
333       ifndef GIT
334          GIT := git
335       endif
336       ifeq ($(shell $(GIT) --version $(nullerror)),)
337          export GIT_NA := $(GIT)NotAvailable
338       else
339          ifneq ($(shell $(GIT) log -n 1 --format="%%%%" $(nullerror)),)
340             export GIT_REPOSITORY := yes
341             export REPOSITORY_VER := $(shell $(GIT) describe --tags --dirty=" (dirty)" --always)
342          endif
343       endif
344    endif
345    ifndef REPOSITORY_VER
346       DIR_VER := $(call locationversion,$(CURDIR))
347       ifneq ($(DIR_VER),)
348          export REPOSITORY_VER := $(DIR_VER)
349       endif
350    endif
351    ifndef REPOSITORY_VER
352       export REPOSITORY_VER := unknown
353    endif
354 endif
355
356 # COMPILER OPTIONS
357 ECSLIBOPT := $(if $(STATIC_LIBRARY_TARGET),-staticlib,$(if $(SHARED_LIBRARY_TARGET),-dynamiclib,))
358 FVISIBILITY := $(if $(WINDOWS_TARGET),,-fvisibility=hidden)
359 FPIC := $(if $(WINDOWS_TARGET),,-fPIC)
360 EXECUTABLE := $(if $(WINDOWS_TARGET),$(if $(EXECUTABLE_TARGET),$(CONSOLE),),)
361 INSTALLNAME := $(if $(OSX_TARGET),$(if $(SHARED_LIBRARY_TARGET),-install_name $(LP)$(MODULE)$(SO),),)
362
363 # LINKER OPTIONS
364 SHAREDLIB := $(if $(SHARED_LIBRARY_TARGET),$(if $(OSX_TARGET),-dynamiclib -single_module -multiply_defined suppress,-shared),)
365 LINKOPT :=
366 STRIPOPT := $(if $(OSX_TARGET),$(if $(SHARED_LIBRARY_TARGET),-x, -u -r), -x --strip-unneeded --remove-section=.comment --remove-section=.note)
367 HOST_SODESTDIR := $(if $(WINDOWS_HOST),obj/$(HOST_PLATFORM)$(COMPILER_SUFFIX)$(DEBUG_SUFFIX)/bin/,obj/$(HOST_PLATFORM)$(COMPILER_SUFFIX)$(DEBUG_SUFFIX)/lib/)
368 SODESTDIR := $(if $(WINDOWS_TARGET),obj/$(TARGET_PLATFORM)$(COMPILER_SUFFIX)$(DEBUG_SUFFIX)/bin/,obj/$(TARGET_PLATFORM)$(COMPILER_SUFFIX)$(DEBUG_SUFFIX)/lib/)
369
370 # EXCLUDED_LIBS TOOL
371 _L = $(if $(filter $(1),$(EXCLUDED_LIBS)),,-l$(1))
372
373 # DEBIAN
374 ifdef DEBIAN_PACKAGE
375 CFLAGS += $(CPPFLAGS)
376 endif
377
378 ifdef DEBUG
379 CFLAGS += -D_DEBUG
380 endif
381
382 # COMMON LIBRARIES DETECTION
383 ifdef WINDOWS_TARGET
384  ifdef OPENSSL_CONF
385   _OPENSSL_CONF = $(call hidspace,$(call slash_path,$(OPENSSL_CONF)))
386   OPENSSL_INCLUDE_DIR = $(call shwspace,$(subst /bin/openssl.cfg,/include,$(_OPENSSL_CONF)))
387   OPENSSL_LIB_DIR = $(call shwspace,$(subst /bin/openssl.cfg,/lib,$(_OPENSSL_CONF)))
388   OPENSSL_BIN_DIR = $(call shwspace,$(subst /bin/openssl.cfg,/bin,$(_OPENSSL_CONF)))
389  else
390 # to avoid issues with empty -L/-I
391   OPENSSL_INCLUDE_DIR = .
392   OPENSSL_LIB_DIR = .
393   OPENSSL_BIN_DIR = .
394  endif
395 endif