-
Notifications
You must be signed in to change notification settings - Fork 0
/
gensrcs.sh
executable file
·65 lines (54 loc) · 1.23 KB
/
gensrcs.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
#! /bin/bash
DEST=srcs.mk
SRCDIR=${1:-srcs}
INCDIR=${2:-includes}
DEPTH=0
function usage()
{
echo "Usage: ${0} [ srcsdir ] [ incdir ]"$'\n'"(default are: \"${SRCDIR}/\", \"${INCDIR}/\")"
}
# $1="amount of tabs"
function padd_tabs()
{
local AMOUNT=${1}
while [[ ${AMOUNT} -ge 1 ]] ; do
echo -n $'\t' >> ${DEST}
let AMOUNT--
done
}
# $1="entry point (a directory)"
function index_dir()
{
let DEPTH++
padd_tabs ${DEPTH}-1
local BASENAME=`basename ${1}`
echo "\$(addprefix ${BASENAME}/," $'\\' >> ${DEST}
for i in ${1}/* ; do
BASENAME=`basename ${i}`
if [[ -d ${i} ]] ; then
index_dir ${i}
elif [[ -f ${i} ]] ; then
padd_tabs ${DEPTH}-1
echo $'\t'"${BASENAME}" $'\\' >> ${DEST}
fi
done
padd_tabs ${DEPTH}-1
echo -n ")" >> ${DEST}
if [[ ${DEPTH} -ge 2 ]] ; then
echo -n " "$'\\' >> ${DEST}
fi
echo >> ${DEST}
let DEPTH--
}
if [ -f ${DEST} ] ; then
rm ${DEST}
fi
if [ ! -d ${SRCDIR} ] || [ ! -d ${INCDIR} ] ; then
echo "Error: Invalid SRCDIR (${SRCDIR}) or INCDIR (${INCDIR}), must be a directory"
usage
fi
echo "INCDIR"$'\t'"="$'\t'${INCDIR}$'\n'"SRCDIR"$'\t'"="$'\t'${SRCDIR}$'\n' >> ${DEST}
echo "HDRS"$'\t'"=" $'\\' >> ${DEST}
index_dir ${INCDIR}
echo "SRCS"$'\t'"=" $'\\' >> ${DEST}
index_dir ${SRCDIR}