@@ -1165,9 +1165,12 @@ function m.linkTarget(cfg)
11651165 end
11661166 end
11671167
1168+ local postbuildStamp = nil
11681169 if hasPostBuild then
1169- m .buildPostBuildEvents (cfg , targetPath )
1170+ postbuildStamp = m .buildPostBuildEvents (cfg , targetPath )
11701171 end
1172+
1173+ cfg ._postbuildStamp = postbuildStamp
11711174end
11721175
11731176function m .buildPreBuildEvents (cfg )
@@ -1178,30 +1181,33 @@ function m.buildPreBuildEvents(cfg)
11781181 return nil
11791182 end
11801183
1181- local targetPath = path .getrelative (cfg .workspace .location , cfg .buildtarget .directory ) .. " /" .. cfg .buildtarget .name
1182- local prebuildTarget = path .getrelative (cfg .workspace .location , cfg .buildtarget .directory ) .. " /" .. cfg .project .name .. " .prebuild"
1184+ local stampFile = path .getrelative (cfg .workspace .location , cfg .buildtarget .directory ) .. " /" .. cfg .project .name .. " .prebuild.stamp"
1185+
1186+ -- Determine touch command based on target system, not host system
1187+ local shell = _OPTIONS .shell or iif (cfg .system == p .WINDOWS , " cmd" , " posix" )
1188+ local touchCmd = iif (shell == " cmd" , " type nul > \" " .. stampFile .. " \" " , " touch \" " .. stampFile .. " \" " )
11831189
11841190 local implicitDeps = " "
11851191 if cfg ._dependsOnTarget then
11861192 implicitDeps = " | " .. cfg ._dependsOnTarget
11871193 end
11881194
11891195 if hasMessage and not hasCommands then
1190- _p (" build %s: prebuildmessage%s" , prebuildTarget , implicitDeps )
1191- _p (" prebuildmessage = \" %s\" " , cfg .prebuildmessage )
1196+ _p (" build %s: prebuildmessage%s" , stampFile , implicitDeps )
1197+ _p (" prebuildmessage = \" %s && %s \" " , cfg .prebuildmessage , touchCmd )
11921198 elseif hasCommands and not hasMessage then
11931199 local commands = os .translateCommandsAndPaths (cfg .prebuildcommands , cfg .project .basedir , cfg .project .location )
1194- local cmdStr = table.concat (commands , " && " )
1195- _p (" build %s: prebuild%s" , prebuildTarget , implicitDeps )
1200+ local cmdStr = table.concat (commands , " && " ) .. " && " .. touchCmd
1201+ _p (" build %s: prebuild%s" , stampFile , implicitDeps )
11961202 _p (" prebuildcommands = %s" , cmdStr )
11971203 else
11981204 local commands = os .translateCommandsAndPaths (cfg .prebuildcommands , cfg .project .basedir , cfg .project .location )
1199- local cmdStr = " echo \" " .. cfg .prebuildmessage .. " \" && " .. table.concat (commands , " && " )
1200- _p (" build %s: prebuild%s" , prebuildTarget , implicitDeps )
1205+ local cmdStr = " echo \" " .. cfg .prebuildmessage .. " \" && " .. table.concat (commands , " && " ) .. " && " .. touchCmd
1206+ _p (" build %s: prebuild%s" , stampFile , implicitDeps )
12011207 _p (" prebuildcommands = %s" , cmdStr )
12021208 end
12031209
1204- return prebuildTarget
1210+ return stampFile
12051211end
12061212
12071213function m .buildPreLinkEvents (cfg , objectFiles )
@@ -1212,30 +1218,33 @@ function m.buildPreLinkEvents(cfg, objectFiles)
12121218 return nil
12131219 end
12141220
1215- local targetPath = path .getrelative (cfg .workspace .location , cfg .buildtarget .directory ) .. " /" .. cfg .buildtarget .name
1216- local prelinkTarget = path .getrelative (cfg .workspace .location , cfg .buildtarget .directory ) .. " /" .. cfg .project .name .. " .prelinkevents"
1221+ local stampFile = path .getrelative (cfg .workspace .location , cfg .buildtarget .directory ) .. " /" .. cfg .project .name .. " .prelink.stamp"
1222+
1223+ -- Determine touch command based on target system, not host system
1224+ local shell = _OPTIONS .shell or iif (cfg .system == p .WINDOWS , " cmd" , " posix" )
1225+ local touchCmd = iif (shell == " cmd" , " type nul > \" " .. stampFile .. " \" " , " touch \" " .. stampFile .. " \" " )
12171226
12181227 local objDeps = " "
12191228 if objectFiles and # objectFiles > 0 then
12201229 objDeps = " " .. table.concat (objectFiles , " " )
12211230 end
12221231
12231232 if hasMessage and not hasCommands then
1224- _p (" build %s: prelinkmessage%s" , prelinkTarget , objDeps )
1225- _p (" prelinkmessage = \" %s\" " , cfg .prelinkmessage )
1233+ _p (" build %s: prelinkmessage%s" , stampFile , objDeps )
1234+ _p (" prelinkmessage = \" %s && %s \" " , cfg .prelinkmessage , touchCmd )
12261235 elseif hasCommands and not hasMessage then
12271236 local commands = os .translateCommandsAndPaths (cfg .prelinkcommands , cfg .project .basedir , cfg .project .location )
1228- local cmdStr = table.concat (commands , " && " )
1229- _p (" build %s: prelink%s" , prelinkTarget , objDeps )
1237+ local cmdStr = table.concat (commands , " && " ) .. " && " .. touchCmd
1238+ _p (" build %s: prelink%s" , stampFile , objDeps )
12301239 _p (" prelinkcommands = %s" , cmdStr )
12311240 else
12321241 local commands = os .translateCommandsAndPaths (cfg .prelinkcommands , cfg .project .basedir , cfg .project .location )
1233- local cmdStr = " echo \" " .. cfg .prelinkmessage .. " \" && " .. table.concat (commands , " && " )
1234- _p (" build %s: prelink%s" , prelinkTarget , objDeps )
1242+ local cmdStr = " echo \" " .. cfg .prelinkmessage .. " \" && " .. table.concat (commands , " && " ) .. " && " .. touchCmd
1243+ _p (" build %s: prelink%s" , stampFile , objDeps )
12351244 _p (" prelinkcommands = %s" , cmdStr )
12361245 end
12371246
1238- return prelinkTarget
1247+ return stampFile
12391248end
12401249
12411250function m .buildPostBuildEvents (cfg , targetPath )
@@ -1246,22 +1255,28 @@ function m.buildPostBuildEvents(cfg, targetPath)
12461255 return
12471256 end
12481257
1249- local postbuildPhony = path .getrelative (cfg .workspace .location , cfg .buildtarget .directory ) .. " /" .. cfg .project .name .. " .postbuild"
1258+ local stampFile = path .getrelative (cfg .workspace .location , cfg .buildtarget .directory ) .. " /" .. cfg .project .name .. " .postbuild.stamp"
1259+
1260+ -- Determine touch command based on target system, not host system
1261+ local shell = _OPTIONS .shell or iif (cfg .system == p .WINDOWS , " cmd" , " posix" )
1262+ local touchCmd = iif (shell == " cmd" , " type nul > \" " .. stampFile .. " \" " , " touch \" " .. stampFile .. " \" " )
12501263
12511264 if hasMessage and not hasCommands then
1252- _p (" build %s: postbuildmessage | %s" , postbuildPhony , targetPath )
1253- _p (" postbuildmessage = \" %s\" " , cfg .postbuildmessage )
1265+ _p (" build %s: postbuildmessage | %s" , stampFile , targetPath )
1266+ _p (" postbuildmessage = \" %s && %s \" " , cfg .postbuildmessage , touchCmd )
12541267 elseif hasCommands and not hasMessage then
12551268 local commands = os .translateCommandsAndPaths (cfg .postbuildcommands , cfg .project .basedir , cfg .project .location )
1256- local cmdStr = table.concat (commands , " && " )
1257- _p (" build %s: postbuild | %s" , postbuildPhony , targetPath )
1269+ local cmdStr = table.concat (commands , " && " ) .. " && " .. touchCmd
1270+ _p (" build %s: postbuild | %s" , stampFile , targetPath )
12581271 _p (" postbuildcommands = %s" , cmdStr )
12591272 else
12601273 local commands = os .translateCommandsAndPaths (cfg .postbuildcommands , cfg .project .basedir , cfg .project .location )
1261- local cmdStr = " echo \" " .. cfg .postbuildmessage .. " \" && " .. table.concat (commands , " && " )
1262- _p (" build %s: postbuild | %s" , postbuildPhony , targetPath )
1274+ local cmdStr = " echo \" " .. cfg .postbuildmessage .. " \" && " .. table.concat (commands , " && " ) .. " && " .. touchCmd
1275+ _p (" build %s: postbuild | %s" , stampFile , targetPath )
12631276 _p (" postbuildcommands = %s" , cmdStr )
12641277 end
1278+
1279+ return stampFile
12651280end
12661281
12671282function m .buildTargets (prj )
@@ -1272,10 +1287,8 @@ function m.buildTargets(prj)
12721287 local targetPath = path .getrelative (cfg .workspace .location , cfg .buildtarget .directory ) .. " /" .. cfg .buildtarget .name
12731288 local cfgName = ninja .key (cfg )
12741289
1275- local hasPostBuild = # cfg .postbuildcommands > 0 or cfg .postbuildmessage
1276- if hasPostBuild then
1277- local postbuildTarget = path .getrelative (cfg .workspace .location , cfg .buildtarget .directory ) .. " /" .. cfg .project .name .. " .postbuild"
1278- _p (" build %s: phony %s" , cfgName , postbuildTarget )
1290+ if cfg ._postbuildStamp then
1291+ _p (" build %s: phony %s" , cfgName , cfg ._postbuildStamp )
12791292 else
12801293 _p (" build %s: phony %s" , cfgName , targetPath )
12811294 end
@@ -1290,13 +1303,10 @@ function m.projectPhonies(prj)
12901303
12911304 local firstCfg = project .getfirstconfig (prj )
12921305 if firstCfg then
1293- local targetPath = path .getrelative (firstCfg .workspace .location , firstCfg .buildtarget .directory ) .. " /" .. firstCfg .buildtarget .name
1294-
1295- local hasPostBuild = # firstCfg .postbuildcommands > 0 or firstCfg .postbuildmessage
1296- if hasPostBuild then
1297- local postbuildTarget = path .getrelative (firstCfg .workspace .location , firstCfg .buildtarget .directory ) .. " /" .. firstCfg .project .name .. " .postbuild"
1298- _p (" build %s: phony %s" , prj .name , postbuildTarget )
1306+ if firstCfg ._postbuildStamp then
1307+ _p (" build %s: phony %s" , prj .name , firstCfg ._postbuildStamp )
12991308 else
1309+ local targetPath = path .getrelative (firstCfg .workspace .location , firstCfg .buildtarget .directory ) .. " /" .. firstCfg .buildtarget .name
13001310 _p (" build %s: phony %s" , prj .name , targetPath )
13011311 end
13021312 end
0 commit comments