5.14. Compiling and Loading C Code
(lsh/libc/make.lsh)


It is often useful to compile and load C subroutines that either define new Lush primitives, or provide support functions to compiled lush functions.

Class LushMake provides a familiar interface for controlling the compilation of these subroutines and for loading them into the Lush system.

 (let ((lm (new LushMake)))
   ;; Define the rules
   (==> lm rule "foo.o" '("foo.c" "foo.h"))
   (==> lm rule "bar.o" '("bar.f" "foo.h")
           "$F77 $DEFS $LUSHFLAGS -c $SRC -o $OBJ" )
   ;; Compile and load
   (==> lm make)
   (==> lm load) )

A more extensive example can be seen in "packages/sn28/sn28common.lsh" .



5.14.0. (new LushMake [srcdir [objdir]])
[CLASS] (lsh/libc/make.lsh)


Create a new LushMake object.

The source files will be searched under directory srcdir . The default is to search source files under the directory containing the file being loaded. The object files will be created in architecture dependent subdirectories of objdir . The default is to create these subdirectories inside the source directory.



5.14.1. (==> lushmake setdirs srcdir [objdir])
[MSG] (lsh/libc/make.lsh)


Sets the source directory srcdir (where source files are searched) and the object directory objdir (where architecture dependent subdirectories are created to hold the object files). The default value for objdir is equal to srcdir .

5.14.2. (==> lushmake setflags flags)
[MSG] (lsh/libc/make.lsh)


Sets additional compilation flags. These additional compilation flags will be appended to the contents of the rule variable "$LUSHFLAGS" .

5.14.3. (==> lushmake rule target deps [command])
[MSG] (lsh/libc/make.lsh)


Define a compilation rule in the spirit of makefiles.

Argument target is the name of the object file to create relative to an architecture dependent subdirectory of the object directory.

Argument deps is a list containing the names of the files on which the target depends. The target is rebuilt if any of these files is more recent than the current target.

The optional argument command is a string containing the command to execute to rebuild target . The default command is provided in variable dhc-make-command and should be adequate for C programs. Environment variables in the command are expanded using getenv or getconf . The following additional variables are also defined:

See: dhc-make-command
See: dhc-make-lushflags
See: (dhc-substitute-env str [ htable ])
See: (dhc-generate-include-flags [ includepath ])



5.14.4. (==> lushmake show [...target...])
[MSG] (lsh/libc/make.lsh)


Show what commands need to be executed to bring targets ...target... up to date. Calling this method without arguments processes all targets defined by the rules.

5.14.5. (==> lushmake make [...target...])
[MSG] (lsh/libc/make.lsh)


Makes sure that the targets listed as argument are up-to-date relative to their dependencies. This method finds the relevant rule and checks each dependency file. It first checks whether the dependency files themselves must be rebuilt. The rule command is then invoked if any of the dependency is more recent than the target.

Calling this method without arguments processes all targets defined by the rules.



5.14.6. (==> lushmake load [...targets...])
[MSG] (lsh/libc/make.lsh)


Makes sure that all listed targets are up-to-date and loads all listed object files using mod-load . In addition all the relevant dependencies will be recorded using libload-add-dependency .

Calling this method without arguments processes all object file targets defined by the rules.