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

132 lines, 71 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 FLAGS*
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 string
23
24 --variant ARG [default 'opt']
25 The build variant, e.g. dbg, opt, asan
26
27 --ldflags LDFLAGS [default '']
28 Space-separated list of additional linker flags.
29
30 --translator ARG [default 'mycpp']
31 Which bundle of translated source code to compile: mycpp, mycpp-souffle
32
33 --skip-rebuild
34 If the output exists, skip the build
35
36Environment variable respected:
37
38 OILS_PARALLEL_BUILD=
39 BASE_CXXFLAGS= # See build/ninja-rules-cpp.sh for details
40 CXXFLAGS=
41 OILS_CXX_VERBOSE=
42
43EOF
44}
45
46FLAG_cxx=cxx # default is system compiler
47FLAG_variant=opt # default is optimized build
48FLAG_ldflags= # default is no flags
49
50FLAG_translator=mycpp # or mycpp-souffle
51FLAG_skip_rebuild='' # false
52
53parse_flags() {
54 # Note: not supporting --cxx=foo like ./configure, only --cxx foo
55
56 while true; do
57 # ${1:-} needed for set -u
58 case "${1:-}" in
59 '')
60 break
61 ;;
62
63 -h|--help)
64 show_help
65 exit 0
66 ;;
67
68 --cxx)
69 if test $# -eq 1; then
70 die "--cxx requires an argument"
71 fi
72 shift
73 FLAG_cxx=$1
74 ;;
75
76 --ldflags)
77 if test $# -eq 1; then
78 die "--ldflags requires an argument"
79 fi
80 shift
81 FLAG_ldflags=$1
82 ;;
83
84 --variant)
85 if test $# -eq 1; then
86 die "--variant requires an argument"
87 fi
88 shift
89 FLAG_variant=$1
90 ;;
91
92 --translator)
93 if test $# -eq 1; then
94 die "--translator requires an argument"
95 fi
96 shift
97 FLAG_translator=$1
98 ;;
99
100 --skip-rebuild)
101 FLAG_skip_rebuild=true
102 ;;
103
104 *)
105 die "Invalid argument '$1'"
106 ;;
107 esac
108 shift
109 done
110
111 # legacy interface
112 FLAG_cxx=${1:-$FLAG_cxx}
113 FLAG_variant=${2:-$FLAG_variant}
114 FLAG_translator=${3:-$FLAG_translator}
115 FLAG_skip_rebuild=${4:-$FLAG_skip_rebuild}
116}
117
118
119OILS_PARALLEL_BUILD=${OILS_PARALLEL_BUILD:-1}
120
121_compile_one() {
122 local src=$4
123
124 echo "CXX $src"
125
126 # Delegate to function in build/ninja-rules-cpp.sh
127 if test "${_do_fork:-}" = 1; then
128 compile_one "$@" & # we will wait later
129 else
130 compile_one "$@"
131 fi
132}