Skip to content

Commit 42900a7

Browse files
committed
Refactor build system
1 parent a1f8cda commit 42900a7

12 files changed

+540
-359
lines changed

Makefile

+107-16
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
MKFILE_PATH=$(abspath $(lastword $(MAKEFILE_LIST)))
2-
PROJ_PATH=$(patsubst %/,%,$(dir $(MKFILE_PATH)))
3-
CATKIN_WS=~/catkin_ws
1+
include config.mk
42

53
.PHONY: third_party docs build install tests ci run_test_xyz clean
4+
.PHONY: libxyz benchmarks build scripts shaders test_data viz
65

76
help:
8-
@echo "\033[1;34m[make targets]:\033[0m"
9-
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
7+
@echo "make targets:"
8+
@echo "----------------------------------------"
9+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile \
1010
| awk 'BEGIN {FS = ":.*?## "}; \
11-
{printf "\033[1;36m%-12s\033[0m%s\n", $$1, $$2}'
11+
{printf "%-16s%s\n", $$1, $$2}'
1212

1313
third_party: ## Install dependencies
1414
@git submodule init
@@ -22,17 +22,108 @@ docs: ## Build docs
2222
@rm -rf docs/build
2323
@sphinx-autobuild docs/source docs/build/html
2424

25-
build: ## Build libxyz
26-
@cd src && make -s libxyz
25+
$(BLD_DIR)/%.o: src/%.c src/%.h Makefile
26+
@echo "CC [$<]"
27+
@$(CC) $(CFLAGS) -c $< -o $@
2728

28-
install: build ## Install libxyz
29-
@cd src && make -s install
29+
$(BLD_DIR)/ceres_bridge.o: src/ceres_bridge.cpp Makefile
30+
@echo "CXX [ceres_bridge.c]"
31+
@g++ -Wall -O3 -c src/ceres_bridge.cpp -o $(BLD_DIR)/ceres_bridge.o -I/usr/include/eigen3
3032

31-
tests: ## Run unittests
32-
@cd src && make -s tests
33+
$(BLD_DIR)/libxyz.a: $(LIBXYZ_OBJS)
34+
@echo "AR [libxyz.a]"
35+
@$(AR) $(ARFLAGS) \
36+
$(BLD_DIR)/libxyz.a \
37+
$(LIBXYZ_OBJS) \
38+
> /dev/null 2>&1
3339

34-
ci: ## Run CI tests
35-
@cd src && make -s ci
40+
setup:
41+
@mkdir -p $(BLD_DIR)
42+
@cp -r src/shaders $(BLD_DIR)
43+
@cp -r src/test_data $(BLD_DIR)
3644

