aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2022-03-14 11:39:03 +0000
committerGitHub <noreply@github.com>2022-03-14 11:39:03 +0000
commita882260db6dd781862db6951dc0230ddc8c3e07a (patch)
treebbbdc096defd5d7f0cd3b0dc47ef0d6efbed7127
parent633157f4f81be317560e4f23f6f676c337c1d2a4 (diff)
parent2652c2d7a573cc44379d7843472b9f379246d31b (diff)
Merge pull request #1605 from colrdavidson/linux_build
Make llvm-config build more general for linux
-rw-r--r--.github/workflows/ci.yml6
-rw-r--r--Makefile6
-rwxr-xr-xbuild_odin.sh140
3 files changed, 146 insertions, 6 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 8c26c7a00..2bd3ca9ad 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -7,9 +7,9 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Download LLVM, botan
- run: sudo apt-get install llvm-11 clang-11 llvm libbotan-2-dev botan
+ run: sudo apt-get install llvm-11 clang-11 libbotan-2-dev botan
- name: build odin
- run: make release
+ run: ./build_odin.sh release
- name: Odin version
run: ./odin version
timeout-minutes: 1
@@ -58,7 +58,7 @@ jobs:
TMP_PATH=$(xcrun --show-sdk-path)/user/include
echo "CPATH=$TMP_PATH" >> $GITHUB_ENV
- name: build odin
- run: make release
+ run: ./build_odin.sh release
- name: Odin version
run: ./odin version
timeout-minutes: 1
diff --git a/Makefile b/Makefile
index b8bf26a88..bea0569a9 100644
--- a/Makefile
+++ b/Makefile
@@ -30,10 +30,10 @@ ifeq ($(OS), Darwin)
ifeq ($(shell $(LLVM_CONFIG) --version | grep -E $(LLVM_VERSION_PATTERN)),)
ifeq ($(ARCH), arm64)
$(error "Requirement: llvm-config must be base version 13 for arm64")
- else
+ else
$(error "Requirement: llvm-config must be base version greater than 11 for amd64/x86")
- endif
- endif
+ endif
+ endif
LDFLAGS:=$(LDFLAGS) -liconv -ldl
CFLAGS:=$(CFLAGS) $(shell $(LLVM_CONFIG) --cxxflags --ldflags)
diff --git a/build_odin.sh b/build_odin.sh
new file mode 100755
index 000000000..a323782a1
--- /dev/null
+++ b/build_odin.sh
@@ -0,0 +1,140 @@
+#!/bin/bash
+set -eu
+
+GIT_SHA=$(git rev-parse --short HEAD)
+DISABLED_WARNINGS="-Wno-switch -Wno-macro-redefined -Wno-unused-value"
+LDFLAGS="-pthread -lm -lstdc++"
+CFLAGS="-std=c++14 -DGIT_SHA=\"$GIT_SHA\""
+CFLAGS="$CFLAGS -DODIN_VERSION_RAW=\"dev-$(date +"%Y-%m")\""
+CC=clang
+OS=$(uname)
+
+panic() {
+ printf "%s\n" "$1"
+ exit 1
+}
+
+version() { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
+
+config_darwin() {
+ ARCH=$(uname -m)
+ LLVM_CONFIG=llvm-config
+
+ # allow for arm only llvm's with version 13
+ if [ ARCH == arm64 ]; then
+ MIN_LLVM_VERSION=("13.0.0")
+ else
+ # allow for x86 / amd64 all llvm versions begining from 11
+ MIN_LLVM_VERSION=("11.1.0")
+ fi
+
+ if [ $(version $($LLVM_CONFIG --version)) -lt $(version $MIN_LLVM_VERSION) ]; then
+ if [ ARCH == arm64 ]; then
+ panic "Requirement: llvm-config must be base version 13 for arm64"
+ else
+ panic "Requirement: llvm-config must be base version greater than 11 for amd64/x86"
+ fi
+ fi
+
+ LDFLAGS="$LDFLAGS -liconv -ldl"
+ CFLAGS="$CFLAGS $($LLVM_CONFIG --cxxflags --ldflags)"
+ LDFLAGS="$LDFLAGS -lLLVM-C"
+}
+
+config_openbsd() {
+ LLVM_CONFIG=/usr/local/bin/llvm-config
+
+ LDFLAGS="$LDFLAGS -liconv"
+ CFLAGS="$CFLAGS $($LLVM_CONFIG --cxxflags --ldflags)"
+ LDFLAGS="$LDFLAGS $($LLVM_CONFIG --libs core native --system-libs)"
+}
+
+config_linux() {
+ if which llvm-config > /dev/null 2>&1; then
+ LLVM_CONFIG=llvm-config
+ elif which llvm-config-11 > /dev/null 2>&1; then
+ LLVM_CONFIG=llvm-config-11
+ elif which llvm-config-11-64 > /dev/null 2>&1; then
+ LLVM_CONFIG=llvm-config-11-64
+ else
+ panic "Unable to find LLVM-config"
+ fi
+
+ MIN_LLVM_VERSION=("11.0.0")
+ if [ $(version $($LLVM_CONFIG --version)) -lt $(version $MIN_LLVM_VERSION) ]; then
+ echo "Tried to use " $(which $LLVM_CONFIG) "version" $($LLVM_CONFIG --version)
+ panic "Requirement: llvm-config must be base version greater than 11"
+ fi
+
+ LDFLAGS="$LDFLAGS -ldl"
+ CFLAGS="$CFLAGS $($LLVM_CONFIG --cxxflags --ldflags)"
+ LDFLAGS="$LDFLAGS $($LLVM_CONFIG --libs core native --system-libs)"
+}
+
+build_odin() {
+ case $1 in
+ debug)
+ EXTRAFLAGS="-g"
+ ;;
+ release)
+ EXTRAFLAGS="-O3"
+ ;;
+ release-native)
+ EXTRAFLAGS="-O3 -march=native"
+ ;;
+ nightly)
+ EXTRAFLAGS="-DNIGHTLY -O3"
+ ;;
+ *)
+ panic "Build mode unsupported!"
+ esac
+
+ set -x
+ $CC src/main.cpp src/libtommath.cpp $DISABLED_WARNINGS $CFLAGS $EXTRAFLAGS $LDFLAGS -o odin
+ set +x
+}
+
+run_demo() {
+ ./odin run examples/demo/demo.odin
+}
+
+case $OS in
+Linux)
+ config_linux
+ ;;
+Darwin)
+ config_darwin
+ ;;
+OpenBSD)
+ config_openbsd
+ ;;
+*)
+ panic "Platform unsupported!"
+esac
+
+if [[ $# -eq 0 ]]; then
+ build_odin debug
+ run_demo
+ exit 0
+fi
+
+if [[ $# -eq 1 ]]; then
+ case $1 in
+ report)
+ if [[ ! -f "./odin" ]]; then
+ build_odin debug
+ fi
+
+ ./odin report
+ exit 0
+ ;;
+ *)
+ build_odin $1
+ ;;
+ esac
+
+ run_demo
+ exit 0
+else
+ panic "Too many arguments!"
+fi