OILS / build / oils-preamble.sh View on Github | oils.pub

169 lines, 75 significant
1#!/bin/sh
2#
3# __FILE_COMMENT__
4#
5# For usage, run:
6#
7# _build/oils.sh --help
8
9. build/ninja-rules-cpp.sh
10
11show_help() {
12 cat <<'EOF'
13Compile the oils-for-unix source into an executable.
14
15Usage:
16 _build/oils.sh FLAG*
17 _build/oils.sh --help
18
19Flags:
20
21 --cxx CXX [default 'cxx']
22 The C++ compiler to use: 'cxx' for system compiler, 'clang', or custom
23 string
24
25 --variant ARG [default 'opt']
26 The build variant, e.g. dbg, opt, asan, which adds compile and link flags.
27
28 --translator ARG [default 'mycpp']
29 Which bundle of translated source code to compile: mycpp, mycpp-souffle
30
31 --suffix ARG [default '']
32 Append a string like '-static' to oils-for-unix, and symlinks like osh, ysh
33
34 --without-readline
35 Don't link with GNU readline. This overrides ./configure --without-readline
36
37 --skip-rebuild
38 If the output exists, skip the build
39
40Env vars respected:
41
42 OILS_PARALLEL_BUILD= [default 1]
43 Set to 0 to disable parallel compilation.
44
45 OILS_CXX_VERBOSE= [default '']
46 Set to 1 to show build details.
47
48Compile/link flags:
49
50 BASE_CXXFLAGS= (defined in build/common.sh)
51 Override this to disable basic flags like -fno-omit-frame-pointer
52
53 CXXFLAGS= [default ''] (defined in build/ninja-rules-cpp.sh)
54 Space-separated list of more compiler flags
55
56 LDFLAGS= [default ''] (defined in build/ninja-rules-cpp.sh)
57 Space-separated list of more linker flags
58
59Compiler flags come from these sources:
60
61 1. The $BASE_CXXFLAGS var
62 2. -I $REPO_ROOT is hard-coded
63 3. The build --variant, e.g. 'asan' adds -fsanitizer=address and more
64 4. Flags detected by ./configure, e.g. for GNU readline
65 5. The $CXXFLAGS var
66
67Linker flags come from these sources:
68
69 1. The build --variant, e.g. 'asan' adds -fsanitizer=address
70 2. Flags detected by ./configure, like $STRIP_FLAGS and -lreadline for GNU
71 readline
72 3. The $LDFLAGS var
73
74EOF
75}
76
77FLAG_cxx=cxx # default is system compiler
78FLAG_variant=opt # default is optimized build
79
80FLAG_translator=mycpp # or mycpp-souffle
81FLAG_suffix='' # false
82
83FLAG_without_readline=''
84FLAG_skip_rebuild=''
85
86parse_flags() {
87 # Note: not supporting --cxx=foo like ./configure, only --cxx foo
88
89 while true; do
90 # ${1:-} needed for set -u
91 case "${1:-}" in
92 '')
93 break
94 ;;
95
96 -h|--help)
97 show_help
98 exit 0
99 ;;
100
101 --cxx)
102 if test $# -eq 1; then
103 die "--cxx requires an argument"
104 fi
105 shift
106 FLAG_cxx=$1
107 ;;
108
109 --variant)
110 if test $# -eq 1; then
111 die "--variant requires an argument"
112 fi
113 shift
114 FLAG_variant=$1
115 ;;
116
117 --translator)
118 if test $# -eq 1; then
119 die "--translator requires an argument"
120 fi
121 shift
122 FLAG_translator=$1
123 ;;
124
125 --suffix)
126 if test $# -eq 1; then
127 die "--suffix requires an argument"
128 fi
129 shift
130 FLAG_suffix=$1
131 ;;
132
133 --without-readline)
134 FLAG_without_readline=true
135 ;;
136
137 --skip-rebuild)
138 FLAG_skip_rebuild=true
139 ;;
140
141 *)
142 die "Invalid argument '$1'"
143 ;;
144 esac
145 shift
146 done
147
148 # legacy interface
149 FLAG_cxx=${1:-$FLAG_cxx}
150 FLAG_variant=${2:-$FLAG_variant}
151 FLAG_translator=${3:-$FLAG_translator}
152 FLAG_skip_rebuild=${4:-$FLAG_skip_rebuild}
153}
154
155
156OILS_PARALLEL_BUILD=${OILS_PARALLEL_BUILD:-1}
157
158_compile_one() {
159 local src=$4
160
161 echo "CXX $src"
162
163 # Delegate to function in build/ninja-rules-cpp.sh
164 if test "${_do_fork:-}" = 1; then
165 compile_one "$@" & # we will wait later
166 else
167 compile_one "$@"
168 fi
169}