# HOST PLATFORM DETECTION
-ifeq "$(OS)" "Windows_NT"
+ifeq ($(OS),Windows_NT)
HOST_PLATFORM := win32
WINDOWS_HOST := defined
else
_UNAME := $(shell uname)
UNAME_P := $(shell uname -p)
- ifeq "$(_UNAME)" "FreeBSD"
+ ifeq ($(_UNAME),FreeBSD)
# Using Linux platform for Unix OSes for now
# HOST_PLATFORM := bsd
BSD_HOST := defined
HOST_PLATFORM := linux
LINUX_HOST := defined
else
- ifeq "$(_UNAME)" "Darwin"
+ ifeq ($(_UNAME),Darwin)
HOST_PLATFORM := apple
OSX_HOST := defined
else
ifndef PLATFORM
PLATFORM := $(TARGET_PLATFORM)
endif
-ifeq "$(TARGET_PLATFORM)" "win32"
+ifeq ($(TARGET_PLATFORM),win32)
WINDOWS_TARGET := defined
else
-ifeq "$(TARGET_PLATFORM)" "apple"
+ifeq ($(TARGET_PLATFORM),apple)
OSX_TARGET := defined
else
-#ifeq "$(TARGET_PLATFORM)" "bsd"
+#ifeq ($(TARGET_PLATFORM),bsd)
# BSD_TARGET := defined
#else
LINUX_TARGET := defined
endif
# CROSS_TARGET
-ifneq "$(TARGET_PLATFORM)" "$(HOST_PLATFORM)"
+ifneq ($(TARGET_PLATFORM),$(HOST_PLATFORM))
CROSS_TARGET := defined
endif
# TARGET_TYPE
-ifeq "$(TARGET_TYPE)" "staticlib"
+ifeq ($(TARGET_TYPE),staticlib)
STATIC_LIBRARY_TARGET := defined
else
-ifeq "$(TARGET_TYPE)" "sharedlib"
+ifeq ($(TARGET_TYPE),sharedlib)
SHARED_LIBRARY_TARGET := defined
else
-ifeq "$(TARGET_TYPE)" "executable"
+ifeq ($(TARGET_TYPE),executable)
EXECUTABLE_TARGET := defined
endif
endif
endif
-ifeq "$(GCC_PREFIX)" "i586-mingw32msvc-"
+ifeq ($(GCC_PREFIX),i586-mingw32msvc-)
export ARCH
ARCH := x32
endif
-ifeq "$(GCC_PREFIX)" "i686-w64-mingw32-"
+ifeq ($(GCC_PREFIX),i686-w64-mingw32-)
export ARCH
ARCH := x32
endif
# Accept different things for ARCH but standardize on x32/x64
# This will be used for object directories
ifdef ARCH
- ifeq "$(ARCH)" "32"
+ ifeq ($(ARCH),32)
override ARCH := x32
endif
- ifeq "$(ARCH)" "x86"
+ ifeq ($(ARCH),x86)
override ARCH := x32
endif
- ifeq "$(ARCH)" "i386"
+ ifeq ($(ARCH),i386)
override ARCH := x32
endif
- ifeq "$(ARCH)" "i686"
+ ifeq ($(ARCH),i686)
override ARCH := x32
endif
- ifeq "$(ARCH)" "64"
+ ifeq ($(ARCH),64)
override ARCH := x64
endif
- ifeq "$(ARCH)" "amd64"
+ ifeq ($(ARCH),amd64)
override ARCH := x64
endif
- ifeq "$(ARCH)" "x86_64"
+ ifeq ($(ARCH),x86_64)
override ARCH := x64
endif
# Set ARCH_FLAGS only if ARCH is set
- ifeq "$(ARCH)" "x64"
+ ifeq ($(ARCH),x64)
TARGET_ARCH := x86_64
ARCH_FLAGS := -m64
endif
- ifeq "$(ARCH)" "x32"
+ ifeq ($(ARCH),x32)
TARGET_ARCH := i386
ARCH_FLAGS := -m32
endif
# On Windows/32 bit systems, pass -m32 as TDM-GCC packaged with the installer produces 64 bit executables by default
# Disable this if your compiler does not accept -m32
ifndef ARCH
- ifeq "$(HOST_PLATFORM)" "win32"
- ifeq "$(TARGET_PLATFORM)" "win32"
+ ifeq ($(HOST_PLATFORM),win32)
+ ifeq ($(TARGET_PLATFORM),win32)
ifndef ProgramFiles(x86)
ARCH := x32
TARGET_ARCH := i386
# COMPILER SUFFIX
COMPILER_SUFFIX = $(ARCH_SUFFIX)
ifdef COMPILER
-ifneq "$(COMPILER)" "default"
+ifneq ($(COMPILER),default)
COMPILER_SUFFIX = .$(COMPILER)$(ARCH_SUFFIX)
endif
endif
-# MISC STRING TOOLS
+# STRING TOOLS
empty :=
esc := $(empty)\7f$(empty)
space := $(empty) $(empty)
comma := ,
+quote := "
slash := $(empty)/$(empty)
backslash := $(empty)\$(empty)
escspace = $(subst $(space),$(backslash)$(space),$(subst $(backslash)$(space),$(space),$(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)\7f$(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,<list>,<command_function>)
+# hs_crossloop will call <command_function> 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
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
psep := $(slash)
- slash_path = $(1)
sys_path = $(1)
quote_path = $(1)
endif
# PREFIXES AND EXTENSIONS
-.SUFFIXES: .c .ec .sym .imp .bowl .o .a
EC := .ec
S := .sym
I := .imp
B := .bowl
C := .c
+ifndef O
O := .o
+endif
A := .a
E := $(if $(WINDOWS_TARGET),.exe,)
SO := $(if $(WINDOWS_TARGET),.dll,$(if $(OSX_TARGET),.dylib,.so))
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)
+.SUFFIXES: .c .ec .sym .imp .bowl $(O) $(A)
# TARGET VERSION
VER := $(if $(LINUX_TARGET),$(if $(LINUX_HOST),$(if $(VERSION),.$(VERSION),),),)
_SYSROOT = $(if $(SYSROOT),$(space)--sysroot=$(SYSROOT),)
+_MAKE = $(call fp_opt_quotes,$(MAKE))
+
# SHELL COMMANDS
ifdef WINDOWS_HOST
-ifndef MSYSCON
- WIN_SHELL_COMMANDS := defined
+ ifneq ($(TERM),cygwin)
+ ifndef MSYSCON
+ WIN_SHELL_COMMANDS := defined
+ endif
+ endif
+endif
+ifneq ($(V),1)
+ SILENT_IS_ON := defined
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%%)")
- 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)
+ 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,))
+ 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,))
+ 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))
+ 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))
- 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))
+ 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