-
Notifications
You must be signed in to change notification settings - Fork 2
/
compile.sh
executable file
·136 lines (118 loc) · 4.13 KB
/
compile.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env bash
# This script will compile your project and generate a compile_commands.json.
# How friggin awesome is that??
# Let's start off our journey by creaing a build directory.
if ! [[ -n $BUILD_DIR ]]; then
BUILD_DIR="build/"
fi
mkdir -p $BUILD_DIR
cd $BUILD_DIR
# Handy-dandy ASCII color variables
normal=\\e[0m
red=\\e[31m
yellow=\\e[33m
cyan=\\e[36m
green=\\e[32m
blue=\\e[34m
################################
# Process command-line options #
################################
if [[ $# < 1 ]]; then
echo ""
elif [[ "$1" == "help" ]] || [[ "$1" == "h" ]] || [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]]; then
echo "compile.sh"
printf "$yellow"
echo "A tool for compiling your project and generating a compile_commands.json."
echo ""
printf "$cyan"
echo "Usage:"
printf "$normal"
echo " * View the help screen:"
echo " ./compile.sh --help"
echo ""
echo " * General Usage:"
echo " ./compile.sh"
echo ""
echo " * Clean your build:"
echo " ./compile.sh clean"
echo ""
printf "$cyan"
echo "Environmental Variables:"
printf "$normal"
echo " * \$BUILD_DIR"
echo " Directory for project to be created"
echo " --Defaults to \"build/\""
echo ""
echo " Keep in mind that build/ is recommended because it"
echo " is also gitignored. Also note that if your specified"
echo " path does not exist, it will be recursively created."
echo ""
echo " * \$QMAKE_CMD"
echo " Custom qmake command. (ex: \"qmake-qt5\")"
echo " --Defaults to \"qmake\""
echo ""
exit
elif [[ $1 == "clean" ]]; then
make clean
rm -f ../compile_commands.json
exit
elif [[ $1 == "only_hope" ]]; then
printf $blue
printf " .==.\n ()''()-.\n .---. ;--; /\n .'_:___\". _..'. __'.\n |__ --==|'-''' \'...;\n [ ] :[| |---\\n |__| I=[| .' '.\n / / ____| : '._\n |-/.____.' | : :\n /___\ /___\ '-'._----'\n $normal art by Shanaka Dias\n\n"
exit
else
echo "Unknown option \"$1\" :-("
exit
fi
####################################
# Do a very basic dependency check #
####################################
# We are going to test if bear, qmake, and make are availible.
export HAS_BEAR=0 HAS_QMAKE=0 HAS_MAKE=0
# If user did not specify the QMAKE_CMD variable, default to "qmake"
if ! [[ -n $QMAKE_CMD ]]; then
QMAKE_CMD="qmake"
fi
# Compile tool dependency checking function
function dep_check {
program_name=$1
missing_message=$2
var_name=$3
if ! which $program_name>/dev/null 2>&1; then
printf "\n$missing_message"
else
eval $var_name=true
fi
}
# Check for bear, qmake, and make
dep_check "bear" \
"$yellow[WARNING]$normal 'bear' not found. compile_commands.json will not be generated.\n\tNeed to install bear? Get it here: https://github.com/rizsotto/Bear\n" \
"HAS_BEAR"
dep_check $QMAKE_CMD \
"$red[FATAL]$normal 'qmake' not found.\n If you would like to specify a custom qmake command, you may set the QMAKE_CMD environmental variable\n $cyan ex. QMAKE_CMD=\"qmake-qt5\" ./compile.sh$normal\n" \
"HAS_QMAKE"
dep_check "make" \
"$red[FATAL]$normal 'make' not found. Please ensure GNU make is installed\n" \
"HAS_MAKE"
# Display error/warning messages if needed
if [[ $HAS_QMAKE != true || $HAS_MAKE != true ]]; then
printf "$red\n========== Failed dependency check :( ==========$normal\n\n"
exit
elif [[ $HAS_BEAR != true ]]; then
printf "$yellow\n========== You've got 1 warning ¯\_(ツ)_/¯ ==========$normal\n\n"
fi
# Inform user that we are now compiling their project
printf "$yellow"
printf "Compiling your project...\n\n"
printf "$normal"
####################################
# Compiling the project #
####################################
echo "QT += testlib" > VibratoNotes.pro
echo "include(../VibratoNotes-Desktop.pro)" >> VibratoNotes.pro
qmake VibratoNotes.pro
if [[ $HAS_BEAR == true ]]; then
bear -a -o ../compile_commands.json make -j$(nproc)
else
make -j$(nproc)
fi