tags:

views:

127

answers:

1

Hello,

gcc 4.4.2 c89

I have written this Makefile. I am wondering is it a good design and easy to maintain?

I thing I am thinking about is that cltsvr_ults.o gets linked with both the SVR_OBJECTS and CLT_OBJECTS. Does this look correct?

Many thanks for any suggestions,

# ------------- SOURCE FILE ------------------------
SVR_OBJECTS = server.o cltsvr_ults.o test_svr.o
CLT_OBJECTS = client.o cltsvr_ults.o test_clt.o

# ------------- COMPILER OPTIONS -------------------
CFLAGS = -ggdb -Wall -pthread -std=c89 
CC = gcc
PLATFORM = -DLINUX
LIBS = -lpthread

# ------------- TARGETS ----------------------------
all: svr clt

svr: $(SVR_OBJECTS)
    $(CC) $(CFLAGS) $(PLATFORM) $(SVR_OBJECTS) -o svr

clt: $(CLT_OBJECTS)
    $(CC) $(CFLAGS) $(PLATFORM) $(CLT_OBJECTS) -o clt

clean:
    rm -f clt svr *.o *~

# -------------- DEPENDENCIES ---------------------
server.o:   server.h
client.o:   client.h
test_svr.o: test_svr.c
test_clt.o: test_clt.c
cltsvr_ults.o:  cltsvr_ults.h

svr.o:      server.h cltsvr_ults.h test_svr.c
clt.o:      client.h cltsvr_ults.h test_clt.c
+1  A: 

The only suggestion I would make is to rely on the default rules. IOW, if you simply write:

CFLAGS := -ggdb -Wall -pthread -std=c89
CPPFLAGS := -DLINUX
LOADLIBES := -lpthread
CC := gcc
all: svr clt
svr: $(SVR_OBJECTS)
clt: $(CLT_OBJECTS)
...snip...

without explicitly writing a rule for svr, then (gnumake) will generate the correct rule. However, this may not be portable across all different flavors of make. If that is a concern, you are far better off using automake. (In other words, don't worry about Make portability unless you must, but if you must you don't want to be writing your Makefile by hand.) Note that you must use LOADLIBES instead of LIBS to get the default rule to work for you.

William Pursell