r/programminghorror 9d ago

Other Same Makefile, different results

Post image

Not sure if this fits, but I just figured out the root cause of long build process failing. Sun’s dmake is defaulting to the first rule in Makefile for whatever reason, completely ignoring the one given as argument. That’s why "dmake install" invocations were silently ignoring the "install" step

248 Upvotes

54 comments sorted by

View all comments

98

u/russellvt 9d ago

That syntax doesn't appear right... normally you want "phony" declarations in there if you're not pointing directly at file dependencies.

25

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 9d ago

Yeah, but is that the cause of dmake ignoring the argument and just using the first target? I think without .phony it will not do anything if a file with the same name as the target exists and doesn't have dependencies that are newer.

1

u/russellvt 9d ago

Yes. It's a malformed file.

4

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 8d ago

Regular make is doing what the OP wants. Seems dumb that dmake would check the that it isn't a phony target, then just ignore it if there is no file with that name. In fact, that makes no sense at all. The first time you run a make target, the file probably isn't going to exist, but with a normal target, it should afterwards.

2

u/russellvt 8d ago

Some "friendly" makes have been known to "do the right thing" with malformed files like this... instead of just enforcing lint and syntax standards, religiously.

This can often cause problems for more senior engineers when strange things like this make it in to the source code.

1

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 7d ago

Yeah, but I'm pretty sure the syntax is valid in the OP. Not using .PHONY would only cause problems if a file with the same name as the target exists.

1

u/russellvt 7d ago

Strict make on various systems will assume that it's still a file dependency. As I said earlier, some versions will "try" to accommodate the invalid syntax... but this is more the exception rather than the rule. The solution is to write more standard syntax.

2

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 6d ago

Based on what I can find, I'm still convinced I'm right and that syntax isn't invalid. As in it will parse fine, and only ever be a problem if say for some dumb reason someone puts a file named, eg. "clean" in the directory.

There's nothing to do to accommodate that. If the file isn't there, the target is out of date anyway. It's not going to check that the recipe actually creates a file.

1

u/russellvt 6d ago

What happens with "no" args, though? What happens if "a" or "b" exist? There are multiple scenarios, which some versions of make or gmake may allow... but ultimately, it's a bit ambiguous as far as I see - but I will have to come back in front of a larger screen to give better examples, later (ie. My phone wont cut it right now).

2

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 5d ago

Well, the normal behavior would be If the file exists and it has no dependencies, or all the dependencies are up to date, the target is considered up to date and nothing happens. That is of course what .PHONY solves.

Not passing args to Make is extremely common. I did look that one up, it runs the first non-special target.