37-
clean: ## Clean
38-
@cd src && make -s clean
45+
clean: ## Clean
46+
@rm -rf $(BLD_DIR)
47+
48+
libxyz: setup $(BLD_DIR)/libxyz.a ## Build libxyz
49+
50+
install: ## Install libxyz
51+
mkdir -p $(PREFIX)
52+
mkdir -p $(PREFIX)/lib
53+
mkdir -p $(PREFIX)/include
54+
ln -sf $(CUR_DIR)/build/libxyz.a $(PREFIX)/lib/libxyz.a
55+
ln -sf $(CUR_DIR)/aprilgrid.h $(PREFIX)/include/aprilgrid.h
56+
ln -sf $(CUR_DIR)/ceres_bridge.h $(PREFIX)/include/ceres_bridge.h
57+
ln -sf $(CUR_DIR)/euroc.h $(PREFIX)/include/euroc.h
58+
ln -sf $(CUR_DIR)/gui.h $(PREFIX)/include/gui.h
59+
ln -sf $(CUR_DIR)/http.h $(PREFIX)/include/http.h
60+
ln -sf $(CUR_DIR)/xyz.h $(PREFIX)/include/xyz.h
61+
ln -sf $(CUR_DIR)/sbgc.h $(PREFIX)/include/sbgc.h
62+
ln -sf $(CUR_DIR)/stb_image.h $(PREFIX)/include/stb_image.h
63+
ln -sf $(CUR_DIR)/xyz.py $(PYTHON3_PATH)/xyz.py
64+
65+
uninstall: ## Uninstall libxyz
66+
rm $(PREFIX)/lib/libxyz.a
67+
rm $(PREFIX)/include/aprilgrid.h
68+
rm $(PREFIX)/include/euroc.h
69+
rm $(PREFIX)/include/gui.h
70+
rm $(PREFIX)/include/http.h
71+
rm $(PREFIX)/include/xyz.h
72+
rm $(PREFIX)/include/sbgc.h
73+
rm $(PREFIX)/include/stb_image.h
74+
rm $(PYTHON3_PATH)/xyz.py
75+
76+
avs: $(BLD_DIR)/libxyz.a
77+
@g++ \
78+
-std=c++17 \
79+
-fsanitize=address -static-libasan \
80+
-fopenmp \
81+
-g \
82+
-I$(DEPS_DIR)/include \
83+
-I/usr/include/eigen3 \
84+
$(shell pkg-config opencv4 --cflags) \
85+
avs.cpp \
86+
-o $(BLD_DIR)/avs \
87+
$(LDFLAGS) \
88+
-lxyz \
89+
$(shell pkg-config opencv4 --libs)
90+
91+
test_xyz: libxyz ## Run test_xyz
92+
@echo "CC [$@]"
93+
@$(CC) $(CFLAGS) src/test_xyz.c -o $(BLD_DIR)/test_xyz $(LDFLAGS)
94+
@cd build && ./test_xyz --target $(TEST_TARGET)
95+
96+
test_aprilgrid: ## Run test_aprilgrid
97+
@echo "CC [$@]"
98+
@$(CC) $(CFLAGS) src/test_aprilgrid.c -o $(BLD_DIR)/test_aprilgrid $(LDFLAGS)
99+
@cd build && ./test_aprilgrid
100+
101+
test_euroc: ## Run test_euroc
102+
@echo "CC [$@]"
103+
@$(CC) $(CFLAGS) src/test_euroc.c -o $(BLD_DIR)/test_euroc $(LDFLAGS)
104+
@cd build && ./test_euroc
105+
106+
test_gui: ## Run test_gui
107+
@echo "CC [$@]"
108+
@$(CC) $(CFLAGS) src/test_gui.c -o $(BLD_DIR)/test_gui $(LDFLAGS)
109+
110+
test_sbgc: ## Run test_sbgc
111+
@echo "CC [$@]"
112+
@$(CC) $(CFLAGS) src/test_sbgc.c -o $(BLD_DIR)/test_sbgc $(LDFLAGS)
113+
@cd build && ./test_sbgc
114+
115+
test_ubx: ## Run test_ubx
116+
@echo "CC [$@]"
117+
@$(CC) $(CFLAGS) src/test_ubx.c -o $(BLD_DIR)/test_ubx $(LDFLAGS)
118+
@cd build && ./test_ubx
119+
120+
test_http: ## Run test_http
121+
@echo "CC [$@]"
122+
@$(CC) $(CFLAGS) src/test_http.c -o $(BLD_DIR)/test_http $(LDFLAGS)
123+
@cd build && ./test_http
124+
125+
tests: test_aprilgrid test_gui test_ubx test_xyz ## Run tests
126+
127+
ci: ## Run CI tests
128+
@$(CC) $(CFLAGS) -DMU_REDIRECT_STREAMS=1 src/test_xyz.c -o $(BLD_DIR)/test_xyz $(LDFLAGS)
129+
@cd build && ./test_xyz

