-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
52 lines (39 loc) · 1.1 KB
/
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
43
44
45
46
47
48
49
50
51
52
# Copyright (c) 2022-2024 Dr. Colin Hirsch
.SUFFIXES:
.SECONDARY:
UNAME_S := $(shell uname -s)
# For Darwin (Mac OS X / macOS) we assume that the default compiler
# clang++ is used; when $(CXX) is some version of g++, then
# $(CXXSTD) has to be set to -std=c++17 (or newer) so
# that -stdlib=libc++ is not automatically added.
ifeq ($(CXXSTD),)
CXXSTD := -std=c++17
ifeq ($(UNAME_S),Darwin)
CXXSTD += -stdlib=libc++
endif
endif
CPPFLAGS ?= -pedantic
CXXFLAGS ?= -Wall -Wextra -Werror -O3
HEADERS := $(shell find . -name '*.hpp')
SOURCES := $(shell find . -name '*.cpp')
DEPENDS := $(SOURCES:./%.cpp=build/dep/%.d)
BINARIES := $(SOURCES:./%.cpp=build/bin/%)
.PHONY: all
all: compile tests
.PHONY: compile
compile: $(BINARIES)
tests: build/bin/tests
build/bin/tests
.PHONY: clean
clean:
@rm -rf build/*
@find . -name '*~' -delete
build/dep/%.d: ./%.cpp Makefile
@mkdir -p $(@D)
$(CXX) $(CXXSTD) $(CPPFLAGS) -MM -MQ $@ $< -o $@
build/bin%: ./%.cpp build/dep/%.d
@mkdir -p $(@D)
$(CXX) $(CXXSTD) $(CPPFLAGS) $(CXXFLAGS) $< $(LDFLAGS) -o $@
ifeq ($(findstring $(MAKECMDGOALS),clean),)
-include $(DEPENDS)
endif