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

146 lines, 63 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 --skip-rebuild
32 If the output exists, skip the build
33
34Env vars respected:
35
36 OILS_PARALLEL_BUILD= [default 1]
37 Set to 0 to disable parallel compilation.
38
39 OILS_CXX_VERBOSE= [default '']
40 Set to 1 to show build details.
41
42Compile/link flags:
43
44 BASE_CXXFLAGS= (defined in build/common.sh)
45 Override this to disable basic flags like -fno-omit-frame-pointer
46
47 CXXFLAGS= [default ''] (defined in build/ninja-rules-cpp.sh)
48 Space-separated list of more compiler flags
49
50 LDFLAGS= [default ''] (defined in build/ninja-rules-cpp.sh)
51 Space-separated list of more linker flags
52
53Compiler flags come from 4 sources:
54
55 1. The $BASE_CXXFLAGS var
56 2. -I $REPO_ROOT is hard-coded
57 3. The build --variant, e.g. 'asan' adds -fsanitizer=address and more
58 4. The $CXXFLAGS var
59
60Linker flags come from 3 sources:
61
62 1. The build --variant, e.g. 'asan' adds -fsanitizer=address
63 2. $STRIP_FLAGS, a variable detected by ./configure
64 3. The $LDFLAGS var
65
66EOF
67}
68
69FLAG_cxx=cxx # default is system compiler
70FLAG_variant=opt # default is optimized build
71
72FLAG_translator=mycpp # or mycpp-souffle
73FLAG_skip_rebuild='' # false
74
75parse_flags() {
76 # Note: not supporting --cxx=foo like ./configure, only --cxx foo
77
78 while true; do
79 # ${1:-} needed for set -u
80 case "${1:-}" in
81 '')
82 break
83 ;;
84
85 -h|--help)
86 show_help
87 exit 0
88 ;;
89
90 --cxx)
91 if test $# -eq 1; then
92 die "--cxx requires an argument"
93 fi
94 shift
95 FLAG_cxx=$1
96 ;;
97
98 --variant)
99 if test $# -eq 1; then
100 die "--variant requires an argument"
101 fi
102 shift
103 FLAG_variant=$1
104 ;;
105
106 --translator)
107 if test $# -eq 1; then
108 die "--translator requires an argument"
109 fi
110 shift
111 FLAG_translator=$1
112 ;;
113
114 --skip-rebuild)
115 FLAG_skip_rebuild=true
116 ;;
117
118 *)
119 die "Invalid argument '$1'"
120 ;;
121 esac
122 shift
123 done
124
125 # legacy interface
126 FLAG_cxx=${1:-$FLAG_cxx}
127 FLAG_variant=${2:-$FLAG_variant}
128 FLAG_translator=${3:-$FLAG_translator}
129 FLAG_skip_rebuild=${4:-$FLAG_skip_rebuild}
130}
131
132
133OILS_PARALLEL_BUILD=${OILS_PARALLEL_BUILD:-1}
134
135_compile_one() {
136 local src=$4
137
138 echo "CXX $src"
139
140 # Delegate to function in build/ninja-rules-cpp.sh
141 if test "${_do_fork:-}" = 1; then
142 compile_one "$@" & # we will wait later
143 else
144 compile_one "$@"
145 fi
146}