annotate branches/carfac_cpp/makefile @ 588:1668e8e09a71

(none)
author Ulf.Hammarqvist@gmail.com
date Thu, 11 Oct 2012 21:32:30 +0000
parents d59c0d65624b
children 186972c88472
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@587 26 UNITS = CARFAC AGC CAR Ear IHC unit_conversion #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@588 35 make cleanup
Ulf@585 36
Ulf@585 37 libcarfac : $(SRC_DIR)/CARFAC.o $(SRC_OBJ)
Ulf@586 38 $(CXX) -shared $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@$(LIB_EXTENSION) -fPIC
Ulf@585 39
Ulf@585 40 example_program : libcarfac
Ulf@585 41 # likely some example executable that runs the whole thing...
Ulf@585 42
Ulf@587 43 unittest: $(foreach unit, $(UNITS), $(addsuffix _unittest, $(unit)))
Ulf@585 44 $(foreach binary, $^, ./$(addsuffix $(EXE_EXTENSION), $(binary));)
Ulf@585 45
Ulf@587 46 CARFAC_unittest : $(SRC_OBJ)
Ulf@587 47 CAR_unittest : $(SRC_OBJ) #$(SRC_DIR)/unit_conversion.o
Ulf@587 48 Ear_unittest : $(SRC_OBJ)
Ulf@564 49
Ulf@588 50 cleanup :
Ulf@588 51 rm -f *.o *.a src/*.o unittest/*.o
Ulf@588 52
Ulf@588 53 clean : cleanup
Ulf@588 54 rm -f *.dll *.exe
Ulf@564 55
Ulf@564 56 # pattern magic
Ulf@564 57 $(SRC_DIR)/%.o : %.cpp $(SRC_HEADERS) #normal source
Ulf@585 58 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(.SOURCE)
Ulf@564 59
Ulf@564 60 $(SRC_TESTDIR)/%.o : %.cpp $(SRC_HEADERS) $(GTEST_HEADERS) # unittest
Ulf@585 61 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(.SOURCE)
Ulf@564 62
Ulf@564 63 %_unittest : $(SRC_DIR)/%.o $(SRC_TESTDIR)/%_unittest.o gtest_main.a #unittest
Ulf@585 64 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
Ulf@564 65 # end pattern magic
Ulf@564 66
Ulf@564 67 # gtest stuff
Ulf@564 68 gtest-all.o : $(GTEST_SRCS_)
Ulf@585 69 $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
Ulf@585 70 $(GTEST_DIR)/src/gtest-all.cc
Ulf@564 71
Ulf@564 72 gtest_main.o : $(GTEST_SRCS_)
Ulf@585 73 $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
Ulf@585 74 $(GTEST_DIR)/src/gtest_main.cc
Ulf@564 75
Ulf@564 76 gtest.a : gtest-all.o
Ulf@585 77 $(AR) $(ARFLAGS) $@ $^
Ulf@564 78
Ulf@564 79 gtest_main.a : gtest-all.o gtest_main.o
Ulf@585 80 $(AR) $(ARFLAGS) $@ $^
Ulf@564 81 # end gtest stuff