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

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