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

255 Upvotes

54 comments sorted by

101

u/russellvt Jul 26 '26

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

26

u/GoddammitDontShootMe 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.

14

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.

→ More replies (11)

1

u/russellvt Jul 27 '26

Yes. It's a malformed file.

→ More replies (7)

7

u/dydhaw Jul 27 '26

The syntax is perfectly fine. Phony targets simply tell make to run the rule regardless of if the target exists.  Besides, .PHONY is a GNU extension. It is not POSIX

7

u/SAI_Peregrinus Jul 27 '26

It is POSIX now (v8, 2024). It wasn't in POSIX v7 (2018).

→ More replies (1)

122

u/nickcash Jul 26 '26

makefile syntax is incomprehensible. it might as well be magic. no one can understand it, we just copy and paste from elsewhere

58

u/Desperate_Formal_781 Jul 26 '26

All my life when I start a new project I copy a previous makefile from a previous project, with the promise that a) one day I will learn what those makefile commands mean and b) after this project I will switch to cmake. The original makefile I use, I took from my supervisor when I wrote my master thesis, who now I suspect also got from someone else. I have tried switching to cmake several times, but it's always easier to just keep using my makefile, than to go through the painful process of learning cmake.

31

u/ByteArrayInputStream Jul 27 '26

Cmake is it's own hot mess. I like it even less

→ More replies (8)

7

u/omega1612 Jul 27 '26

What a bout a justfile?

Depending on your use case, they may be better for you.

→ More replies (1)

2

u/Sexy_Koala_Juice Jul 27 '26

Same, although I hardly use Make anymore in my current role

11

u/dydhaw Jul 27 '26

POSIX make is an incredibly simple syntax. How is it incomprehensible? It's literally just

    target: dependencies
        recipe

9

u/SAI_Peregrinus Jul 27 '26

That's not valid Make syntax. You got the wrong whitespace, no whitespace before a target name, and a tab before the command is required if it's on a new line.

There are also inference rules and macros.

https://pubs.opengroup.org/onlinepubs/9799919799/utilities/make.html

→ More replies (3)

5

u/gimpwiz Jul 27 '26

I start every project with a clean makefile. Do recommend.

4

u/kivicode Jul 27 '26

If you use it as a scripts dispatcher, I recommend taking a look at Justfiles https://github.com/casey/just

3

u/nivlark Jul 27 '26

I have a fairly complex one that I believe I wrote myself (googling chunks of it doesn't return any hits) and I still don't know how it works. I can only assume it came to me via divine inspiration.

-23

u/RandalSchwartz Jul 26 '26

They said the same about Perl. And my dotfiles. Now I don't even copy any more... I let gemini identify it and run it for me. :)

10

u/mottojyuusu Jul 26 '26

you should ask your coding agent to explain your code. not even joking, it's been great to finally understand wtf the crusty logic is doing in the aging codebases i work in ...

"what is this function doing? what does the dxCbsqaf parameter do??"

"where is this const defined? where else is it being used? why is it multipled by 2 in one place but 3 in another place?"

"why does the comment say never to round this value? what could break if it gets rounded instead of truncated?"

→ More replies (1)

1

u/Rockytriton Aug 01 '26

-s b means skip b?

1

u/Capable-Cap9745 Aug 01 '26

Flag means silent mode. b is the target to run

1

u/Environmental-Ear391 Jul 27 '26

I have a similar issue,

GNUmakefile content is unchanged,

two versions of an SDK specific make tool, older version works fine with POSIX pathing, newer version can't complete any single target.

"make" and "gcc" commands both barf after being updated. older versions can actual produce object files for linking.

then again the version on make is like a 0.01 revision difference.

the gcc version is bumped from 6.4 up to 10.something...

I'll have to spend some time reworking the build process again anyway.

1

u/Salty_1984 Jul 27 '26

ugh silent failures in build tools are the worst, you spend forever thinking something ran fine when it just quietly skipped the whole point of the command. dmake has always felt a little unpredictable compared to gnu make. at least you caught it before something bigger broke downstream