一个比较通用的Makefile
一个比较通用的Makefile
TARGET = xxx
SRCDIRS = .
SRCEXTS := .c .cpp
SRC = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
OBJ = $(foreach x,$(SRCEXTS), $(patsubst %$(x),%.o,$(filter %$(x),$(SRC))))
CFLAGS += -Wall -g \
-I../libjson/include/ \
-I../mylib \
CPPFLAGS += $(CFLAGS)
CXXFLAGS += $(CFLAGS)
LDLIBS += -lm \
../libjson/lib/$(CROSS)/libjson.a \
../netzip_build/lib/libz.a
$(TARGET): $(OBJ)
$(CXX) -o $(TARGET) $(OBJ) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LDLIBS)
%.o: %.c
$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
%.o: %.cpp
$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
%.d: %.c
@set -e; rm -f $@; \
$(CC) -MM $(CFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
%.d: %.cpp
@set -e; rm -f $@; \
$(CXX) -MM $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
include $(OBJ:.o=.d)
install:
cp $(TARGET) /srv/nfs
clean:
rm -f $(TARGET)
rm -f $(OBJ)