-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
76 lines (51 loc) · 1.71 KB
/
Copy pathMakefile
File metadata and controls
76 lines (51 loc) · 1.71 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
PROJ_NAME := YInit
SRC_DIR := ./src
BLD_DIR := ./build
OUTPUT := yinit-bin
MODULE := yinit
ENTRY_POINT := launcher.py
CFLAGS := -fno-strict-overflow -Wsign-compare -O2 -Wall
PY_CFLAGS = $(shell python3-config --cflags)
PY_INCLUDES := $(shell python3-config --includes)
PY_LIB = $(shell python3-config --ldflags)
PY_FILES := $(shell find ${SRC_DIR}/${MODULE} -name '*.py' | grep -ve '__.*__\.py')
PY_SRC := $(patsubst ${SRC_DIR}/%, %, ${PY_FILES})
C_SRC := $(patsubst ${SRC_DIR}/%.py, ${BLD_DIR}/%.c, ${PY_FILES})
OBJS := $(patsubst %.c, %.o, ${C_SRC})
MOD_NAMES := $(patsubst ${SRC_DIR}/%.py, %, ${PY_FILES} | tr '/' '.')
ENTRY_POINT_C := $(patsubst %.py,%.c, ${ENTRY_POINT})
ifdef DEBUG
$(info ---=== DEBUG mode is ON: Compiling with debug flags. ===---)
ifeq ("${DEBUG}","y")
CFLAGS += -g1
else ifeq ("${DEBUG}","Y")
CFLAGS += -g3
endif
# TODO: if ${DEBUG}: 0-3 add appropriate level
else
CFLAGS += -DNDEBUG -g
endif
all: ${OUTPUT}
cythonize:
mkdir -p ${BLD_DIR}/yinit
cython --embed -3 -w ${SRC_DIR} \
${ENTRY_POINT} \
--embed-modules 'main,runenv' \
-o ../${BLD_DIR}/launcher.c
$(foreach mod_file,${PY_SRC}, \
cython -3 -w ${SRC_DIR} ${mod_file} -o $(patsubst %.py, ../${BLD_DIR}/%.c, ${mod_file});)
# Final compilation
compile:
$(foreach mod_file,${PY_SRC}, \
gcc ${CFLAGS} ${PY_INCLUDES} -c ${BLD_DIR}/$(patsubst %.py,%.c, ${mod_file}) -o ${BLD_DIR}/$(patsubst %.py,%.o, ${mod_file});)
gcc ${CFLAGS} ${PY_INCLUDES} \
${BLD_DIR}/${ENTRY_POINT_C} \
$(patsubst %.py, ${BLD_DIR}/%.o, ${PY_SRC}) \
$(shell python3-config --ldflags --embed) \
-o ${BLD_DIR}/${OUTPUT}
${OUTPUT}: cythonize compile
cpyrun:
cd src && python -m yinit ${ARGS}
clean:
rm -f ${C_SRC} ${OBJS} \
${BLD_DIR}/${OUTPUT}