-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathMakefile
More file actions
89 lines (73 loc) · 2.46 KB
/
Copy pathMakefile
File metadata and controls
89 lines (73 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
################################################################################
#
# @file Makefile
#
# @brief Set of commands to create and remove object files
#
# @author Tarun Malviya <malviya.t@northeastern.edu>
#
################################################################################
CXX ?= g++
# path #
SRC_PATH = src
INCLUDE_PATH = include
BUILD_PATH = build
# extensions #
SRC_EXT = cpp
# code lists #
# Find all source files in the source directory, sorted by
# most recently modified
SOURCES = $(shell find $(SRC_PATH) -name '*.$(SRC_EXT)' | sort -k 1nr | cut -f2-)
# Set the object file names, with the source directory stripped
# from the path, and the build path prepended in its place
OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o)
# Set the dependency files that will be used to add header dependencies
DEPS = $(OBJECTS:.o=.d)
# flags #
COMPILE_FLAGS = -std=c++17 -Wall -Wextra -g -w -fPIC
LDFLAGS = -lgtest -lpthread
INCLUDES = -I include/ -I /usr/local/include
# Space-separated pkg-config libraries used by this project
LIBS =
.PHONY: default_target
default_target: release
.PHONY: release
release: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS)
release: dirs
@$(MAKE) all
.PHONY: dirs
dirs:
@echo "Creating directories"
@mkdir -p $(BUILD_PATH)
.PHONY: clean
clean:
@echo "Deleting directories"
@$(RM) -r $(BUILD_PATH)
@$(RM) test.vcd
@$(RM) dump.vcd
.PHONY: all
all: $(BUILD_PATH)/libvcdwriter.so $(BUILD_PATH)/libvcdwriter.a $(BUILD_PATH)/main $(BUILD_PATH)/test
# Creation of the shared library
$(BUILD_PATH)/libvcdwriter.so: $(OBJECTS)
@echo "Building shared library: $@"
${CXX} $(CXXFLAGS) $(INCLUDES) -shared -o $@ $^
# Creation of the static library
$(BUILD_PATH)/libvcdwriter.a: $(OBJECTS)
@echo "Building static library: $@"
ar rcs $@ $(OBJECTS)
# Creation of the simple test
$(BUILD_PATH)/main: $(OBJECTS)
@echo "Building exe file for simple test: $@"
${CXX} $(CXXFLAGS) test/main.cpp $(INCLUDES) -o $@ $^
# Creation of the unit tests
$(BUILD_PATH)/test: $(OBJECTS)
@echo "Building exe file for unit tests: $@"
${CXX} $(CXXFLAGS) test/vcd_tests.cpp $(INCLUDES) -o $@ $^ $(LDFLAGS)
# Add dependency files, if they exist
-include $(DEPS)
# Source file rules
# After the first compilation they will be joined with the rules from the
# dependency files to provide header dependencies
$(BUILD_PATH)/%.o: $(SRC_PATH)/%.$(SRC_EXT)
@echo "Compiling: $< -> $@"
$(CXX) $(CXXFLAGS) $(INCLUDES) $(LIBS) -fPIC -MP -MMD -c $< -o $@