config.mk

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# PATHS
2+
MKFILE_PATH=$(abspath $(lastword $(MAKEFILE_LIST)))
3+
CUR_DIR := $(shell pwd)
4+
BLD_DIR := build
5+
INC_DIR := $(realpath $(PWD))
6+
DEPS_DIR := $(realpath third_party)
7+
PREFIX := /opt/xyz
8+
PYTHON3_PATH := $(shell python3 -c "import site; print(site.getsitepackages()[0])")
9+
10+
# COMPILER SETTINGS
11+
BUILD_TYPE := debug
12+
# BUILD_TYPE := release
13+
ADDRESS_SANITIZER := 1
14+
# ADDRESS_SANITIZER := 0
15+
# CC := clang
16+
CC := gcc
17+
# CC := tcc
18+
19+
20+
# LIBRARIES
21+
STB_CFLAGS:=-I$(DEPS_DIR)/src/stb
22+
OPENSSL_LDFLAGS := -lssl -lcrypto
23+
GLEW_LDFLAGS := -lGLEW
24+
SDL2_CFLAGS:=$(shell sdl2-config --cflags)
25+
SDL2_LDFLAGS := $(shell sdl2-config --libs) -lSDL2_image
26+
OPENGL_LDFLAGS := $(SDL2_LDFLAGS) $(GLEW_LDFLAGS) -lGL
27+
BLAS_LDFLAGS := -lblas -llapack -llapacke
28+
SUITESPARSE_LDFLAGS := -llapack -lcamd -lamd -lccolamd -lcolamd -lcholmod -lcxsparse
29+
CERES_CFLAGS := -I/usr/include/eigen3
30+
CERES_LDFLAGS := -lgflags -lglog -lceres
31+
ASSIMP_LDFLAGS := -lassimp
32+
APRILTAG_LDFLAGS := -L$(DEPS_DIR)/lib -lapriltag
33+
YAML_LDFLAGS := -lyaml
34+
XYZ_LDFLAGS := -L$(BLD_DIR) -lxyz
35+
36+
37+
# CFLAGS
38+
CFLAGS := -Wall -Wpedantic -Wstrict-prototypes
39+
40+
ifeq ($(BUILD_TYPE), debug)
41+
CFLAGS += -g -fopenmp
42+
else
43+
CFLAGS += -g -O2 -march=native -mtune=native -DNDEBUG -fopenmp
44+
endif
45+
46+
ifeq ($(ADDRESS_SANITIZER), 1)
47+
ifeq ($(CC), gcc)
48+
CFLAGS += -fsanitize=address -static-libasan
49+
else
50+
CFLAGS += -fsanitize=address -static-libsan
51+
endif
52+
endif
53+
54+
CFLAGS += \
55+
-I$(INC_DIR) \
56+
-I$(DEPS_DIR)/include \
57+
-fPIC \
58+
$(SDL2_CFLAGS) \
59+
$(STB_CFLAGS) \
60+
$(CERES_CFLAGS)
61+
62+
63+
# LDFLAGS
64+
RPATH := -Wl,-rpath,$(DEPS_DIR)/lib
65+
LDFLAGS= \
66+
$(RPATH) \
67+
$(XYZ_LDFLAGS) \
68+
$(CERES_LDFLAGS) \
69+
$(APRILTAG_LDFLAGS) \
70+
$(OPENGL_LDFLAGS) \
71+
$(SUITESPARSE_LDFLAGS) \
72+
$(BLAS_LDFLAGS) \
73+
$(OPENSSL_LDFLAGS) \
74+
$(ASSIMP_LDFLAGS) \
75+
$(YAML_LDFLAGS) \
76+
-lglfw3 \
77+
-lstdc++ \
78+
-lpthread \
79+
-lm
80+
81+
82+
# ARCHIVER SETTTINGS
83+
AR = ar
84+
ARFLAGS = rvs
85+
86+
87+
# TARGETS
88+
LIBXYZ := $(BLD_DIR)/libxyz.a
89+
LIBXYZ_OBJS := \
90+
$(BLD_DIR)/xyz.o \
91+
$(BLD_DIR)/aprilgrid.o \
92+
$(BLD_DIR)/euroc.o \
93+
$(BLD_DIR)/gui.o \
94+
$(BLD_DIR)/sbgc.o \
95+
$(BLD_DIR)/ceres_bridge.o
96+
97+
TESTS := \
98+
test_xyz \
99+
test_aprilgrid \
100+
test_sbgc \
101+
test_ubx

src/aprilgrid.h

