summaryrefslogtreecommitdiff
path: root/Makefile
blob: 6d3a4ab9c602a5db6535f6a3db9432e2198f6b4a (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
OPTIMIZE ?= -O3
DEBUG ?= -g

AR ?= ar
CXX ?= g++

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

PARTS := $(shell find * -type d -\( -name build -prune -o -print -\))
PARTARS := $(addprefix build/lib, $(addsuffix .a, ${PARTS}))
PARTSOS := $(addprefix build/lib, $(addsuffix .so, ${PARTS}))

MAINOBJS := $(addprefix build/, $(addsuffix .o, $(basename $(wildcard *.cpp))))
MAINOBJS += build/git-tag.o

all: issim

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 $@)
	./get-git-tag > $@
.PHONY: build/git-tag.cpp

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

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

.SUFFIXES:
.SECONDARY:

.SECONDEXPANSION:

build/lib%.a: $$(addprefix build/, $$(addsuffix .o, $$(basename $$(wildcard %/*.cpp))))
	@mkdir -p $(dir $@)
	${AR} cr $@ $+

build/lib%.so: $$(addprefix build/, $$(addsuffix .o, $$(basename $$(wildcard %/*.cpp))))
	@mkdir -p $(dir $@)
	${CXX} ${CXXFLAGS} -shared -o $@ $+