diff --git a/modules/gmake2/gmake2.lua b/modules/gmake2/gmake2.lua index e73549783..ca141f67a 100644 --- a/modules/gmake2/gmake2.lua +++ b/modules/gmake2/gmake2.lua @@ -129,6 +129,15 @@ _p('endif') end + function gmake2.copyfile_cmds(source, dest) + local cmd = '$(SILENT) {COPYFILE} ' .. source .. ' ' .. dest + return { 'ifeq (posix,$(SHELLTYPE))', + '\t' .. os.translateCommands(cmd, 'posix'), + 'else', + '\t' .. os.translateCommands(cmd, 'windows'), + 'endif' } + end + function gmake2.mkdirRules(dirname) _p('%s:', dirname) _p('\t@echo Creating %s', dirname) diff --git a/modules/gmake2/gmake2_cpp.lua b/modules/gmake2/gmake2_cpp.lua index a02893dfd..a0bf17b22 100644 --- a/modules/gmake2/gmake2_cpp.lua +++ b/modules/gmake2/gmake2_cpp.lua @@ -162,7 +162,19 @@ end -- process custom build commands. - if fileconfig.hasCustomBuildRule(filecfg) then + if filecfg.buildaction == "Copy" then + local output = '$(TARGETDIR)/' .. node.name + local file = { + buildoutputs = { output }, + source = node.relpath, + buildmessage = '$(notdir $<)', + verbatimbuildcommands = gmake2.copyfile_cmds('"$<"', '"$@"'), + buildinputs = {'$(TARGETDIR)'} + } + table.insert(cfg._gmake.fileRules, file) + cpp.addGeneratedFile(cfg, node, output) + + elseif fileconfig.hasCustomBuildRule(filecfg) then local env = table.shallowcopy(filecfg.environ) env.PathVars = { ["file.basename"] = { absolute = false, token = node.basename }, @@ -761,7 +773,11 @@ end end end - + if file.verbatimbuildcommands then + for _, cmd in ipairs(file.verbatimbuildcommands) do + _p('%s', cmd); + end + end -- TODO: this is a hack with some imperfect side-effects. -- better solution would be to emit a dummy file for the rule, and then outputs depend on it (must clean up dummy in 'clean') -- better yet, is to use pattern rules, but we need to detect that all outputs have the same stem diff --git a/modules/gmake2/tests/test_gmake2_file_rules.lua b/modules/gmake2/tests/test_gmake2_file_rules.lua index c420779ed..4e61ce975 100644 --- a/modules/gmake2/tests/test_gmake2_file_rules.lua +++ b/modules/gmake2/tests/test_gmake2_file_rules.lua @@ -409,3 +409,27 @@ test2.obj: test2.rule $(SILENT) dorule S1 "test2.rule" ]] end + + function suite.fileRulesOnBuildactionCopy() + files { "hello.dll" } + filter { "Debug", "files:hello.dll" } + buildaction "Copy" + filter {} + prepare() + test.capture [[ +# File Rules +# ############################################# + +ifeq ($(config),debug) +$(TARGETDIR)/hello.dll: hello.dll $(TARGETDIR) + @echo "$(notdir $<)" +ifeq (posix,$(SHELLTYPE)) + $(SILENT) cp -f "$<" "$@" +else + $(SILENT) copy /B /Y "$<" "$@" +endif + +endif +]] + end + diff --git a/modules/gmake2/tests/test_gmake2_objects.lua b/modules/gmake2/tests/test_gmake2_objects.lua index 2c7881d46..2314fe47a 100644 --- a/modules/gmake2/tests/test_gmake2_objects.lua +++ b/modules/gmake2/tests/test_gmake2_objects.lua @@ -494,3 +494,26 @@ endif ]] end + + function suite.objectsOnBuildactionCopy() + files { "hello.dll" } + filter { "Debug", "files:hello.dll" } + buildaction "Copy" + filter {} + prepare() + test.capture [[ +# File sets +# ############################################# + +CUSTOM := +GENERATED := + +ifeq ($(config),debug) +CUSTOM += $(TARGETDIR)/hello.dll +GENERATED += $(TARGETDIR)/hello.dll + +endif + + ]] + end +