user1883212
user1883212

Reputation: 7859

Are there any good reasons in using a makefile?

In C++ I can achieve the same results by using a shell script where I write all the compilation instructions. So my question is:

Are there any good reasons in using a makefile?

Do you have any examples to demonstrate this?

Upvotes: 2

Views: 183

Answers (4)

Carl
Carl

Reputation: 44458

Let's say you do write a shell script. It will work and you will be happy. You will keep using it every chance you get. You will add parameters to it to allow you to specify options. You will also notice that it re-compiles everything, all the time. So you will then try and make it smarter so it only re-compiles the files that have changed. What you will be doing, in effect, is writing your own make system.

That's fine as long as you had a good reason to do it. For example: Existing make solutions don't do X well, so you wrote one to solve that problem.

You, however, don't have a problem that cannot be solved by an existing make system (or at least, it sounds like you don't :) ). The problem you're trying to solve has already been solved. Just read up and use the solution - a make file :)

So, to answer your question, yes, there are a lot - most of which you won't be aware of until you need the functionality. When you do, you will be grateful it already does what you want.

It's the same logic you apply to using libraries in code.

Upvotes: 1

hetepeperfan
hetepeperfan

Reputation: 4411

You might want to take a look on autotools. The will make a Makefile for you while they can help with code portebility as well. However, you have to make some relatively simple template files that the auto tools will use to construct configure file and a end user can run ./configure [options]; make. They provide many features to your makefile that a end user might expect. For a good introduction see : http://www.freesoftwaremagazine.com/articles/brief_introduction_to_gnu_autotools

Upvotes: 1

Ed Heal
Ed Heal

Reputation: 60007

  1. Wear and tear on the keyboard.
  2. Preventing it taking ages to compile everything
  3. Easier to change between compiling for debugging and production

As to examples - See most GNU projects wrote in C/C++

Upvotes: 1

Code-Apprentice
Code-Apprentice

Reputation: 83537

One of the main reasons to use a makefile is that it will recompile only the source files which have changed since the last time you built your project. Writing a shell script to do this will take much more work than writing the makefile.

Upvotes: 12

Related Questions