summaryrefslogtreecommitdiff
path: root/Makefile
blob: 91a92e4d149acafc3e8fd340fb5886f12fcc1823 (plain) (blame)
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
OPTIMIZE ?= -O3
DEBUG ?= -g

AR ?= ar
CXX ?= g++

CXXFLAGS := -Wall -Werror -std=c++20 -fPIC -iquote . ${OPTIMIZE} ${DEBUG}

.DEFAULT: issim

libname = $(shell realpath --canonicalize-missing --relative-to . build/$(dir $(1))/lib$(notdir $(1)))

define mklib =

ifneq ($(wildcard $(1)/*.cpp),)

$$(info Component $(call libname,$(1)))

$(call libname,$(1).a): $(patsubst %.cpp,build/%.o,$(wildcard $(1)/*.cpp))
	@mkdir -p $$(dir $$@)
	$${AR} cr $$@ $$+

$(call libname,$(1).so): $(patsubst %.cpp,build/%.o,$(wildcard $(1)/*.cpp))
	@mkdir -p $$(dir $$@)
	$${CXX} $${CXXFLAGS} -shared -o $$@ $$+

PARTARS += $(call libname,$(1).a)
PARTSOS += $(call libname,$(1).so)

else

$$(info Header-only component $(1))

endif

endef

PARTS := $(shell find * -type d -\( -name build -prune -o -name tools -prune -o -print -\))
PARTARS :=
PARTSOS :=

$(foreach part,${PARTS},$(eval $(call mklib,${part})))

MAINOBJS := $(patsubst %.cpp,build/%.o,$(wildcard *.cpp))
MAINOBJS += build/git-tag.o

$(info )

issim: build/issim-dynamic
	@ln -sf $< $@
.PHONY: issim

issim-static: build/issim-static
	@ln -sf $< $@
.PHONY: issim-static

build/issim-dynamic: ${MAINOBJS} ${PARTSOS}
	@mkdir -p $(dir $@)
	${CXX} ${CXXFLAGS} -o $@ $+

build/issim-static: ${MAINOBJS} ${PARTARS}
	@mkdir -p $(dir $@)
	${CXX} ${CXXFLAGS} -o $@ $+

clean:
	rm -rf build issim issim-static
.PHONY: clean

build/git-tag.cpp:
	@mkdir -p $(dir $@)
	tools/get-git-tag > $@
.PHONY: build/git-tag.cpp

include $(shell find -type f -name \*.d)

build/%.o: %.cpp
	@mkdir -p $(dir $@)
	${CXX} ${CXXFLAGS} -MMD -c -o $@ $<

build/%.o: build/%.cpp
	@mkdir -p $(dir $@)
	${CXX} ${CXXFLAGS} -MMD -c -o $@ $<

.SUFFIXES:
.SECONDARY: