Permalink
Browse files

add --pymain example

Add an example of building a Python interpreter to the README and to the
Makefile.
  • Loading branch information...
1 parent a365380 commit 8e144375a1124d2ae17fff734033658871c0df9e @MarkLodato committed Oct 4, 2009
Showing with 32 additions and 6 deletions.
  1. +2 −0 .gitignore
  2. +21 −1 README.rst
  3. +9 −5 example/Makefile
View
@@ -2,3 +2,5 @@
/example/combinatorics.c
/example/nCr.c
/example/nCr
+/example/python.c
+/example/python
View
@@ -74,7 +74,27 @@ contains a Python interpreter and both Cython modules. ::
$ ./nCr 15812351235 12
5.10028093999e+113
-
+You may wish to build a normal Python interpreter, rather than having one
+module as "main". This may happen if you want to use your module from an
+interactive shell or from another script, yet you still want it statically
+linked so you can profile it with gprof. To do this, add the ``--pymain``
+flag to ``cython_freeze``. In the Makefile, the *python* executable is built
+like this. ::
+
+ $ cython_freeze --pymain combinatorics cmath -o python.c
+ $ gcc -c python.c
+ $ gcc python.o combinatorics.o cmath.o -o python
+
+Now ``python`` is a normal Python interpreter, but the cmath and combinatorics
+modules will be built into the executable. ::
+
+ $ python
+ Python 2.6.2 (release26-maint, Apr 19 2009, 01:58:18)
+ [GCC 4.3.3] on linux2
+ Type "help", "copyright", "credits" or "license" for more information.
+ >>> import cmath
+ >>> cmath.factorial(155)
+ 4.7891429014634364e+273
PREREQUISITES
View
@@ -14,25 +14,29 @@ LDLIBS = $(PY_LDLIBS)
# Name of executable
-TARGET = nCr
+TARGETS = nCr python
# List of Cython source files, with main module first.
CYTHON_SOURCE = combinatorics.pyx cmath.pyx
CYTHON_SECONDARY = $(CYTHON_SOURCE:.pyx=.c)
-all : $(TARGET)
+all : $(TARGETS)
-$(TARGET) : $(TARGET).o $(CYTHON_SOURCE:.pyx=.o)
+nCr : nCr.o $(CYTHON_SOURCE:.pyx=.o)
+python : python.o $(CYTHON_SOURCE:.pyx=.o)
-$(TARGET).c :
+nCr.c :
$(CYTHON_FREEZE) $(CYTHON_SOURCE:.pyx=) > $@
+python.c :
+ $(CYTHON_FREEZE) --pymain $(CYTHON_SOURCE:.pyx=) > $@
+
%.c : %.pyx
$(CYTHON) $(CYTHONFLAGS) $^
clean:
- $(RM) *.o $(CYTHON_SECONDARY) $(TARGET)
+ $(RM) *.o $(CYTHON_SECONDARY) $(TARGETS)
.PHONY: clean
.SECONDARY: $(CYTHON_SECONDARY)

0 comments on commit 8e14437

Please sign in to comment.