Did you know ... Search Documentation:
GIT commit info
Updated foreign package description.
authorJan Wielemaker
Wed Nov 10 12:01:28 2021 +0100
committerJan Wielemaker
Wed Nov 10 12:01:28 2021 +0100
commit0462f1c673f745a0a6c20c99b289f070636af2a6
tree0bd0093783f1bd31ee79e7efee82864cf72b4001
parent836fd482b44726ac98abc5b04ee62ebf2cf580cd
Diff style: patch stat
diff --git a/howto/ForeignPack.txt b/howto/ForeignPack.txt
index 7699104..09f3ce0 100644
--- a/howto/ForeignPack.txt
+++ b/howto/ForeignPack.txt
@@ -1,10 +1,10 @@
----+ Creating a pack that uses C or C++ code
+# Creating a pack that uses C or C++ code
 
 This page describes the basics for creating packages that contain C or
 C++ code, also known as _foreign_ code.
 
 
----++ Runtime installation
+## Runtime installation
 
 Foreign code must be compiled into a SWI-Prolog extension, a loadable
 library. These things are supported by virtually any modern operating
@@ -16,18 +16,18 @@ can see this extension iff
     <arch> is the Prolog architecture as available through the Prolog
     flag =arch=.  For example:
 
-      ==
+      ```
       ?- current_prolog_flag(arch, Arch).
       Arch = 'x86_64-linux'.
-      ==
+      ```
 
   - The file uses the extension for such objects for the target
     platform.  This extension is also available as a Prolog flag:
 
-      ==
+      ```
       ?- current_prolog_flag(shared_object_extension, Ext).
       Ext = so.
-      ==
+      ```
 
 Provided that the above  installation   guidelines  are followed, Prolog
 code can include the extension using the directive use_foreign_library/1
@@ -36,12 +36,12 @@ The  search  path  =foreign=  searches  the  lib/<arch>  directories  of
 installed packages. The extension must be omitted because it is platform
 dependent.
 
-  ==
+  ```
   :- use_foreign_library(foreign(sqlite4pl)).
-  ==
+  ```
 
 
----++ Binary extensions
+## Binary extensions
 
 Binary packages may include the lib/<arch>   subdirectory in the package
 and suitable precompiled extensions for   the target architectures. Note
@@ -54,9 +54,8 @@ dependencies between Prolog and the extension.  In particular:
   in terms of different Prolog and Windows versions.
 
   $ MacOS :
-  Here, portability is poor.  Provided shared objects (*|.dylib|* files)
-  only work of the same version of SWI-Prolog is installed in the same
-  absolute location.
+  MacOS has both `.dylib` and `.so` shared objects.  The latter are
+  called _modules_ by CMake.  We use `.so` files for foreign extensions.
 
   $ Linux :
   Linux ELF objects (*|.so|* files) resolve symbols against already
@@ -66,7 +65,7 @@ dependencies between Prolog and the extension.  In particular:
   not binary compatible due to different versions of dependencies.
 
 
----++ Source extensions
+## Source extensions
 
 Alternatively, or in  addition,  the  extensions   may  be  provided  as
 sources. The advantage thereof  is  that   the  above  mentioned version
@@ -79,7 +78,7 @@ development libraries for dependencies.   Here are some examples:
   on the same drive as where SWI-Prolog is installed.
 
   $ MacOS :
-  Requires [[Macports][http://www.macports.org/]] installed.
+  Requires Xcode to be installed.
 
   $ Linux :
   Requires the development tools installed.  The package names for this
@@ -87,34 +86,68 @@ development libraries for dependencies.   Here are some examples:
   process and we assume that programmers using a Linux system have these
   tools installed.
 
----++ The build process
-
-The build process consists of several   steps, described below. Of these
-steps, only (3) is obligatory. In  many   cases,  using configure can be
-omitted  because  these  programs  are  called   with  a  fair  deal  of
-information provided through the environment (see below).
-
-  1. If there is a file =configure.in= and no =configure=, run
-       - autoconf
-       - autoheader
-     to create =configure=
-
-  2. If there is a file =configure= (distributed or created by the
-     previous step), run
-       - configure
-
-  3. If there is a file =Makefile= (distributed or created by the
-     previous steps), run
-       - make all
-       - make check
-       - make install
-
-*Note* Ideally, if there is a suitable binary for the platform,
-pack_install/1 should not try to rebuild it. It is not clear how to
-verify this.
-
-
----+++ Build environment
+## The build process
+
+The build process is defined by the following steps:
+
+  1. clean
+  2. dependencies
+  3. configure
+  4. build
+  5. test
+  6. install
+
+The __clean__ step is optional and used by pack_rebuild/1 in the mode
+`distclean`. For each of the steps the system asks its build plugins to
+identify known configuration files and perform the step. The planning
+for a next step may depend on the output of the previous step.  Below
+is a list that describes the current strategy.  New strategies may be
+added by providing additional plugins for library(build/tools).
+
+  - dependencies
+    - conan
+      If a file `conanfile.txt` or `conanfile.py` is found in the
+      toplevel directory, create a directory `build` and run
+
+	  conan install -b missing ..
+
+      If, as a result, a file `environment.sh.env` is created in the
+      `build` directory, load the environment variables.  This exploits
+      conan's `virtualenv`.
+  - configure
+    - cmake
+      If a file `CMakeLists.txt` is present create a subdirectory `build`
+      and run
+
+          cmake -DSWILP=.. -DCMAKE_INSTALL_PREFIX=... ..
+
+    - make
+      Performs GNU style configuration.  Knows about `Makefile.am`,
+      `congigure.in`, `congigure.ac` and `configure`.
+  - build
+    - cmake
+      If cmake was detected, run `cmake --build .` in the `build`
+      directory.
+    - make
+      If a ``Makefile`` or `makefile` is found, run `make`
+  - test
+    - cmake
+      If a file ``CTestTestfile.cmake`` is found in build, run
+      `ctest`.
+    - make
+      If a ``Makefile`` or `makefile` is found, run `make check`
+  - install
+    - cmake
+      If cmake was detected, run `cmake --install .` in the `build`
+      directory.
+    - make
+      If a ``Makefile`` or `makefile` is found, run `make install`
+
+During all these steps the tools have access to details about Prolog
+through the environment variables described in the next section.
+
+
+### Build environment
 
 The configuration and installation steps  are executed by pack_install/1
 and provide the following environment variables:
@@ -160,7 +193,7 @@ provided  additional  environment  variables.  Answers   for  the  above
 mentioned variables replace the above described value.
 
 
----+++ Windows MinGW builds
+### Windows MinGW builds
 
 The infrastructure assumes using [[MinGW][http://www.mingw.org]] and
 MSYS for building foreign packages on Windows. If pack_install/1 detects