-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
148 lines (130 loc) · 4.54 KB
/
Copy pathMakefile
File metadata and controls
148 lines (130 loc) · 4.54 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# vortex - GCode machine emulator
# Copyright (C) 2024-2026 Mitko Haralanov
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This project uses Meson and meson-python as the build system.
# However, to simplify development, this Makefile is here for
# convinience and to record the require build commands.
PYTHON ?= $(shell which python3)
PYTHON_DEBUG ?= $(shell which python3-debug)
GDB := $(shell which gdb)
VENV ?=
VENV_PYTHON := $(VENV)/bin/python3
DEBUG_OPTS :=
MESON_DEBUG_OPTS :=
VERSION=$(shell git describe --tags --abbrev=0)
KVER := $(shell uname -r)
ARCH := $(shell uname -m)
PYTHON_VERSION=$(shell $(PYTHON) -c "import platform; print(platform.python_version())")
PYTHON_VERSION_NUMS = $(subst ., ,$(PYTHON_VERSION))
# Setup Clang
CLANG_INCLUDE_DIR=$(shell llvm-config --includedir)
CLANG_LIB_DIR=$(shell llvm-config --libdir)
LIBRARY_PATH=$(shell llvm-config --libdir)
CC=clang
LD_LIBRATY_PATH += $(shell llvm-config --libdir)
CFLAGS += $(shell llvm-config --cflags)
LDFLAGS += -L$(shell llvm-config --libdir)
ifeq ($(DEBUG),1)
CFLAGS += -DVORTEX_DEBUG -g
ifeq ($(TIMER_DEBUG),1)
CFLAGS += -DVORTEX_TIMERS_DEBUG
ifeq ($(TIMER_DEBUG_LISTS),1)
CFLAGS += -DVORTEX_TIMERS_DEBUG_LISTS
endif
endif
MESON_BUILD_OPTS=--config-settings=setup-args="-Dbuildtype=debug"
endif
ifeq ($(VERBOSE),1)
MESON_BUILD_OPTS += -v -Ccompile-args="-v"
endif
export CC
export CFLAGS
export LDFLAGS
export CLANG_INCLUDE_DIR
export CLANG_LIB_DIR
export LIBRARY_PATH
export LD_LIBRARY_PATH
all: version
$(PYTHON) -m pip install --no-build-isolation \
--editable . $(MESON_BUILD_OPTS)
@if [ ! -L compile_commands.json ]; then \
ln -s build/cp$(word 1,$(PYTHON_VERSION_NUMS))$(word 2,$(PYTHON_VERSION_NUMS))/compile_commands.json \
compile_commands.json; \
fi
kmod:
mkdir -p build/kmod
$(MAKE) -C /lib/modules/$(KVER)/build M=$${PWD}/src/kmod
kmod_sign: kmod
/lib/modules/$(KVER)/build/scripts/sign-file sha256 \
/etc/pki/akmods/private/private_key.priv \
/etc/pki/akmods/certs/public_key.der \
$${PWD}/src/kmod/vortex.ko
kmod_install: kmod_sign
$(MAKE) -C /lib/modules/$(KVER)/build M=$${PWD}/src/kmod modules_install
version:
@echo $(VERSION) > version.txt
venv:
@if [ -z "$(VENV)" ]; then \
echo "ERROR: Virtual environment path not set"; \
exit 1; \
fi
@echo "Creating virtual environment in $(VENV)..."
@if [ ! -d $(VENV) ]; then \
virtualenv $(VENV); \
fi
@echo "Installing dependencies..."
$(VENV)/bin/pip install -r ./virtualenv.txt
wheel: venv version
$(VENV_PYTHON) -m build -w .
package: version
$(PYTHON) -m build -w .
mkdir -p vortex-$(VERSION)-$(ARCH)
mkdir vortex-$(VERSION)-$(ARCH)/vortex-kmod
cp src/kmod/vortex.[ch] src/kmod/Makefile vortex-$(VERSION)-$(ARCH)/vortex-kmod
cp dist/vortex-*.whl vortex-$(VERSION)-$(ARCH)
tar -jcf vortex-$(VERSION)-$(ARCH).tar.bz2 vortex-$(VERSION)-$(ARCH)
rm -rf vortex-$(VERSION)-$(ARCH)
install: wheel
$(VENV_PYTHON) -m pip install --force-reinstall dist/vortex-*.whl
gdb:
$(GDB) $(PYTHON_DEBUG) -ex 'r ./vortex_run.py $(GDB_OPTS)'
action-test:
@if [ -z "$(ACT)" ]; then \
echo "ERROR: Path to 'act' missing"; \
exit 1; \
fi
@mkdir -p /tmp/artifacts
@if ! sudo systemctl is-active -q docker.service; then \
sudo systemctl start docker.service; \
fi
sudo $(ACT) -W .github/workflows/build-check.yml -j build-x86 \
--artifact-server-path /tmp/artifacts
clean:
$(MAKE) -C /lib/modules/$(KVER)/build M=$${PWD}/src/kmod clean
rm -rf build dist builddir
rm -f compile_commands.json version.txt vortex-*.tar.bz2
help:
@echo "Makefile targets:"
@echo " venv - Setup emulator virtual environment"
@echo " wheel - Build wheel package"
@echo " package - Build source source/wheel package"
@echo " install - Install emulator in a virtual environment"
@echo " gdb - Start GDB debug sesion"
@echo " action-test - Test Github actions (requires 'act' tool)"
@echo " kmod - Build timing kernel module"
@echo " kmod_sign - Sign kernel module"
@echo " kmod_install - Install kernel module"
@echo " clean - Clean the build environment"