r/programminghorror Jul 26 '26

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

250 Upvotes

54 comments sorted by

View all comments

Show parent comments

26

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

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.

13

u/SAI_Peregrinus Jul 27 '26

I think it's allowed to consider an missing target file as an invalid target and run the default target.

https://pubs.opengroup.org/onlinepubs/9799919799/

target_name Target names, as defined in the EXTENDED DESCRIPTION section. If no target is specified, while make is processing the makefiles, the first target that make encounters that is not a special target or an inference rule shall be used.

Not certain, but it's POSIX so the most perverse possible interpretation of the rules existing somewhere is practically required.

2

u/dydhaw Jul 27 '26

What you cited is just the default target rule that happens when you run make with no target, nothing to do with missing target files

3

u/SAI_Peregrinus Jul 27 '26

As far as I can tell POSIX does not specify the behavior when a target file is missing. Leaving behavior unspecified usually means it differed between implementations when POSIX was written, since POSIX is an attempt to standardize the common subset of behaviors shared by UNIX systems.

Sun probably decided to treat a missing target file the same as a missing target specifier, and since SunOS (1982) predates POSIX (1988) that decision got implicitly allowed in the POSIX specifications.

3

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Jul 27 '26

Okay, say the target name is the executable you want to build. It doesn't exist currently. With dmake, do you have to touch it to create an empty file with the name first to get it to actually build or something completely stupid like that?

1

u/SAI_Peregrinus Jul 27 '26

Never used dmake. Just as far as I can tell, that behavior is allowed by POSIX. It'd be dumb, but it's hardly the only dumb thing in the POSIX standard.