-1

I've been for long using VIM as my main editor and never touched an IDE since. This works great for most of the programming languages on the market. When it comes to C, though, I still fell limited to simple projects, because writing makefiles is too cumbersome. How do the "Unix as IDE" philosophy deal with makefiles? Is there a tool I'm not aware of that does that particular job from the command line, or is everyone just writing the makefiles themselves?

  • 3
    I'm not sure I understand...in what way does vim fail you when it comes to makefiles? Or are the makefiles themselves what's troubling you? – schaiba Sep 6 '16 at 11:27
  • @schaiba when I used IDEs, I didn't have to write makefiles. As I heard, makefiles are too big and have tons of OS specific options so they're not supposed to be written by hand. What I'm asking is if there is any tool to write those automatically, like an IDE does, without the IDE part - or if I'm mistaken, and writing makefiles manually is actually the proper way. – MaiaVictor Sep 6 '16 at 11:29
  • 3
    People have been using tools to write Makefiles from simpler description for ages. imake, autoconf are two examples, more recently CMake seems to be dominant among those who favor that approach. – AProgrammer Sep 6 '16 at 11:30
7

There are quite a few tools around to generate makefiles. The two most common ones are CMake and Automake; both of these ask you to describe the components of your project and the desired output, and generate makefiles for you.

This is no doubt a matter of opinion, but you'll probably find CMake easier to get to grips with; if you ever need to cross-compile though, you'll end up needing Automake (and Autoconf).

For simple projects, the built-in rules provided with GNU Make can help quite a bit; for example, to build a project consisting of two source files, a.c and b.c, the following Makefile works:

all: a

a: a.o b.o

Running make will figure out that a.c and b.c need to be compiled, and linked to produce a...

(As AProgrammer points out, the built-in rules only go so far, and your makefile needs to specify all the relationships between files, including your project's headers; you'll quickly end up reaching for other tools to help manage dependencies etc.)

  • Simply put, that was the answer I was looking for. Thanks. – MaiaVictor Sep 6 '16 at 11:32
  • ... and that Makefile will not recompile a.o when the b.h it includes is modified; it won't even recompile a.o when a.h which provides its external view is modified, which somewhat defeat the purpose of using make. – AProgrammer Sep 6 '16 at 12:49
  • @AProgrammer I didn't say anything about b.h or a.h; I'm assuming a very simple project here. But the makefile will react to changes to a.c and b.c. – Stephen Kitt Sep 6 '16 at 12:51
  • @AProgrammer my point really is that all you need to do in many cases is describe the relationships between files, without needing to explain how to build the files. – Stephen Kitt Sep 6 '16 at 12:55
  • @StephenKitt, a project so simple that it has no include is in the toy category, not in the simple one. As soon as you don't want to manually manage the list of dependencies, your makefile become more complex. With a little compiler (or external tools) support it's feasible, but the default rules are not adequate far too often to state they can be enough without pointing to the caveats, even when restricting yourself to "simple projects". – AProgrammer Sep 6 '16 at 13:10
1

You are misinformed about Makefiles. Unless you are building something complex, a simple project will call for a simple Makefile, easily maintained in VIM. No need for an IDE. It is true that IDEs love to create horribly complex Makefiles, but that's why you hate IDEs, isn't it?

Makefiles become complex as you ask them to do more complex things, such as adapt to multiple operating systems, or complex code generation schemes. If you have a pile of source files and you need to compile them and link them into an application, you have nothing to fear.

  • I think I am, thank you for sharing your knowledge. – MaiaVictor Sep 7 '16 at 0:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.