Next: , Previous: , Up: Installing SCM   [Contents][Index]

2.3 Building SCM

The file build loads the file build.scm, which constructs a relational database of how to compile and link SCM executables. build.scm has information for the platforms which SCM has been ported to (of which I have been notified). Some of this information is old, incorrect, or incomplete. Send corrections and additions to agj@alum.mit.edu.


Next: , Previous: , Up: Building SCM   [Contents][Index]

2.3.1 Invoking Build

This section teaches how to use build, a Scheme program for creating compilation scripts to produce SCM executables and library modules. The options accepted by ‘build’ are documented in Build Options.

Use the any method if you encounter problems with the other two methods (MS-DOS, Unix).

MS-DOS

From the SCM source directory, type ‘build’ followed by up to 9 command line arguments.

Unix

From the SCM source directory, type ‘./build’ followed by command line arguments.

any

From the SCM source directory, start ‘scm’ or ‘scmlit’ and type (load "build"). Alternatively, start ‘scm’ or ‘scmlit’ with the command line argument ‘-ilbuild’. This method will also work for MS-DOS and Unix.

After loading various SLIB modules, the program will print:

type (b "build <command-line>") to build
type (b*) to enter build command loop

The ‘b*’ procedure enters into a build shell where you can enter commands (with or without the ‘build’). Blank lines are ignored. To create a build script with all defaults type ‘build’.

If the build-shell encouters an error, you can reenter the build-shell by typing ‘(b*)’. To exit scm type ‘(quit)’.

Here is a transcript of an interactive (b*) build-shell.

bash$ scmlit
SCM version 5e7, Copyright (C) 1990-2006 Free Software Foundation.
SCM comes with ABSOLUTELY NO WARRANTY; for details type `(terms)'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `(terms)' for details.
> (load "build")
;loading build
;  loading /home/jaffer/slib/getparam
;    loading /home/jaffer/slib/coerce
...
;  done loading build.scm
type (b "build <command-line>") to build
type (b*) to enter build command loop
;done loading build
#<unspecified>
> (b*)
;loading /home/jaffer/slib/comparse
;done loading /home/jaffer/slib/comparse.scm
build> -t exe
#! /bin/sh
# unix (linux) script created by SLIB/batch Wed Oct 26 17:14:23 2011
# [-p linux]
# ================ Write file with C defines
rm -f scmflags.h
echo '#define IMPLINIT "Init5e7.scm"'>>scmflags.h
echo '#define BIGNUMS'>>scmflags.h
echo '#define FLOATS'>>scmflags.h
echo '#define ARRAYS'>>scmflags.h
# ================ Compile C source files
gcc -c continue.c scm.c scmmain.c findexec.c script.c time.c repl.c scl.c eval.c sys.c subr.c debug.c unif.c rope.c
# ================ Link C object files
gcc -rdynamic -o scm continue.o scm.o scmmain.o findexec.o script.o time.o repl.o scl.o eval.o sys.o subr.o debug.o unif.o rope.o -lm -lc
"scm"
build> -t exe -w myscript.sh
"scm"
build> (quit)

No compilation was done. The ‘-t exe’ command shows the compile script. The ‘-t exe -w myscript.sh’ line creates a file myscript.sh containing the compile script. To actually compile and link it, type ‘./myscript.sh’.

Invoking build without the ‘-F’ option will build or create a shell script with the arrays, inexact, and bignums options as defaults. Invoking ‘build’ with ‘-F lit -o scmlit’ will make a script for compiling ‘scmlit’.

bash$ ./build
-|
#! /bin/sh
# unix (linux) script created by SLIB/batch 
# ================ Write file with C defines
rm -f scmflags.h
echo '#define IMPLINIT "Init5f4.scm"'>>scmflags.h
echo '#define BIGNUMS'>>scmflags.h
echo '#define FLOATS'>>scmflags.h
echo '#define ARRAYS'>>scmflags.h
# ================ Compile C source files
gcc -O2 -c continue.c scm.c scmmain.c findexec.c script.c time.c repl.c scl.c eval.c sys.c subr.c debug.c unif.c rope.c
# ================ Link C object files
gcc -rdynamic -o scm continue.o scm.o scmmain.o findexec.o script.o time.o repl.o scl.o eval.o sys.o subr.o debug.o unif.o rope.o -lm -lc

