15.5.2.1 Compiling a foreign extension using a simple Makefile
If the package requires some C code to be compiled that has no
dependencies and needs no configuration it is probably easiest to use a
simple Unix make file. We assume pack_version(2). Here is a
simple Makefile. We assume the pack contains a file
c/environ.c that contains the C source. Following the GNU
guidelines, the Makefile must define the following targets:
- all (default)
- Build the foreign extension. In this very simple case we build the resulting module directly in the target directory.
- check
- Test the package. This is executed after the default build target.
- install
- Install the package. In this case this does nothing.
- clean
- Clean the package. This target disposes intermediate build products.
- distclean
- Restore the package to its fully clean state. This implies that all
built products and intermediate build products are removed. The
distcleantarget is used by pack_rebuild/1.
MODULE= $(SWIPL_MODULE_DIR)/environ.$(SOEXT)
CFLAGS= $(SWIPL_CFLAGS)
all: $(MODULE)
OBJ=c/environ.o
$(MODULE): $(OBJ)
mkdir -p $(SWIPL_MODULE_DIR)
$(SWIPL_LD) $(SWIPL_MODULE_LDFLAGS) -o $@ $(OBJ) $(SWIPL_MODULE_LIB)
check::
$(SWIPL) -g run_tests -t halt test/test_environ.pl
install::
clean:
rm -f $(OBJ)
distclean: clean
rm -f $(MODULE)