-
Notifications
You must be signed in to change notification settings - Fork 56
Building ANTLR 4
Below are the versions of ANTLR (ANother Tool for Language Recognition) that are available in their respective distributions at the time of creation of these build instructions:
- Ubuntu 20.04 has
4.7.2-2
- Ubuntu 22.04 has
4.7.2-5
- Ubuntu 24.04 has
4.9.2-2
- Ubuntu 24.10 has
4.9.2-2
The instructions provided below specify the steps to build ANTLR v4.13.2 on Linux on IBM Z for the following distributions:
- RHEL (8.8, 8.10, 9.2, 9.4, 9.5)
- SLES 15 SP6
- Ubuntu (20.04, 22.04, 24.04, 24.10)
If only the Java runtime is required, then the pre-built jars for ANTLR v4.13.2 can be downloaded from here.
If you want to build AntLR4 using manual steps, go to STEP 1
Use the following commands to build AntLR4 using the build script. Please make sure you have wget installed.
wget -q https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/AntLR/4.13.2/build_antlr4.sh
# Build antlr4, skipping test cases
bash build_antlr4.sh [Provide -j (Semeru11|Semeru17|Semeru21|Temurin11|Temurin17|Temurin21|OpenJDK11|OpenJDK17|OpenJDK21) option for building with specific java]
The instructions below describe:
- Installing some tools needed for the installation or building.
- How to download and install the required Java SDK.
- If only the ANTLR Java runtime is required - how to download and install ANTLR pre-built binaries
- If other ANTLR build targets are required - how to download and install the required packages, build ANTLR and the supported build targets from source.
General Notes:
- When following the steps below please use a standard permission user unless otherwise specified.
- A directory
/<source_root>/
will be referred to in these instructions, this is a temporary writable directory anywhere you'd like to place it.
-
RHEL (8.8, 8.10, 9.2, 9.4, 9.5)
sudo yum install -y wget tar which curl diffutils --allowerasing
-
SLES 15 SP6
sudo zypper install -y wget gzip tar curl xz diffutils
-
Ubuntu (20.04, 22.04, 24.04, 24.10)
sudo apt-get update sudo apt-get install -y wget tar curl diffutils
-
With IBM Semeru Runtime
- Download and install IBM Semeru Runtime (Java 11, 17, 21) from here.
-
With Eclipse Adoptium Temurin Runtime
- Download and install Eclipse Adoptium Temurin Runtime (Java 11, 17, 21) from here.
-
With OpenJDK 11:
-
RHEL (8.8, 8.10, 9.2, 9.4, 9.5)
sudo yum install -y java-11-openjdk-devel
-
SLES 15 SP6
sudo zypper install -y java-11-openjdk java-11-openjdk-devel
-
Ubuntu (20.04, 22.04, 24.04, 24.10)
sudo apt-get update sudo apt-get install -y openjdk-11-jre openjdk-11-jdk
-
-
With OpenJDK 17:
-
RHEL (8.8, 8.10, 9.2, 9.4, 9.5)
sudo yum install -y java-17-openjdk-devel
-
SLES 15 SP6
sudo zypper install -y java-17-openjdk java-17-openjdk-devel
-
Ubuntu (20.04, 22.04, 24.04, 24.10)
sudo apt-get update sudo apt-get install -y openjdk-17-jre openjdk-17-jdk
-
-
With OpenJDK 21:
-
RHEL (8.8, 8.10, 9.2, 9.4, 9.5)
sudo yum install -y java-21-openjdk-devel
-
SLES 15 SP6
sudo zypper install -y java-21-openjdk java-21-openjdk-devel
-
Ubuntu (20.04, 22.04, 24.04, 24.10)
sudo apt-get update sudo apt-get install -y openjdk-21-jre openjdk-21-jdk
-
Note: At the time of creation of these build instructions, ANTLR was verified with Eclipse Adoptium Temurin Runtim (build 11.0.24+8, 17.0.12+7, 21.0.4+7)
and IBM Semeru Runtime Open Edition (build 11.0.24+8, 17.0.12+7, 21.0.4+7)
.
export SOURCE_ROOT=/<source_root>/
export JAVA_HOME=<path to installed java>
export PATH=$JAVA_HOME/bin:$PATH
cd $SOURCE_ROOT
curl -s -S -L -O https://www.antlr.org/download/antlr-4.13.2-complete.jar
JAR=$SOURCE_ROOT/antlr-4.13.2-complete.jar
export CLASSPATH=".:$JAR:$CLASSPATH"
Test the tool and runtime using the example provided here.
alias antlr4='java -Xmx500M -cp $CLASSPATH org.antlr.v4.Tool'
alias grun='java -Xmx500M -cp $CLASSPATH org.antlr.v4.gui.TestRig'
cd $SOURCE_ROOT
mkdir antlrtest
cd antlrtest
cat > Hello.g4 <<'EOF'
grammar Hello;
r : 'hello' ID ;
ID : [a-z]+ ;
WS : [ \t\r\n]+ -> skip ;
EOF
antlr4 Hello.g4
javac Hello*.java
diff -w <(grun Hello r -tree <<<"hello world") <(echo "(r hello world)")
- RHEL (8.8, 8.10)
sudo yum install -y unzip xz libuuid-devel curl wget git make diffutils gcc gcc-c++ python2 python38 cmake libarchive \
clang
- RHEL (9.2, 9.4, 9.5)
sudo yum install -y unzip xz libuuid-devel curl wget git make diffutils gcc gcc-c++ python3 cmake libarchive clang
- SLES 15 SP6
sudo zypper install -y unzip xz xz-devel libuuid-devel curl wget git make diffutils gcc13 gcc13-c++ python cmake \
clang7 gawk gdbm-devel libbz2-devel libdb-4_8-devel libffi-devel libnsl-devel libopenssl-devel libuuid-devel make \
ncurses-devel readline-devel sqlite3-devel tar tk-devel zlib-devel gzip
#switch to GCC 13
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-13 40
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 40
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 40
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-13 40
- Ubuntu 20.04
sudo apt-get update
sudo apt-get install -y unzip xz-utils uuid-dev curl wget git make python python3.8 gcc g++ cmake clang pkg-config \
libssl-dev libcurl4-openssl-dev zlib1g-dev
- Ubuntu 22.04
sudo apt-get update
sudo apt-get install -y unzip xz-utils uuid-dev curl wget git make python2 bzip2 tk-dev libghc-bzlib-dev gcc g++ cmake \
clang pkg-config
- Ubuntu (24.04, 24.10)
sudo apt-get update
sudo apt-get install -y unzip xz-utils uuid-dev curl wget git make bzip2 tk-dev libghc-bzlib-dev gcc g++ cmake clang \
pkg-config
- Install Go 1.19.5, then use the following command to set the GO111MODULE environment variable to
auto
:
cd $SOURCE_ROOT
export GO_VERSION="1.19.5"
export GOROOT=$SOURCE_ROOT/go
wget -q https://storage.googleapis.com/golang/go"$GO_VERSION".linux-s390x.tar.gz
sudo tar -xzf go"$GO_VERSION".linux-s390x.tar.gz
export PATH=$GOROOT/bin:$PATH
export CC=gcc
go env -w GO111MODULE=auto
go version
- Download NodeJS, Maven and ANTLR source for all distros.
cd $SOURCE_ROOT
export NODE_TAR=node-v16.17.1-linux-s390x.tar.xz
curl -s -S -L -O https://nodejs.org/dist/v16.17.1/${NODE_TAR}
tar xJf ${NODE_TAR}
export MAVEN_TAR=apache-maven-3.8.6-bin.tar.gz
curl -s -S -L -O https://archive.apache.org/dist/maven/maven-3/3.8.6/binaries/${MAVEN_TAR}
tar xzf ${MAVEN_TAR}
export ZIP=antlr4-4.13.2.zip
curl -s -S -L -o ${ZIP} https://github.com/antlr/antlr4/archive/4.13.2.zip
unzip -q ${ZIP}
- Set the PATH environment variable
export PATH=$SOURCE_ROOT/node-v16.17.1-linux-s390x/bin:$SOURCE_ROOT/apache-maven-3.8.6/bin:${PATH}
- Build the ANTLR tool, then build the supported runtimes.
export MAVEN_OPTS="-Xmx1G"
cd $SOURCE_ROOT/antlr4-4.13.2
mvn install -DskipTests=true
cd runtime/Cpp
mkdir build && mkdir run
cd build
cmake -DWITH_LIBCXX=Off -DCMAKE_BUILD_TYPE=release ..
make -j 8
DESTDIR=$SOURCE_ROOT/antlr4-4.13.2/runtime/Cpp/run make install
Note: If multiple gcc versions are installed, DCMAKE_CXX_COMPILER and DCMAKE_C_COMPILER flags can be used in cmake command to give correct version path.
Note: ANTLR 4.13.2 runtimes supported for Linux on IBM Z are Java, Python, Go, NodeJS and C++.
cd $SOURCE_ROOT/antlr4-4.13.2/runtime-testsuite
mvn -Dtest=java.** test
mvn -Dtest=python2.** test # except for RHEL 9.x, SLES 15.x and Ubuntu 24.x as Python 2 has been removed from these distros
mvn -Dtest=python3.** test
sudo env "PATH=$PATH" "GOROOT=$GOROOT" mvn -Dtest=go.** test
mvn -Dtest=javascript.** test
mvn -Dtest=cpp.** test
- http://www.antlr.org
- https://github.com/antlr/antlr4/blob/master/doc/getting-started.md
- https://github.com/antlr/antlr4/blob/master/doc/antlr-project-testing.md
- https://github.com/antlr/antlr4/blob/master/doc/targets.md
- https://www.suse.com/releasenotes/s390x/SUSE-SLES/15-SP4/index.html#jsc-SLE-16747
- https://access.redhat.com/solutions/4455511
The information provided in this article is accurate at the time of writing, but on-going development in the open-source projects involved may make the information incorrect or obsolete. Please open issue or contact us on IBM Z Community if you have any questions or feedback.