Update C runtime instructions

This commit is contained in:
Inari Listenmaa
2021-07-15 10:39:54 +08:00
parent aa530233fb
commit 13f845d127

View File

@@ -162,94 +162,63 @@ Configuring gf-3.x...
setup: Distribution/Simple/PackageIndex.hs:124:8-13: Assertion failed setup: Distribution/Simple/PackageIndex.hs:124:8-13: Assertion failed
``` ```
The exact cause of this problem is unclear, but it seems to happen == Compiling GF with C runtime system support ==
during the configure phase if the same version of GF is already installed,
so a workaround is to remove the existing installation with
``` The C runtime system is a separate implementation of the PGF runtime services.
ghc-pkg unregister gf
```
You can check with ``ghc-pkg list gf`` that it is gone.
== Compilation with make ==
If you feel more comfortable with Makefiles then there is a thin Makefile
wrapper arround Cabal for you. If you just type:
```
$ make
```
the configuration phase will be run automatically if needed and after that
the sources will be compiled.
%% cabal build rgl-none does not work with recent versions of Cabal
%If you don't want to compile the resource library
%every time then you can use:
%```
%$ make gf
%```
For installation use:
```
$ make install
```
For cleaning:
```
$ make clean
```
%and to build source distribution archive run:
%```
%$ make sdist
%```
== Compiling GF with C run-time system support ==
The C run-time system is a separate implementation of the PGF run-time services.
It makes it possible to work with very large, ambiguous grammars, using It makes it possible to work with very large, ambiguous grammars, using
probabilistic models to obtain probable parses. The C run-time system might probabilistic models to obtain probable parses. The C runtime system might
also be easier to use than the Haskell run-time system on certain platforms, also be easier to use than the Haskell runtime system on certain platforms,
e.g. Android and iOS. e.g. Android and iOS.
To install the C run-time system, go to the ``src/runtime/c`` directory To install the C runtime system, go to the ``src/runtime/c`` directory.
%and follow the instructions in the ``INSTALL`` file.
and use the ``install.sh`` script: - **On Linux and Mac OS —**
``` You should have autoconf, automake, libtool and make.
bash setup.sh configure If you are missing some of them, follow the
bash setup.sh build instructions in the [INSTALL https://github.com/GrammaticalFramework/gf-core/blob/master/src/runtime/c/INSTALL] file.
bash setup.sh install
``` Once you have the required libraries, the easiest way to install the C runtime is to use the ``install.sh`` script. Just type
This will install
the C header files and libraries need to write C programs that use PGF grammars. ``$ bash install.sh``
% Some example C programs are included in the ``utils`` subdirectory, e.g. ``pgf-translate.c``.
This will install the C header files and libraries need to write C programs
that use PGF grammars.
% If this doesn't work for you, follow the manual instructions in the [INSTALL https://github.com/GrammaticalFramework/gf-core/blob/master/src/runtime/c/INSTALL] file under your operating system.
- **On other operating systems —** Follow the instructions in the
[INSTALL https://github.com/GrammaticalFramework/gf-core/blob/master/src/runtime/c/INSTALL] file under your operating system.
Depending on what you want to do with the C runtime, you can follow one or more of the following steps. Depending on what you want to do with the C runtime, you can follow one or more of the following steps.
=== 1. Use the C runtime from another programming language === === Use the C runtime from another programming language ===[bindings]
% **If you just want to use the C runtime from Python, Java, or Haskell, you don't need to change your GF installation.** % **If you just want to use the C runtime from Python, Java, or Haskell, you don't need to change your GF installation.**
==== What ==== - **What —**
This is the most common use case for the C runtime: compile
**This is the most common use case for the C runtime:** compile
your GF grammars into PGF with the standard GF executable, your GF grammars into PGF with the standard GF executable,
and manipulate the PGFs from another programming language, and manipulate the PGFs from another programming language,
using the bindings to the C runtime. using the bindings to the C runtime.
==== How ====
- **How —**
The Python, Java and Haskell bindings are found in the The Python, Java and Haskell bindings are found in the
``src/runtime/{python,java,haskell-bind}`` directories, ``src/runtime/{python,java,haskell-bind}`` directories,
respecively. Compile them by following the instructions respecively. Compile them by following the instructions
in the ``INSTALL`` or ``README`` files in those directories. in the ``INSTALL`` or ``README`` files in those directories.
The Python library can also be installed from PyPI using ``pip install pgf``. The Python library can also be installed from PyPI using ``pip install pgf``.
(If you are on Mac and get an error about ``clang`` version, you can try
some of [these solutions https://stackoverflow.com/questions/63972113/big-sur-clang-invalid-version-error-due-to-macosx-deployment-target]—but be careful before removing any existing installations.)
=== 2. Use GF shell with C runtime support === //If you are on Mac and get an error about ``clang`` version, you can try some of [these solutions https://stackoverflow.com/questions/63972113/big-sur-clang-invalid-version-error-due-to-macosx-deployment-target]—but be careful before removing any existing installations.//
==== What ====
=== Use GF shell with C runtime support ===
- **What —**
If you want to use the GF shell with C runtime functionalities, then you need to (re)compile GF with special flags. If you want to use the GF shell with C runtime functionalities, then you need to (re)compile GF with special flags.
The GF shell can be started with ``gf -cshell`` or ``gf -crun`` to use The GF shell can be started with ``gf -cshell`` or ``gf -crun`` to use
@@ -259,19 +228,18 @@ modes (use the ``help`` command in the shell for details).
(Re)compiling your GF with these flags will also give you (Re)compiling your GF with these flags will also give you
Haskell bindings to the C runtime, as a library called ``PGF2``, Haskell bindings to the C runtime, as a library called ``PGF2``,
but if you want Python or Java bindings, you need to do step 1. but if you want Python or Java bindings, you need to do [the previous step #bindings].
% ``PGF2``: a module to import in Haskell programs, providing a binding to the C run-time system. % ``PGF2``: a module to import in Haskell programs, providing a binding to the C run-time system.
==== How ==== - **How —**
If you use cabal, run the following command: If you use cabal, run the following command:
``` ```
cabal install -fc-runtime cabal install -fc-runtime
``` ```
from the top directory. from the top directory (``gf-core``).
If you use stack, uncomment the following lines in the ``stack.yaml`` file: If you use stack, uncomment the following lines in the ``stack.yaml`` file:
@@ -282,26 +250,20 @@ flags:
extra-lib-dirs: extra-lib-dirs:
- /usr/local/lib - /usr/local/lib
``` ```
and then run ``stack install`` from the top directory (``gf-core``).
First you will need to install the following libraries if not already installed:
autoconf, automake, libtool, make
On Ubuntu ``apt-get install autotools-dev`` //If you get an "``error while loading shared libraries``" when trying to run GF with C runtime, remember to declare your ``LD_LIBRARY_PATH``.//
On Fedora ``dnf install autoconf automake libtool`` //Add ``export LD_LIBRARY_PATH="/usr/local/lib"`` to either your ``.bashrc`` or ``.profile``. You should now be able to start GF with C runtime.//
and then run ``stack install``, also from the top directory.
If you get an error ``error while loading shared libraries`` when trying to run gf with C runtime, remember to declare your LD_LIBRARY_PATH. Add ``export LD_LIBRARY_PATH="/usr/local/lib"`` to either your .bashrc or .profile. You should now be able to start GF with C runtime. === Use GF server mode with C runtime ===
=== 3. Use GF server mode with C runtime ===
==== What ====
- **What —**
With this feature, ``gf -server`` mode is extended with new requests to call the C run-time With this feature, ``gf -server`` mode is extended with new requests to call the C run-time
system, e.g. ``c-parse``, ``c-linearize`` and ``c-translate``. system, e.g. ``c-parse``, ``c-linearize`` and ``c-translate``.
==== How ==== - **How —**
If you use cabal, run the following command: If you use cabal, run the following command:
``` ```
@@ -309,8 +271,7 @@ cabal install -fc-runtime -fserver
``` ```
from the top directory. from the top directory.
If you use stack, add the following lines in the If you use stack, add the following lines in the ``stack.yaml`` file:
If you use stack, uncomment the following lines in the ``stack.yaml`` file:
``` ```
flags: flags: