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