Live data from Hacker News

Makefiles – Best Practices

danyspin97.org

121–127 of 127 posts

Re: Makefiles – Best Practices

#121
post #120
post #117

Earlier quoted context omitted.

Can you humor a dumb question and tell me how you got the manual in your terminal? I'm on Debian, and when I `man make`, I just get a typical GNU CLI util manpage that's five paragraphs of intro and a line-by-line explanation of each command line option. Same for `info make`.

Have you installed the make-info ( https://packages.debian.org/jessie/make-doc ) package? It adds info documentation as well as pdf and html formats.

Brilliant, didn't even realize it was a separate package. Thanks!

Re: Makefiles – Best Practices

#122

Earlier quoted context omitted.

Because CFLAGS may not be set in the environment, resulting in concatenation to an undefined variable error.

No such error occurs. $ cat Makefile FOO += foo all: ; @echo $(FOO) $ make foo

My bad, I felt like I've seen that error pop up before in my Makefiles, but I should have double-checked before commenting.

Re: Makefiles – Best Practices

#123

Earlier quoted context omitted.

Because CFLAGS may not be set in the environment, resulting in concatenation to an undefined variable error.

There's no such thing as an undefined variable in Make. The variable expands to text. Variables which are not defined by definition expand to no text.

My bad, I felt like I've seen that error pop up before in my Makefiles, but I should have double-checked before commenting.

Re: Makefiles – Best Practices

#124
post #66

I really wish blog posts like this would at least mention that they are going to use GNUMake extensions. There's some good stuff in here, but just calling it "make" and leaving it at that is misleading. It's not going to work on my minimal (non-GNU) Linux boxes that mostly run NetBSD make (bmake in many distros) or busybox style tools. I know a very small minority of people do something like that (or maybe not, what…

I doubt most people even know that there are different versions. (I didn't!)

Yah, this is probably true. Another good reason to mention it if you're writing a blog post! :)

Re: Makefiles – Best Practices

#125
post #39

I really wish blog posts like this would at least mention that they are going to use GNUMake extensions. There's some good stuff in here, but just calling it "make" and leaving it at that is misleading. It's not going to work on my minimal (non-GNU) Linux boxes that mostly run NetBSD make (bmake in many distros) or busybox style tools. I know a very small minority of people do something like that (or maybe not, what…

/ # make --version GNU Make 4.2.1 Built for x86_64-alpine-linux-musl Copyright (C) 1988-2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

Good to know; thanks! I'm kind of suprised; given how tiny Alpine is supposed to be and how they're muscl based I assumed they would have taken that philosophy into the userspace tools and used busybox or something. Not that I really know anything about Alpine except that it's nice when you just want something small.

Re: Makefiles – Best Practices

#126
post #110

Earlier quoted context omitted.

Its not actually all that hard to make well-parallelized makefiles, provided you follow a few basic rules. - Each build step has a unique artifact. - That artifact is visible to Make as a file in the filesystem. - That artifact is named $@ in the rule's recipe. - Every time the recipe is executed, $@ is updated on success. - If the recipe fails, it must return nonzero to Make. - All of the dependencies of the artifac…

That's a nice set of rules, although I don't think they're all easy to follow or verify that 1000 lines of Make is following. I considered 3 main use cases, and I wrote Makefiles from scratch for all of them. Make works to an extent for each case, but I still have problems. 1. Building mixed Python/C app bundles [1] 2. Building my website [2]. Notably people actually do complain about Jekyll build speed, to the point…

> A pet peeve of mind is having to "make clean" between a debug and a release build, and nearly all usages of Make have that problem, e.g. Python and bash's build system. You could say they are violating your rules because each artifact doesn't have a unique name on the file system (i.e. debug and release versions of the same object file.)

There are at least two ways that this problem can be addressed. One is to support out-of-tree builds, one side directory per configuration. Builds based on the autotools do this by default.

The other is to use a separate build directory per configuration within the build. My current project uses local in-tree directories named .host-release, .host-debug (including asan), .host-tsan, .cross-release, and .cross-debug. All of them are built in parallel with a single invocation of Make, and I use target-scoped variables to control the various toolchain options.

The engineer's incremental work factor to add another build configuration isn't quite constant time, since each top-level target needs to opt into each build configuration that is relevant for that target.

> I hit the multiple outputs problem

I wouldn't really classify that as a problem in GNU Make, as long as you can specify the rule as a pattern rule.

I hear you on the testing problem. Make certainly behaves as if the Makefile's correctness isn't decidable. Even if you levied the requirement that a Makefile's decidability was predicated on the recipes being well-behaved, I'm not sure that the correctness is decidable.

Re: Makefiles – Best Practices

#127
post #7

CFLAGS := ${CFLAGS} CFLAGS += -ansi -std=99 What's the point of the first line? Why not just: CFLAGS += -ansi -std=99

My guess is that the left hand side is a make variable while the right hand side is an environment variable. However the make manual says “Every environment variable that make sees when it starts up is transformed into a make variable with the same name and value.“ so maybe it’s not necessary?...

This reminds me why I stopped visiting HN. People down vote you for trying to help! Screw whoever asshole that downvoted me even though I prefixed my answer with “My GUESS is...”.
Post reply on HN