Created
October 23, 2012 16:27
-
-
Save stephenLee/3939892 to your computer and use it in GitHub Desktop.
Tiny Makefile template for c++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# define variable, use using $() | |
# -g add debug information to the executable file | |
# -Wall turns on most, but not all, compiler warnings | |
# using Emacs and M-x replace-string RET string RET newstring RET | |
# to replace xx to your file name. | |
# Use google's testing framework | |
GTEST_DIR = ../gtest | |
# Where to find user code. | |
USER_DIR = ../gtest_sample | |
# Flags to passed to the preprocessor | |
CPPFLAGS += -I$(GTEST_DIR)/include | |
CXX_FLAGS += -g -Wall -Wextra | |
TESTS = sample_test | |
# All Google test headers. | |
GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \ | |
$(GTEST_DIR)/include/gtest/internal/*.h | |
all : $(TESTS) | |
clean : | |
rm -f $(TESTS) gtest.a gtest_main.a *.o | |
# Builds gtest.a gtest_main.a | |
GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS) | |
gtest-all.o : $(GTEST_SRCS_) | |
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \ | |
$(GTEST_DIR)/src/gtest-all.cc | |
gtest_main.o : $(GTEST_SRCS_) | |
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \ | |
$(GTEST_DIR)/src/gtest_main.cc | |
gtest.a : gtest-all.o | |
$(AR) $(ARFLAGS) $@ $^ | |
gtest_main.a : gtest-all.o gtest_main.o | |
$(AR) $(ARFLAGS) $@ $^ | |
sample.o : $(USER_DIR)/sample.cc $(USER_DIR)/sample.h $(GTEST_HEADERS) | |
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample.cc | |
sample_test.o : $(USER_DIR)/sample_test.cc \ | |
$(USER_DIR)/sample.h $(GTEST_HEADERS) | |
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample_test.cc | |
sample_test : sample.o sample_test.o gtest_main.a | |
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment