forked from littleglassdiode/irl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ldt.sh
executable file
·127 lines (109 loc) · 2.46 KB
/
ldt.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
#!/bin/sh
# ldt.sh
prog="raelives"
src="src"
dest="build"
files="*.c"
cc="gcc"
# Only the flags that apply to all settings here
cflags="-Wall -std=c99"
libs="-lm"
ldt="build"
info() {
printf "\033[1;32m$1\033[0m\n"
}
note() {
printf "\033[36m$1\033[0m\n"
}
fatal() {
printf "\033[1;31m$1\033[0m\n"
printf "\033[1;31mFatal error; aborting\033[0m\n"
exit 1
}
pexec() {
printf "\t$*\n"
$*
}
if [ ! $1 = '' ]; then
ldt=$1
fi
case $sys in
lin|'')
libs="$libs -lncurses"
ldtlast=".ldtsh_last"
;;
win)
prog="${prog}.exe"
dest="${dest}win"
cc="i486-mingw32-gcc"
libs="$libs -lpdcurses"
ldtlast=".ldtsh_win_last"
esac
case $build in
debug|'')
cflags="$cflags -g"
;;
rel)
cflags="$cflags -O3"
;;
esac
case $ldt in
help)
printf "\033[1mL\033[0met's \033[1md\033[0mo "
printf "\033[1mt\033[0mhis\033[1;30m.\033[37ms\033[0mtuff "
printf "\033[1mh\033[0mere!\n"
printf "usage: ldt.sh [subcommand]\n"
printf "where subcommand is one of:\n"
printf " build (default): compile the project\n"
printf " clean: remove anything ldt.sh created\n"
printf " help: show this message\n"
;;
clean)
info "Let's clean this stuff here!"
if [ -d "$dest" ]; then
pexec rm -r "$dest"
fi
if [ -f "$ldtlast" ]; then
pexec rm "$ldtlast"
fi
;;
build)
info "Let's build this stuff here!"
if [ ! -d "$src" ]; then
fatal "Source directory not found!"
fi
if [ ! -d "$dest" ]; then
note "Destination directory not found; creating it now."
mkdir "$dest"
fi
cwd=$PWD
last="$cwd/$ldtlast"
cf="last"
if [ ! -f "$ldtlast" ]; then
cf="f"
fi
f="$src"
if [ "$src" -ot $(eval echo \\$$cf) ]; then
note "No change since last build."
exit 0
fi
cd "$src"
for f in $files; do
# if it's a regular file that has been changed since last build
if [ -f "$f" -a ! $(eval echo \\$$cf) -nt "$f" ]; then
filename="${f%.*}"
cd "$cwd"
# Okay, yeah, this is a dirty hack, but it gets the job done without
# having to write the same command twice.
pexec $cc -o $dest/$filename.o -c $cflags $src/$f
if [ $? -ne 0 ]; then
fatal "Build error!"
fi
cd "$src"
fi
done
cd "$cwd"
pexec $cc -o $dest/$prog $dest/*.o $libs
touch $ldtlast
;;
esac