-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqc
executable file
·96 lines (76 loc) · 1.81 KB
/
qc
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
#!/bin/sh
# https://github.com/jason-thinks/quick-build/qc
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
# Copyright (C) 2004 Sam Hocevar <[email protected]>
#
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
#
# 0. You just DO WHAT THE FUCK YOU WANT TO.
# Builds with gcc. Could work with others, but IDK if they provide the
# profiler and debugging info.
name=$(basename "$PWD")
CFLAGS="-Wall -Wextra -Werror $CFLAGS"
if [ -f qc.env ]; then
. $PWD/qc.env
fi
src_file='main.c'
cmd="$1"
if [ -z "$cmd" ]; then
cmd='run'
fi
log() {
[ -z "$LOG" ] || echo "LOG: $1" >&2
}
build() {
extra_flags="$1"
log "extra_flags: $extra_flags"
log 'build'
time -f 'compile: %e seconds' gcc $CFLAGS $extra_flags -o "$name" "$src_file" $lib_flags
}
debug() {
log 'debug'
build '-Og -g' && gdb "$name"
}
profile() {
log 'profile'
build '-fprofile-arcs -pg' && "./$name" $run_args
gprof --brief "$name" gmon.out > "$name.profile"
}
run() {
local prog_name="$1"
if [ -z "$prog_name" ]; then
prog_name="./$name"
fi
log 'run'
build '-Og' && "$prog_name" $run_args
}
clean() {
log 'clean'
[ ! -e "$name" ] || rm "$name"
rm -f gmon.out "$name.profile" main.gcda
exit 0
}
if [ "$cmd" = 'build' ]; then
build
elif [ "$cmd" = 'clean' ]; then
clean
elif [ "$cmd" = 'debug' ]; then
debug
elif [ "$cmd" = 'profile' ]; then
profile
elif [ "$cmd" = 'run' ]; then
run
else
# build to /tmp
name=$(mktemp)
src_file="$cmd"
run "$name"
rm "$name"
fi