Skip to content

Commit

Permalink
Add configure.sh script (#89)
Browse files Browse the repository at this point in the history
Add `configure.sh` script to simplify the build set up.
  • Loading branch information
daniel-larraz authored Nov 5, 2024
1 parent 84dd280 commit 5b74e02
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 31 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
name: [linux-x86_64, macOS-x86_64, macOS-arm64, windows-x86_64]
build-type: [ Release, Debug ]
build-type: [ release, debug ]
include:
- name: linux-x86_64
os: ubuntu-20.04
Expand Down Expand Up @@ -64,20 +64,16 @@ jobs:
- name: Build
run: |
mkdir build
./configure.sh ${{ matrix.build-type }}
cd build
if [[ "$RUNNER_OS" == "Windows" ]]; then
export CMAKE_GENERATOR="MSYS Makefiles"
fi
cmake -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} ..
make -j2
- name: Test
run: ctest --output-on-failure
working-directory: build

- name: Upload binary
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && matrix.build-type == 'production'
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && matrix.build-type == 'release'
uses: actions/upload-artifact@v4
with:
name: ethos-${{ matrix.name }}
Expand Down
38 changes: 14 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,33 @@

## Building the Ethos checker

You need cmake (>= version 3.12) and gmp to build the Ethos Checker.
You need CMake (>= version 3.12) and GMP to build the Ethos Checker.

To build a regular build, issue:

```bash
cd /path/to/ethos_checker
mkdir build
cd build
cmake ..
make
./configure.sh
# use --prefix to specify an install prefix (default: /usr/local)
# use --name=<PATH> for custom build directory
cd <build_dir> # default is ./build
make # use -jN for parallel build with N threads
make install # to install into the prefix specified above
```

The executable, called `ethos`, will be created in the build/src folder.
The executable, called `ethos`, will be created in the `<build_dir>/src` folder.

Alternatively you can configure a regular build with
The ethos's build system provides the following pre-defined build profiles:

```bash
cmake -DCMAKE_BUILD_TYPE=Release ..
```
To build a regular build and install it into /path/to/install, issue:
- *release*: Optimized, assertions and tracing disabled.

```bash
cd /path/to/ethos_checker
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX:PATH=/path/to/install ..
make install
```
- *debug*: Unoptimized, debug symbols, assertions, and tracing enabled.

To build a debug build, issue:
The default build profile is **release**, which you will get if you just run
`./configure.sh`. To choose a different build profile use:

```bash
cd /path/to/ethos_checker
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
make
./configure.sh <profile>
```

## Using the Ethos checker
Expand Down
109 changes: 109 additions & 0 deletions configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/usr/bin/env bash
#--------------------------------------------------------------------------#

set -e -o pipefail

usage () {
cat <<EOF
Usage: $0 [<build type>] [<option> ...]
Build types:
release
debug
General options;
-h, --help display this help and exit
--prefix=STR install directory
--name=STR use custom build directory name (optionally: +path)
CMake Options (Advanced)
-DVAR=VALUE manually add CMake options
EOF
exit 0
}

#--------------------------------------------------------------------------#

die () {
echo "*** configure.sh: $*" 1>&2
exit 1
}

msg () {
echo "[configure.sh] $*"
}

#--------------------------------------------------------------------------#

[ ! -e src ] && die "$0 not called from ethos base directory"

#--------------------------------------------------------------------------#

build_dir=build
install_prefix=default

#--------------------------------------------------------------------------#

buildtype=default

#--------------------------------------------------------------------------#

cmake_opts=""

while [ $# -gt 0 ]
do
case $1 in

-h|--help) usage;;

--prefix) die "missing argument to $1 (try -h)" ;;
--prefix=*)
install_prefix=${1##*=}
# Check if install_prefix is an absolute path and if not, make it
# absolute.
case $install_prefix in
/*) ;; # absolute path
*) install_prefix=$(pwd)/$install_prefix ;; # make absolute path
esac
;;

--name) die "missing argument to $1 (try -h)" ;;
--name=*) build_dir=${1##*=} ;;

-D*) cmake_opts="${cmake_opts} $1" ;;

-*) die "invalid option '$1' (try -h)";;

*) case $1 in
release) buildtype=Release;;
debug) buildtype=Debug;;
*) die "invalid build type (try -h)";;
esac
;;
esac
shift
done

#--------------------------------------------------------------------------#

[ $buildtype != default ] \
&& cmake_opts="$cmake_opts -DCMAKE_BUILD_TYPE=$buildtype"
[ "$install_prefix" != default ] \
&& cmake_opts="$cmake_opts -DCMAKE_INSTALL_PREFIX=$install_prefix"

uname_output=$(uname)
[[ $uname_output =~ ^MSYS || $uname_output =~ ^MINGW ]] \
&& export CMAKE_GENERATOR="MSYS Makefiles"

root_dir=$(pwd)

mkdir -p "$build_dir"

cd "$build_dir"

[ -e CMakeCache.txt ] && rm CMakeCache.txt
build_dir_escaped=$(echo "$build_dir" | sed 's/\//\\\//g')
cmake "$root_dir" $cmake_opts 2>&1 | \
sed "s/^Now just/Now change to '$build_dir_escaped' and/"

0 comments on commit 5b74e02

Please sign in to comment.