Commit | Line | Data |
---|---|---|
a881d7c9 JG |
1 | #!/usr/bin/env bash |
2 | # Copyright (C) 2024 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
3 | # | |
4 | # SPDX-License-Identifier: LGPL-2.1-only | |
5 | # | |
6 | ||
7 | source_dir="$1" | |
8 | ||
9 | # Run make quietly to check if a Makefile exists | |
10 | make_output=$(make -C "$source_dir" -q 2>&1) | |
11 | make_exit_status=$? | |
12 | ||
13 | # Check the return status of make -q | |
14 | if [ $make_exit_status -eq 2 ]; then | |
15 | # It seems the Makefiles don't exist. Most likely the user forgot to | |
16 | # setup their tree. | |
17 | echo "$make_output" | |
18 | echo -e "\033[33mMake couldn't find a Makefile: did you run ./bootstrap and ./configure ?\033[0m" | |
19 | exit 1 | |
20 | fi | |
21 | ||
22 | # Check if compile_commands.json does not exist in the source directory and if bear is installed | |
23 | if [ ! -f "$source_dir/compile_commands.json" ] && which bear >/dev/null 2>&1; then | |
24 | # Bear is installed and compile_commands.json is not present | |
25 | # Perform a make clean since compile_commands.json is missing and bear is installed | |
26 | make -C "$source_dir" clean | |
27 | ||
28 | # Prefix bear to the make command | |
29 | command_prefix="bear -- " | |
30 | fi | |
31 | ||
32 | # Run make with or without bear prefix, depending on the condition above | |
33 | eval "${command_prefix}"make -C "$source_dir" -j "$(nproc)" |