Skip to content

Commit

Permalink
Reorganize boolexpr Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdrake committed May 21, 2015
1 parent 6358b14 commit 8085424
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 60 deletions.
14 changes: 1 addition & 13 deletions extension/boolexpr/.gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
# Filename: .gitignore

# C/C++ compilation
*.o
*.a

# Binaries
a.out

# Coverage
*.gcda
*.gcno
coverage.info
coverage/

bld/
115 changes: 68 additions & 47 deletions extension/boolexpr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,41 @@ AR := ar
CC := c99
CXX := g++

CPPFLAGS :=
CFLAGS :=
CXXFLAGS :=
ARFLAGS := -crs
LDFLAGS :=
LDLIBS := -lgtest -lpthread

GENHTML := genhtml
LCOV := lcov
VALGRIND := valgrind

ifdef COVER_ON
CFLAGS += --coverage
LDFLAGS += --coverage
endif

.PHONY: do_test
do_test: a.out
.PHONY: help
help:
@printf "Usage: make [options] [target] ...\n"
@printf "\n"
@printf "Valid targets:\n"
@printf "\n"
@printf " help Display this help message\n"
@printf " test Run unit test suite\n"
@printf " memtest Check for memory leaks\n"
@printf " cover Collect coverage\n"
@printf " all Build all binary targets\n"

.PHONY: test
test: bld/test/run
@./$<

.PHONY: do_valgrind
do_valgrind: a.out
.PHONY: memtest
memtest: bld/test/run
@$(VALGRIND) ./$<

.PHONY: clean
clean:
@rm -f *.o
@rm -f *.gcda *.gcno coverage.info
@rm -rf coverage

.PHONY: cover
cover: clean
@$(MAKE) clean
@$(MAKE) do_test COVER_ON=1
@$(LCOV) -c -d . -o coverage.info
@$(GENHTML) coverage.info -o coverage
cover: bld/cover/run
@./$<
@$(LCOV) -c -d bld/cover -o bld/cover/coverage.info
@$(GENHTML) -o bld/cover/html bld/cover/coverage.info

.PHONY: all
all: bld/test/run bld/cover/run bld/lib/libboolexpr.a

#===============================================================================
# Source code
# Source Code
#===============================================================================

BOOLEXPR_HDRS := boolexpr.h
Expand All @@ -62,9 +58,9 @@ BOOLEXPR_SRCS := \
util.c \
vector.c \

TEST_HDRS := test/boolexprtest.hpp
BOOLEXPR_TEST_HDRS := test/boolexprtest.hpp

TEST_SRCS := \
BOOLEXPR_TEST_SRCS := \
test/main.cpp \
test/boolexprtest.cpp \
test/test_array.cpp \
Expand All @@ -81,30 +77,55 @@ TEST_SRCS := \
test/test_vector.cpp \

#===============================================================================
# Generic rules
# Build Rules
#===============================================================================

%.o: %.c $(BOOLEXPR_HDRS)
$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
bld/:
@mkdir $@

test/%.o: test/%.cpp $(TEST_HDRS)
$(CXX) -c -I. $(CXXFLAGS) $(CPPFLAGS) -o $@ $<
# Unit tests
bld/test/: | bld/
@mkdir $@

#===============================================================================
# boolexpr library
#===============================================================================
bld/test/%.o: %.c $(BOOLEXPR_HDRS) | bld/test/
$(CC) -c -o $@ $<

BOOLEXPR_OBJS := $(patsubst %.c,%.o,$(BOOLEXPR_SRCS))
bld/test/%.o: test/%.cpp $(BOOLEXPR_TEST_HDRS) | bld/test/
$(CXX) -c -I. -o $@ $<

libboolexpr.a: $(BOOLEXPR_OBJS)
$(AR) $(ARFLAGS) $@ $^
TEST_OBJS := \
$(patsubst %.c,bld/test/%.o,$(BOOLEXPR_SRCS)) \
$(patsubst test/%.cpp,bld/test/%.o,$(BOOLEXPR_TEST_SRCS)) \

#===============================================================================
# Unit tests
#===============================================================================
bld/test/run: $(TEST_OBJS)
$(CXX) -o $@ $^ -lgtest -lpthread

# Coverage
bld/cover/: | bld/
@mkdir $@

bld/cover/%.o: %.c $(BOOLEXPR_HDRS) | bld/cover/
$(CC) -c --coverage -o $@ $<

bld/cover/%.o: test/%.cpp $(BOOLEXPR_TEST_HDRS) | bld/cover/
$(CXX) -c -I. -o $@ $<

COVER_OBJS := \
$(patsubst %.c,bld/cover/%.o,$(BOOLEXPR_SRCS)) \
$(patsubst test/%.cpp,bld/cover/%.o,$(BOOLEXPR_TEST_SRCS)) \

bld/cover/run: $(COVER_OBJS)
$(CXX) -o $@ --coverage $^ -lgtest -lpthread

# Library archive
bld/lib/: bld/
@mkdir $@

bld/lib/%.o: %.c $(BOOLEXPR_HDRS) | bld/lib/
$(CC) -c -o $@ $<

TEST_OBJS := $(patsubst test/%.cpp,test/%.o,$(TEST_SRCS))
LIB_OBJS := $(patsubst %.c,bld/lib/%.o,$(BOOLEXPR_SRCS))

a.out: $(BOOLEXPR_OBJS) $(TEST_OBJS)
$(CXX) -o $@ $(LDFLAGS) $^ $(LDLIBS)
bld/lib/libboolexpr.a: $(LIB_OBJS)
$(AR) -o $@ -crs $@ $^

0 comments on commit 8085424

Please sign in to comment.