Live data from Hacker News

Using Make – writing less Makefile

text.causal.agency

41–50 of 200 posts

Re: Using Make – writing less Makefile

#41
post #8

With gnu make you don't even need OBJs for a simple directory in which all the .c files are compiled: .SECONDEXPANSION foo: $$(patsubst %.c,%.o,$$(wildcard *.c)) $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ Admittedly you can end up with short, very general Makefiles that look like they were a Prolog program written in TECO. But the advantage is that they are general so don't need to be fiddled with as your project grows. I m…

I admittedly don't have a ton of experience with make, but what's the point of doing this vs just throwing the compile commands in a shell script?

Re: Using Make – writing less Makefile

#42
post #8

With gnu make you don't even need OBJs for a simple directory in which all the .c files are compiled: .SECONDEXPANSION foo: $$(patsubst %.c,%.o,$$(wildcard *.c)) $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ Admittedly you can end up with short, very general Makefiles that look like they were a Prolog program written in TECO. But the advantage is that they are general so don't need to be fiddled with as your project grows. I m…

I admittedly don't have a ton of experience with make, but what's the point of doing this vs just throwing the compile commands in a shell script?

The biggest practical difference is that make can test to see if a file needs to be rebuilt before proceeding.

Re: Using Make – writing less Makefile

#43
Make is fantastic. I’m using it to rebuild and run containers in my development environment, and to build a full repository of RPM packages (that my project needs and which CentOS Stream lacks). I suppose that if javascript tooling was more amenable to process one file at a time, I could do parallel transpiling and bundling of a hefty frontend with make as well.

I also use its metaprogramming and late evaluation capabilities a lot, heavily inspired by the tricks Buildroot is doing.

If you are mindful of its restrictions (it works with “words” separated by spaces, thus paths with spaces in them are a problem unfixable without severely breaking backward compatibility; and your targets need to be expressible as files with meaningful modification timestamps), it’s a very powerful tool. It deserves more appreciation.

Re: Using Make – writing less Makefile

#44
post #25

Earlier quoted context omitted.

Maybe other people do not use the same setup as you do.

That much is obvious given that a vanilla phone setup has no trouble with even 90-character lines. Not my business to stop anyone making things hard on themselves, though, so good luck you all! (do we have anyone who reads HN over a morse clacker?)

I have vision problems, I increase zoom a lot in desktop and mobile.

What do you have against people different than youself?

Re: Using Make – writing less Makefile

#45
post #8

With gnu make you don't even need OBJs for a simple directory in which all the .c files are compiled: .SECONDEXPANSION foo: $$(patsubst %.c,%.o,$$(wildcard *.c)) $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ Admittedly you can end up with short, very general Makefiles that look like they were a Prolog program written in TECO. But the advantage is that they are general so don't need to be fiddled with as your project grows. I m…

I admittedly don't have a ton of experience with make, but what's the point of doing this vs just throwing the compile commands in a shell script?

Make will automatically do all the steps, and stop if any one fails. Of course you van do manually, but is much more work.

Re: Using Make – writing less Makefile

#48

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.

Why would you want that? In decades of programming in very varied environments I have never compiled any software project otherwise than by using globbing, so that I have never needed to waste time to write the name of any source file in a Makefile. I have never seen any reason to do otherwise. For instance, using special compilation flags for a certain source file, different from the others, is something that I cons…

Globbing means that the directory has to be scanned on every build

Once you start getting to multiple directories and recursive scans, the build time begins to grow enormously and usually unexpectedly.

Not a problem at all for small or even medium size projects on a fast machine.

But once you start building very large projects with multiple sub-projects, it generally slows the machine to a crawl on every build.

Re: Using Make – writing less Makefile

#49
post #36

Earlier quoted context omitted.

Using these and other similar features of GNU make it is possible to write a generic Makefile that works for any software project. It appears that almost nobody reads the manual of GNU make, despite the fact that it is extremely instructive. I have read the GNU make manual once, about 25 years ago. Then I have written a set of small Makefiles that I have used in all my software projects forever, until now, with only…

I think you’re overstating the ease of use of make. How does one discover dependencies in a cross platform way with Make without writing the logic themselves to stay up to date with platform changes? Or picking up configuration options from dependencies. How does one make use of Ninja with make? Or discover changes to sdk paths for new platforms? You end up having to duplicate that logic across every repo that needs…

Discovering the dependencies depends on the compilers, not on the platform.

I have stopped using MSVC many years ago, so I do not know how it handles dependencies, but with gcc or clang that works regardless of platform, with compiler-specific options.

Moreover, software for one platform can be built on another platform. What matters is only the platform used for building, where the compilers are hosted, not the target platform for the built software.

In general, I extract all platform specific definitions, like the names of the compilers and their command-line options in platform-specific Makefiles, which include a generic Makefile with platform-independent definitions, rules and make targets. Any platform-specific details, like SDK paths, are encapsulated in the definitions of certain "make" variables.

While I have not needed to update the platform-independent generic Makefile for decades, the platform-dependent sections need updates from time to time, but that is not done for every software project, but perhaps once per year or more seldom, when significant new compiler versions, standard libraries or other new software tools become available.

I have not seen yet any reason for using Ninja. Perhaps it may be faster when building something like chrome, but because chrome is likely to be the slowest-compiling software project known to mankind, it is hard to tell how much is gained by Ninja. For software projects of more typical sizes I have not seen noticeable advantages of Ninja. Traditional make can keep all the cores of a CPU 100% busy, so there is no way any other building system can be appreciably faster. There are some very bad Makefiles that are intrinsically slow, but that is a problem of those Makefiles, not of "make" in general.

Using a minimum project-specific Makefile section can only simplify debugging, not making it difficult.

I have never seen any evidence for the claim that cmake scales better. On the contrary, at least in all the open-source software projects that I have ever seen cmake is a major source of bugs in the building process that nobody knows how to fix. (i.e. after some software updates cmake fails to find files that exist, presumably due to some errors in the cmakelists that appear to be arcane enough that they are hard to find) I have never seen in projects that use traditional make such errors that are so frequent in all the projects that use cmake.

I have a lot of experience in building software projects, because for many decades, with the exception of a few professional programs without alternatives, I have been using only programs that I compile from sources. Most projects have very bad Makefiles, which are very hard to maintain, i.e. to change when files are added, deleted, moved or renamed, but at least they build the software projects reliably. Whenever cmake is used, building a new version is always an adventure with unpredictable outcome.

Re: Using Make – writing less Makefile

#50
post #17

I like the man page format each post has on this website. A little hard to read, but very unique.

This is supposed to be functional, not art work. Make it legible; easy to digest. I guess it's fitting for a tool (make) that is also unergonomic by today's standards.

Typography isn’t set. It _is_ about legibility and therefore proper typography _is_ functional.

This site simply isn’t as legible as it could be. I am not suggesting it needs to be “pretty”. A monospaced Markdown file would be more legible.

Post reply on HN