Skip to content

Commit e026aff

Browse files
authored
build: fix makefile rules and windows path separator used in build (#57472)
Closes #45262
1 parent 58ce713 commit e026aff

File tree

7 files changed

+106
-106
lines changed

7 files changed

+106
-106
lines changed

Make.inc

+46-35
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ endef
111111
COMMA:=,
112112
SPACE:=$(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
115120
export LC_ALL=C
116121
export LANG=C
@@ -644,12 +649,12 @@ CXX += -Qunused-arguments
644649
export CCACHE_CPP2 := yes
645650
endif
646651
else #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-)
653658
endif
654659

655660
JFFLAGS := -O2 $(fPIC)
@@ -776,7 +781,7 @@ LDFLAGS += -L$(build_libdir) -Wl,-rpath,$(build_libdir)
776781
endif # gfortran
777782
endif # 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)
781786
endif
782787

@@ -1663,6 +1668,12 @@ $(subst /,\\,$(subst $(shell $(2) pwd),$(shell $(2) cmd //C cd),$(abspath $(1)))
16631668
endef
16641669
endif
16651670

1671+
ifeq ($(OS), WINNT)
1672+
normalize_path = $(subst /,\,$1)
1673+
else
1674+
normalize_path = $1
1675+
endif
1676+
16661677
define symlink_target # (from, to-dir, to-name)
16671678
CLEAN_TARGETS += clean-$$(abspath $(2)/$(3))
16681679
clean-$$(abspath $(2)/$(3)):
@@ -1729,20 +1740,20 @@ JULIA_SYSIMG_release := $(build_private_libdir)/sys.$(SHLIB_EXT)
17291740
JULIA_SYSIMG := $(JULIA_SYSIMG_$(JULIA_BUILD_MODE))
17301741

17311742
define 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)))
17331744
endef
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

17471758
ifeq ($(OS),WINNT)
17481759
ifeq ($(BINARY),32)
@@ -1770,34 +1781,34 @@ endif
17701781

17711782
# USE_SYSTEM_CSL causes it to get symlinked into build_private_shlibdir
17721783
ifeq ($(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))
17741785
else
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))
17761787
endif
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.
17811792
ifeq ($(OS),Linux)
17821793
LIBSTDCXX_NAME := libstdc++.so.6
17831794
ifeq ($(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))
17851796
else
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))
17871798
endif
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))
17891800
endif
17901801

17911802

17921803
# USE_SYSTEM_LIBM and USE_SYSTEM_OPENLIBM causes it to get symlinked into build_private_shlibdir
17931804
ifeq ($(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))
17951806
else 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))
17971808
else
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))
17991810
endif
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

18621873
QUIET_MAKE = -s
18631874

1864-
GOAL=$(subst ','\'',$(subst $(abspath $(JULIAHOME))/,,$(abspath $@)))
1875+
GOAL=$(call shell_escape,$(subst $(abspath $(JULIAHOME))/,,$(abspath $@)))
18651876

18661877
PRINT_CC = printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$(GOAL)$(ENDCOLOR); $(1)
18671878
PRINT_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

18741885
else
18751886
QUIET_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

18841895
endif # 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)
18891900
print-%:
1890-
@echo '$*=$(subst ','\'',$(subst $(newline),\n,$($*)))'
1901+
@printf "%s\n" $(call shell_escape,$*)=$(call shell_escape,$(subst $(newline),\n,$($*)))

Makefile

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ include $(JULIAHOME)/Make.inc
44
include $(JULIAHOME)/deps/llvm-ver.make
55

