Skip to content

Commit 33438f9

Browse files
build.sh:
- Change default dir to `build` (pwd-relative), for usage in other projects. - Check for `CMakeLists.txt` before `rm -rf $BUILD_DIR`. - Document example usages. - Use `/usr/bin/env bash` for Mac users with homebrew bash.
1 parent 125fac8 commit 33438f9

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

scripts/build.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
#
3+
# release build:
4+
# ~/pyth-client$ ./scripts/build.sh [build]
5+
#
6+
# debug build:
7+
# ~/pyth-client$ ./scripts/build.sh debug
8+
#
9+
# build other project:
10+
# ~/pyth-client$ ./scripts/build.sh ../serum-pyth/build
11+
# ~/serum-pyth$ ../pyth-client/scripts/build.sh
12+
#
213

314
set -eu
415

@@ -7,10 +18,7 @@ then
718
BUILD_DIR="$1"
819
shift
920
else
10-
THIS_DIR="$( dirname "${BASH_SOURCE[0]}" )"
11-
THIS_DIR="$( cd "${THIS_DIR}" && pwd )"
12-
ROOT_DIR="$( dirname "${THIS_DIR}" )"
13-
BUILD_DIR="${ROOT_DIR}/build"
21+
BUILD_DIR="build"
1422
fi
1523

1624
ROOT_DIR="$( mkdir -p "${BUILD_DIR}" && cd "${BUILD_DIR}/.." && pwd )"
@@ -21,6 +29,13 @@ then
2129
CMAKE_ARGS=( "-DCMAKE_BUILD_TYPE=Debug" )
2230
fi
2331

32+
# Check before rm -rf $BUILD_DIR
33+
if [[ ! -f "${ROOT_DIR}/CMakeLists.txt" ]]
34+
then
35+
>&2 echo "Not a cmake project dir: ${ROOT_DIR}"
36+
exit 1
37+
fi
38+
2439
set -x
2540

2641
cd "${ROOT_DIR}"

0 commit comments

Comments
 (0)