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 |
|
11 | show_help() {
|
12 | cat <<'EOF'
|
13 | Compile the oils-for-unix source into an executable.
|
14 |
|
15 | Usage:
|
16 | _build/oils.sh FLAG*
|
17 | _build/oils.sh --help
|
18 |
|
19 | Flags:
|
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 |
|
34 | Env 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 |
|
42 | Compile/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 |
|
53 | Compiler flags come from these 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. Flags detected by ./configure, e.g. for GNU readline
|
59 | 5. The $CXXFLAGS var
|
60 |
|
61 | Linker flags come from these sources:
|
62 |
|
63 | 1. The build --variant, e.g. 'asan' adds -fsanitizer=address
|
64 | 2. Flags detected by ./configure, like $STRIP_FLAGS and -lreadline for GNU
|
65 | readline
|
66 | 3. The $LDFLAGS var
|
67 |
|
68 | EOF
|
69 | }
|
70 |
|
71 | FLAG_cxx=cxx # default is system compiler
|
72 | FLAG_variant=opt # default is optimized build
|
73 |
|
74 | FLAG_translator=mycpp # or mycpp-souffle
|
75 | FLAG_skip_rebuild='' # false
|
76 |
|
77 | parse_flags() {
|
78 | # Note: not supporting --cxx=foo like ./configure, only --cxx foo
|
79 |
|
80 | while true; do
|
81 | # ${1:-} needed for set -u
|
82 | case "${1:-}" in
|
83 | '')
|
84 | break
|
85 | ;;
|
86 |
|
87 | -h|--help)
|
88 | show_help
|
89 | exit 0
|
90 | ;;
|
91 |
|
92 | --cxx)
|
93 | if test $# -eq 1; then
|
94 | die "--cxx requires an argument"
|
95 | fi
|
96 | shift
|
97 | FLAG_cxx=$1
|
98 | ;;
|
99 |
|
100 | --variant)
|
101 | if test $# -eq 1; then
|
102 | die "--variant requires an argument"
|
103 | fi
|
104 | shift
|
105 | FLAG_variant=$1
|
106 | ;;
|
107 |
|
108 | --translator)
|
109 | if test $# -eq 1; then
|
110 | die "--translator requires an argument"
|
111 | fi
|
112 | shift
|
113 | FLAG_translator=$1
|
114 | ;;
|
115 |
|
116 | --skip-rebuild)
|
117 | FLAG_skip_rebuild=true
|
118 | ;;
|
119 |
|
120 | *)
|
121 | die "Invalid argument '$1'"
|
122 | ;;
|
123 | esac
|
124 | shift
|
125 | done
|
126 |
|
127 | # legacy interface
|
128 | FLAG_cxx=${1:-$FLAG_cxx}
|
129 | FLAG_variant=${2:-$FLAG_variant}
|
130 | FLAG_translator=${3:-$FLAG_translator}
|
131 | FLAG_skip_rebuild=${4:-$FLAG_skip_rebuild}
|
132 | }
|
133 |
|
134 |
|
135 | OILS_PARALLEL_BUILD=${OILS_PARALLEL_BUILD:-1}
|
136 |
|
137 | _compile_one() {
|
138 | local src=$4
|
139 |
|
140 | echo "CXX $src"
|
141 |
|
142 | # Delegate to function in build/ninja-rules-cpp.sh
|
143 | if test "${_do_fork:-}" = 1; then
|
144 | compile_one "$@" & # we will wait later
|
145 | else
|
146 | compile_one "$@"
|
147 | fi
|
148 | }
|