embedding example
authorRobert Bradshaw <robertwb@math.washington.edu>
Tue, 21 Apr 2009 09:10:19 +0000 (02:10 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Tue, 21 Apr 2009 09:10:19 +0000 (02:10 -0700)
Windows fixing needs help

Demos/embed/Makefile
Demos/embed/Makefile.unix
Demos/embed/embedded.pyx

index cd20f004913741c6154ce95e54f0a54e1ed6ab9a..1356f9a2a7902c3e3c58ac8e62bb4995cb9e5f4e 100644 (file)
@@ -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)
+\r
+embedded: embedded.o
+       gcc -o $@ $^ -lpython$(PYVERSION)\r
 
-%.c:   %.pyx
-       ../../bin/cython $<
+embedded.o: embedded.c
+       gcc -c $^ $(INCLUDES)\r
 
-%.o:   %.c
-       gcc -c -fPIC $(PYINCLUDE) $<
+embedded.c: embedded.pyx
+       @python ../../cython.py --embed embedded.pyx\r
 
-#%.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
index cd20f004913741c6154ce95e54f0a54e1ed6ab9a..1356f9a2a7902c3e3c58ac8e62bb4995cb9e5f4e 100644 (file)
@@ -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)
+\r
+embedded: embedded.o
+       gcc -o $@ $^ -lpython$(PYVERSION)\r
 
-%.c:   %.pyx
-       ../../bin/cython $<
+embedded.o: embedded.c
+       gcc -c $^ $(INCLUDES)\r
 
-%.o:   %.c
-       gcc -c -fPIC $(PYINCLUDE) $<
+embedded.c: embedded.pyx
+       @python ../../cython.py --embed embedded.pyx\r
 
-#%.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
index 90d62f67eb6e22ba22194d19c0f6d4ea61b13970..85c15ae5b4d05ba2cd1fcdb83e16e4fd3def7935 100644 (file)
@@ -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."