Thierry FOURNIER | d8b5c77 | 2018-02-23 11:40:03 +0100 | [diff] [blame] | 1 | DESTDIR = |
| 2 | PREFIX = /usr/local |
| 3 | BINDIR = $(PREFIX)/bin |
| 4 | |
| 5 | CC = gcc |
| 6 | LD = $(CC) |
| 7 | |
| 8 | CFLAGS = -g -O2 -Wall -Werror -pthread |
| 9 | LDFLAGS = -lpthread |
| 10 | |
| 11 | OBJS = spoa.o |
| 12 | |
Thierry FOURNIER | 6908c95 | 2018-02-23 15:20:55 +0100 | [diff] [blame] | 13 | ifneq ($(USE_LUA),) |
| 14 | OBJS += ps_lua.o |
| 15 | ifneq ($(LUA_INC),) |
| 16 | CFLAGS += -I$(LUA_INC) |
| 17 | endif |
| 18 | ifneq ($(LUA_LIB),) |
| 19 | LDLIBS += -L$(LUA_LIB) |
| 20 | endif |
| 21 | LDLIBS += -ldl -Wl,--export-dynamic -llua -lm -Wl,--no-export-dynamic |
| 22 | endif |
Thierry FOURNIER | d8b5c77 | 2018-02-23 11:40:03 +0100 | [diff] [blame] | 23 | |
Thierry FOURNIER | 00a0225 | 2018-02-25 20:59:57 +0100 | [diff] [blame] | 24 | ifneq ($(USE_PYTHON),) |
| 25 | OBJS += ps_python.o |
Gilchrist Dadaglo | 3e235d3 | 2020-05-06 12:25:31 +0000 | [diff] [blame] | 26 | |
| 27 | # "--embed" flag is supported (and required) only from python 3.8+ |
| 28 | check_python_config := $(shell if python3-config --embed; then echo "python3.8+"; \ |
| 29 | elif hash python3-config; then echo "python3"; \ |
| 30 | elif hash python-config; then echo "python2"; fi) |
| 31 | |
| 32 | ifeq ($(check_python_config), python3.8+) |
| 33 | PYTHON_DEFAULT_INC := $(shell python3-config --includes) |
| 34 | PYTHON_DEFAULT_LIB := $(shell python3-config --libs --embed) |
| 35 | else ifeq ($(check_python_config), python3) |
| 36 | PYTHON_DEFAULT_INC := $(shell python3-config --includes) |
| 37 | PYTHON_DEFAULT_LIB := $(shell python3-config --libs) |
| 38 | else ifeq ($(check_python_config), python2) |
| 39 | PYTHON_DEFAULT_INC := $(shell python-config --includes) |
| 40 | PYTHON_DEFAULT_LIB := $(shell python-config --libs) |
| 41 | endif |
| 42 | |
| 43 | |
| 44 | # Add default path |
| 45 | ifneq ($(PYTHON_DEFAULT_INC),) |
| 46 | CFLAGS += $(PYTHON_DEFAULT_INC) |
| 47 | else |
Thierry FOURNIER | 00a0225 | 2018-02-25 20:59:57 +0100 | [diff] [blame] | 48 | CFLAGS += -I/usr/include/python2.7 |
Gilchrist Dadaglo | 3e235d3 | 2020-05-06 12:25:31 +0000 | [diff] [blame] | 49 | endif |
| 50 | ifneq ($(PYTHON_DEFAULT_LIB),) |
| 51 | LDLIBS += $(PYTHON_DEFAULT_LIB) |
| 52 | else |
Thierry FOURNIER | 00a0225 | 2018-02-25 20:59:57 +0100 | [diff] [blame] | 53 | LDLIBS += -lpython2.7 |
| 54 | endif |
| 55 | |
Gilchrist Dadaglo | 3e235d3 | 2020-05-06 12:25:31 +0000 | [diff] [blame] | 56 | # Add user additional paths if any |
| 57 | ifneq ($(PYTHON_INC),) |
| 58 | CFLAGS += -I$(PYTHON_INC) |
| 59 | endif |
| 60 | ifneq ($(PYTHON_LIB),) |
| 61 | LDLIBS += -L$(PYTHON_LIB) |
| 62 | endif |
| 63 | |
| 64 | LDLIBS +=-Wl,--export-dynamic |
| 65 | endif |
| 66 | |
Thierry FOURNIER | d8b5c77 | 2018-02-23 11:40:03 +0100 | [diff] [blame] | 67 | spoa: $(OBJS) |
Thierry FOURNIER | 6908c95 | 2018-02-23 15:20:55 +0100 | [diff] [blame] | 68 | $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS) |
Thierry FOURNIER | d8b5c77 | 2018-02-23 11:40:03 +0100 | [diff] [blame] | 69 | |
| 70 | install: spoa |
| 71 | install spoa $(DESTDIR)$(BINDIR) |
| 72 | |
| 73 | clean: |
| 74 | rm -f spoa $(OBJS) |
| 75 | |
| 76 | %.o: %.c |
| 77 | $(CC) $(CFLAGS) -c -o $@ $< |