forked from ruby/ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild
More file actions
executable file
·119 lines (101 loc) · 2.69 KB
/
Copy pathbuild
File metadata and controls
executable file
·119 lines (101 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env bash
# Install as `build` Git alias:
# git config alias.build '!git show origin/HEAD:build | bash -s -'
#
# Build debug & release targets
# git build
# Build a single target
# git build debug
# Build a new target with configure options and variables
# git build gcc CC=gcc
set -euo pipefail
target_configure_args='---
_:
- --disable-shared
- --disable-install-doc
- --with-ext=openssl,psych,json,+
- cflags=-march=native
debug: &debug
- --enable-devel
- --enable-debug-env
- cppflags=-DRUBY_DEBUG=1 -DUSE_RUBY_DEBUG_LOG=1
- optflags=-O0 -fno-omit-frame-pointer
jit:
- --enable-yjit=dev
- --enable-zjit=dev
- *debug
asan:
- cflags=-fsanitize=address
- cppflags=-DUSE_MN_THREADS=0
release: []
'
targets=()
[[ $# != 0 ]] || targets=(debug release)
candidates=$(ruby -ryaml -e 'puts YAML.load(STDIN, aliases: true).keys - ["_"]' "${1-_}" \
<<< "$target_configure_args"
)
readarray -t candidates <<< "$candidates"
for target do
if [[ " ${candidates[*]} " =~ $target ]]; then
targets+=("$target")
shift
else
break
fi
done
mkdir -p target
git check-ignore -q target || echo '/target/' >> "$(git rev-parse --git-common-dir)/info/exclude"
fail() {
set +x
local target=$1
shift
>&2 echo "[$target] $*"
return 1
}
trap -- exit INT
set -x
configure_args=(--cache-file="config.cache")
if [[ $(uname -s) = Darwin ]]; then
brew install autoconf openssl@3 libyaml gmp
configure_args+=(
--with-libyaml-dir="$(brew --prefix libyaml)"
--with-openssl-dir="$(brew --prefix openssl@3)"
--with-gmp-dir="$(brew --prefix gmp)"
)
elif type apt-get &>/dev/null; then
sudo apt-get install --yes --no-install-recommends autoconf openssl libyaml-dev libgmp-dev zlib1g-dev
elif type pacman &>/dev/null; then
sudo pacman -Sy --needed autoconf gmp libyaml zlib
fi
target_args() {
ruby -ryaml -e 'puts YAML.load(STDIN, aliases: true).fetch(ARGV.shift).flatten' "${1-_}" \
<<< "$target_configure_args"
}
readarray -tO"${#configure_args[@]}" configure_args <<< "$(target_args)"
./autogen.sh
nproc=$(getconf _NPROCESSORS_ONLN)
build() {
target=$1; shift
target_args=("$@")
mkdir -p target/"$target"
cd target/"$target"
target_args+=(--prefix="$PWD/-")
if [[ ${DEBUG-} ]]; then
./config.status --config 2>/dev/null ||:
printf "%b\n" "${configure_args[@]}" "${target_args[@]}"
cd -
return
fi
./config.status --recheck ||
../../configure "${configure_args[@]}" "${target_args[@]}" ||
fail "$target" configure failed
make -j "$nproc" || fail "$target" make failed
cd -
}
for target in "${targets[@]}"; do
readarray -t target_args <<< "$(target_args "$target")"
build "$target" "${target_args[@]}"
done
[[ $# = 0 ]] && exit
[[ $# = 1 ]] && fail "$1" no configure option or variable
build "$@"