Re: Makefile???, not very good with them.



On Sun, 19 Jan 2003 13:57:07 +0000
"Hammamur Rahman" <hrahman10 hotmail com> wrote:

The error i'm presently getting is:

gcc.exe: no input files
MAKE: *** [duv.exe] Error 1

I think this a very simple problem.  The main problem is I just don't
know how to write a makefile properly.  Could you please amend the one
I'v given and if you have time explain alitlle what each line does.


Quite simple. Basically, the Makefile serves to define "targets" and what
to do to obtain them. The simplest posible Makefile, equivalent to running
gcc foo.c -o bar would be:

bar: foo.c
        gcc foo.c -o bar

This makes hardly any sense, but it shows nicely what it's all about. The
target is "bar" (watch the format of the file; a target is something that
begins on the first character of a line, commands begin with an empty
space), and its dependence is what is behind the colon (:). Make checks
the datastamps of both files, and runs the command beneath the target
definition, if:
1) there's no "bar" file
2) the datastamps show that "foo.c" is newer than "bar" - if foo.c is
edited, that is.
Otherwise, make says bar is up to date and does nothing.
Most makefiles use variables for commands. So you can have:
GCC=gcc
CFLAGS=-Wall -pedantic
and the command for the target is then:
        $(GCC) $(CFLAGS) foo.c -o bar

A bit more complex Makefile (a Makefile that makes sense) may look like
this:
GCC=gcc
CFLAGS=-Wall -pedantic

foobar: foo.o bar.o
        $(GCC) $(CFLAGS) foo.o bar.o -o foobar

foo.o: foo.c
        $(GCC) $(CFLAGS) -c foo.c

bar.o: bar.c
        $(GCC) $(CFLAGS) -c bar.c

The first target is the default target. Its dependancies are further
targets, so make jumps to them and checks their dependancies. Whenever it
finds a target that's not up to date, it will execute the command below
the target definition. In this case, if you edit bar.c, it will check
foo.o and do nothing, check bar.o and find it's not up to date, compile
it, and link both object files to foobar.
When invoked without arguments, make will make the default target (the
first appearing), otherwise you can specify them - like "make clean" to
clean the directory of .o files, if you've defined a target "clean":

clean:
        rm -f *.o

The commands executed are those available from the shell you're using. I
use Linux, so you see bash commands here. If you're using dos, use
commands available there, "del *.o" instead of "rm -f *.o" etc...

Cheers

-- 
Horror Vacui

Registered Linux user #257714

Go get yourself... counted: http://counter.li.org/
- and keep following the GNU.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]