X-Git-Url: https://ecere.com/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=crossplatform.mk;h=28d725b16e3f7d2fe001793c77d99d5cd54715a4;hb=cbfb3544f67e37f8eb4485ca4faccc8c5a796317;hp=916a9e81528f8f33348958eccc29c43d38508dd4;hpb=8a35e377eb38d5f9b72082bcb72384ebdc448ce2;p=sdk diff --git a/crossplatform.mk b/crossplatform.mk index 916a9e8..28d725b 100644 --- a/crossplatform.mk +++ b/crossplatform.mk @@ -150,11 +150,15 @@ endif # MISC STRING TOOLS empty := +esc := $(empty)$(empty) space := $(empty) $(empty) comma := , -escspace = $(subst $(space),\$(space),$(subst \$(space),$(space),$1)) -hidspace = $(subst $(space),,$(subst \$(space),,$1)) -shwspace = $(subst ,\$(space),$1) +slash := $(empty)/$(empty) +backslash := $(empty)\$(empty) +escspace = $(subst $(space),$(backslash)$(space),$(subst $(backslash)$(space),$(space),$(1))) +hidspace = $(subst $(space),$(esc),$(subst $(backslash)$(space),$(esc),$(1))) +shwspace = $(subst $(esc),$(backslash)$(space),$(1)) +unescp_all = $(subst $(esc),$(backslash),$(subst $(backslash),,$(subst $(backslash)$(backslash),$(esc),$(1)))) # PATH SEPARATOR STRING TOOLS ifdef WINDOWS_HOST @@ -163,13 +167,17 @@ ifndef MSYSCON endif endif ifdef WIN_PS_TOOLS - fixps = $(subst \,/,$(1)) - psep = $(subst \\,/,$(subst /,\,$(1))) - PS := $(strip \) + psep := $(backslash) + slash_path = $(subst $(backslash),$(slash),$(1)) + sys_path = $(subst $(backslash)$(backslash),$(slash),$(subst $(slash),$(backslash),$(1))) + quote_path = "$(call sys_path,$(call unescp_all,$(1)))" + each_path_quote = $(if $(findstring $(esc),$(path)),"$(call unescp_all,$(call shwspace,$(path)))",$(call unescp_all,$(path))) + sys_path_list = $(foreach path,$(1),$(each_path_quote)) else - fixps = $(1) - PS := $(strip /) - psep = $(1) + psep := $(slash) + slash_path = $(1) + sys_path = $(1) + quote_path = $(1) endif # PREFIXES AND EXTENSIONS @@ -188,7 +196,7 @@ HOST_E := $(if $(WINDOWS_HOST),.exe,) HOST_SO := $(if $(WINDOWS_HOST),.dll,$(if $(OSX_HOST),.dylib,.so)) HOST_LP := $(if $(WINDOWS_HOST),$(if $(STATIC_LIBRARY_TARGET),lib,),lib) -# VERSIONING +# TARGET VERSION VER := $(if $(LINUX_TARGET),$(if $(LINUX_HOST),$(if $(VERSION),.$(VERSION),),),) # SUPER TOOLS @@ -214,21 +222,75 @@ ifndef MSYSCON endif endif ifdef WIN_SHELL_COMMANDS + nullerror = 2>NUL echo = $(if $(1),echo $(1)) - touch = $(if $(1),@type nul >> $(1) & @copy $(call psep,$(1)+,,) > nul 2>&1) - cpq = $(if $(1),@cmd /c for %%I in ($(call psep,$(1))) do @copy /y %%I $(call psep,$(2)) > nul 2>&1) - rmq = $(if $(1),-@del /f /q $(call psep,$(1)) > nul 2>&1) - rmrq = $(if $(1),-@rmdir /q /s $(call psep,$(1)) > nul 2>&1) - mkdirq = $(if $(1),-@mkdir $(call psep,$(1)) > nul 2>&1) - rmdirq = $(if $(1),-@rmdir /q $(call psep,$(1)) > nul 2>&1) + 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%%)") + cpq = $(if $(1),@cmd /c "for %%I in ($(call sys_path,$(1))) do copy /by %%I $(call sys_path,$(2))" > nul 2>&1) + rmq = $(if $(1),-del /f /q $(call sys_path,$(call sys_path_list,$(1))) > nul 2>&1) + rmrq = $(if $(1),-rmdir /q /s $(call sys_path,$(1)) > nul 2>&1) + mkdirq = $(if $(1),-mkdir $(call sys_path,$(1)) > nul 2>&1) + rmdirq = $(if $(1),-rmdir /q $(call sys_path,$(1)) > nul 2>&1) else + nullerror = 2>/dev/null echo = $(if $(1),echo "$(1)") - touch = $(if $(1),@touch $(1)) - cpq = $(if $(1),@cp $(1) $(2)) - rmq = $(if $(1),-@rm -f $(1)) - rmrq = $(if $(1),-@rm -f -r $(1)) - mkdirq = $(if $(1),-@mkdir -p $(1)) - rmdirq = $(if $(1),-@rmdir $(1)) + touch = $(if $(1),touch $(1)) + cpq = $(if $(1),cp $(1) $(2)) + rmq = $(if $(1),-rm -f $(1)) + rmrq = $(if $(1),-rm -f -r $(1)) + mkdirq = $(if $(1),-mkdir -p $(1)) + rmdirq = $(if $(1),-rmdir $(1)) +endif + +# potential common use variables +numbers := 0 1 2 3 4 5 6 7 8 9 + +# potential common use functions +reverselist = $(if $(1),$(call reverselist,$(strip $(wordlist 2,$(words $(1)),$(1))))) $(firstword $(1)) +dirlistfromlocation = $(strip $(subst $(slash),$(space),$(subst $(backslash),$(space),$(1)))) +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))))))))))) +hasnumbers = $(if $(filter $(numbers),$(call spacenumbers,$(1))),$(1),) +isanumber = $(if $(filter-out $(numbers),$(call spacenumbers,$(1))),,$(1)) + +# location version utility functions (lv_*) +lv_issimplever = $(if $(call isanumber,$(firstword $(call spacenumbers,$(subst .,,$(1))))),$(1),) +lv_isversionver = $(if $(call lv_issimplever,$(1:v%=%)),$(1),$(if $(call lv_issimplever,$(1:ver%=%)),$(1),$(if $(call lv_issimplever,$(1:version%=%)),$(1),))) +lv_isreleasever = $(if $(call lv_issimplever,$(1:r%=%)),$(1),$(if $(call lv_issimplever,$(1:rel%=%)),$(1),$(if $(call lv_issimplever,$(1:release%=%)),$(1),))) +lv_isbuildver = $(if $(call lv_issimplever,$(1:b%=%)),$(1),$(if $(call lv_issimplever,$(1:bld%=%)),$(1),$(if $(call lv_issimplever,$(1:build%=%)),$(1),))) +lv_iscomplexver = $(if $(call lv_isversionver,$(1)),$(1),$(if $(call lv_isreleasever,$(1)),$(1),$(if $(call lv_isbuildver,$(1)),$(1),))) +lv_isver = $(if $(call lv_issimplever,$(1)),$(1),$(if $(call lv_iscomplexver,$(1)),$(1),)) +lv_possibleverorver = $(if $(findstring -,$(1)),$(if $(call hasnumbers,$(1)),$(1),),$(if $(call lv_isver,$(1)),$(1),)) +lv_termslistfromdir = $(strip $(subst -,$(space),$(1))) +lv_verfromtermlist = $(if $(1)$(2),$(if $(1),$(1)$(if $(2),-,),)$(call lv_verfromtermlist,$(firstword $(2)),$(wordlist 2,$(words $(2)),$(2))),) +lv_termwalker = $(if $(firstword $(1)),$(if $(call lv_isver,$(firstword $(1))),$(call lv_verfromtermlist,,$(1)),$(call lv_termwalker,$(wordlist 2,$(words $(1)),$(1)))),) +lv_version = $(if $(call lv_possibleverorver,$(1)),$(call lv_termwalker,$(call lv_termslistfromdir,$(1))),) +lv_dirwalker = $(if $(firstword $(1)),$(if $(call lv_version,$(firstword $(1))),$(call lv_version,$(firstword $(1))),$(call lv_dirwalker,$(wordlist 2,$(words $(1)),$(1)))),) +locationversion = $(call shwspace,$(call lv_dirwalker,$(call reverselist,$(subst $(space)$(space),$(space),$(call dirlistfromlocation,$(call hidspace,$(1))))))) + +# SOURCE CODE REPOSITORY VERSION +ifndef REPOSITORY_VER + # TODO: support other VCS + ifndef GIT_REPOSITORY + ifndef GIT + GIT := git + endif + ifeq ($(shell $(GIT) --version $(nullerror)),) + export GIT_NA := $(GIT)NotAvailable + else + ifneq ($(shell $(GIT) log -n 1 --format="%%%%" $(nullerror)),) + export GIT_REPOSITORY := yes + export REPOSITORY_VER := $(shell $(GIT) describe --tags --dirty="\ (dirty)" --always) + endif + endif + endif + ifndef REPOSITORY_VER + DIR_VER := $(call locationversion,$(CURDIR)) + ifneq ($(DIR_VER),) + export REPOSITORY_VER := $(DIR_VER) + endif + endif + ifndef REPOSITORY_VER + export REPOSITORY_VER := unknown + endif endif # COMPILER OPTIONS @@ -260,7 +322,7 @@ endif # COMMON LIBRARIES DETECTION ifdef WINDOWS_TARGET ifdef OPENSSL_CONF - _OPENSSL_CONF = $(call hidspace,$(call fixps,$(OPENSSL_CONF))) + _OPENSSL_CONF = $(call hidspace,$(call slash_path,$(OPENSSL_CONF))) OPENSSL_INCLUDE_DIR = $(call shwspace,$(subst /bin/openssl.cfg,/include,$(_OPENSSL_CONF))) OPENSSL_LIB_DIR = $(call shwspace,$(subst /bin/openssl.cfg,/lib,$(_OPENSSL_CONF))) OPENSSL_BIN_DIR = $(call shwspace,$(subst /bin/openssl.cfg,/bin,$(_OPENSSL_CONF)))