-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathccmd.sh
executable file
·39 lines (29 loc) · 856 Bytes
/
ccmd.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
#!/bin/bash
# Check arguments
if [ $# -lt 2 ]; then
echo "Usage: ccmd <source_dir> <include_dir> [<flag1> <flag2> ...]"
exit 1
fi
# Name variables
src_dir=$1
include_dir=$2
dir=$(pwd)
# Set flags
flags=""
for arg in "${@:3}"; do
flags="$flags $arg"
done
# Creates the file
echo "[" > compile_commands.json
for file in "$src_dir"/*.c; do
# write the JSON object to the file
echo " {" >> compile_commands.json
echo " \"directory\": \"$dir\"," >> compile_commands.json
echo " \"file\": \"$file\"," >> compile_commands.json
echo " \"command\": \"gcc $flags -I$include_dir -c $file\"" >> compile_commands.json
echo " }," >> compile_commands.json
done
# Removes the last character (,)
sed -i '$ s/.$//' compile_commands.json
echo "]" >> compile_commands.json
echo "Succesfully created compile_commands.json"