-
Notifications
You must be signed in to change notification settings - Fork 8
/
setup.sh
executable file
·163 lines (132 loc) · 4.18 KB
/
setup.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
#
#
MKL_RED="\033[031m"
MKL_GREEN="\033[032m"
MKL_YELLOW="\033[033m"
MKL_BLUE="\033[034m"
MKL_CLR_RESET="\033[0m"
# Set to "-v" for verbose file copies
CP_V=
function puts {
echo -e "$*"
}
function fatal {
puts "${MKL_RED}Fatal error: $*${MKL_CLR_RESET}"
exit 1
}
interactive=1
inst_conf=n
inst_mkb=n
while true ; do
case "$1" in
--all)
inst_conf=y
inst_mkb=y
interactive=0
;;
--mk)
inst_mkb=y
interactive=0
;;
--conf)
inst_conf=y
interactive=0
;;
*)
break
;;
esac
shift
done
mklove_dir=$(pwd)
proj_dir=$1
#
# Check usage
#
if [[ ! -d $proj_dir ]]; then
puts "mklove setup.sh"
puts "Interactive utility for setting up mklove for your project"
puts ""
puts "Usage: ./setup.sh [options] <your-project-directory>"
puts ""
puts "Options:"
puts " --all Set up both configure and Makefile.base"
puts " --mk Set up Makefile.base"
puts " --conf Set up configure"
exit 1
fi
puts "${MKL_GREEN}Welcome to mklove setup${MKL_CLR_RESET}"
puts ""
#
# Check that paths make sense
#
if [[ ! -f $mklove_dir/configure || ! -f $mklove_dir/Makefile.base ]]; then
puts "${MKL_YELLOW}NOTE: setup.sh must be run from the mklove directory${MKL_CLR_RESET}"
puts ""
fatal "$mklove_dir does not look like the mklove directory"
fi
if [[ $mklove_dir == $proj_dir ]]; then
fatal "setup.sh should be run from your project's directory, not the mklove directory"
fi
#
# Ask what parts of mklove are to be set up.
#
while [[ $interactive == 1 ]] ; do
puts "${MKL_BLUE}What parts of mklove do you want to use in your project:${MKL_CLR_RESET}"
puts " 1 - configure and Makefile.base"
puts " 2 - configure only"
puts " 3 - Makefile.base only"
read -p "Choice(1)> " -e what
[[ -z $what ]] && what=1
case $what in
1)
inst_conf=y
inst_mkb=y
;;
2)
inst_conf=y
;;
3)
inst_mkb=y
;;
*)
puts "${MKL_RED}Unknown option: $what${MKL_CLR_RESET}"
continue
esac
break
done
#
# Ask for confirmation
#
puts ""
puts "${MKL_BLUE}Will set up your project with:${MKL_CLR_RESET}"
[[ $inst_conf == y ]] && puts " - configure script"
[[ $inst_mkb == y ]] && puts " - Makefile.base"
puts " - from mklove directory $mklove_dir"
puts " - to project directory $proj_dir"
[[ $interactive == 1 ]] && read -p "Press enter to confirm or Ctrl-C to abort"
puts ""
puts "${MKL_BLUE}Creating $proj_dir/mklove/modules and copying files${MKL_CLR_RESET}"
mkdir -p "$proj_dir/mklove/modules" || fatal "Failed to create directory"
if [[ $inst_conf == y ]]; then
cp $CP_V "$mklove_dir/configure" "$proj_dir/" || fatal "Copy failure"
cp $CP_V "$mklove_dir/modules/configure.base" "$proj_dir/mklove/modules" || fatal "Copy failure"
# Let configure resolve initial dependencies
puts ""
puts "${MKL_BLUE}Calling ./configure --update-modules to resolve initial dependencies${MKL_CLR_RESET}"
(cd "$proj_dir" && MKL_REPO_URL="$mklove_dir" ./configure --update-modules) || puts "${MKL_RED}Update modules failed${MKL_CLR_RESET}"
fi
if [[ $inst_mkb == y ]]; then
cp $CP_V "$mklove_dir/Makefile.base" "$proj_dir/mklove/" || fatal "Copy failure"
fi
puts ""
puts "${MKL_GREEN}Congratulations! mklove is now set up for your project${MKL_CLR_RESET}"
puts "Things to do in your project directory $proj_dir:"
[[ $inst_conf == y ]] && puts " - Create a configure.<yourprojectname> to add your own checks and --options"
[[ $inst_conf == y ]] && puts " - Use existing mklove configure modules by calling 'mkl_require <modname>' from configure.<yourprojectname>"
[[ $inst_conf == y ]] && puts " - You should ship your project with all required mklove modules included,
do this by calling ./configure --update-modules"
[[ $inst_mkb == y ]] && puts " - Create a Makefile including both Makefile.base and Makefile.config"
[[ $inst_mkb == y ]] && puts " - Write your own targets in your Makefile, or use the available standard targets from Makefile.base"
puts ""