Software Development on LinuxWriting MakefilesMakefile Variables

4.2. Makefile Variables

CC= gcc
LD= gcc
CC_FLAGS = -ansi -Wall -c
LD_FLAGS = -Wall

all: foo bar

foo: foo.o helper.o
    $(LD) $(LD_FLAGS) foo.o helper.o -o foo
bar: bar.o helper.o
    $(LD) $(LD_FLAGS) bar.o helper.o -o bar

bar.o: bar.c
    $(CC) $(CC_FLAGS) bar.c
foo.o: foo.c foo.h
    $(CC) $(CC_FLAGS) foo.c

clean:
    rm -f *.o foo bar

Written by Shlomi Fish