Live data from Hacker News

Using Make – writing less Makefile

text.causal.agency

141–150 of 200 posts

Re: Using Make – writing less Makefile

#141
post #108

Make is the grilling of the hacker world. You just want to light up some quality lumpwood charcoal and get a nice smokey crust on some steaks, cook up some hamburgers, and crisp up some chicken for your guests over the course of an afternoon… …but oh no there is a constant stream of inquisitive folk coming over, beer in hand, suggesting cool adjustments / hacks / “improvements” to your setup. With grilling it’s actua…

make is very useful. The idea that things depend on each other and are built as a hierarchy is important.

But it is the opposite of beauty, or elegance, or organization.

Honestly all the millions of man months that have gone into writing makefiles should have gone into making make more usable.

for example:

all the implicit rules in this article? Nobody¹ uses them, they should just be explicit.

You shold explicitly distinguish between a target and a file and a directory. don't let them depend on each other helter-skelter.

indent, tabs, spaces. what a mess.

requiring continuation lines and juggling return codes?

macros that break with whitespace?

I could go on, but ugh.

I actually like cmake better than make. Just having IF statements and a flow makes things more understandable. But yeah, you trade one set of problems for another.

look up "modern cmake" and you'll see the nitty-gritty between nice theory and ugly practice.

[1] for practical purposes

Re: Using Make – writing less Makefile

#142
post #32

Earlier quoted context omitted.

Autoconf, that's the thing that spends time making sure that my software can be built on BeOS and A/UX?

I have a vivid memory of autoconf. I set it up best as I could. Someone ran ./configure. It triggered a new run of autoconf that failed because of mismatching autoconf version. Why it triggered a new run? Because of mtime checks. Why did they say it needed to be rerun? Because git doesn't preserve mtime. I guess it's just assumed that everyone distributes their sources as a tarball. I spent many hours trying to figur…

> I spent many hours trying to figure out how to bypass those issues, and I can't remember if I ever succeeded.

Might I suggest “got-restore-mtime” for this, upstream in Debian and Ubuntu already.

Did you really spend hours on this?

Re: Using Make – writing less Makefile

#143

Earlier quoted context omitted.

With all due respect, I don't understand the first part of your comment. Make's core purpose is to execute commands, isn't it? How was it not designed to execute commands?

> Make's core purpose is to execute commands, isn't it? How was it not designed to execute commands? Some people on HN believe that if you use make primarily as a task runner that you're doing it wrong and should use something else. I don't agree. Most users are using multiple aspects of make: as a task runner and as something that handles the dependency graph when building something digital. As a web developer, I us…

What’s the point of using another tool to manage your shell scripts though? Why not just use shell scripts

Re: Using Make – writing less Makefile

#144
post #141
post #108

Make is the grilling of the hacker world. You just want to light up some quality lumpwood charcoal and get a nice smokey crust on some steaks, cook up some hamburgers, and crisp up some chicken for your guests over the course of an afternoon… …but oh no there is a constant stream of inquisitive folk coming over, beer in hand, suggesting cool adjustments / hacks / “improvements” to your setup. With grilling it’s actua…

make is very useful. The idea that things depend on each other and are built as a hierarchy is important. But it is the opposite of beauty, or elegance, or organization. Honestly all the millions of man months that have gone into writing makefiles should have gone into making make more usable. for example: all the implicit rules in this article? Nobody¹ uses them, they should just be explicit. You shold explicitly di…

Apparently the reasoning behind a bunch of Make’s warts is that by the time Stuart Feldman realized the problem, it already had half a dozen users, and, well, he wasn’t gonna go and break it for them!

Re: Using Make – writing less Makefile

#145
post #91

Earlier quoted context omitted.

With all due respect, I don't understand the first part of your comment. Make's core purpose is to execute commands, isn't it? How was it not designed to execute commands?

No, no. Make's principal purpose is to put a set of files into a desired state. It can "make" a particular file by invoking a dependent graph of commands that produce that file from other files. It checks timestamps and only run steps where the resulting files are older than some of the (transitive) source files. You can invoke it by naming a named rule, not a file, but the logic will remain. If this is not what you…

I tell people not to use make if there's no need for a dependency graph.

Just don't.

And do just :-)

Re: Using Make – writing less Makefile

#146
post #142
post #32

Earlier quoted context omitted.

I have a vivid memory of autoconf. I set it up best as I could. Someone ran ./configure. It triggered a new run of autoconf that failed because of mismatching autoconf version. Why it triggered a new run? Because of mtime checks. Why did they say it needed to be rerun? Because git doesn't preserve mtime. I guess it's just assumed that everyone distributes their sources as a tarball. I spent many hours trying to figur…

> I spent many hours trying to figure out how to bypass those issues, and I can't remember if I ever succeeded. Might I suggest “got-restore-mtime” for this, upstream in Debian and Ubuntu already. Did you really spend hours on this?

This?

https://manpages.org/git-restore-mtime

Re: Using Make – writing less Makefile

#147
post #122

Earlier quoted context omitted.

> Any tool/language that wishes to be generally useful in an OS doesn't want to be built by something that is only available much further up the tree like python. This is a non-priority, an unreal use case. I can't build GCC without a functioning C++ compiler and a fairly sophisticated OS environment and that's fine. Real-world use cases for bootstrapping a build environment from rubbing two sticks together are so ex…

Make exists and is used widely and not because everyone's too inept to understand your points. The "assumption-making" build tools are the unicorns that inevitably cannot dominate because they're not generally applicable. The more they assume the more niche they become.

Make is popular because many old projects use it and it comes pre-installed on Linux. It's a cultural thing.

Re: Using Make – writing less Makefile

#148
post #21

Earlier quoted context omitted.

Lists of files are usually used more than once for more than one task. This would only make sense if the only rule that needed the list was that one that builds, no install/uninstall/package/modify/audit/hash/clean/etc, which is never the case. You also don't want to use globbing in place of an explicit list either.

Sure, I'm just pointing out you don't need to type out the C compiler invocation again. FOOOBJS = foo.o bar.o baz.o foo: $(FOOOBJS)

So:

> The example Makefile in its entirety:

           CFLAGS += -Wall -Wextra
           LDLIBS = -lcurses
           OBJS = foo.o bar.o baz.o

           foo: $(OBJS)
                   $(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@

           foo.o bar.o: foo.h

           clean:
                   rm -f $(OBJS) foo
Become:

           CFLAGS += -Wall -Wextra
           LDLIBS = -lcurses
           OBJS = foo.o bar.o baz.o
?

           foo: $(OBJS)

           foo.o bar.o: foo.h

           clean:
                   rm -f $(OBJS) foo

Re: Using Make – writing less Makefile

#149

Earlier quoted context omitted.

Globbing is possible but unwise. You do want a variable with an explicit list of sources, even while trying to make things as automatic and dynamic as possible.

Globbing is how you avoid pointless busy work. If there's a file in the directory that shouldn't be built, it shouldn't be there.

And nothing that shouldn't happen ever does. I guess you also include "." in $PATH, even roots.

Re: Using Make – writing less Makefile

#150
Outside of simple C projects, a Makefile should be just a “here’s how to hold it” reference for the rest of your build system. Shoehorning in all of the build complexity is going to be overwrought, but a good “make dev; make clean; make build; make release” is a very welcome entry point for new or infrequent contributors
Post reply on HN