To cross compile for another platform, invoke build with the ‘-p’ or ‘--platform=’ option. This will create a script for the platform named in the ‘-p’ or ‘--platform=’ option.

bash$ ./build -o scmlit -p darwin -F lit
-|
#! /bin/sh
# unix (darwin) script created by SLIB/batch 
# ================ Write file with C defines
rm -f scmflags.h
echo '#define IMPLINIT "Init5f4.scm"'>>scmflags.h
# ================ Compile C source files
cc -O3 -c continue.c scm.c scmmain.c findexec.c script.c time.c repl.c scl.c eval.c sys.c subr.c debug.c unif.c rope.c
# ================ Link C object files
mv -f scmlit scmlit~
cc -o scmlit continue.o scm.o scmmain.o findexec.o script.o time.o repl.o scl.o eval.o sys.o subr.o debug.o unif.o rope.o

2.3.2 Build Options

The options to build specify what, where, and how to build a SCM program or dynamically linked module. These options are unrelated to the SCM command line options.

Build Option: -p platform-name
Build Option: ---platform=platform-name

specifies that the compilation should be for a computer/operating-system combination called platform-name. Note The case of platform-name is distinguised. The current platform-names are all lower-case.

The platforms defined by table platform in build.scm are:

Table: platform
name              processor         operating-system  compiler          
#f                processor-family  operating-system  #f                
symbol            processor-family  operating-system  symbol            
symbol            symbol            symbol            symbol            
================= ================= ================= ================= 
*unknown*         *unknown*         unix              cc                
acorn-unixlib     acorn             *unknown*         cc                
aix               powerpc           aix               cc                
alpha-elf         alpha             unix              cc                
alpha-linux       alpha             linux             gcc               
amiga-aztec       m68000            amiga             cc                
amiga-dice-c      m68000            amiga             dcc               
amiga-gcc         m68000            amiga             gcc               
amiga-sas         m68000            amiga             lc                
atari-st-gcc      m68000            atari-st          gcc               
atari-st-turbo-c  m68000            atari-st          tcc               
borland-c         i8086             ms-dos            bcc               
darwin            powerpc           unix              cc                
djgpp             i386              ms-dos            gcc               
freebsd           *unknown*         unix              cc                
gcc               *unknown*         unix              gcc               
gnu-win32         i386              unix              gcc               
highc             i386              ms-dos            hc386             
hp-ux             hp-risc           hp-ux             cc                
irix              mips              irix              gcc               
linux             *unknown*         linux             gcc               
linux-aout        i386              linux             gcc               
linux-ia64        ia64              linux             gcc               
microsoft-c       i8086             ms-dos            cl                
microsoft-c-nt    i386              ms-dos            cl                
microsoft-quick-c i8086             ms-dos            qcl               
ms-dos            i8086             ms-dos            cc                
netbsd            *unknown*         unix              gcc               
openbsd           *unknown*         unix              gcc               
os/2-cset         i386              os/2              icc               
os/2-emx          i386              os/2              gcc               
osf1              alpha             unix              cc                
plan9-8           i386              plan9             8c                
sunos             sparc             sunos             cc                
svr4              *unknown*         unix              cc                
svr4-gcc-sun-ld   sparc             sunos             gcc               
turbo-c           i8086             ms-dos            tcc               
unicos            cray              unicos            cc                
unix              *unknown*         unix              cc                
vms               vax               vms               cc                
vms-gcc           vax               vms               gcc               
watcom-9.0        i386              ms-dos            wcc386p           
Build Option: -f pathname

specifies that the build options contained in pathname be spliced into the argument list at this point. The use of option files can separate functional features from platform-specific ones.

The Makefile calls out builds with the options in ‘.opt’ files:

dlls.opt

Options for Makefile targets dlls, myturtle, and x.so.

gdb.opt

Options for udgdbscm and gdbscm.

libscm.opt

Options for libscm.a.

pg.opt

Options for pgscm, which instruments C functions.

udscm4.opt

Options for targets udscm4 and dscm4 (scm).

udscm5.opt

Options for targets udscm5 and dscm5 (scm).

The Makefile creates options files it depends on only if they do not already exist.

