Skip to content

Instantly share code, notes, and snippets.

@yudhastyawan
Created February 3, 2020 05:13
Show Gist options
  • Save yudhastyawan/86c21aea97d981ecfa7f3f8804eddda5 to your computer and use it in GitHub Desktop.
Save yudhastyawan/86c21aea97d981ecfa7f3f8804eddda5 to your computer and use it in GitHub Desktop.
A Makefile example for SWIG (standard)
CXX = gcc
INCLUDES = -I./
COMPFLAGS = -c -Wall -fPIC
PYINC = /home/yudha/applications/miniconda3/include/python3.7m
SWIG = /usr/bin/swig
PACKAGE = example
OPT = -O2
# BUILD_DIR = ./buildpack
BINARIES = $(PACKAGE).o _$(PACKAGE).so $(PACKAGE)_wrap.o $(PACKAGE)_wrap.c
BINARIESEND = $(PACKAGE).o $(PACKAGE)_wrap.o $(PACKAGE)_wrap.c
all: clean $(PACKAGE).o _$(PACKAGE).so cleanend
@echo "it has been finished"
_$(PACKAGE).so: $(PACKAGE).o $(PACKAGE)_wrap.o
@$(CXX) -shared $^ -o $@
$(PACKAGE)_wrap.o: $(PACKAGE)_wrap.c
@$(CXX) $(OPT) $(COMPFLAGS) $(INCLUDES) -I$(PYINC) $(PACKAGE)_wrap.c
$(PACKAGE).o: $(PACKAGE).c
@$(CXX) $(OPT) $(COMPFLAGS) $^
$(PACKAGE)_wrap.c: $(PACKAGE).i
@$(SWIG) -python $(INCLUDES) $^
# $(PACKAGE)_mkdir:
# echo "foo"
# if [ -d "$(BUILD_DIR)" ]; then \
# echo "Dir exists"; \
# else \
# echo "Dir not exists" && mkdir $(BUILD_DIR); \
# fi
clean:
@for file in $(BINARIES); do \
if [ -f $$file ] ; \
then \
echo $$file && echo "is exist -> deleting" && rm -f $$file ; \
fi; \
done;
cleanend:
@for file in $(BINARIESEND); do \
if [ -f $$file ] ; \
then \
echo $$file && echo "is exist -> deleting" && rm -f $$file ; \
fi; \
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment