[pure-lang-svn] SF.net SVN: pure-lang: [158] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-06-01 18:24:50
|
Revision: 158 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=158&view=rev Author: agraef Date: 2008-06-01 11:24:53 -0700 (Sun, 01 Jun 2008) Log Message: ----------- Put runtime and interpreter into a shared library. Modified Paths: -------------- pure/trunk/ChangeLog pure/trunk/INSTALL pure/trunk/Makefile pure/trunk/interpreter.cc Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-05-28 07:52:52 UTC (rev 157) +++ pure/trunk/ChangeLog 2008-06-01 18:24:53 UTC (rev 158) @@ -1,3 +1,12 @@ +2008-06-01 Albert Graef <Dr....@t-...> + + * Makefile, interpreter.cc: Put the runtime and interpreter into a + separate shared library, to make it possible for modules to link + against the runtime, and to reduce the memory footprint when + multiple instances of the interpreter are run as different + processes. Also, this makes it possible to access the runtime + routines on systems where a program cannot dlopen itself. + 2008-05-28 Albert Graef <Dr....@t-...> * interpreter.cc, runtime.cc: Optimization pure_freenew calls. Modified: pure/trunk/INSTALL =================================================================== --- pure/trunk/INSTALL 2008-05-28 07:52:52 UTC (rev 157) +++ pure/trunk/INSTALL 2008-06-01 18:24:53 UTC (rev 158) @@ -4,11 +4,11 @@ These instructions (mostly by courtesy of Eddie Rucker, thanks Eddie!) explain how to compile and install LLVM (which is the compiler backend required by -Pure) and the Pure interpreter itself. More information about installing LLVM -and the required LLVM source packages can be found at http://llvm.org. Please -also have a look at the SYSTEM NOTES section at the end of this file which -describes the tweaks necessary to make Pure compile and run on various -platforms. +Pure) and the Pure interpreter itself. The instructions are for Linux and +similar Unix-like systems; the SYSTEM NOTES section at the end of this file +details the tweaks necessary to make Pure compile and run on various other +platforms. More information about installing LLVM and the required LLVM source +packages can be found at http://llvm.org. Pure is known to work on Linux and Mac OSX, but should compile (with the usual amount of tweaking) on all UNIX/POSIX-based platforms. We recommend using @@ -57,12 +57,15 @@ STEP 3. Configure, build and install LLVM as follows: $ cd llvm-2.2 -$ ./configure +$ ./configure --enable-optimized --disable-assertions --disable-expensive-checks --enable-targets=host-only $ make ENABLE_OPTIMIZED=1 $ sudo make install -(To do a debug build of LLVM, leave away the 'ENABLE_OPTIMIZED=1' parameter. -Note, however, that this will considerably slow down the Pure compiler.) +Note the configure flags; these are for an optimized (non-debug) build and +disable all compilation targets except the one for your system. To do a debug +build of LLVM, simply leave away all the extra configure parameters (except +possibly --enable-targets=host-only). Note, however, that this will +considerably slow down the Pure compiler. STEP 4. Get and unpack the Pure sources at: http://pure-lang.sf.net/ @@ -76,9 +79,12 @@ $ cd pure-x.y $ make $ sudo make install +$ sudo /sbin/ldconfig -Note that compiling Pure with optimizations enabled (this is the default) may -take quite a while, so please have some patience. +(The latter step is required on Linux systems to tell the dynamic linker to +update its cache so that it finds the Pure runtime library, libpure-x.y.so. +On other systems it may be sufficient to install the library in a location +which is searched by the dynamic linker.) After the build is complete, you can check that Pure is working correctly on your computer, as follows: @@ -138,35 +144,42 @@ $ cd pure-lang/pure/trunk $ make $ sudo make install +$ sudo /sbin/ldconfig OTHER COMPILATION OPTIONS ===== =========== ======= -By default, the pure program is installed under /usr/local/bin, with the -library files going into /usr/local/lib/pure. The installation directory can -be changed by editing the definition of the 'prefix' variable in the Makefile, -or by specifying the desired value on the 'make' command line, e.g.: +By default, the pure program is installed under /usr/local/bin, the +libpure-x.y.so library under /usr/local/lib, and the library scripts under +/usr/local/lib/pure. The installation directory can be changed by editing the +definition of the 'prefix' variable in the Makefile, or by specifying the +desired value on the 'make' command line, e.g.: $ make all install prefix=/usr Note that you should specify this option *both* at compile and installation time since certain default paths are hardcoded into the interpreter (but can be changed at runtime by setting corresponding environment variables, see the -manpage for details). +manpage for details). Also note that if you install Pure into a non-standard +location, you may have to set the LD_LIBRARY_PATH variable so that the dynamic +linker finds the Pure runtime library, libpure-x.y.so. After your build is done, you can (and should) also run 'make check' to verify that your Pure interpreter works correctly. This can be done without installing the software. In fact, there's no need to install the interpreter if you just want to take it for a test drive, you can simply run it from the -source directory. Just make sure that you set the PURELIB environment variable -to the lib directory in the sources which holds the prelude and the other -library scripts. The following command, +source directory, if you set up the following environment variables: -$ PURELIB=./lib ./pure +- LD_LIBRARY_PATH=. This is required on Linux systems so that libpure-x.y.so + is found. Other systems may require an analogous setting, or none at all. -will run the Pure interpreter with that setting in Bourne-compatible shells. +- PURELIB=./lib This is required on all systems so that the interpreter finds + the prelude and other library scripts. +After that you should be able to run the Pure interpreter from the source +directory, by typing './pure'. + There are a number of other variables you can set on the 'make' command line if you need special compiler (CXXFLAGS) or linker flags (LDFLAGS), or if you have to add platform-specific libraries (LIBS). Please see the Makefile for @@ -188,6 +201,10 @@ 4.1, YMMV), so you are encouraged to use the 'default' build unless performance is really critical. +To get smaller executables with either the default or the release build, add +'LDFLAGS=-s' to the 'make' command (gcc only, other compilers may provide a +similar flag to strip compiled executables and libraries). + You can also do a 'debug' build as follows: $ make build=debug @@ -241,20 +258,18 @@ ----- Linux is the primary development platform for this software, and the sources -should build out of the box on all recent Linux distributions. However, note -the issues on 64 bit Linux systems described above. +should build out of the box on all recent Linux distributions. MAC OSX --- --- A port by Ryan Schmidt exists in the MacPorts collection at http://www.macports.org/. If you compile Pure from the original sources -yourself, you should remove the -rdynamic option from the link line (it's not -needed on OSX) and add the -liconv flag instead. To these ends, build Pure -with the following make command (add the build=release option for the release -build): +yourself, you should add the -liconv flag to the link line. To these ends, +build Pure with the following make command (add the build=release option for +the release build): -$ make LDFLAGS="" LIBS="-liconv" +$ make LIBS="-liconv" Also note that with at least some current versions of the Apple gcc compiler (4.0.1 and similar) you'll get the (bogus) warning "control reaches end of @@ -266,12 +281,12 @@ MS WINDOWS -- ------- -Nobody has reported a successful port to this platform yet, but it should be -rather straightforward (albeit arduous) to do this with either Cygwin -(http://www.cygwin.com/) or Mingw (http://www.mingw.org/), once you have all -the necessary dependencies and a suitable version of LLVM installed. So *you* -can still be the hero who first got Pure up and running on Windows; if you do, -please let us know! :) +Jiri Spitz is currently working on a Windows port using Mingw. Once this is +finished, we'll provide Windows installation instructions here. For the time +being, you can try for yourself; porting should be rather straightforward with +either Cygwin (http://www.cygwin.com/) or Mingw (http://www.mingw.org/), once +you have all the necessary dependencies and a suitable version of LLVM +installed. May 2008 Modified: pure/trunk/Makefile =================================================================== --- pure/trunk/Makefile 2008-05-28 07:52:52 UTC (rev 157) +++ pure/trunk/Makefile 2008-06-01 18:24:53 UTC (rev 158) @@ -14,9 +14,19 @@ prefix = /usr/local bindir = $(prefix)/bin -libdir = $(prefix)/lib/pure +libdir = $(prefix)/lib mandir = $(prefix)/share/man/man1 +# Pure library name. Currently we use a simple versioning scheme, which +# requires that the library version matches that of the interpreter. With some +# extra fiddling, this enables you to install different versions of the Pure +# interpreter on the same system. + +# NOTE: You might have to change the suffix .so for your system (e.g., use +# .dll on Windows). + +libpure = libpure-$(version).so + # Staging directory for 'make install'. If you use this, make sure that this # ends in a slash. @@ -25,12 +35,9 @@ # Linker flags. Adjust these as necessary for your system. # LDFLAGS is for additional linker options, LIBS for additional libraries that -# might be needed (e.g., -liconv on OSX). Note that the -rdynamic flag is -# required when using gcc with the ELF linker (e.g., Linux on x86) to enable -# the dlopening of the program executable. On OSX this option isn't needed -# (pass LDFLAGS="" to 'make' instead). +# might be needed (e.g., -liconv on OSX and Windows). -LDFLAGS=-rdynamic +LDFLAGS= LIBS= # Compilation flags. We currently provide the following build profiles: @@ -62,9 +69,6 @@ # installation or any other targets except 'all'.) Just 'make' builds with the # default flags. -# Note that both the 'default' and the 'release' build may take quite a while -# to compile (especially runtime.cc), so please be patient. ;-) - build=default LLVM_FLAGS = `llvm-config --cppflags` @@ -104,11 +108,11 @@ # No need to edit below this line. Unless you really have to. :) ############ SOURCE = expr.cc expr.hh funcall.h interpreter.cc interpreter.hh lexer.ll \ -matcher.cc matcher.hh parser.yy printer.cc printer.hh pure.cc \ +matcher.cc matcher.hh parser.yy printer.cc printer.hh \ runtime.cc runtime.h symtable.cc symtable.hh util.cc util.hh EXTRA_SOURCE = lexer.cc parser.cc parser.hh location.hh position.hh stack.hh OBJECT = $(subst .cc,.o,$(filter %.cc,$(SOURCE) $(EXTRA_SOURCE))) -ALL_LIBS = $(LLVM_LIBS) -lreadline -lgmp $(LIBS) +ALL_LIBS = -lreadline -lgmp $(LIBS) examples = $(wildcard examples/*.pure) lib = $(wildcard lib/*.pure) @@ -117,7 +121,7 @@ distlogs = $(wildcard test/*.log) DISTFILES = COPYING ChangeLog INSTALL NEWS README TODO Makefile \ -$(SOURCE) $(EXTRA_SOURCE) w3centities.c pure.1 pure.xml pure.vim \ +$(SOURCE) $(EXTRA_SOURCE) w3centities.c pure.cc pure.1 pure.xml pure.vim \ $(examples) $(lib) $(tests) $(distlogs) .PHONY: all html dvi ps pdf clean realclean depend install uninstall strip \ @@ -127,11 +131,14 @@ all: pure -pure: $(OBJECT) - $(CXX) -o $@ $(LDFLAGS) $(OBJECT) $(ALL_LIBS) +pure: pure.o $(libpure) + $(CXX) -o $@ $(LDFLAGS) pure.o -L. -lpure-$(version) $(ALL_LIBS) +$(libpure): $(OBJECT) + $(CXX) -shared -o $@ $(LDFLAGS) $(OBJECT) $(LLVM_LIBS) $(ALL_LIBS) + pure.o: pure.cc - $(CXX) $(CXXFLAGS) -DVERSION='"$(version)"' -DPURELIB='"$(libdir)"' -c -o $@ $< + $(CXX) $(CXXFLAGS) -DVERSION='"$(version)"' -DPURELIB='"$(libdir)/pure"' -c -o $@ $< lexer.cc: lexer.ll flex -o lexer.cc $< @@ -163,7 +170,7 @@ # cleaning clean: - rm -f *~ *.bak *.html *.dvi *.ps pure $(OBJECT) parser.output + rm -f *~ *.bak *.html *.dvi *.ps pure $(OBJECT) pure.o $(libpure) parser.output cleanlogs: rm -f $(logs) @@ -176,24 +183,17 @@ depend: $(SOURCE) $(EXTRA_SOURCE) makedepend -Y $(SOURCE) $(EXTRA_SOURCE) 2> /dev/null -# Strip symbols from the executable. You might want to run this on Linux -# systems before installation to get a smaller executable. *Never* do this on -# OSX though, as the symbols are needed to properly resolve the runtime -# externals which are linked into the executable. - -strip: pure - strip pure - # installation install: pure $(lib) - install -d $(DESTDIR)$(bindir) $(DESTDIR)$(libdir) $(DESTDIR)$(mandir) + install -d $(DESTDIR)$(bindir) $(DESTDIR)$(libdir)/pure $(DESTDIR)$(mandir) install pure $(DESTDIR)$(bindir)/pure - install -m 644 $(lib) $(DESTDIR)$(libdir) + install $(libpure) $(DESTDIR)$(libdir)/$(libpure) + install -m 644 $(lib) $(DESTDIR)$(libdir)/pure install -m 644 pure.1 $(DESTDIR)$(mandir)/pure.1 uninstall: - rm -rf $(DESTDIR)$(bindir)/pure $(DESTDIR)$(libdir) $(DESTDIR)$(mandir)/pure.1 + rm -rf $(DESTDIR)$(bindir)/pure $(DESTDIR)$(libdir)/$(libpure) $(DESTDIR)$(libdir)/pure $(DESTDIR)$(mandir)/pure.1 # roll a distribution tarball @@ -219,14 +219,14 @@ check: pure @ echo Running tests. - @ (export PURELIB=./lib; echo -n "prelude.pure: "; if ./pure -n -v$(level) lib/prelude.pure 2>&1 | diff -q - test/prelude.log > /dev/null; then echo passed; else echo FAILED; fi) - @ (cd test; export PURELIB=../lib; for x in $(tests); do f="`basename $$x`"; l="`basename $$x .pure`.log"; echo -n "$$x: "; if ../pure -v$(level) < $$f 2>&1 | diff -q - $$l > /dev/null; then echo passed; else echo FAILED; fi; done) + @ (export LD_LIBRARY_PATH=.; export PURELIB=./lib; echo -n "prelude.pure: "; if ./pure -n -v$(level) lib/prelude.pure 2>&1 | diff -q - test/prelude.log > /dev/null; then echo passed; else echo FAILED; fi) + @ (cd test; export LD_LIBRARY_PATH=..; export PURELIB=../lib; for x in $(tests); do f="`basename $$x`"; l="`basename $$x .pure`.log"; echo -n "$$x: "; if ../pure -v$(level) < $$f 2>&1 | diff -q - $$l > /dev/null; then echo passed; else echo FAILED; fi; done) test/prelude.log: lib/prelude.pure lib/primitives.pure lib/strings.pure - PURELIB=./lib ./pure -n -v$(level) $< > $@ 2>&1 + LD_LIBRARY_PATH=. PURELIB=./lib ./pure -n -v$(level) $< > $@ 2>&1 %.log: %.pure - PURELIB=./lib ./pure -v$(level) < $< > $@ 2>&1 + LD_LIBRARY_PATH=. PURELIB=./lib ./pure -v$(level) < $< > $@ 2>&1 # DO NOT DELETE Modified: pure/trunk/interpreter.cc =================================================================== --- pure/trunk/interpreter.cc 2008-05-28 07:52:52 UTC (rev 157) +++ pure/trunk/interpreter.cc 2008-06-01 18:24:53 UTC (rev 158) @@ -61,6 +61,7 @@ if (!g_interp) { g_interp = this; stackdir = c_stack_dir(); + llvm::sys::DynamicLibrary::LoadLibraryPermanently("libpure", 0); } sstk_sz = 0; sstk_cap = 0x10000; // 64K This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |