Live data from Hacker News

Make for hipsters

mattandre.ws

31–40 of 200 posts

Re: Make for hipsters

#31

The single biggest piece of advice I can give for Make is to make sure your text editor uses real tabs in Makefiles. My personal preference for everything is spaces (mostly a habit learned from Python's PEP 8), but Make doesn't honour spaces for indentation - only tabs. Despite being an obvious usability hole, this has never been fixed. Exacerbating the issue is the poor error message given upon encountering a space-…

> Despite being an obvious usability hole, this has never been fixed.

Well, which implementation of make should be fixed? The thing about these truly ubiquitous nix tools is that eventually people discover that there are unixes other than Linux.

…that said, a quick google found that this is* fixed in GNU make; check the docs for .RECIPEPREFIX here: https://www.gnu.org/software/make/manual/html_node/Special-V...

Re: Make for hipsters

#32

Earlier quoted context omitted.

For anyone who's curious: you can use a ".PHONY" target to force targets to be rebuilt (i.e. that they don't correspond to real files). All dependencies of the .PHONY pseudo-target will be rebuilt unconditionally when encountered. Typically, "all", "clean", "install", etc. will all be phony targets as the goal isn't to literally make a file called "all". The syntax is simple: .PHONY: all clean install marks "all", "c…

> All dependencies of the .PHONY pseudo-target will be rebuilt unconditionally when encountered. To be clear, they will rebuilt only if they are not already up to date relative to their own dependencies, right?

yes.

Phony is only about making sure that 'all' is seen as target, not as file or folder

Re: Make for hipsters

#33
post #16

Earlier quoted context omitted.

I suppose so. But there are always many tools for everything. And everyone can select his favorite.

The problem is if you want support (even commercial help) you'll need to follow some kind of prevailing trend. If I've got a system with grunt or gulp and I need help, I can probably find a local web developer. I'm not so sure if I can find someone who's an expert in Makefiles at the moment.

if your devs can't handle learning basic make, all is lost.

Re: Make for hipsters

#34
post #10

Do so many people who go on this site not know how to make makefiles? Also why is it for hipsters? Or is the article for hipsters? Why does the author call his own published notes factually inaccurate? Why is it hacky to use a makefile? Is this all a big ruse?

I dunno. Maybe it's a reaction to the myriad build tools developed for Javascript recently. Could they have been done with makefiles instead?

That was Java all over again.

- you've got dependencies on some basic Unix commands (cp, rm etc.) in your tasks, so better rewrite that all to use your cross-platform language's facilities.

- XML, erm, no, JSON, shall be your only file format.

Re: Make for hipsters

#35
One really neat thing about make: If you include other makefiles then before including them make checks if there are prerequisites of these files and rebuilds them as needed. One can use this to automatically generate header dependencies of translation units for C/C++ projects. Some of the relevant lines in one of my Makefiles:

     include ${DEPENDS}
     
     ${DEPDIR}/%.d: ${SRCDIR}/%.${SRCEXT}
     	@mkdir -p ${shell dirname $@} ; \
     	$(CC) -MM ${INCLUDE} -mmcu='${AVRTARGET}' $> $@
 
If any file in the "include" line needs updating then it is generated by gcc and included in the same make run. I didn't find a good documentation about this feature and I discovered this with make's pretty verbose -d option. Previously I did something like this using multiple makefiles and recursively calling make which is generally frowned upon (for valid reasons).

Re: Make for hipsters

#36
post #8

This introduction neglects to mention that Makefile rules are primarily rules to derive files (usually from other files). Make will not re-run a rule when the target (file) generated by the rule is already up to date. From this perspective, a well structured Makefile can be thought of as a pipeline/graph of functions, that derive values (files) from previously known values (files). Expressing a build process in this…

For anyone who's curious: you can use a ".PHONY" target to force targets to be rebuilt (i.e. that they don't correspond to real files). All dependencies of the .PHONY pseudo-target will be rebuilt unconditionally when encountered. Typically, "all", "clean", "install", etc. will all be phony targets as the goal isn't to literally make a file called "all". The syntax is simple: .PHONY: all clean install marks "all", "c…

I prefer to put the phony rule right before the actual rules, it's better for understanding:

    .PHONY: all
    all: ...

    .PHONY: clean
    clean: ...

Re: Make for hipsters

#37
post #25
post #10

Do so many people who go on this site not know how to make makefiles? Also why is it for hipsters? Or is the article for hipsters? Why does the author call his own published notes factually inaccurate? Why is it hacky to use a makefile? Is this all a big ruse?

(1) I imagine quite a lot of this site's visitors use different platforms/toolchains, and haven't encountered make. (2) Its a fun/joke title, the article is for "hipsters", the kind who know the latest fancy build tools but not make, I suppose. I wouldn't take it too seriously. (3) It's a disclaimer against people attacking him for errors, and also to warn people that he's not an expert. Again, this is written in a l…

If not a ruse, this is a dumb post that discredits itself and calls makefiles hacky, not noticing that they are used by many people for most native programming on most (unix type) platforms.

I'm feeling cranky every day, but just today this post is at the top of hacker news, and that's frustrating.

Re: Make for hipsters

#38

> You need to create a makefile to tell make what to do. Nope. You can say "make hello" and have make automatically use its default rules - which can be configured - to e.g. compile hello.c into a hello executable. I use this frequently.

I hate implicit rules. Also the %: %.c implicit rule is especially idiotic, it causes to check this rule for every single file, so if you have hello.h, then it will search for hello.h.c too.

Re: Make for hipsters

#40
post #8

This introduction neglects to mention that Makefile rules are primarily rules to derive files (usually from other files). Make will not re-run a rule when the target (file) generated by the rule is already up to date. From this perspective, a well structured Makefile can be thought of as a pipeline/graph of functions, that derive values (files) from previously known values (files). Expressing a build process in this…

Yes, not mentioning .PHONY encourages people to do things incorrectly and not inline with how make actually works.
Post reply on HN