Browse code

* now mulle-bootstrap can also build autoconf projects * mulle-bootstrap is generally smarter to localize projectfiles that aren't at the toplevel directory

Nat! authored on 21-08-2017 18:19:53
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,258 @@
1
+#! /usr/bin/env bash
2
+#
3
+#   Copyright (c) 2015 Nat! - Mulle kybernetiK
4
+#   All rights reserved.
5
+#
6
+#   Redistribution and use in source and binary forms, with or without
7
+#   modification, are permitted provided that the following conditions are met:
8
+#
9
+#   Redistributions of source code must retain the above copyright notice, this
10
+#   list of conditions and the following disclaimer.
11
+#   Redistributions in binary form must reproduce the above copyright notice,
12
+#   this list of conditions and the following disclaimer in the documentation
13
+#   and/or other materials provided with the distribution.
14
+#
15
+#   Neither the name of Mulle kybernetiK nor the names of its contributors
16
+#   may be used to endorse or promote products derived from this software
17
+#   without specific prior written permission.
18
+#
19
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+#   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+#   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+#   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23
+#   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+#   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+#   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+#   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+#   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+#   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+#   POSSIBILITY OF SUCH DAMAGE.
30
+#
31
+MULLE_BOOTSTRAP_BUILD_PLUGIN_AUTOCONF_SH="included"
32
+
33
+
34
+find_autoconf()
35
+{
36
+   local name="$1"
37
+
38
+   local toolname
39
+
40
+   toolname=`read_build_setting "${name}" "autoconf" "autoconf"`
41
+   verify_binary "${toolname}" "autoconf" "autoconf"
42
+}
43
+
44
+
45
+find_autoreconf()
46
+{
47
+   local name="$1"
48
+
49
+   local toolname
50
+
51
+   toolname=`read_build_setting "${name}" "autoreconf" "autoreconf"`
52
+   verify_binary "${toolname}" "autoreconf" "autoreconf"
53
+}
54
+
55
+
56
+tools_environment_autoconf()
57
+{
58
+   local name="$1"
59
+#   local projectdir="$2"
60
+
61
+   tools_environment_make "$@"
62
+
63
+   AUTOCONF="`find_autoconf "${name}"`"
64
+   AUTORECONF="`find_autoreconf "${name}"`"
65
+}
66
+
67
+
68
+build_autoconf()
69
+{
70
+   log_entry "build_autoconf" "$@"
71
+
72
+   local projectfile="$1"
73
+   local configuration="$2"
74
+   local srcdir="$3"
75
+   local builddir="$4"
76
+   local name="$5"
77
+   local sdk="$6"
78
+
79
+   local projectdir
80
+
81
+   projectdir="`dirname -- "${projectfile}"`"
82
+
83
+   local autoconf_flags
84
+   local autoreconf_flags
85
+
86
+   autoconf_flags="`read_build_setting "${name}" "autoconf_flags"`"
87
+   autoreconf_flags="`read_build_setting "${name}" "autoreconf_flags" "-vif"`"
88
+
89
+   mkdir_if_missing "${builddir}"
90
+
91
+   local flaglines
92
+   local mapped
93
+
94
+   mapped="`read_build_setting "${name}" "autoconf-${configuration}.map" "${configuration}"`"
95
+   flaglines="`build_unix_flags "$@" "${mapped}"`"
96
+
97
+   local dependenciesdir
98
+
99
+   dependenciesdir="`echo "${flaglines}"  | sed -n '9p'`"
100
+
101
+   local binpath
102
+
103
+   binpath="${dependenciesdir}/bin"
104
+
105
+   # CMAKE_CPP_FLAGS does not exist in cmake
106
+   # so merge into CFLAGS and CXXFLAGS
107
+
108
+   local logfile1
109
+
110
+   mkdir_if_missing "${BUILDLOGS_DIR}"
111
+
112
+   logfile1="`build_log_name "autoreconf" "${name}" "${configuration}" "${sdk}"`"
113
+   logfile1="`build_log_name "autoconf" "${name}" "${configuration}" "${sdk}"`"
114
+
115
+   (
116
+      local owd
117
+      local nativewd
118
+
119
+      owd="${PWD}"
120
+      nativewd="`pwd ${BUILD_PWD_OPTIONS}`"
121
+
122
+      exekutor cd "${projectdir}" || fail "failed to enter ${projectdir}"
123
+
124
+      # DONT READ CONFIG SETTING IN THIS INDENT
125
+      set -f
126
+
127
+      if [ "$MULLE_FLAG_VERBOSE_BUILD" = "YES" ]
128
+      then
129
+         logfile1="`tty`"
130
+         logfile2="`tty`"
131
+      fi
132
+
133
+      if [ "$MULLE_FLAG_EXEKUTOR_DRY_RUN" = "YES" ]
134
+      then
135
+         logfile1="/dev/null"
136
+         logfile2="/dev/null"
137
+      fi
138
+
139
+      log_verbose "Build log will be in \"${logfile1}\""
140
+
141
+      local oldpath
142
+      local rval
143
+
144
+      oldpath="$PATH"
145
+      PATH="${binpath}:${BUILDPATH}"
146
+
147
+      log_fluff "PATH temporarily set to $PATH"
148
+
149
+      if ! [ -f "aclocal4.am" ]
150
+      then
151
+          # use absolute paths for configure, safer (and easier to read IMO)
152
+         logging_redirect_eval_exekutor "${logfile1}" \
153
+            "${AUTORECONF}" \
154
+            "${autoreconf_flags}"
155
+         rval=$?
156
+
157
+         if [ $rval -ne 0 ]
158
+         then
159
+            PATH="${oldpath}"
160
+            build_fail "${logfile1}" "autoreconf"
161
+         fi
162
+      fi
163
+
164
+       # use absolute paths for configure, safer (and easier to read IMO)
165
+      logging_redirect_eval_exekutor "${logfile2}" \
166
+         "${AUTOCONF}" \
167
+         "${autoconf_flags}"
168
+      rval=$?
169
+
170
+      if [ $rval -ne 0 ]
171
+      then
172
+         PATH="${oldpath}"
173
+         build_fail "${logfile2}" "autoconf"
174
+      fi
175
+
176
+      set +f
177
+
178
+   ) || exit 1
179
+
180
+
181
+   local WASXCODE
182
+   local PROJECTFILE
183
+   local TOOLNAME
184
+   local AUX_INFO
185
+
186
+   # daisy chain configure onto it
187
+   TOOLNAME=configure
188
+   WASXCODE="NO"
189
+
190
+   test_configure "${configuration}" "${srcdir}" "${builddir}" "${name}"
191
+   if [ $? -ne 0 ]
192
+   then
193
+      fail "Could not run configure for \"${srcdir}"\"
194
+   fi
195
+
196
+   [ -z "${PROJECTFILE}" ] && internal_fail "test_${preference} did not set PROJECTFILE"
197
+         #statements
198
+
199
+   log_info "Let ${C_RESET_BOLD}${TOOLNAME}${C_INFO} do a \
200
+${C_MAGENTA}${C_BOLD}${configuration}${C_INFO} build of \
201
+${C_MAGENTA}${C_BOLD}${name}${C_INFO} for SDK \
202
+${C_MAGENTA}${C_BOLD}${sdk}${C_INFO}${AUX_INFO} in \"${builddir}\" ..."
203
+
204
+   build_configure "${PROJECTFILE}" "${configuration}" "${srcdir}" "${builddir}" "${name}" "${sdk}"
205
+   if [ $? -ne 0 ]
206
+   then
207
+      internal_fail "$build_${preference} should exit on failure and not return"
208
+   fi
209
+}
210
+
211
+
212
+test_autoconf()
213
+{
214
+   log_entry "test_autoconf" "$@"
215
+
216
+   local configuration="$1"
217
+   local srcdir="$2"
218
+   local builddir="$3"
219
+   local name="$4"
220
+
221
+   local projectfile
222
+   local projectdir
223
+
224
+   projectfile="`find_nearest_matching_pattern "${srcdir}" "configure.ac"`"
225
+   if [ -z "${projectfile}" ]
226
+   then
227
+      projectfile="`find_nearest_matching_pattern "${srcdir}" "configure.in"`"
228
+      if [ -z "${projectfile}" ]
229
+      then
230
+         log_fluff "There is no autoconf project in \"${srcdir}\""
231
+         return 1
232
+      fi
233
+   fi
234
+   projectfile="${srcdir}/${projectfile}"
235
+   projectdir="`dirname -- "${projectfile}"`"
236
+
237
+   tools_environment_autoconf "${name}" "${projectdir}"
238
+
239
+   if [ -z "${AUTOCONF}" ]
240
+   then
241
+      log_warning "Found a `basename -- "${projectfile}"`, but ${C_RESET}${C_BOLD}autconf${C_WARNING} is not installed"
242
+      return 1
243
+   fi
244
+
245
+   if [ -z "${AUTORECONF}" ]
246
+   then
247
+      log_warning "No autoreconf found, will continue though"
248
+   fi
249
+
250
+   if [ -z "${MAKE}" ]
251
+   then
252
+      log_warning "No make found"
253
+      return 1
254
+   fi
255
+
256
+   PROJECTFILE="${projectfile}"
257
+   return 0
258
+}