-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·54 lines (45 loc) · 1.06 KB
/
configure
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
#!/bin/bash
#global consts
CONFIG_HPP="include/config.hpp"
PROG_DIR="std::string(getenv(\"HOME\")) + \"/local/$(basename $(pwd))\""
SCRIPT_NAME="configure"
#displays usage information and exits program
function usage {
echo -e "\nusage: $SCRIPT_NAME [-d <program_dir>] [-h]\n"
exit
}
#returns the absolute path of a relative reference
function absPath {
if [ -d "$1" ]; then
( cd "$1"; echo $(dirs -l +0))
else
( cd "$(dirname "$1")"; d=$(dirs -l +0); echo "${d%/}/${1##*/}" )
fi
}
#checks that $1 is not empty or a flag
function isArg {
if [[ $1 == -* ]] || [[ -z "$1" ]] ; then
usage
fi
}
#begin main
#get args
while ! [[ -z "$1" ]] ; do
case $1 in
"-d"|"--program-directory")
shift
isArg "$1"
PROG_DIR="\"$(absPath "$1")\"" ;;
"-h"|"--help")
usage ;;
*)
usage ;;
esac
shift
done
#update config.hpp
echo "Updating $CONFIG_HPP..."
echo -e "\n#ifndef config_hpp" > $CONFIG_HPP
echo -e "#define config_hpp\n" >> $CONFIG_HPP
echo "#define CONFIG_PROG_WD_DIR $PROG_DIR;" >> $CONFIG_HPP
echo -e "\n#endif /* config_hpp */" >> $CONFIG_HPP