-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmakefile
More file actions
133 lines (96 loc) · 3.19 KB
/
makefile
File metadata and controls
133 lines (96 loc) · 3.19 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#-----------------------------------------------------------------------------#
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 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
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
#-----------------------------------------------------------------------------#
# tests
test: $(EXE) python-build
@echo "Running all tests..."
@PYTHONPATH=./ pytest
test-cli: $(EXE)
@echo "Running CLI tests..."
@PYTHONPATH=./ pytest tests/test_cli.py
test-python: python-build
@echo "Running Python tests..."
@PYTHONPATH=./ pytest tests/test_python.py
#-----------------------------------------------------------------------------#
# clean
test-clean:
rm -rf .pytest_cache
find tests/ -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
clean: cpp-clean python-clean test-clean
#-----------------------------------------------------------------------------#
# github actions
github-action-lint: .github/workflows/pypi-deploy.yml
actionlint $<
# for reference, see:
# https://github.com/rhysd/actionlint
#-----------------------------------------------------------------------------#