@@ -111,6 +111,11 @@ endef
111111COMMA: =,
112112SPACE: =$(eval ) $(eval )
113113
114+ # define various helper macros for safe interpolation into various parsers
115+ shell_escape ='$(subst ','\'',$1) '
116+ c_escape ="$(subst ",\",$(subst \,\\,$1) ) "
117+ julia_escape =$(call c_escape,$1)
118+
114119# force a sane / stable configuration
115120export LC_ALL =C
116121export LANG =C
@@ -644,12 +649,12 @@ CXX += -Qunused-arguments
644649export CCACHE_CPP2 := yes
645650endif
646651else #USECCACHE
647- CC_BASE := $(shell echo $( CC ) | cut -d' ' -f1)
648- CC_ARG := $(shell echo $( CC ) | cut -s -d' ' -f2-)
649- CXX_BASE := $(shell echo $( CXX ) | cut -d' ' -f1)
650- CXX_ARG := $(shell echo $( CXX ) | cut -s -d' ' -f2-)
651- FC_BASE := $(shell echo $( FC ) 2>/dev/null | cut -d' ' -f1)
652- FC_ARG := $(shell echo $( FC ) 2>/dev/null | cut -s -d' ' -f2-)
652+ CC_BASE := $(shell printf " % s\n" $( call shell_escape, $( CC ) ) | cut -d' ' -f1)
653+ CC_ARG := $(shell printf " % s\n" $( call shell_escape, $( CC ) ) | cut -s -d' ' -f2-)
654+ CXX_BASE := $(shell printf " % s\n" $( call shell_escape, $( CXX ) ) | cut -d' ' -f1)
655+ CXX_ARG := $(shell printf " % s\n" $( call shell_escape, $( CXX ) ) | cut -s -d' ' -f2-)
656+ FC_BASE := $(shell printf " % s\n" $( call shell_escape, $( FC ) ) 2>/dev/null | cut -d' ' -f1)
657+ FC_ARG := $(shell printf " % s\n" $( call shell_escape, $( FC ) ) 2>/dev/null | cut -s -d' ' -f2-)
653658endif
654659
655660JFFLAGS := -O2 $(fPIC )
@@ -776,7 +781,7 @@ LDFLAGS += -L$(build_libdir) -Wl,-rpath,$(build_libdir)
776781endif # gfortran
777782endif # FreeBSD
778783
779- ifneq ($(CC_BASE )$(CXX_BASE ) ,$(shell echo $( CC ) | cut -d' ' -f1)$(shell echo $( CXX ) | cut -d' ' -f1) )
784+ ifneq ($(CC_BASE )$(CXX_BASE ) ,$(shell printf " % s\n" $( call shell_escape, $( CC )) | cut -d' ' -f1)$(shell printf " % s\n" $( call shell_escape, $( CXX ) ) | cut -d' ' -f1) )
780785 $(error Forgot override directive on CC or CXX in Make.user? Cowardly refusing to build)
781786endif
782787
@@ -1663,6 +1668,12 @@ $(subst /,\\,$(subst $(shell $(2) pwd),$(shell $(2) cmd //C cd),$(abspath $(1)))
16631668endef
16641669endif
16651670
1671+ ifeq ($(OS ) , WINNT)
1672+ normalize_path = $(subst /,\,$1)
1673+ else
1674+ normalize_path = $1
1675+ endif
1676+
16661677define symlink_target # (from, to-dir, to-name)
16671678CLEAN_TARGETS += clean-$$(abspath $(2 ) /$(3 ) )
16681679clean-$$(abspath $(2 ) /$(3 ) ) :
@@ -1729,20 +1740,20 @@ JULIA_SYSIMG_release := $(build_private_libdir)/sys.$(SHLIB_EXT)
17291740JULIA_SYSIMG := $(JULIA_SYSIMG_$(JULIA_BUILD_MODE ) )
17301741
17311742define dep_lib_path
1732- $(shell $(PYTHON ) $(call python_cygpath,$(JULIAHOME ) /contrib/relative_path.py) $(1 ) $(2 ) )
1743+ $(call normalize_path, $( shell $(PYTHON ) $(call python_cygpath,$(JULIAHOME ) /contrib/relative_path.py) $(1 ) $(2 ) ) )
17331744endef
17341745
1735- LIBJULIAINTERNAL_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir ) ,$(build_shlibdir ) /libjulia-internal.$(JL_MAJOR_SHLIB_EXT ) )
1736- LIBJULIAINTERNAL_INSTALL_DEPLIB := $(call dep_lib_path,$(libdir ) ,$(private_shlibdir ) /libjulia-internal.$(JL_MAJOR_SHLIB_EXT ) )
1746+ LIBJULIAINTERNAL_BUILD_DEPLIB := $(call dep_lib_path,$(build_shlibdir ) ,$(build_shlibdir ) /libjulia-internal.$(JL_MAJOR_SHLIB_EXT ) )
1747+ LIBJULIAINTERNAL_INSTALL_DEPLIB := $(call dep_lib_path,$(shlibdir ) ,$(private_shlibdir ) /libjulia-internal.$(JL_MAJOR_SHLIB_EXT ) )
17371748
1738- LIBJULIAINTERNAL_DEBUG_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir ) ,$(build_shlibdir ) /libjulia-internal-debug.$(JL_MAJOR_SHLIB_EXT ) )
1739- LIBJULIAINTERNAL_DEBUG_INSTALL_DEPLIB := $(call dep_lib_path,$(libdir ) ,$(private_shlibdir ) /libjulia-internal-debug.$(JL_MAJOR_SHLIB_EXT ) )
1749+ LIBJULIAINTERNAL_DEBUG_BUILD_DEPLIB := $(call dep_lib_path,$(build_shlibdir ) ,$(build_shlibdir ) /libjulia-internal-debug.$(JL_MAJOR_SHLIB_EXT ) )
1750+ LIBJULIAINTERNAL_DEBUG_INSTALL_DEPLIB := $(call dep_lib_path,$(shlibdir ) ,$(private_shlibdir ) /libjulia-internal-debug.$(JL_MAJOR_SHLIB_EXT ) )
17401751
1741- LIBJULIACODEGEN_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir ) ,$(build_shlibdir ) /libjulia-codegen.$(JL_MAJOR_SHLIB_EXT ) )
1742- LIBJULIACODEGEN_INSTALL_DEPLIB := $(call dep_lib_path,$(libdir ) ,$(private_shlibdir ) /libjulia-codegen.$(JL_MAJOR_SHLIB_EXT ) )
1752+ LIBJULIACODEGEN_BUILD_DEPLIB := $(call dep_lib_path,$(build_shlibdir ) ,$(build_shlibdir ) /libjulia-codegen.$(JL_MAJOR_SHLIB_EXT ) )
1753+ LIBJULIACODEGEN_INSTALL_DEPLIB := $(call dep_lib_path,$(shlibdir ) ,$(private_shlibdir ) /libjulia-codegen.$(JL_MAJOR_SHLIB_EXT ) )
17431754
1744- LIBJULIACODEGEN_DEBUG_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir ) ,$(build_shlibdir ) /libjulia-codegen-debug.$(JL_MAJOR_SHLIB_EXT ) )
1745- LIBJULIACODEGEN_DEBUG_INSTALL_DEPLIB := $(call dep_lib_path,$(libdir ) ,$(private_shlibdir ) /libjulia-codegen-debug.$(JL_MAJOR_SHLIB_EXT ) )
1755+ LIBJULIACODEGEN_DEBUG_BUILD_DEPLIB := $(call dep_lib_path,$(build_shlibdir ) ,$(build_shlibdir ) /libjulia-codegen-debug.$(JL_MAJOR_SHLIB_EXT ) )
1756+ LIBJULIACODEGEN_DEBUG_INSTALL_DEPLIB := $(call dep_lib_path,$(shlibdir ) ,$(private_shlibdir ) /libjulia-codegen-debug.$(JL_MAJOR_SHLIB_EXT ) )
17461757
17471758ifeq ($(OS ) ,WINNT)
17481759ifeq ($(BINARY ) ,32)
@@ -1770,34 +1781,34 @@ endif
17701781
17711782# USE_SYSTEM_CSL causes it to get symlinked into build_private_shlibdir
17721783ifeq ($(USE_SYSTEM_CSL ) ,1)
1773- LIBGCC_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir ) ,$(build_private_shlibdir ) /$(LIBGCC_NAME ) )
1784+ LIBGCC_BUILD_DEPLIB := $(call dep_lib_path,$(build_shlibdir ) ,$(build_private_shlibdir ) /$(LIBGCC_NAME ) )
17741785else
1775- LIBGCC_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir ) ,$(build_shlibdir ) /$(LIBGCC_NAME ) )
1786+ LIBGCC_BUILD_DEPLIB := $(call dep_lib_path,$(build_shlibdir ) ,$(build_shlibdir ) /$(LIBGCC_NAME ) )
17761787endif
1777- LIBGCC_INSTALL_DEPLIB := $(call dep_lib_path,$(libdir ) ,$(private_shlibdir ) /$(LIBGCC_NAME ) )
1788+ LIBGCC_INSTALL_DEPLIB := $(call dep_lib_path,$(shlibdir ) ,$(private_shlibdir ) /$(LIBGCC_NAME ) )
17781789
17791790# We only bother to define this on Linux, as that's the only platform that does libstdc++ probing
17801791# On all other platforms, the LIBSTDCXX_*_DEPLIB variables will be empty.
17811792ifeq ($(OS ) ,Linux)
17821793LIBSTDCXX_NAME := libstdc++.so.6
17831794ifeq ($(USE_SYSTEM_CSL ) ,1)
1784- LIBSTDCXX_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir ) ,$(build_private_shlibdir ) /$(LIBSTDCXX_NAME ) )
1795+ LIBSTDCXX_BUILD_DEPLIB := $(call dep_lib_path,$(build_shlibdir ) ,$(build_private_shlibdir ) /$(LIBSTDCXX_NAME ) )
17851796else
1786- LIBSTDCXX_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir ) ,$(build_shlibdir ) /$(LIBSTDCXX_NAME ) )
1797+ LIBSTDCXX_BUILD_DEPLIB := $(call dep_lib_path,$(build_shlibdir ) ,$(build_shlibdir ) /$(LIBSTDCXX_NAME ) )
17871798endif
1788- LIBSTDCXX_INSTALL_DEPLIB := $(call dep_lib_path,$(libdir ) ,$(private_shlibdir ) /$(LIBSTDCXX_NAME ) )
1799+ LIBSTDCXX_INSTALL_DEPLIB := $(call dep_lib_path,$(shlibdir ) ,$(private_shlibdir ) /$(LIBSTDCXX_NAME ) )
17891800endif
17901801
17911802
17921803# USE_SYSTEM_LIBM and USE_SYSTEM_OPENLIBM causes it to get symlinked into build_private_shlibdir
17931804ifeq ($(USE_SYSTEM_LIBM ) ,1)
1794- LIBM_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir ) ,$(build_private_shlibdir ) /$(LIBMNAME ) .$(SHLIB_EXT ) )
1805+ LIBM_BUILD_DEPLIB := $(call dep_lib_path,$(build_shlibdir ) ,$(build_private_shlibdir ) /$(LIBMNAME ) .$(SHLIB_EXT ) )
17951806else ifeq ($(USE_SYSTEM_OPENLIBM),1)
1796- LIBM_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir ) ,$(build_private_shlibdir ) /$(LIBMNAME ) .$(SHLIB_EXT ) )
1807+ LIBM_BUILD_DEPLIB := $(call dep_lib_path,$(build_shlibdir ) ,$(build_private_shlibdir ) /$(LIBMNAME ) .$(SHLIB_EXT ) )
17971808else
1798- LIBM_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir ) ,$(build_shlibdir ) /$(LIBMNAME ) .$(SHLIB_EXT ) )
1809+ LIBM_BUILD_DEPLIB := $(call dep_lib_path,$(build_shlibdir ) ,$(build_shlibdir ) /$(LIBMNAME ) .$(SHLIB_EXT ) )
17991810endif
1800- LIBM_INSTALL_DEPLIB := $(call dep_lib_path,$(libdir ) ,$(private_shlibdir ) /$(LIBMNAME ) .$(SHLIB_EXT ) )
1811+ LIBM_INSTALL_DEPLIB := $(call dep_lib_path,$(shlibdir ) ,$(private_shlibdir ) /$(LIBMNAME ) .$(SHLIB_EXT ) )
18011812
18021813# We list:
18031814# * libgcc_s, because FreeBSD needs to load ours, not the system one.
@@ -1861,7 +1872,7 @@ ifeq ($(VERBOSE), 0)
18611872
18621873QUIET_MAKE = -s
18631874
1864- GOAL =$(subst ','\'' ,$(subst $(abspath $(JULIAHOME ) ) /,,$(abspath $@ ) ) )
1875+ GOAL =$(call shell_escape ,$(subst $(abspath $(JULIAHOME ) ) /,,$(abspath $@ ) ) )
18651876
18661877PRINT_CC = printf ' %b %b\n' $(CCCOLOR ) CC$(ENDCOLOR ) $(SRCCOLOR )$(GOAL )$(ENDCOLOR ) ; $(1 )
18671878PRINT_ANALYZE = printf ' %b %b\n' $(CCCOLOR ) ANALYZE$(ENDCOLOR ) $(SRCCOLOR )$(GOAL )$(ENDCOLOR ) ; $(1 )
@@ -1873,18 +1884,18 @@ PRINT_DTRACE = printf ' %b %b\n' $(DTRACECOLOR)DTRACE$(ENDCOLOR) $(BINCOLOR)$
18731884
18741885else
18751886QUIET_MAKE =
1876- PRINT_CC = echo ' $( subst ','\'', $(1 ) )' ; $(1 )
1877- PRINT_ANALYZE = echo ' $( subst ','\'', $(1 ) )' ; $(1 )
1878- PRINT_LINK = echo ' $( subst ','\'', $(1 ) )' ; $(1 )
1879- PRINT_PERL = echo ' $( subst ','\'', $(1 ) )' ; $(1 )
1880- PRINT_FLISP = echo ' $( subst ','\'', $(1 ) )' ; $(1 )
1881- PRINT_JULIA = echo ' $( subst ','\'', $(1 ) )' ; $(1 )
1882- PRINT_DTRACE = echo ' $( subst ','\'', $(1 ) )' ; $(1 )
1887+ PRINT_CC = printf "%s\n" $( call shell_escape, $(1 ) ) ; $(1 )
1888+ PRINT_ANALYZE = printf "%s\n" $( call shell_escape, $(1 ) ) ; $(1 )
1889+ PRINT_LINK = printf "%s\n" $( call shell_escape, $(1 ) ) ; $(1 )
1890+ PRINT_PERL = printf "%s\n" $( call shell_escape, $(1 ) ) ; $(1 )
1891+ PRINT_FLISP = printf "%s\n" $( call shell_escape, $(1 ) ) ; $(1 )
1892+ PRINT_JULIA = printf "%s\n" $( call shell_escape, $(1 ) ) ; $(1 )
1893+ PRINT_DTRACE = printf "%s\n" $( call shell_escape, $(1 ) ) ; $(1 )
18831894
18841895endif # VERBOSE
18851896
18861897# Makefile debugging trick:
18871898# call print-VARIABLE to see the runtime value of any variable
18881899# (hardened against any special characters appearing in the output)
18891900print-% :
1890- @echo ' $* =$(subst ' , ' \ ' ' , $(subst $(newline),\n,$($*)))'
1901+ @printf " %s\n " $( call shell_escape, $* ) =$(call shell_escape, $(subst $(newline ) ,\n,$($* ) ) )
0 commit comments