-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
194 lines (145 loc) · 5.42 KB
/
Copy pathMakefile
File metadata and controls
194 lines (145 loc) · 5.42 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#
# 2025 Palmer Lab
#
######################################################################
# machine dependent options
######################################################################
# CXXFLAGS note: Remember that -g flag is for generating source-level
# debug info.
# OBJ_OUTPUT_OPTIONS: compiler options. Clang, and I presume
# also gcc, support the creation of dependency files (-MMD) and (-MP) phony
# targets required for constructing an object file. The (-o) and $@
# are the standard output file designation submitted to the compiler,
# and $@ is an automatic variable storing the rules target.
# library archive program
#
ifneq ($(shell which clang++),)
CXX = clang++
CXXFLAGS = -pedantic # -Wextra
else ifneq ($(shell which g++),)
CXX = g++
CXXFLAGS = -Wpedantic -Wextra
else
$(error "Couldn't establish either clang or gcc compiler availability")
endif
CXXFLAGS += -g -std=c++17 -Wall -Werror
ifndef VIM
CXXFLAGS += -fdiagnostics-color=always
endif
# Recall that -c flag prevents the compiler linking object files
OBJ_OUTPUT_OPTIONS = -c -MMD -MP -o $@
AR = ar
AR_FLAGS = crs
LOCAL_LIB = $(HOME)/.local/lib
LOCAL_LD = $(HOME)/.local/include
######################################################################
# define src and obj variables
######################################################################
SRC_DIR = src
HEADER_DIR = include
BUILD_DIR = build
CXXLD := $(PWD)/include $(LOCAL_LD) $(CXXLD)
CXXLDFLAGS = $(addprefix -I, $(CXXLD))
CXXLIB += $(LOCAL_LIB)
CXXLIBFLAGS = $(addprefix -L, $(CXXLIB))
# APPLICATION FILES
# APP_FILES = matrix.cpp bcfio.cpp
APP_SRC = $(filter-out $(SRC_DIR)/main.cpp, $(wildcard $(SRC_DIR)/*.cpp))
#APP_SRC = $(addprefix $(SRC_DIR)/, $(APP_FILES))
APP_OBJS = $(subst $(SRC_DIR), $(BUILD_DIR), $(APP_SRC:.cpp=.o))
APP_DEPS = $(APP_OBJS:.o=.d)
# TESTS
TEST_DIR = tests
TEST_SRC = $(wildcard $(TEST_DIR)/test_*.cpp)
TEST_OBJS = $(subst $(TEST_DIR), $(BUILD_DIR), $(TEST_SRC:.cpp=.o))
TEST_DEPS = $(TEST_OBJS:.o=.d)
TEST_DATA_SRC = $(wildcard $(TEST_DIR)/geno_test_data.*)
TEST_DATA_DST = $(subst $(TEST_DIR), $(BUILD_DIR), $(TEST_DATA_SRC))
TEST_TARGET_PRG = $(BUILD_DIR)/runtests
######################################################################
# Executable Build Rules
######################################################################
TARGET = $(BUILD_DIR)/grm
.PHONY: all
all: $(TARGET) $(TEST_TARGET_PRG) data
$(TARGET): $(SRC_DIR)/main.cpp $(APP_OBJS)
$(CXX) $(CXXFLAGS) $(CXXLDFLAGS) $(CXXLIBFLAGS) -o $@ $^ -largparse -lhts
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp | $(BUILD_DIR)
$(CXX) $(CXXFLAGS) $(CXXLDFLAGS) $(OBJ_OUTPUT_OPTIONS) $<
$(BUILD_DIR):
mkdir $@
######################################################################
# Test Build Rules
######################################################################
$(TEST_TARGET_PRG): $(TEST_DIR)/main.cpp $(TEST_OBJS) $(APP_OBJS) | $(TARGET)
$(CXX) $(CXXFLAGS) $(CXXLDFLAGS) $(CXXLIBFLAGS) -o $@ $^ -lgtest -lhts
$(BUILD_DIR)/test_%.o: $(TEST_DIR)/test_%.cpp
$(CXX) $(CXXFLAGS) $(CXXLDFLAGS) $(OBJ_OUTPUT_OPTIONS) $<
TEST_GRM_PRG = $(BUILD_DIR)/test_grm
test_grm: $(TEST_GRM_PRG)
./$(TEST_GRM_PRG)
$(TEST_GRM_PRG): $(BUILD_DIR)/test_grm.o $(BUILD_DIR)/grm.o | $(BUILD_DIR)
$(CXX) $(CXXFLAGS) $(CXXLDFLAGS) $(CXXLIBFLAGS) -o $@ $^ -lgtest -lgtest_main
data: | $(TEST_DATA_DST)
$(BUILD_DIR)/geno_test_data%: $(TEST_DIR)/geno_test_data%
rsync -avz $< $(BUILD_DIR)/
# tests: $(BUILD_DIR)/test_log #$(BUILD_DIR)/test_argparse
#
# $(BUILD_DIR)/test_log: $(BUILD_DIR)/test_log.o $(BUILD_DIR)/logger.o ~/.local/lib/libgtest.a
# $(CXX) $(CXXFLAGS) $(CXXLDFLAGS) $(CXXLIBFLAGS) -o $@ $^
#
# $(BUILD_DIR)/test_argparse: $(BUILD_DIR)/test_argparse.o \
# $(BUILD_DIR)/argparse.o \
# ~/.local/lib/libgtest.a
# $(CXX) $(CXXFLAGS) $(CXXLDFLAGS) -I$(LOCAL_INCLUDE) -L$(LOCAL_LIB) -o $@ $^
# $(TEST_OBJS): $(TEST_SRC)
# $(CXX) $(CXXFLAGS) $(CXXLDFLAGS) -I$(LOCAL_INCLUDE) $(OBJ_OUTPUT_OPTIONS) $<
#
# $(BUILD_DIR)/test_log.o: $(TEST_DIR)/test_log.cpp
# $(CXX) $(CXXFLAGS) $(CXXLDFLAGS) $(OBJ_OUTPUT_OPTIONS) $^
# $(TEST_OBJS): $(TEST_SRC)
# $(CXX) $(CXXFLAGS) $(CXXLDFLAGS) -I$(LOCAL_INCLUDE) -L$(LOCAL_LIB) -o $@ $^
# $(CXX) $(CXXFLAGS) $(CXXLDFLAGS) $(CXXLIBFLAGS) $(OBJ_OUTPUT_OPTIONS) $^
######################################################################
#
######################################################################
check:
./$(TEST_TARGET_PRG)
######################################################################
#
######################################################################
-include $(APP_DEPS)
-include $(TEST_DEPS)
.PHONY: help
help:
-@echo "build grm"
-@echo "2025 Palmer Lab"
-@echo ""
-@echo "make grm executable"
-@echo "make libargparse"
######################################################################
# install
######################################################################
# install:
# dir_header=$${prefix%/}/include/stitchr; \
# if [ ! -d $${dir_header} ]; then \
# mkdir -p $${dir_header}; \
# fi; \
# for hfile in $$(ls $(HEADER_DIR)); do \
# cp $$hfile $${dir_header}/$${hfile}; \
# done; \
# \
# dir_lib=$${prefix%/}/lib; \
# if [ ! -d $${dir_lib} ]; then \
# mkdir -p $${dir_lib}; \
# fi; \
# for libfile in $$(ls $(BUILD_DIR)/*.a); do
# cp $$libfile $${dir_lib}/$${libfile}; \
# done; \
# \
# dir_bin = $${prefix%/}/bin; \
# if [ ! -d $${dir_bin} ]; then \
# mkdir -p $${dir_bin}; \
# fi; \
# cp $(TARGET) $${dir_bin}/$(notdir $(TARGET))
#