Skip to content

Instantly share code, notes, and snippets.

@SpotlightKid
Created October 7, 2020 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SpotlightKid/5fcf20783738692994ab5d4b09218527 to your computer and use it in GitHub Desktop.
Save SpotlightKid/5fcf20783738692994ab5d4b09218527 to your computer and use it in GitHub Desktop.
Makefile for creating a standalone program via Cython from a *.py / *.pyx file
# Makefile for creating a standalone program via Cython from a *.py / *.pyx file
PYX ?= main.pyx
PROG ?= $(basename $(PYX))
PYTHON ?= python
PYVERSION = $(shell $(PYTHON) -c 'import sys;print("%d.%d" % sys.version_info[:2])')
PYMAJOR = $(shell $(PYTHON) -c 'import sys;print(sys.version_info[0])')
PYPREFIX = /usr
INCLUDES = -I$(PYPREFIX)/include/python$(PYVERSION)
$(PROG): $(PROG).o
@echo "Linking $(PROG) ..."
gcc -o $@ -lpython$(PYVERSION) $(LDFLAGS) $^
$(PROG).o: $(PROG).c
@echo "Compiling $(PROG).o ..."
gcc $(CFLAGS) -c $^ $(INCLUDES)
$(PROG).c: $(PYX)
@echo "Cythonizing $(PYX) ..."
@cython -$(PYMAJOR) --embed $(PYX)
all: $(PROG)
clean:
@echo Cleaning $(PROG)...
@rm -f *~ *.o *.so core core.* *.c $(PROG)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment