Created
January 14, 2015 12:44
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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