-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
75 lines (61 loc) · 1.71 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
# Python related variables.
PYTHON_VERSION := 3.12.6
PYTHON_SRC_DIR := $(PWD)/.Python
PYTHON_TGT_DIR := $(PWD)/.venv
PYTHON_MAKE_FLAGS := -s -j
PYTHON_SRC_REPO := https://github.com/python/cpython.git
# Pip install options.
PIP_REQUIREMENTS_FILE := $(PWD)/requirements.txt
PIP_INSTALL_PACKAGE_INDEX_OPTIONS :=
VPATH := $(PYTHON_SRC_DIR):$(PYTHON_TGT_DIR)/bin
configure:
mkdir -p $(PYTHON_SRC_DIR)
cd $(PYTHON_SRC_DIR); \
git clone $(PYTHON_SRC_REPO) --branch v$(PYTHON_VERSION) --depth 1 .
# Compile Python.
python: configure
@echo "Creating target dir..."
mkdir -p $(PYTHON_TGT_DIR)
@echo "Creating target dir...Done!"
@echo "Compiling Python..."
cd $(PYTHON_SRC_DIR); \
./configure --prefix=$(PYTHON_TGT_DIR); \
make $(PYTHON_MAKE_FLAGS); \
make install
@echo "Compiling Python...Done!"
# Create symlink for python.
ln -sf $(PYTHON_TGT_DIR)/bin/python3 $(PYTHON_TGT_DIR)/bin/python
pip: python
# Create symlink for pip.
ln -sf $(PYTHON_TGT_DIR)/bin/pip3 $(PYTHON_TGT_DIR)/bin/pip
run: python
$< $(argv)
.PHONY: ping
ping: python
@echo "$$(date +'%T.%N') ping!"
@$< -c "import datetime;print(datetime.datetime.now().strftime('%H:%M:%S.%f'),'pong!')"
.PHONY: pip_install
pip_install: pip
$< install -r $(PIP_REQUIREMENTS_FILE) $(PIP_INSTALL_PACKAGE_INDEX_OPTIONS)
.PHONY: install
install: pip
# Install setuptools first.
$< install setuptools
$< install -e .
.PHONY: clean_venv
clean_venv:
rm -rf $(PYTHON_TGT_DIR)
.PHONY: clean
clean:
rm -rf $(PYTHON_SRC_DIR) $(PYTHON_TGT_DIR)
# Function for starting scripts.
define run_script
if [ "$(RUNNER)" = "python" ]; then \
$(2) $(1).py; \
elif [ "$(RUNNER)" = "bash" ]; then \
bash $(1).sh; \
else \
echo "Unsupported runner: $(RUNNER)"; \
exit 1; \
fi
endef