Monday, May 29, 2006

Makefile for c++ project

#---------------------------------------------------------------#
# Written By Vaibhav Gupta
#---------------------------------------------------------------#
# TARGETS:
# wire - default target
# dwire - debug target
# tag - For generating tag file
# clean/fresh - clean obj files.
#---------------------------------------------------------------#
#-- Customized variables
BINDIR=bin
OBJDIR=obj
SRCDIR=src
INCDIR=include

CC = g++
CWARN = -W -Wall -Wshadow -Wimplicit -Wreturn-type -Wcomment -Wtrigraphs -Wformat -Wparentheses -Wpointer-arith -Wuninitialized -O

CDBG = -g $(CWARN) -fno-inline
CFLAGS = -I$(INCDIR) $(CDBG)
DFLAGS = -I$(INCDIR) -g $(CWARN) -fno-inline -DDEBUG=1

CTAG = ctags
CTAGFILE = filelist
# src, object and bin files
TGT=wire
#Debug Target
DBGTGT=dwire

HEADERS = $(INCDIR)/global.h

COMMONOBJS = $(OBJDIR)/BaseStation.o $(OBJDIR)/SubscriberStation.o
$(OBJDIR)/Packet.o $(OBJDIR)/Queue.o $(OBJDIR)/Global.o $(OBJDIR)/Simulate.o

OBJS = $(COMMONOBJS) $(OBJDIR)/main.o
DBGOBJS = $(COMMONOBJS) $(OBJDIR)/main.dbg.o

#-- Rules
all: $(TGT)
dbg: $(DBGTGT)

$(TGT): $(BINDIR)/$(TGT)
@echo "$@ uptodate"

$(DBGTGT): $(BINDIR)/$(DBGTGT)
@echo "$@ uptodate"

$(BINDIR)/$(DBGTGT): $(DBGOBJS)
$(CC) $(CFLAGS) -o $@ $(DBGOBJS)

$(OBJDIR)/%.dbg.o: $(SRCDIR)/%.cpp
$(CC) $(CFLAGS) -DDEBUG=1 -c -o $@ $?

$(BINDIR)/$(TGT): $(OBJS)
$(CC) $(CFLAGS) -o $@ $(OBJS)

$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
$(CC) $(CFLAGS) -c -o $@ $?

.PHONY : clean depend fresh
tag :
find src/*.cpp include/*.h > filelist
$(CTAG) -L $(CTAGFILE)

clean :
-rm -f $(OBJDIR)/*.o $(PARSE_C) $(PARSE_H)
-rm -f $(SRCDIR)/*.output $(LEX_C)
-rm -f */*~ *~ core
-rm -f $(BINDIR)/$(TGT) $(BINDIR)/$(DBGTGT)

fresh : clean all