Build Option: -o filename
Build Option: ---outname=filename

specifies that the compilation should produce an executable or object name of filename. The default is ‘scm’. Executable suffixes will be added if neccessary, e.g. ‘scm’ ⇒ ‘scm.exe’.

Build Option: -l libname
Build Option: ---libraries=libname

specifies that the libname should be linked with the executable produced. If compile flags or include directories (‘-I’) are needed, they are automatically supplied for compilations. The ‘c’ library is always included. SCM features specify any libraries they need; so you shouldn’t need this option often.

Build Option: -D definition
Build Option: ---defines=definition

specifies that the definition should be made in any C source compilations. If compile flags or include directories (‘-I’) are needed, they are automatically supplied for compilations. SCM features specify any flags they need; so you shouldn’t need this option often.

Build Option: ---compiler-options=flag

specifies that that flag will be put on compiler command-lines.

Build Option: ---linker-options=flag

specifies that that flag will be put on linker command-lines.

Build Option: -s pathname
Build Option: ---scheme-initial=pathname

specifies that pathname should be the default location of the SCM initialization file Init5f4.scm. SCM tries several likely locations before resorting to pathname (see File-System Habitat). If not specified, the current directory (where build is building) is used.

Build Option: -c pathname
Build Option: ---c-source-files=pathname

specifies that the C source files pathname … are to be compiled.

Build Option: -j pathname
Build Option: ---object-files=pathname

specifies that the object files pathname … are to be linked.

Build Option: -i call
Build Option: ---initialization=call

specifies that the C functions call … are to be invoked during initialization.

Build Option: -t build-what
Build Option: ---type=build-what

specifies in general terms what sort of thing to build. The choices are:

exe

executable program.

lib

library module.

dlls

archived dynamically linked library object files.

dll

dynamically linked library object file.

The default is to build an executable.

Build Option: -h batch-syntax
Build Option: --batch-dialect=batch-syntax

specifies how to build. The default is to create a batch file for the host system. The SLIB file batch.scm knows how to create batch files for:

  • unix
  • dos
  • vms
  • amigaos (was amigados)
  • system

    This option executes the compilation and linking commands through the use of the system procedure.

  • *unknown*

    This option outputs Scheme code.

Build Option: -w batch-filename
Build Option: --script-name=batch-filename

specifies where to write the build script. The default is to display it on (current-output-port).

Build Option: -F feature
Build Option: ---features=feature

specifies to build the given features into the executable. The defined features are:

array

Alias for ARRAYS

array-for-each

array-map! and array-for-each (arrays must also be featured).

arrays

Use if you want arrays, uniform-arrays and uniform-vectors.

bignums

Large precision integers.

byte

Treating strings as byte-vectors.

byte-number

Byte/number conversions

careful-interrupt-masking

Define this for extra checking of interrupt masking and some simple checks for proper use of malloc and free. This is for debugging C code in sys.c, eval.c, repl.c and makes the interpreter several times slower than usual.

cautious

Normally, the number of arguments arguments to interpreted closures (from LAMBDA) are checked if the function part of a form is not a symbol or only the first time the form is executed if the function part is a symbol. defining ‘reckless’ disables any checking. If you want to have SCM always check the number of arguments to interpreted closures define feature ‘cautious’.

cheap-continuations

If you only need straight stack continuations, executables compile with this feature will run faster and use less storage than not having it. Machines with unusual stacks need this. Also, if you incorporate new C code into scm which uses VMS system services or library routines (which need to unwind the stack in an ordrly manner) you may need to use this feature.

compiled-closure

Use if you want to use compiled closures.

curses

For the curses screen management package.

debug

Turns on the features ‘cautious’ and ‘careful-interrupt-masking’; uses -g flags for debugging SCM source code.

differ

Sequence comparison

dont-memoize-locals

SCM normally converts references to local variables to ILOCs, which make programs run faster. If SCM is badly broken, try using this option to disable the MEMOIZE_LOCALS feature.

dump

Convert a running scheme program into an executable file.

dynamic-linking

Be able to load compiled files while running.

edit-line

interface to the editline or GNU readline library.

engineering-notation

Use if you want floats to display in engineering notation (exponents always multiples of 3) instead of scientific notation.

