Build RTS as shared library

The C RTS is now built as a shared library, so that the functions in the Idris
standard library that use parts of it will work in :x and in type providers.
This commit is contained in:
David Christiansen 2013-04-01 18:47:42 +02:00
parent 9af2d93d3e
commit f8fcd92122
4 changed files with 25 additions and 4 deletions

4
.gitignore vendored
View File

@ -3,6 +3,9 @@ cabal-dev/
*.ibc
*.o
*.a
*.so
*.dll
*.dylib
*.swp
*~
custom.mk
@ -11,3 +14,4 @@ test/test???/output
test/reg???/output
test/test???/*.exe
test/reg???/*.exe

View File

@ -1,5 +1,8 @@
GMP_INCLUDE_DIR :=
CC :=gcc
SHLIB_SUFFIX :=.so
# Mac OS X: SHLIB_SUFFIX :=.dylib
# Windows: SHLIB_SUFFIX :=.DLL
CABAL :=cabal
CABALFLAGS :=
## Enable Java RTS:

View File

@ -2,26 +2,30 @@ include ../config.mk
OBJS = idris_rts.o idris_heap.o idris_gc.o idris_gmp.o idris_stdfgn.o idris_bitstring.o idris_opts.o idris_stats.o
HDRS = idris_rts.h idris_heap.h idris_gc.h idris_gmp.h idris_stdfgn.h idris_bitstring.h idris_opts.h idris_stats.h
CFLAGS = -O2 -Wall
CFLAGS = -O2 -Wall -fPIC
ifneq ($(GMP_INCLUDE_DIR),)
CFLAGS += -isystem $(GMP_INCLUDE_DIR)
endif
LIBTARGET = libidris_rts.a
DYLIBTARGET = libidris_rts$(SHLIB_SUFFIX)
check : $(LIBTARGET)
check : $(LIBTARGET) $(DYLIBTARGET)
$(LIBTARGET) : $(OBJS)
ar r $(LIBTARGET) $(OBJS)
ranlib $(LIBTARGET)
$(DYLIBTARGET) : $(OBJS)
$(CC) $(CFLAGS) -shared -o $(DYLIBTARGET) $(OBJS)
install : .PHONY
mkdir -p $(TARGET)
install $(LIBTARGET) $(HDRS) $(TARGET)
install $(LIBTARGET) $(DYLIBTARGET) $(HDRS) $(TARGET)
clean : .PHONY
rm -f $(OBJS) $(LIBTARGET)
rm -f $(OBJS) $(LIBTARGET) $(DYLIBTARGET)
idris_rts.o: idris_rts.h

View File

@ -552,6 +552,16 @@ idrisMain opts =
[] -> setIBCSubDir ""
(d:_) -> setIBCSubDir d
setImportDirs importdirs
-- attempt to load the RTS as a shared lib in the interpreter
idrisCatch (do rtslib <- lift (getDataFileName $ "rts" </> "libidris_rts")
handle <- lift (tryLoadLib rtslib)
case handle of
Nothing -> return ()
Just x -> do i <- getIState
let libs = idris_dynamic_libs i
putIState $ i { idris_dynamic_libs = x:libs })
(\e -> iputStrLn (show e))
addPkgDir "base"
mapM_ addPkgDir pkgdirs
elabPrims