annotate branches/carfac_cpp/makefile @ 585:b8a961149499

seemingly mingw likes tabs for makefiles ...? + some restructure and automatic execution of unittests after build...
author Ulf.Hammarqvist@gmail.com
date Thu, 11 Oct 2012 19:37:10 +0000
parents b4650540cb24
children f3dde307f4b8
rev   line source
Ulf@564 1 # How to use:
Ulf@564 2 # Add your cpp code to the list in UNITS.
Ulf@564 3 #
Ulf@564 4 # Unit test:
Ulf@564 5 # If you want to add a test build target for that cpp file ONLY, please see
Ulf@564 6 # example "AGC_unittest". (no need to add explicit build rule)
Ulf@564 7 #
Ulf@564 8 # If you intend to test a class including instanciated members, you need to
Ulf@564 9 # make a explicit rule to link properly. See example "CARFAC_unittest".
Ulf@564 10
Ulf@585 11 # settings
Ulf@585 12 GTEST_DIR = ../../../googletest
Ulf@585 13 LIB_EXTENSION = .dll
Ulf@585 14 EXE_EXTENSION = .exe
Ulf@585 15 # end settings
Ulf@585 16
Ulf@564 17 SRC_HEADERDIR = include
Ulf@564 18 SRC_DIR = src
Ulf@564 19 SRC_TESTDIR = unittest
Ulf@564 20
Ulf@564 21 SRC_HEADERS = $(SRC_HEADERDIR)/*.h
Ulf@564 22
Ulf@564 23 CPPFLAGS += -I$(SRC_HEADERDIR) -I$(GTEST_DIR)/include
Ulf@564 24 CXXFLAGS += -g -Wall -Wextra -std=gnu++0x #IMPORTANT note gnu++0x
Ulf@564 25
Ulf@584 26 UNITS = CARFAC AGC CAR Ear IHC #Add build units here (without the .cpp)
Ulf@564 27 SRC_OBJ = $(addprefix $(SRC_DIR)/, $(addsuffix .o, $(UNITS)))
Ulf@564 28
Ulf@564 29 GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
Ulf@564 30 $(GTEST_DIR)/include/gtest/internal/*.h
Ulf@564 31
Ulf@564 32 GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
Ulf@564 33
Ulf@585 34 all : libcarfac unittest
Ulf@585 35
Ulf@585 36 libcarfac : $(SRC_DIR)/CARFAC.o $(SRC_OBJ)
Ulf@585 37 $(CXX) -shared $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@.$(LIB_EXTENSION) -fPIC
Ulf@585 38
Ulf@585 39 example_program : libcarfac
Ulf@585 40 # likely some example executable that runs the whole thing...
Ulf@585 41
Ulf@585 42 unittest: CARFAC_unittest AGC_unittest
Ulf@585 43 $(foreach binary, $^, ./$(addsuffix $(EXE_EXTENSION), $(binary));)
Ulf@585 44
Ulf@585 45 CARFAC_unittest : $(SRC_TESTDIR)/CARFAC_unittest.o $(SRC_OBJ)
Ulf@564 46
Ulf@564 47 clean :
Ulf@585 48 rm -f *.o *.a src/*.o unittest/*.o *_unittest* *.dll *.exe
Ulf@564 49
Ulf@564 50 # pattern magic
Ulf@564 51 $(SRC_DIR)/%.o : %.cpp $(SRC_HEADERS) #normal source
Ulf@585 52 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(.SOURCE)
Ulf@564 53
Ulf@564 54 $(SRC_TESTDIR)/%.o : %.cpp $(SRC_HEADERS) $(GTEST_HEADERS) # unittest
Ulf@585 55 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(.SOURCE)
Ulf@564 56
Ulf@564 57 %_unittest : $(SRC_DIR)/%.o $(SRC_TESTDIR)/%_unittest.o gtest_main.a #unittest
Ulf@585 58 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
Ulf@564 59 # end pattern magic
Ulf@564 60
Ulf@564 61 # gtest stuff
Ulf@564 62 gtest-all.o : $(GTEST_SRCS_)
Ulf@585 63 $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
Ulf@585 64 $(GTEST_DIR)/src/gtest-all.cc
Ulf@564 65
Ulf@564 66 gtest_main.o : $(GTEST_SRCS_)
Ulf@585 67 $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
Ulf@585 68 $(GTEST_DIR)/src/gtest_main.cc
Ulf@564 69
Ulf@564 70 gtest.a : gtest-all.o
Ulf@585 71 $(AR) $(ARFLAGS) $@ $^
Ulf@564 72
Ulf@564 73 gtest_main.a : gtest-all.o gtest_main.o
Ulf@585 74 $(AR) $(ARFLAGS) $@ $^
Ulf@564 75 # end gtest stuff