summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2019-01-15 02:26:54 +0100
committerCharles Pigott <charlespigott@googlemail.com>2019-01-16 19:27:06 +0000
commitee84f98f1e1c2063bb2a0c3405200c1a8ff9b970 (patch)
tree63da22a2139d0529d617ba6670a70fa9810af189
parent5a09337c2018a7ee371e2e96220ee0d06b1df753 (diff)
downloadopenttd-ee84f98f1e1c2063bb2a0c3405200c1a8ff9b970.tar.xz
Fix: deps calculation call could fail due to command line length
-rw-r--r--Makefile.src.in22
-rw-r--r--config.lib2
2 files changed, 15 insertions, 9 deletions
diff --git a/Makefile.src.in b/Makefile.src.in
index 0589ba69a..c07015cfe 100644
--- a/Makefile.src.in
+++ b/Makefile.src.in
@@ -159,6 +159,19 @@ $(SRC_OBJS_DIR)/$(DEPEND): $(SRC_DIR)/depend/depend.cpp
$(Q)$(CXX_BUILD) $(CFLAGS_BUILD) $(CXXFLAGS_BUILD) $(LDFLAGS_BUILD) -o $@ $<
endif
+# Macro for invoking a command on groups of 100 words at a time
+# (analogous to xargs(1)). The macro invokes itself recursively
+# until the list of words is depleted.
+#
+# Usage: $(call xargs,COMMAND,LIST)
+#
+# COMMAND should be a shell command to which the words will be
+# appended as arguments in groups of 100.
+define xargs
+$(1) $(wordlist 1,100,$(2))
+$(if $(word 101,$(2)),$(call xargs,$(1),$(wordlist 101,$(words $(2)),$(2))))
+endef
+
# Make sure that only 'make depend' ALWAYS triggers a recheck
ifeq ($(filter depend, $(MAKECMDGOALS)),)
Makefile.dep: $(FILE_DEP) $(SRCS:%=$(SRC_DIR)/%) $(CONFIG_CACHE_SOURCE) $(DEP)
@@ -170,14 +183,7 @@ endif
$(Q)touch Makefile.dep.tmp
# Calculate the deps via makedepend
- $(Q)$(MAKEDEPEND) -f$(SRC_OBJS_DIR)/Makefile.dep.tmp -o.o -Y -v -- $(CFLAGS_MAKEDEP) -- $(SRCS:%=$(SRC_DIR)/%) 2>/dev/null
-
-# Convert x:/... paths to /x/... for mingw
-ifeq ($(OS), MINGW)
- @cat Makefile.dep.tmp | sed 's@/\([a-zA-Z]\):\/@\/\1\/@g' > Makefile.dep.tmp.mingw
- @cp Makefile.dep.tmp.mingw Makefile.dep.tmp
- @rm -f Makefile.dep.tmp.mingw
-endif
+ $(call xargs,$(Q)$(MAKEDEPEND) -f$(SRC_OBJS_DIR)/Makefile.dep.tmp -o.o -Y -v -a -- $(CFLAGS_MAKEDEP) -- 2>/dev/null,$(SRCS:%=$(SRC_DIR)/%))
# Remove all comments and includes that don't start with $(SRC_DIR)
# Remove $(SRC_DIR) from object-file-name
diff --git a/config.lib b/config.lib
index 566309ada..1ef51f72a 100644
--- a/config.lib
+++ b/config.lib
@@ -1959,7 +1959,7 @@ make_cflags_and_ldflags() {
cflags_makedep="`echo | $cxx_host $CXXFLAGS -E -x c++ -dM - | sed 's@.define @-D@g;s@ .*@ @g;s@(.*)@@g' | tr -d '\r\n'`"
# Please escape ALL " within ` because e.g. "" terminates the string in some sh implementations
- cflags_makedep="$cflags_makedep `echo \"$CFLAGS\" \"$CXXFLAGS\" | sed 's@ /@ -@g;s@-I[ ]*[^ ]*@@g'`"
+ cflags_makedep="$cflags_makedep `echo \"$CFLAGS\" \"$CXXFLAGS\" | sed 's@ /@ -@g;s@-I[ ]*[^ ]*@@g;s@[ ]*-[^D][^ ]*@@g'`"
else
makedepend=""
fi