Learn C the Hard Way – Making and making and GNUmaking and throwing things across the room

Ex 2 of Learn C the Hard Way introduces how the makefile works. I’ve tried and failed to use this before, when trying to make an Arch package, so it’ll be good to work out how to do that. I’m not looking forward to failure, of course. This blog is basically a lie.

emacs Makefile

and I created the file as I was told to. My ex1 still has


in it, so it didn’t throw up any warnings, but when I commented that line out, it did. So my computer’s now in much the same state as what Zed was using to write, and I’m not getting my compiler screaming where his wasn’t. I did have to read down his page to a note saying that he had an unfixed ex1, but I was pretty sure that’s what had happened. I’d put that note up at the top.

If I have two tabs instead of none, I don’t have any errors thrown. This is unlike Python’s unexpected indent. I wonder why it needs an indent at all, but I’m going to go with BECAUSE and ignore that for the moment.

I had to go looking for more information for extra credit. According to
‘make’ on its own will execute the first command in the file. So, my first attempt at putting all: ex1 into the file was after clean: and it didn’t work. My second attempt had line breaks, which was a guess at how to separate functions. I then went without separating functions at all. -o is a flag that should take one file name, and then the next bit of info should be separate by default. And whaddyaknow, this works. I have, readers may have noticed, a way of making things difficult for myself, mostly by assuming they will be more complicated than they actually are.

I’ve decided I want to add -d to the makefile flags, if that does what I think it will. I like debugging info.
-o seems to mean we’ve got an old file, which is… odd. So it must be that the internal makefile syntax and the syntax we use to call it are different. It sort of makes sense.

man make

has a typo in it.

$ man cc

– no manual entry for cc. Yerwhat? I assume cc is the c compiler…

$ which cc

– /usr/bin/cc . So I have it. I just don’t have a man page.

$ man -k '^cc$'

– nothing appropriate. This isn’t about an adult filter, either. This man page isn’t in my distro. So, over to


to get my fix. And aaaah. ‘gcc’ exists.

$ man gcc

– Result! And wow, that’s complicated. I mean, that’s a whole set of stuff that I could do, with huge options lists I can’t (yet) hope to comprehend. But here I am failing in public, so let’s look at the last bit of the Extra Credit. I don’t know what ‘better’ means in this case, for a future case of what a Makefile does.

Online research – http://mrbook.org/blog/tutorials/make/ is helpful. It’s coming from the angle of people who can code and want to automate it, but it’s still explaining things simply. all: is a default. Anything after the colon is dependencies. I think this should be expanded and explained more. I’m not getting it from Zed’s explanation, and a couple of sentences there would have made the first part of the Extra Credit much easier to understand. I think I’m learning too far ahead of things, though. I went back and stopped ex1 from being a dependency of all: and that’s where I’m leaving it. I’ve cruised through a few examples, but there’s too much to hold in my head to stay here. I need to move on and see how it works.