+10-9
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ aprilgrid_t *aprilgrid_detector_detect(const aprilgrid_detector_t *det,
194194
#endif
195195
#endif // APRILGRID_H
196196

197+
197198
//////////////////////////////////////////////////////////////////////////////
198199
// IMPLEMENTATION //
199200
//////////////////////////////////////////////////////////////////////////////
@@ -888,7 +889,7 @@ static int nb_failed = 0;
888889
* @param[in] test_name Test name
889890
* @param[in] test_ptr Pointer to unittest
890891
*/
891-
void run_test(const char *test_name, int (*test_ptr)()) {
892+
void run_test(const char *test_name, int (*test_ptr)(void)) {
892893
if ((*test_ptr)() == 0) {
893894
printf("-> [%s] " TERM_GRN "OK!\n" TERM_NRM, test_name);
894895
fflush(stdout);
@@ -932,7 +933,7 @@ static int fltcmp(const float x, const float y) {
932933
return -1;
933934
}
934935

935-
int test_aprilgrid_malloc_and_free() {
936+
int test_aprilgrid_malloc_and_free(void) {
936937
// Setup
937938
const int num_rows = 6;
938939
const int num_cols = 7;
@@ -952,7 +953,7 @@ int test_aprilgrid_malloc_and_free() {
952953
return 0;
953954
}
954955

955-
int test_aprilgrid_center() {
956+
int test_aprilgrid_center(void) {
956957
// Setup
957958
int num_rows = 5;
958959
int num_cols = 2;
@@ -974,7 +975,7 @@ int test_aprilgrid_center() {
974975
return 0;
975976
}
976977

977-
int test_aprilgrid_grid_index() {
978+
int test_aprilgrid_grid_index(void) {
978979
// Setup
979980
const int num_rows = 6;
980981
const int num_cols = 6;
@@ -1012,7 +1013,7 @@ int test_aprilgrid_grid_index() {
10121013
return 0;
10131014
}
10141015

1015-
int test_aprilgrid_object_point() {
1016+
int test_aprilgrid_object_point(void) {
10161017
// Setup
10171018
const int num_rows = 6;
10181019
const int num_cols = 6;
@@ -1049,7 +1050,7 @@ int test_aprilgrid_object_point() {
10491050
return 0;
10501051
}
10511052

1052-
int test_aprilgrid_add_and_remove_corner() {
1053+
int test_aprilgrid_add_and_remove_corner(void) {
10531054
// Setup
10541055
const int num_rows = 6;
10551056
const int num_cols = 6;
@@ -1084,7 +1085,7 @@ int test_aprilgrid_add_and_remove_corner() {
10841085
return 0;
10851086
}
10861087

1087-
int test_aprilgrid_add_and_remove_tag() {
1088+
int test_aprilgrid_add_and_remove_tag(void) {
10881089
// Setup
10891090
const int num_rows = 6;
10901091
const int num_cols = 6;
@@ -1125,7 +1126,7 @@ int test_aprilgrid_add_and_remove_tag() {
11251126
return 0;
11261127
}
11271128

1128-
int test_aprilgrid_save_and_load() {
1129+
int test_aprilgrid_save_and_load(void) {
11291130
// Setup
11301131
const int num_rows = 6;
11311132
const int num_cols = 6;
@@ -1176,7 +1177,7 @@ int test_aprilgrid_save_and_load() {
11761177

11771178
#if ENABLE_APRILGRID_DETECTOR == 1
11781179

1179-
int test_aprilgrid_detector_detect() {
1180+
int test_aprilgrid_detector_detect(void) {
11801181
// Load test image
11811182
// -- Load JPG
11821183
const char *test_image = "./test_data/images/aprilgrid_tag36h11.jpg";

src/ceres_bridge.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ typedef void (*ceres_loss_function_t)(void *user_data,
3333
/**
3434
* Initialize ceres
3535
*/
36-
void ceres_init();
36+
void ceres_init(void);
3737

3838
/* Create and destroy ceres::Problem */
39-
ceres_problem_t *ceres_create_problem();
39+
ceres_problem_t *ceres_create_problem(void);
4040
void ceres_free_problem(ceres_problem_t *problem);
4141

4242
/* Create and destroy ceres::LocalParameterization */
43-
ceres_local_parameterization_t *ceres_create_pose_local_parameterization();
43+
ceres_local_parameterization_t *ceres_create_pose_local_parameterization(void);
4444
void ceres_free_local_parameterization(ceres_local_parameterization_t *p);
4545

4646
// /**

0 commit comments

Comments
 (0)