diff options
| author | ruki <[email protected]> | 2023-04-27 00:15:55 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-04-27 00:15:55 +0800 |
| commit | ae92dae8d3e9e5acc5a82f8c6e1cc33fcbdfa715 (patch) | |
| tree | 53d57f4bac99a243d7f4c2f85d272789b05e1e0e /xmake/plugins/project/make/makefile.lua | |
| parent | e988ef97f3a07d02a8bf4404beff8a3f2890c9ae (diff) | |
add custom commands for generators
Diffstat (limited to 'xmake/plugins/project/make/makefile.lua')
| -rw-r--r-- | xmake/plugins/project/make/makefile.lua | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/xmake/plugins/project/make/makefile.lua b/xmake/plugins/project/make/makefile.lua index ef1122857..4cea85d15 100644 --- a/xmake/plugins/project/make/makefile.lua +++ b/xmake/plugins/project/make/makefile.lua @@ -141,7 +141,6 @@ function _get_common_flags(target, sourcekind, sourcebatch) return commonflags, sourceflags_ end - -- mkdir directory function _add_create_directory(makefile, dir) if is_subhost("windows") then @@ -271,7 +270,7 @@ function _add_flags(makefile, targetflags, outputdir) end -- add build object -function _add_build_object(makefile, target, sourcefile, objectfile, sourceflags, outputdir) +function _add_build_object(makefile, target, sourcefile, objectfile, sourceflags, outputdir, precmds_label) -- get the source file kind local sourcekind = language.sourcekind_of(sourcefile) @@ -321,6 +320,9 @@ function _add_build_object(makefile, target, sourcefile, objectfile, sourceflags -- make head makefile:printf("%s:", objectfile) + if precmds_label then + makefile:printf(" %s", precmds_label) + end -- make dependence makefile:print(" %s", sourcefile) @@ -335,7 +337,7 @@ function _add_build_object(makefile, target, sourcefile, objectfile, sourceflags end -- add build objects -function _add_build_objects(makefile, target, sourcekind, sourcebatch, sourceflags, outputdir) +function _add_build_objects(makefile, target, sourcekind, sourcebatch, sourceflags, outputdir, precmds_label) local handled_objects = target:data("makefile.handled_objects") if not handled_objects then handled_objects = {} @@ -345,7 +347,8 @@ function _add_build_objects(makefile, target, sourcekind, sourcebatch, sourcefla -- remove repeat -- this is because some rules will repeatedly bind the same sourcekind, e.g. `rule("c++.build.modules.builder")` if not handled_objects[objectfile] then - _add_build_object(makefile, target, sourcebatch.sourcefiles[index], objectfile, sourceflags, outputdir) + _add_build_object(makefile, target, + sourcebatch.sourcefiles[index], objectfile, sourceflags, outputdir, precmds_label) handled_objects[objectfile] = true end end @@ -362,12 +365,32 @@ function _add_build_phony(makefile, target) makefile:print("") end +-- add custom commands before building target +function _add_build_target_custom_commands_before(makefile, target, outputdir) + local targetname = target:name() + local label = "precmds_" .. targetname + + makefile:print("%s:", label) + makefile:print("\techo hello %s", targetname) + makefile:print("") + return label +end + +-- add custom commands after building target +function _add_build_target_custom_commands_after(makefile, target, outputdir) + local targetname = target:name() + makefile:print("\techo hello %s", targetname) +end + -- add build target function _add_build_target(makefile, target, targetflags, outputdir) -- https://github.com/xmake-io/xmake/issues/2337 target:data_set("plugin.project.kind", "makefile") + -- add custom commands before building target + local precmds_label = _add_build_target_custom_commands_before(makefile, target, outputdir) + -- is phony target? if target:is_phony() then return _add_build_phony(makefile, target) @@ -382,10 +405,16 @@ function _add_build_target(makefile, target, targetflags, outputdir) -- in these cases, the targetfile rule is not created if target:targetfile() == "./" .. targetname then makefile:printf("%s:", targetname) + if precmds_label then + makefile:printf(" %s", precmds_label) + end else makefile:print("%s: %s", targetname, targetfile) makefile:printf("%s:", targetfile) end + if precmds_label then + makefile:printf(" %s", precmds_label) + end -- make dependence for the dependent targets for _, depname in ipairs(target:get("deps")) do @@ -442,6 +471,11 @@ function _add_build_target(makefile, target, targetflags, outputdir) makefile:print("\t@echo linking.$(mode) %s", path.filename(targetfile)) _add_create_directory(makefile, path.directory(targetfile)) makefile:writef("\t$(VV)%s\n", command) + + -- add custom commands after building target + _add_build_target_custom_commands_after(makefile, target, outputdir) + + -- end makefile:print("") -- build source batches @@ -450,7 +484,7 @@ function _add_build_target(makefile, target, targetflags, outputdir) if sourcekind then -- compile source files to single object at once local sourceflags = targetflags[target:name() .. '_' .. sourcekind:upper()] - _add_build_objects(makefile, target, sourcekind, sourcebatch, sourceflags, outputdir) + _add_build_objects(makefile, target, sourcekind, sourcebatch, sourceflags, outputdir, precmds_label) end end end |
