forked from RecordEvolution/IMCtermite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
114 lines (82 loc) · 2.73 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#-----------------------------------------------------------------------------#
SHELL := /bin/bash
# name of executable and CLI tool
EXE = imctermite
# directory names
SRC = src/
LIB = lib/
PYT = python/
# list headers and include directories
HPP = $(wildcard $(LIB)/*.hpp)
IPP = $(shell find $(LIB) -type f -name '*.hpp')
KIB = $(shell find $(LIB) -type d)
MIB = $(foreach dir,$(KIB),-I $(dir))
# choose compiler and its options
CC = g++ -std=c++17
OPT = -O3 -Wall -Wconversion -Wpedantic -Werror -Wunused-variable -Wsign-compare
# determine git version/commit and release tag
GTAG := $(shell git tag -l --sort=version:refname | tail -n1 | sed "s/$^v//g")
GHSH := $(shell git rev-parse HEAD | head -c8)
GVSN := $(shell cat python/VERSION | tr -d ' \n')
# current timestamp
TMS = $(shell date +%Y%m%dT%H%M%S)
# define install location
INST := /usr/local/bin
#-----------------------------------------------------------------------------#
# C++ and CLI tool
# build executable
$(EXE): check-tags $(GVSN) main.o
$(CC) $(OPT) main.o -o $@
# build main.cpp and include git version/commit tag
main.o: src/main.cpp $(IPP)
@cp $< $<.cpp
@sed -i 's/TAGSTRING/$(GTAG)/g' $<.cpp
@sed -i 's/HASHSTRING/$(GHSH)/g' $<.cpp
@sed -i 's/TIMESTAMPSTRING/$(TMS)/g' $<.cpp
$(CC) -c $(OPT) $(MIB) $<.cpp -o $@
@rm $<.cpp
install: $(EXE)
cp $< $(INST)/
uninstall: $(INST)/$(EXE)
rm $<
cpp-clean:
rm -vf $(EXE)
rm -vf *.o
#-----------------------------------------------------------------------------#
# C++ linter
check-code:
cppcheck --enable=all -I lib/ src/main.cpp
#-----------------------------------------------------------------------------#
# versions
$(GTAG):
@echo "consistent versions check successful: building $(GTAG)"
check-tags:
@echo "latest git tag: $(GTAG)"
@echo "latest git hash: $(GHSH)"
@echo "python version: $(GVSN)"
#-----------------------------------------------------------------------------#
# Docker
docker-build:
docker build ./ --tag imctermite:0.1
docker-run:
docker run -it --rm imctermite:0.1 /bin/bash
#-----------------------------------------------------------------------------#
# python
python-build: check-tags $(GVSN)
make -C python/ build-inplace
cp python/imctermite*.so ./ -v
python-clean:
make -C python/ clean
rm -vf imctermite*.so
python-test:
PYTHONPATH=./ python python/examples/usage.py
#-----------------------------------------------------------------------------#
# clean
clean: cpp-clean python-clean
#-----------------------------------------------------------------------------#
# github actions
github-action-lint: .github/workflows/pypi-deploy.yml
actionlint $<
# for reference, see:
# https://github.com/rhysd/actionlint
#-----------------------------------------------------------------------------#