From e047f9dbbd5214ac4c6a463c4e79968666ec3906 Mon Sep 17 00:00:00 2001 From: Thomas Desveaux Date: Fri, 1 Jun 2018 21:26:36 +0200 Subject: [PATCH] gmake: Add rule to create directories + set dependencies to said rules + fix tests --- modules/d/actions/gmake.lua | 12 ------- modules/gmake/gmake_cpp.lua | 37 +++++++++++++------ modules/gmake/tests/cpp/test_file_rules.lua | 40 --------------------- modules/gmake/tests/cpp/test_make_pch.lua | 22 +++++------- 4 files changed, 34 insertions(+), 77 deletions(-) diff --git a/modules/d/actions/gmake.lua b/modules/d/actions/gmake.lua index cae03bfb33..75bebc0334 100644 --- a/modules/d/actions/gmake.lua +++ b/modules/d/actions/gmake.lua @@ -73,18 +73,6 @@ end end) --- --- Don't create $(OBJDIR) in the d-file rules --- - - p.override(make, "objDirInFileRules", function(oldfn, prj, node) - -- node is nil when making pch rules - if not node or not path.isdfile(node.abspath) then - oldfn(prj, node) - end - end) - - --- -- Add namespace for element definition lists for p.callarray() diff --git a/modules/gmake/gmake_cpp.lua b/modules/gmake/gmake_cpp.lua index e56e1aed95..ab09397bcc 100644 --- a/modules/gmake/gmake_cpp.lua +++ b/modules/gmake/gmake_cpp.lua @@ -34,6 +34,9 @@ make.cppObjects, make.shellType, make.cppTargetRules, + make.cppCustomFilesRules, + make.cppTargetDirRules, + make.cppObjDirRules, make.cppCleanRules, make.preBuildRules, make.preLinkRules, @@ -69,10 +72,6 @@ _p('\t@echo $(notdir $<)') end - function make.objDirInFileRules(prj, node) - make.mkdir('$(OBJDIR)') - end - function make.cpp.generate(prj) p.eol("\n") p.callArray(cpp.elements.makefile, prj) @@ -85,7 +84,6 @@ cpp.elements.standardFileRules = function(prj, node) return { make.fileDependency, - make.objDirInFileRules, cpp.standardFileRules, } end @@ -93,7 +91,6 @@ cpp.elements.customFileRules = function(prj, node) return { make.fileDependency, - make.objDirInFileRules, cpp.customFileRules, } end @@ -454,14 +451,31 @@ end function make.cppTargetRules(prj) - _p('$(TARGET): $(GCH) ${CUSTOMFILES} $(OBJECTS) $(LDDEPS) $(RESOURCES)') + _p('$(TARGET): $(GCH) ${CUSTOMFILES} $(OBJECTS) $(LDDEPS) $(RESOURCES) | $(TARGETDIR)') _p('\t@echo Linking %s', prj.name) - make.mkdir('$(TARGETDIR)') _p('\t$(SILENT) $(LINKCMD)') _p('\t$(POSTBUILDCMDS)') _p('') end + function make.cppCustomFilesRules(prj) + _p('$(CUSTOMFILES): | $(OBJDIR)') + _p('') + end + + function make.cppTargetDirRules(prj) + _p('$(TARGETDIR):') + _p('\t@echo Creating $(TARGETDIR)') + make.mkdir('$(TARGETDIR)') + _p('') + end + + function make.cppObjDirRules(prj) + _p('$(OBJDIR):') + _p('\t@echo Creating $(OBJDIR)') + make.mkdir('$(OBJDIR)') + _p('') + end function make.cppTools(cfg, toolset) local tool = toolset.gettoolname(cfg, "cc") @@ -600,14 +614,15 @@ end function make.pchRules(prj) _p('ifneq (,$(PCH))') - _p('$(OBJECTS): $(GCH) $(PCH)') - _p('$(GCH): $(PCH)') + _p('$(OBJECTS): $(GCH) $(PCH) | $(OBJDIR)') + _p('$(GCH): $(PCH) | $(OBJDIR)') _p('\t@echo $(notdir $<)') - make.objDirInFileRules(prj, nil) local cmd = iif(prj.language == "C", "$(CC) -x c-header $(ALL_CFLAGS)", "$(CXX) -x c++-header $(ALL_CXXFLAGS)") _p('\t$(SILENT) %s -o "$@" -MF "$(@:%%.gch=%%.d)" -c "$<"', cmd) + _p('else') + _p('$(OBJECTS): | $(OBJDIR)') _p('endif') _p('') end diff --git a/modules/gmake/tests/cpp/test_file_rules.lua b/modules/gmake/tests/cpp/test_file_rules.lua index f54bbb9121..29fc29464b 100644 --- a/modules/gmake/tests/cpp/test_file_rules.lua +++ b/modules/gmake/tests/cpp/test_file_rules.lua @@ -37,19 +37,9 @@ test.capture [[ $(OBJDIR)/hello.o: src/greetings/hello.cpp @echo $(notdir $<) -ifeq (posix,$(SHELLTYPE)) - $(SILENT) mkdir -p $(OBJDIR) -else - $(SILENT) mkdir $(subst /,\\,$(OBJDIR)) -endif $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<" $(OBJDIR)/hello1.o: src/hello.cpp @echo $(notdir $<) -ifeq (posix,$(SHELLTYPE)) - $(SILENT) mkdir -p $(OBJDIR) -else - $(SILENT) mkdir $(subst /,\\,$(OBJDIR)) -endif $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<" ]] @@ -66,19 +56,9 @@ endif test.capture [[ $(OBJDIR)/hello.o: src/hello.c @echo $(notdir $<) -ifeq (posix,$(SHELLTYPE)) - $(SILENT) mkdir -p $(OBJDIR) -else - $(SILENT) mkdir $(subst /,\\,$(OBJDIR)) -endif $(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<" $(OBJDIR)/test.o: src/test.cpp @echo $(notdir $<) -ifeq (posix,$(SHELLTYPE)) - $(SILENT) mkdir -p $(OBJDIR) -else - $(SILENT) mkdir $(subst /,\\,$(OBJDIR)) -endif $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<" ]] @@ -96,11 +76,6 @@ endif test.capture [[ $(OBJDIR)/hello.o: src/hello.c @echo $(notdir $<) -ifeq (posix,$(SHELLTYPE)) - $(SILENT) mkdir -p $(OBJDIR) -else - $(SILENT) mkdir $(subst /,\\,$(OBJDIR)) -endif ifeq ($(config),debug) $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<" endif @@ -109,11 +84,6 @@ ifeq ($(config),release) endif $(OBJDIR)/test.o: src/test.c @echo $(notdir $<) -ifeq (posix,$(SHELLTYPE)) - $(SILENT) mkdir -p $(OBJDIR) -else - $(SILENT) mkdir $(subst /,\\,$(OBJDIR)) -endif $(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<" ]] end @@ -130,11 +100,6 @@ endif test.capture [[ $(OBJDIR)/hello.o: src/hello.c @echo $(notdir $<) -ifeq (posix,$(SHELLTYPE)) - $(SILENT) mkdir -p $(OBJDIR) -else - $(SILENT) mkdir $(subst /,\\,$(OBJDIR)) -endif ifeq ($(config),debug) $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<" endif @@ -143,11 +108,6 @@ ifeq ($(config),release) endif $(OBJDIR)/test.o: src/test.c @echo $(notdir $<) -ifeq (posix,$(SHELLTYPE)) - $(SILENT) mkdir -p $(OBJDIR) -else - $(SILENT) mkdir $(subst /,\\,$(OBJDIR)) -endif $(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<" ]] end diff --git a/modules/gmake/tests/cpp/test_make_pch.lua b/modules/gmake/tests/cpp/test_make_pch.lua index bdd134070a..b79ab4ee57 100644 --- a/modules/gmake/tests/cpp/test_make_pch.lua +++ b/modules/gmake/tests/cpp/test_make_pch.lua @@ -93,15 +93,12 @@ prepareRules() test.capture [[ ifneq (,$(PCH)) -$(OBJECTS): $(GCH) $(PCH) -$(GCH): $(PCH) +$(OBJECTS): $(GCH) $(PCH) | $(OBJDIR) +$(GCH): $(PCH) | $(OBJDIR) @echo $(notdir $<) -ifeq (posix,$(SHELLTYPE)) - $(SILENT) mkdir -p $(OBJDIR) -else - $(SILENT) mkdir $(subst /,\\,$(OBJDIR)) -endif $(SILENT) $(CXX) -x c++-header $(ALL_CXXFLAGS) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<" +else +$(OBJECTS): | $(OBJDIR) endif ]] end @@ -117,15 +114,12 @@ endif prepareRules() test.capture [[ ifneq (,$(PCH)) -$(OBJECTS): $(GCH) $(PCH) -$(GCH): $(PCH) +$(OBJECTS): $(GCH) $(PCH) | $(OBJDIR) +$(GCH): $(PCH) | $(OBJDIR) @echo $(notdir $<) -ifeq (posix,$(SHELLTYPE)) - $(SILENT) mkdir -p $(OBJDIR) -else - $(SILENT) mkdir $(subst /,\\,$(OBJDIR)) -endif $(SILENT) $(CC) -x c-header $(ALL_CFLAGS) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<" +else +$(OBJECTS): | $(OBJDIR) endif ]] end