-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
42 lines (32 loc) · 937 Bytes
/
Makefile
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
CXX = g++
CXXFLAGS = -std=c++14 -Wall -Wextra
TEST_FLAGS = -lgtest -lgmock -pthread
# Find all subdirectories in the apps folder
APP_DIRS := $(wildcard apps/*)
# Generate targets for each app
APPS := $(notdir $(APP_DIRS))
# Find all test directories
TEST_DIRS := $(wildcard tests/*)
# Generate include paths for all app directories
APP_INCLUDE_PATHS := $(addprefix -I,$(APP_DIRS))
# Default target to build all apps and tests
all: $(APPS) tests
# Rule to build each app
$(APPS):
@echo "Building $@..."
$(MAKE) -C apps/$@
# Build and run tests
tests: $(TEST_DIRS)
$(TEST_DIRS):
@echo "Building and running tests for $@..."
$(CXX) $(CXXFLAGS) $(APP_INCLUDE_PATHS) -o $@/run_tests $@/*.cpp $(TEST_FLAGS)
$@/run_tests
# Clean all apps and tests
clean:
@for dir in $(APP_DIRS); do \
$(MAKE) -C $$dir clean; \
done
@for dir in $(TEST_DIRS); do \
rm -f $$dir/run_tests; \
done
.PHONY: all $(APPS) clean tests $(TEST_DIRS)