GNU makefile example
# Settings
CC = g++
CPPFBASE = -Wall -g -ggdb #-DNDEBUG
CPPFLAGS = $(CPPFBASE) -O2
LDFLAGS =
LIBS =
SRCS = alphabet.cpp abstract_score_policy.cpp simple_score_policy.cpp global_alignment.cpp phoneme_seq.cpp alignment_result.cpp alignment_inspector.cpp matching_stat.cpp
SRCS1 = $(SRCS) app.cpp
SRCS2 = $(SRCS) test.cpp
PROGRAM = app
TEST = test
OBJS = $(SRCS:.cpp=.o)
OBJS1 = $(SRCS1:.cpp=.o)
OBJS2 = $(SRCS2:.cpp=.o)
DEPS = $(SRCS:.cpp=.d)
DEPS1 = $(SRCS1:.cpp=.d)
DEPS2 = $(SRCS2:.cpp=.d)
SHELL = sh
# Builds
all: $(DEPS1) $(PROGRAM)
$(PROGRAM): $(OBJS1) Makefile
$(CC) $(LDFLAGS) $(OBJS1) $(LIBS) -o $@
$(TEST): $(DEPS2) $(OBJS2) Makefile
$(CC) $(LDFLAGS) $(OBJS2) $(LIBS) -o $@
# Cleanup
clean: tagclean
rm -f *.o *.d core $(PROGRAM) $(TEST)
# Tags
tag:
ctags -R *
ls *.hpp *.cpp > cscope.files
cscope -R -b *.cpp *.hpp
tagclean:
rm -f tags cscope.files cscope.out *.d
%.d: %.cpp
$(SHELL) -ec ‘$(CC) -M $(CPPFLAGS) $< \
| sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \
[ -s $@ ] || rm -f $@’
%.o: %.cpp %.hpp
$(CC) $(CPPFLAGS) -c $<
include $(SRCS:.cpp=.d)
[/code]