[gambit-list] cmake for projects written in gambit?

Marc Feeley feeley at iro.umontreal.ca
Tue Nov 30 18:18:03 EST 2010


On 2010-11-30, at 1:56 AM, Matthew Koichi Grimes wrote:

> Has anybody used CMake as a build system for their Gambit projects? I'm not talking about building Gambit itself, but rather building projects that are written in Gambit. If so, could I see your CMakeList bulid files? 
> 
> I would also be interested in other build systems' makefiles (make, ant, etc), if people are wiling to share, or point me to an open-source project written in Gambit that I could download.
> 
> Best,
> -- Matt

The attached tar ball shows how to write a makefile for a simple project built
with Gambit-C which combines Scheme and C code.

The C "main" function starts the execution of the Scheme code and it
also contains a call to a Scheme procedure.  There are also calls to C
functions within the Scheme code.  The project is composed of the
following source files:

  main.c              : program's "main" function which calls Scheme
  mod1.h and mod1.c   : defines the mod1 C function
  mod2.h and mod2.c   : defines the mod2 C function
  mod3.h and mod3.scm : defines the interface between Scheme and C
  mod4.scm            : Scheme code which calls C

The makefile is designed to depend only on the gsc compiler.  The gsc
compiler will invoke the appropriate C compiler and linker, even for
compiling the C source files of the project.  This makes this makefile
very portable as many system dependencies have been taken care of when
Gambit was installed.

To try it out, make sure you have Gambit-C v4.6.0 with
commit 02c1427d40eb080a4ada916d55ecbb14cc191772.

To build the project enter:

  make

To build and run the project enter:

  make run

To cleanup enter:

  make clean

The makefile and tar ball are below.

Marc


# Simple makefile for project built with Gambit-C system.

# Copyright (c) 2010 by Marc Feeley, All Rights Reserved.

# This makefile is designed to depend only on the gsc compiler.  The
# gsc compiler will invoke the appropriate C compiler and linker, even
# for compiling the C source files of the project.  This makes this
# makefile very portable as many system dependencies have been taken
# care of when Gambit was installed.  If gsc isn't installed in a
# standard location, define GSC accordingly here:

GSC = gsc

# You should redefine C_MODULES and SCHEME_MODULES as needed for your
# project.  Define ALL_MODULES_O as the set of object files for the C
# and Scheme modules.  Define PROG_NAME as the program name.

PROG_NAME = prog
C_MODULES = mod1.c mod2.c main.c
SCHEME_MODULES = mod3.scm mod4.scm
SCHEME_MODULES_C = mod3.c mod4.c
ALL_MODULES_O = mod1.o mod2.o main.o mod3.o mod4.o

# You may want to add stuff to CC_OPTIONS and LD_OPTIONS (directories
# for header files, libraries, etc).  You must keep -D___LIBRARY in
# CC_OPTIONS so that the compiled Scheme code does not implement its
# own "main" function (in the link file generated by gsc).

CC_OPTIONS = -D___LIBRARY
LD_OPTIONS = 

# The rest of the makefile shouldn't need to be modified.

GSC_OPTIONS = -cc-options "$(CC_OPTIONS)" -ld-options "$(LD_OPTIONS)"
#GSC_OPTIONS = -cc-options "$(CC_OPTIONS)" -ld-options "$(LD_OPTIONS)" -verbose
ALL_MODULES_C = $(C_MODULES) $(SCHEME_MODULES_C)
ALL_MODULES = $(C_MODULES) $(SCHEME_MODULES)

.SUFFIXES:
.SUFFIXES: .scm .c .o

all: $(PROG_NAME)

$(PROG_NAME): $(ALL_MODULES_O) $(PROG_NAME)_.o
	$(GSC) $(GSC_OPTIONS) -exe -o $@ $^

$(PROG_NAME)_.c:  $(SCHEME_MODULES_C)
	$(GSC) -link -o $@ $^

.c.o:
	$(GSC) $(GSC_OPTIONS) -obj $^

.scm.c:
	$(GSC) $(GSC_OPTIONS) -c $^

run: $(PROG_NAME)
	./$(PROG_NAME)

clean:
	rm -f $(SCHEME_MODULES_C) $(ALL_MODULES_O) $(PROG_NAME)_.* $(PROG_NAME)


# Note: It is possible to compile and link a program in a single
# invocation of gsc but this is not recommended for large projects
# which usually benefit from separate compilation.  The command is:
#
#   $(GSC) $(GSC_OPTIONS) -exe -o $(PROG_NAME) $(ALL_MODULES)
#
# Moreover, this requires changing the name of the link file in main.c
# from prog_.c to mod4_.c (the name is derived from the last Scheme
# source file in ALL_MODULES).

-------------- next part --------------
A non-text attachment was scrubbed...
Name: simple-make-project.tgz
Type: application/octet-stream
Size: 3155 bytes
Desc: not available
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20101130/66bfdc40/attachment.obj>


More information about the Gambit-list mailing list