annotate makefile @ 577:e4285e69a73d carfac_cpp

(none)
author Ulf.Hammarqvist@gmail.com
date Wed, 10 Oct 2012 19:30:59 +0000
parents 83cd5bbf2a3e
children 86601f76f47a
rev   line source
Ulf@503 1 # How to use:
Ulf@503 2 # Add your cpp code to the list in UNITS.
Ulf@503 3 #
Ulf@503 4 # Unit test:
Ulf@503 5 # If you want to add a test build target for that cpp file ONLY, please see
Ulf@503 6 # example "AGC_unittest". (no need to add explicit build rule)
Ulf@503 7 #
Ulf@503 8 # If you intend to test a class including instanciated members, you need to
Ulf@503 9 # make a explicit rule to link properly. See example "CARFAC_unittest".
Ulf@503 10
Ulf@503 11 SRC_HEADERDIR = include
Ulf@503 12 SRC_DIR = src
Ulf@503 13 SRC_TESTDIR = unittest
Ulf@503 14
Ulf@503 15 GTEST_DIR = ../../../googletest
Ulf@503 16
Ulf@503 17 SRC_HEADERS = $(SRC_HEADERDIR)/*.h
Ulf@503 18
Ulf@503 19 CPPFLAGS += -I$(SRC_HEADERDIR) -I$(GTEST_DIR)/include
Ulf@503 20 CXXFLAGS += -g -Wall -Wextra -std=gnu++0x #IMPORTANT note gnu++0x
Ulf@503 21
Ulf@577 22 UNITS = CARFAC AGC CAR Ear IHC #Add build units here (without the .cpp)
Ulf@503 23 SRC_OBJ = $(addprefix $(SRC_DIR)/, $(addsuffix .o, $(UNITS)))
Ulf@503 24
Ulf@503 25 GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
Ulf@503 26 $(GTEST_DIR)/include/gtest/internal/*.h
Ulf@503 27
Ulf@503 28 GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
Ulf@503 29
Ulf@577 30 all :
Ulf@577 31 CARFAC_unittest AGC_unittest #make some other "main" target
Ulf@503 32
Ulf@503 33 clean :
Ulf@577 34 rm -f *.o *.a src/*.o unittest/*.o *_unittest.exe
Ulf@503 35
Ulf@503 36 CARFAC_unittest : $(SRC_TESTDIR)/CARFAC_unittest.o $(SRC_OBJ)
Ulf@503 37
Ulf@503 38 # pattern magic
Ulf@503 39 $(SRC_DIR)/%.o : %.cpp $(SRC_HEADERS) #normal source
Ulf@577 40 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(.SOURCE)
Ulf@503 41
Ulf@503 42 $(SRC_TESTDIR)/%.o : %.cpp $(SRC_HEADERS) $(GTEST_HEADERS) # unittest
Ulf@577 43 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(.SOURCE)
Ulf@503 44
Ulf@503 45 %_unittest : $(SRC_DIR)/%.o $(SRC_TESTDIR)/%_unittest.o gtest_main.a #unittest
Ulf@577 46 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
Ulf@503 47 # ./$@.exe # launches the test - disabled, as failing tests stops the build
Ulf@503 48 # end pattern magic
Ulf@503 49
Ulf@503 50 # gtest stuff
Ulf@503 51 gtest-all.o : $(GTEST_SRCS_)
Ulf@577 52 $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
Ulf@503 53 $(GTEST_DIR)/src/gtest-all.cc
Ulf@503 54
Ulf@503 55 gtest_main.o : $(GTEST_SRCS_)
Ulf@577 56 $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
Ulf@503 57 $(GTEST_DIR)/src/gtest_main.cc
Ulf@503 58
Ulf@503 59 gtest.a : gtest-all.o
Ulf@577 60 $(AR) $(ARFLAGS) $@ $^
Ulf@503 61
Ulf@503 62 gtest_main.a : gtest-all.o gtest_main.o
Ulf@577 63 $(AR) $(ARFLAGS) $@ $^
Ulf@503 64 # end gtest stuff