blob: e7b20db4c00fb869cac65ad07ec090a279f42750 [file] [log] [blame]
Thierry FOURNIERd8b5c772018-02-23 11:40:03 +01001DESTDIR =
2PREFIX = /usr/local
3BINDIR = $(PREFIX)/bin
4
5CC = gcc
6LD = $(CC)
7
8CFLAGS = -g -O2 -Wall -Werror -pthread
9LDFLAGS = -lpthread
10
11OBJS = spoa.o
12
Thierry FOURNIER6908c952018-02-23 15:20:55 +010013ifneq ($(USE_LUA),)
14OBJS += ps_lua.o
15ifneq ($(LUA_INC),)
16CFLAGS += -I$(LUA_INC)
17endif
18ifneq ($(LUA_LIB),)
19LDLIBS += -L$(LUA_LIB)
20endif
21LDLIBS += -ldl -Wl,--export-dynamic -llua -lm -Wl,--no-export-dynamic
22endif
Thierry FOURNIERd8b5c772018-02-23 11:40:03 +010023
Thierry FOURNIER00a02252018-02-25 20:59:57 +010024ifneq ($(USE_PYTHON),)
25OBJS += ps_python.o
Gilchrist Dadaglo3e235d32020-05-06 12:25:31 +000026
27# "--embed" flag is supported (and required) only from python 3.8+
28check_python_config := $(shell if python3-config --embed; then echo "python3.8+"; \
29elif hash python3-config; then echo "python3"; \
30elif hash python-config; then echo "python2"; fi)
31
32ifeq ($(check_python_config), python3.8+)
33PYTHON_DEFAULT_INC := $(shell python3-config --includes)
34PYTHON_DEFAULT_LIB := $(shell python3-config --libs --embed)
35else ifeq ($(check_python_config), python3)
36PYTHON_DEFAULT_INC := $(shell python3-config --includes)
37PYTHON_DEFAULT_LIB := $(shell python3-config --libs)
38else ifeq ($(check_python_config), python2)
39PYTHON_DEFAULT_INC := $(shell python-config --includes)
40PYTHON_DEFAULT_LIB := $(shell python-config --libs)
41endif
42
43
44# Add default path
45ifneq ($(PYTHON_DEFAULT_INC),)
46CFLAGS += $(PYTHON_DEFAULT_INC)
47else
Thierry FOURNIER00a02252018-02-25 20:59:57 +010048CFLAGS += -I/usr/include/python2.7
Gilchrist Dadaglo3e235d32020-05-06 12:25:31 +000049endif
50ifneq ($(PYTHON_DEFAULT_LIB),)
51LDLIBS += $(PYTHON_DEFAULT_LIB)
52else
Thierry FOURNIER00a02252018-02-25 20:59:57 +010053LDLIBS += -lpython2.7
54endif
55
Gilchrist Dadaglo3e235d32020-05-06 12:25:31 +000056# Add user additional paths if any
57ifneq ($(PYTHON_INC),)
58CFLAGS += -I$(PYTHON_INC)
59endif
60ifneq ($(PYTHON_LIB),)
61LDLIBS += -L$(PYTHON_LIB)
62endif
63
64LDLIBS +=-Wl,--export-dynamic
65endif
66
Thierry FOURNIERd8b5c772018-02-23 11:40:03 +010067spoa: $(OBJS)
Thierry FOURNIER6908c952018-02-23 15:20:55 +010068 $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
Thierry FOURNIERd8b5c772018-02-23 11:40:03 +010069
70install: spoa
71 install spoa $(DESTDIR)$(BINDIR)
72
73clean:
74 rm -f spoa $(OBJS)
75
76%.o: %.c
77 $(CC) $(CFLAGS) -c -o $@ $<