From 9ad9a05e1cfabf252a538e786f303e03acd18743 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Tue, 21 Apr 2009 02:10:19 -0700 Subject: [PATCH] embedding example Windows fixing needs help --- Demos/embed/Makefile | 37 +++++++++++++------------------------ Demos/embed/Makefile.unix | 37 +++++++++++++------------------------ Demos/embed/embedded.pyx | 10 ++++++---- 3 files changed, 32 insertions(+), 52 deletions(-) diff --git a/Demos/embed/Makefile b/Demos/embed/Makefile index cd20f004..1356f9a2 100644 --- a/Demos/embed/Makefile +++ b/Demos/embed/Makefile @@ -1,30 +1,19 @@ -PYVERSION = 2.2 -PYHOME = $(HOME)/pkg/python/$(PYVERSION) -PYARCH = $(PYHOME)/$(ARCH) -PYINCLUDE = \ - -I$(PYHOME)/include/python$(PYVERSION) \ - -I$(PYARCH)/include/python$(PYVERSION) -PYLIB = -L$(PYARCH)/lib/python$(PYVERSION)/config \ - -lpython$(PYVERSION) \ - -ldl -lpthread -lutil -lm +# Makefile for creating our standalone Cython program +PYVERSION=2.3 +PYPREFIX=/usr +INCLUDES=-I$(PYPREFIX)/include/python$(PYVERSION) + +embedded: embedded.o + gcc -o $@ $^ -lpython$(PYVERSION) -%.c: %.pyx - ../../bin/cython $< +embedded.o: embedded.c + gcc -c $^ $(INCLUDES) -%.o: %.c - gcc -c -fPIC $(PYINCLUDE) $< +embedded.c: embedded.pyx + @python ../../cython.py --embed embedded.pyx -#%.so: %.o -# gcc -shared $< -lm -o $@ - -all: main - -main: main.o embedded.o - gcc main.o embedded.o $(PYLIB) -o main +all: embedded clean: @echo Cleaning Demos/embed - @rm -f *~ *.o *.so core core.* embedded.h embedded.c main - -embedded.h: embedded.c -main.o: embedded.h + @rm -f *~ *.o *.so core core.* *.c embedded diff --git a/Demos/embed/Makefile.unix b/Demos/embed/Makefile.unix index cd20f004..1356f9a2 100644 --- a/Demos/embed/Makefile.unix +++ b/Demos/embed/Makefile.unix @@ -1,30 +1,19 @@ -PYVERSION = 2.2 -PYHOME = $(HOME)/pkg/python/$(PYVERSION) -PYARCH = $(PYHOME)/$(ARCH) -PYINCLUDE = \ - -I$(PYHOME)/include/python$(PYVERSION) \ - -I$(PYARCH)/include/python$(PYVERSION) -PYLIB = -L$(PYARCH)/lib/python$(PYVERSION)/config \ - -lpython$(PYVERSION) \ - -ldl -lpthread -lutil -lm +# Makefile for creating our standalone Cython program +PYVERSION=2.3 +PYPREFIX=/usr +INCLUDES=-I$(PYPREFIX)/include/python$(PYVERSION) + +embedded: embedded.o + gcc -o $@ $^ -lpython$(PYVERSION) -%.c: %.pyx - ../../bin/cython $< +embedded.o: embedded.c + gcc -c $^ $(INCLUDES) -%.o: %.c - gcc -c -fPIC $(PYINCLUDE) $< +embedded.c: embedded.pyx + @python ../../cython.py --embed embedded.pyx -#%.so: %.o -# gcc -shared $< -lm -o $@ - -all: main - -main: main.o embedded.o - gcc main.o embedded.o $(PYLIB) -o main +all: embedded clean: @echo Cleaning Demos/embed - @rm -f *~ *.o *.so core core.* embedded.h embedded.c main - -embedded.h: embedded.c -main.o: embedded.h + @rm -f *~ *.o *.so core core.* *.c embedded diff --git a/Demos/embed/embedded.pyx b/Demos/embed/embedded.pyx index 90d62f67..85c15ae5 100644 --- a/Demos/embed/embedded.pyx +++ b/Demos/embed/embedded.pyx @@ -1,5 +1,7 @@ -cdef public void spam(): - praise() -def praise(): - print "Spam, glorious spam!" +print __name__ + +if __name__ == "__main__": + print "Hi, I'm embedded." +else: + print "I'm being imported." -- 2.26.2