X-Git-Url: http://ecere.com/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=crossplatform.mk;h=fe87fd75775a3cc891934ff1ba23557c4531940c;hb=3e9dd9e09ea1d69476041c624edb3a4c2b36e87d;hp=8e9324b5c6f9a08472cf1e1702877db3992c2c98;hpb=c2bd2955523064fe83a303bd0773a62861cda7c5;p=sdk diff --git a/crossplatform.mk b/crossplatform.mk index 8e9324b..fe87fd7 100644 --- a/crossplatform.mk +++ b/crossplatform.mk @@ -162,11 +162,12 @@ COMPILER_SUFFIX = .$(COMPILER)$(ARCH_SUFFIX) endif endif -# MISC STRING TOOLS +# STRING TOOLS empty := esc := $(empty)$(empty) space := $(empty) $(empty) comma := , +quote := " slash := $(empty)/$(empty) backslash := $(empty)\$(empty) escspace = $(subst $(space),$(backslash)$(space),$(subst $(backslash)$(space),$(space),$(1))) @@ -174,11 +175,51 @@ 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)))) +# HIDDEN SPACE STRING TOOLS +temporaty_token := _+;:;+_:;+;:_:+;+:_ +hidden_space := $(empty)$(empty) +hs_hide = $(subst $(space),$(hidden_space),$(1)) +hs_unhide = $(subst $(hidden_space),$(space),$(1)) +hs_escape = $(subst $(hidden_space),$(backslash)$(space),$(1)) +hs_process = $(subst $(space),$(hidden_space),$(subst $(backslash)$(space),$(hidden_space),$(1))) +hs_quote_all = $(foreach item,$(1),"$(call hs_unhide,$(item))") +hs_quote_each = $(foreach item,$(1),$(if $(findstring $(esc),$(item)),"$(call hs_unhide,$(item))",$(item))) + +# FILE PATH TOOLS +fp_unquote = $(subst $(quote),,$(1)) +fp_opt_quotes = $(if $(findstring $(space),$(1)),"$(1)",$(1)) +fp_no_parent_dir = $(foreach item,$(1),$(if $(findstring ..,$(item)),,$(item))) + +# FILE SYSTEM TOOLS +# hs_ls doc +# usage: $(hs_ls) | $(hs_ls_dir) | $(hs_ls_files) +# result: +# - for hs_ls: a list of files and directories in the current dir +# i.e.: fileA dir1/ fileB fileC dir2/ dir3/ +# - for hs_ls_dir: a list of directories in the current dir +# i.e.: dir1 dir2 dir3 +# - for hs_ls_file: a list of files in the current dir +# i.e.: fileA fileB fileC +# notes: +# - hs_ls* functions work in current dir, you can't specify a directory +# - hs_ls* functions do not report hidden files and directories because wildcard doesn't +# you would never get such a list: .fileA .dir1/ +hs_ls = $(subst $(temporaty_token),$(space),$(subst ./,,$(call hs_hide,$(subst $(space)./,$(temporaty_token),$(wildcard ./*/))))) +hs_ls_dir = $(subst /,,$(foreach item,$(hs_ls),$(if $(findstring /,$(item)),$(item),))) +hs_ls_file = $(foreach item,$(hs_ls),$(if $(findstring /,$(item)),,$(item))) + +# CONTROL FLOW TOOLS +# hs_crossloop usage: $(call hs_crossloop,,) +# hs_crossloop will call with the item as first parameter ($(1)) +hs_crossloop = $(call hs_unsafe_crossloop,$(call fp_no_parent_dir,$(1)),$(2)) + # PATH SEPARATOR STRING TOOLS ifdef WINDOWS_HOST -ifndef MSYSCON - WIN_PS_TOOLS := defined -endif + ifneq ($(TERM),cygwin) + ifndef MSYSCON + WIN_PS_TOOLS := defined + endif + endif endif slash_path = $(subst $(backslash),$(slash),$(1)) ifdef WIN_PS_TOOLS @@ -230,11 +271,15 @@ _CPP = $(if $(findstring $(space),$(CPP)),"$(CPP)",$(CPP)) _SYSROOT = $(if $(SYSROOT),$(space)--sysroot=$(SYSROOT),) +_MAKE = $(call fp_opt_quotes,$(MAKE)) + # SHELL COMMANDS ifdef WINDOWS_HOST -ifndef MSYSCON - WIN_SHELL_COMMANDS := defined -endif + ifneq ($(TERM),cygwin) + ifndef MSYSCON + WIN_SHELL_COMMANDS := defined + endif + endif endif ifneq ($(V),1) SILENT_IS_ON := defined @@ -242,7 +287,9 @@ endif ifeq ($(D),1) DEBUG_IS_ON := defined endif +addtolistfile = $(if $(1),@$(call echo,$(1)) >> $(2),) ifdef WIN_SHELL_COMMANDS + cd = @cd nullerror = 2>NUL echo = $(if $(1),echo $(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%%)") @@ -252,16 +299,19 @@ ifdef WIN_SHELL_COMMANDS rmr = $(if $(1),-rmdir /s$(if $(SILENT_IS_ON), /q,) $(call sys_path,$(1))$(if $(SILENT_IS_ON), > nul,)) mkdir = $(if $(1),-mkdir $(call sys_path,$(1))$(if $(SILENT_IS_ON), > nul,)$(if $(DEBUG_IS_ON),, 2>&1)) rmdir = $(if $(1),-rmdir$(if $(SILENT_IS_ON), /q,) $(call sys_path,$(1))$(if $(SILENT_IS_ON), > nul,)) + hs_unsafe_crossloop = ${if $(1),${if $(2),@cmd /c "for %%I in (${call hs_quote_each,$(1)}) do ${call $(2),%%I}",},} else + cd = cd nullerror = 2>/dev/null echo = $(if $(1),echo "$(1)") touch = $(if $(1),touch $(1)) - cp = $(if $(1),cp$(if $(SILENT_IS_ON),, -v) $(1) $(2)) - cpr = $(if $(1),cp -prf$(if $(SILENT_IS_ON),,v) $(1) $(2)) + cp = $(if $(1),cp -P$(if $(SILENT_IS_ON),,v) $(1) $(2)) + cpr = $(if $(1),cp -PR$(if $(SILENT_IS_ON),,v) $(1) $(2)) rm = $(if $(1),-rm -f$(if $(SILENT_IS_ON),,v) $(1)) rmr = $(if $(1),-rm -fr$(if $(SILENT_IS_ON),,v) $(1)) mkdir = $(if $(1),-mkdir -p$(if $(SILENT_IS_ON),,v) $(1)) rmdir = $(if $(1),-rmdir$(if $(SILENT_IS_ON),, -v) $(1)) + hs_unsafe_crossloop = ${if $(1),${if $(2),for item in ${call hs_quote_each,$(1)}; do ${call $(2),"$$item"}; done,},} endif # potential common use variables