Jump to content

Makefiles

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
Aereshaa

Aereshaa

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 790 posts
The venerable make utility is one of the oldest source control methods that exists. It allows one to compile a program in one shot, without any redundancies, simply by typing:
$ make
The make looks in the current directory for a file named "makefile". The makefile determines which files are dependent on which others. Based on these relations and whether the files have been modified, make executes shell commands found in the makefile.
The basic parts of a makefile are the targets. Targets take the form:
file: dependency dependency dependency

        commands
The commands would produce file from the dependencies. A makefile usually has target rules in order to let the compiler do as little work as possible.
An example would be:
grep : grep.o regex.o

        gcc grep.o regex.o -o grep

grep.o : grep.c

        gcc -c grep.c -o grep.o

regex.o : regex.c

        gcc -c regex.c -o regex.o
In this example, when one modifies regex.c, grep.c is not unnecessarily recompiled. Also, all of the variables in your environment are loaded into make as macros, which are accessed like this: $(CC).
So that's how you use source control with make.
Watches: Nanoha, Haruhi, AzuDai. Listens to: E-Type, Dj Melodie, Nightcore.
"When people are wrong they need to be corrected. And then when they can't accept it, an argument ensues." - MeTh0Dz

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Nice little tutorial. +rep

#3
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Very nice. I haven't gotten around to studying make files yet.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#4
whitey6993

whitey6993

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 437 posts
Good tutorial, short and to the point.

#5
Egz0N

Egz0N

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,034 posts
nice tutorial :)

#6
MathX

MathX

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,001 posts
:D..

Interested in participating in community events?
Want to harness your programming skill and turn it into absolute prowess?
Come join our programming events!


#7
kannan v

kannan v

    Newbie

  • Members
  • Pip
  • 2 posts
nice tutorial