66
# Make sure the user didn't try to build in a path that will confuse the shell or make
7-
METACHARACTERS := [][?*{}() $$%:;&|!\#,\\`\":]\|/\./\|/\.\./
7+
METACHARACTERS := [][?*{}() $$%:;&|!\#,\\`\": ]\|/\./\|/\.\./
88
ifneq (,$(findstring ',$(value BUILDROOT)))
99
$(error cowardly refusing to build into directory with a single-quote in the path)
1010
endif
1111
ifneq (,$(findstring ',$(value JULIAHOME)))
1212
$(error cowardly refusing to build from source directory with a single-quote in the path)
1313
endif
14-
ifneq (,$(shell echo '$(value BUILDROOT)/' | grep '$(METACHARACTERS)'))
14+
ifneq (,$(shell printf "%s\n" $(call shell_escape,$(value BUILDROOT)/) | grep '$(METACHARACTERS)'))
1515
$(error cowardly refusing to build into directory with a shell-metacharacter in the path\
1616
(got: $(value BUILDROOT)))
1717
endif
18-
ifneq (,$(shell echo '$(value JULIAHOME)/' | grep '$(METACHARACTERS)'))
18+
ifneq (,$(shell printf "%s\n" $(call shell_escape,$(value JULIAHOME)/) | grep '$(METACHARACTERS)'))
1919
$(error cowardly refusing to build from source directory with a shell-metacharacter in the path\
2020
(got: $(value JULIAHOME)))
2121
endif
@@ -33,9 +33,9 @@ BUILDDIRMAKE := $(addsuffix /Makefile,$(BUILDDIRS)) $(BUILDROOT)/sysimage.mk $(B
3333
DIRS += $(BUILDDIRS)
3434
$(BUILDDIRMAKE): | $(BUILDDIRS)
3535
@# add Makefiles to the build directories for convenience (pointing back to the source location of each)
36-
@echo '# -- This file is automatically generated in julia/Makefile -- #' > $@
37-
@echo 'BUILDROOT=$(BUILDROOT)' >> $@
38-
@echo 'include $(JULIAHOME)$(patsubst $(BUILDROOT)%,%,$@)' >> $@
36+
@printf "%s\n" '# -- This file is automatically generated in julia/Makefile -- #' > $@
37+
@printf "%s\n" 'BUILDROOT=$(BUILDROOT)' >> $@
38+
@printf "%s\n" 'include $(JULIAHOME)$(patsubst $(BUILDROOT)%,%,$@)' >> $@
3939
julia-deps: | $(BUILDDIRMAKE)
4040
configure-y: | $(BUILDDIRMAKE)
4141
configure:
@@ -67,7 +67,7 @@ $(BUILDROOT)/doc/_build/html/en/index.html: $(shell find $(BUILDROOT)/base $(BUI
6767

6868
julia-symlink: julia-cli-$(JULIA_BUILD_MODE)
6969
ifeq ($(OS),WINNT)
70-
echo '@"%~dp0/'"$$(echo '$(call rel_path,$(BUILDROOT),$(JULIA_EXECUTABLE))')"'" %*' | tr / '\\' > $(BUILDROOT)/julia.bat
70+
printf '@"%%~dp0/%s" %%*\n' "$$(printf "%s\n" '$(call rel_path,$(BUILDROOT),$(JULIA_EXECUTABLE))')" | tr / '\\' > $(BUILDROOT)/julia.bat
7171
chmod a+x $(BUILDROOT)/julia.bat
7272
else
7373
ifndef JULIA_VAGRANT_BUILD
@@ -306,7 +306,7 @@ endif
306306
# Note that we disable MSYS2's path munging here, as otherwise
307307
# it replaces our `:`-separated list as a `;`-separated one.
308308
define stringreplace
309-
MSYS2_ARG_CONV_EXCL='*' $(build_depsbindir)/stringreplace $$(strings -t x - '$1' | grep "$2" | awk '{print $$1;}') "$3" 255 "$(call cygpath_w,$1)"
309+
MSYS2_ARG_CONV_EXCL='*' $(build_depsbindir)/stringreplace $$(strings -t x - '$1' | grep '$2' | awk '{print $$1;}') '$3' 255 '$(call cygpath_w,$1)'
310310
endef
311311

312312

0 commit comments

Comments
 (0)