-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.sh
135 lines (118 loc) · 3.02 KB
/
project.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
#!/usr/bin/bash
###########################################################################################
# Cave
###########################################################################################
# there's a project.sh in root of the project. before do anything, source it: . project.sh
#
# tools:
# static code analyzer:
# - c: splint
# memory debugger: valgrind
# system call tracer: strace
# display info about .obj files: objdump
#
# opening/editing files: noevim
# folding/unfolding: z Shift+m, z Shift+r
# switch between source/header: F1
#
# lookup refrences: ctags
# find/replace in single file: neovim
# find/replace in whole project: ambr <source_text> <dest_text>
# find files: ctrl-t | ff <file-name> | fzf | fd
# find string/text in single file: neovim (/)
# find string/text in whole project: ft <text> | rg <text>
# find docs of c standard librariy: install man-pages-devel and man <method>
#
# debugging: seergdb(uses gdb under the hood)
###########################################################################################
# pardis, test
app=""
# debug, release, test
mode="debug"
build_dir="build/$mode"
mode_flags=""
if [ "$mode" == "debug" ]; then
app="cave"
mode_flags="-g -O0"
fi
if [ "$mode" == "release" ]; then
app="cave"
mode_flags="-O3"
fi
if [ "$mode" == "test" ]; then
app="cave_test"
fi
_createBuildDir() {
echo ">>> Creating '$build_dir' directory"
mkdir -p "$build_dir"
}
_generateTags() {
echo ">>> generating tags"
ctags --fields=+iaS --extras=+q --extras=+f -R lib/* example/* assets/*
}
_compile() {
compiler="cc"
flags="-lSDL2 -lSDL2_ttf -lm"
src="lib/util/*.c lib/*.c example/*.c"
echo ">>> Compiling ($mode)"
$compiler $mode_flags $flags -o $build_dir/$app $src
}
_build() {
_createBuildDir
_generateTags
_compile
cp assets/*.ttf $build_dir
}
_debug() {
cd $build_dir
seergdb -s $app
cd ../..
}
_run() {
echo ">>> Running $app - $mode"
cd $build_dir
./$app
cd ../..
}
_clean() {
echo ">>> Cleaning '$build_dir' directory"
rm -r "$build_dir"
}
_valgrind() {
valgrind --leak-check=yes --show-leak-kinds=all -s -v $build_dir/$app
}
_findStrings() {
strings $build_dir/$app | less
}
_findSymbolsInObj() {
nm $build_dir/$app | less
}
p() {
commands=("build" "run" "clean" "debug" "search" "search/replace" "generate tags" "valgrind" "find strings in the binary" "list symbols from object files")
selected=$(printf '%s\n' "${commands[@]}" | fzf --header="project:")
case $selected in
"build")
_build;;
"debug")
_debug;;
"run")
_run;;
"clean")
_clean;;
"search")
read -p "keyword: " p_keyword; rg "$p_keyword" ;;
"search/replace")
read -p "to_search: " to_search
read -p "to_replace: " to_replace
ambr "$to_search" "$to_replace" ;;
"generate tags")
_generateTags;;
"valgrind")
_valgrind;;
"find strings in the binary")
_findStrings;;
"list symbols from object files")
_findSymbolsInObj;;
*) ;;
esac
}