generalized-c-arguments

make_gsubr for arbitrary (< 11) arguments to C functions.

i/o-extensions

Commonly available I/O extensions: exec, line I/O, file positioning, file delete and rename, and directory functions.

inexact

Use if you want floating point numbers.

lit

Lightweight – no features

macro

C level support for hygienic and referentially transparent macros (syntax-rules macros).

mysql

Client connections to the mysql databases.

no-heap-shrink

Use if you want segments of unused heap to not be freed up after garbage collection. This may increase time in GC for *very* large working sets.

none

No features

posix

Posix functions available on all Unix-like systems. fork and process functions, user and group IDs, file permissions, and link.

reckless

If your scheme code runs without any errors you can disable almost all error checking by compiling all files with ‘reckless’.

record

The Record package provides a facility for user to define their own record data types. See SLIB for documentation.

regex

String regular expression matching.

rev2-procedures

These procedures were specified in the Revised^2 Report on Scheme but not in R4RS.

sicp

Use if you want to run code from:

Harold Abelson and Gerald Jay Sussman with Julie Sussman. Structure and Interpretation of Computer Programs. The MIT Press, Cambridge, Massachusetts, USA, 1985.

Differences from R5RS are:

  • (eq? ’() ’#f)
  • (define a 25) returns the symbol a.
  • (set! a 36) returns 36.
single-precision-only

Use if you want all inexact real numbers to be single precision. This only has an effect if SINGLES is also defined (which is the default). This does not affect complex numbers.

socket

BSD socket interface. Socket addr functions require inexacts or bignums for 32-bit precision.

tick-interrupts

Use if you want the ticks and ticks-interrupt functions.

turtlegr

Turtle graphics calls for both Borland-C and X11 from sjm@ee.tut.fi.

unix

Those unix features which have not made it into the Posix specs: nice, acct, lstat, readlink, symlink, mknod and sync.

wb

WB database with relational wrapper.

wb-no-threads

no-comment

windows

Microsoft Windows executable.

x

Alias for Xlib feature.

xlib

Interface to Xlib graphics routines.


Previous: , Up: Building SCM   [Contents][Index]

2.3.3 Compiling and Linking Custom Files

A correspondent asks:

How can we link in our own c files to the SCM interpreter so that we can add our own functionality? (e.g. we have a bunch of tcp functions we want access to). Would this involve changing build.scm or the Makefile or both?

(see Changing Scm has instructions describing the C code format). Suppose a C file foo.c has functions you wish to add to SCM. To compile and link your file at compile time, use the ‘-c’ and ‘-i’ options to build:

bash$ ./build -c foo.c -i init_foo
-|
#! /bin/sh
rm -f scmflags.h
echo '#define IMPLINIT "/home/jaffer/scm/Init5f4.scm"'>>scmflags.h
echo '#define COMPILED_INITS init_foo();'>>scmflags.h
echo '#define BIGNUMS'>>scmflags.h
echo '#define FLOATS'>>scmflags.h
echo '#define ARRAYS'>>scmflags.h
gcc -O2 -c continue.c scm.c findexec.c script.c time.c repl.c scl.c \
        eval.c sys.c subr.c unif.c rope.c foo.c
gcc -rdynamic -o scm continue.o scm.o findexec.o script.o time.o \
        repl.o scl.o eval.o sys.o subr.o unif.o rope.o foo.o -lm -lc

To make a dynamically loadable object file use the -t dll option:

bash$ ./build -t dll -c foo.c
-|
#! /bin/sh
rm -f scmflags.h
echo '#define IMPLINIT "/home/jaffer/scm/Init5f4.scm"'>>scmflags.h
echo '#define BIGNUMS'>>scmflags.h
echo '#define FLOATS'>>scmflags.h
echo '#define ARRAYS'>>scmflags.h
echo '#define DLL'>>scmflags.h
gcc -O2 -fpic -c foo.c
gcc -shared -o foo.so foo.o -lm -lc

Once foo.c compiles correctly (and your SCM build supports dynamic-loading), you can load the compiled file with the Scheme command (load "./foo.so"). See Configure Module Catalog for how to add a compiled dll file to SLIB’s catalog.


Next: , Previous: , Up: Installing SCM   [Contents][Index]