Skip to content

Instantly share code, notes, and snippets.

@guicho271828
Created January 14, 2015 12:44
Show Gist options
  • Save guicho271828/6385601c7a875fe3d77b to your computer and use it in GitHub Desktop.
Save guicho271828/6385601c7a875fe3d77b to your computer and use it in GitHub Desktop.
Makefile for converting C header files with GCC extensions into CFFI binding using SWIG
.PHONY: all clean
# .PRECIOUS: %.i1 %.i2 %.i3
LD = -I/usr/include -I/usr/include/linux
headers = $(shell ls *.h)
$(info $(headers))
lisp = $(patsubst %.h,%.lisp,$(headers))
all: $(lisp) shared.lisp
%.i1: %.h Makefile
cpp -std=c99 -undef $< > $@
%.i2: %.i1 Makefile
awk '/^# [0-9]+ ".*"/{FILE=$$3} /^[^#].*/{if(FILE=="\"$*.h\""){print $$0}else{printf "//%s ignored\n",FILE}}' $< > $@
shared.lisp: shared.swig
swig -cffi $(LD) -importall -module shared $<
%.i3: %.i2 shared.swig Makefile
cat shared.swig $< > $@
%.lisp: %.i3 Makefile
swig -cffi $(LD) -includeall -noswig-lisp -module $* $<
# swig -cffi $(LD) -importall -noswig-lisp -module $* $<
# -importall - Follow all #include statements as imports
# -includeall - Follow all #include statements
clean:
git clean -xf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment