/var/lib/sorcery/modules/build_api/api2
1 #!/bin/bash
2 #---------------------------------------------------------------------
3 ##
4 ##=head1 SYNOPSIS
5 ##
6 ## Functions for dealing with the actual compiling/installation of spells
7 ## and walking through casts 'pass 4' pipeline.
8 ##
9 ##=head1 DESCRIPTION
10 ##
11 ## Contains functions for the build api version 2
12 ## which has the following steps:
13 ## PRE_BUILD -> BUILD -> PRE_INSTALL -> INSTALL -> POST_INSTALL ->
14 ## FINAL -> TRIGGERS
15 ##
16 ##=head1 COPYRIGHT
17 ##
18 ## Copyright (C) 2002 The Source Mage Team <http://www.sourcemage.org>
19 ##
20 ##=head1 FUNCTIONS
21 #---------------------------------------------------------------------
22
23 #---------------------------------------------------------------------
24 ## This runs through the phase 4 pipeline of building and installing
25 ## a spell for BUILD_API 2.
26 #---------------------------------------------------------------------
27 function run_build_spell">run_build_spell() {
28 debug "build_api/api2" "run_build_spell">run_build_spell"
29
30 local CHROOT_CHECK=""
31
32 export C_LOG=$TMP_DIR/$SPELL.compile.log
33 export CASTFS_DBGLOG=$C_LOG.castfs.dbglog
34 export C_FIFO=/dev/stdout # not needed for api2 anymore, but just in case
35 export S_PWD=$TMP_DIR/build.saved.pwd
36 export VOYEUR_STDOUT VOYEUR_STDERR
37 export __DELVE_IN_CAST=on
38
39 rm -f $CASTFS_DBGLOG
40 touch $CASTFS_DBGLOG
41 rm -f $C_LOG
42 touch $C_LOG
43
44 if [[ $SCREEN_NAME ]] ; then
45 screen_new_window "$SCREEN_NAME" $SCREEN_CAST_WIN "cast $SPELL" \
46 tail -f -s 0.1 $C_LOG
47 screen_switch_window "$SCREEN_NAME" $SCREEN_MAIN_WIN
48
49 VOYEUR_STDOUT=/dev/null
50 VOYEUR_STDERR=/dev/null
51 elif [ "$VOYEUR" == "on" -a -z "$SILENT" ] ; then
52 VOYEUR_STDOUT=/dev/stdout
53 VOYEUR_STDERR=/dev/stderr
54 else
55 VOYEUR_STDOUT=/dev/null
56 VOYEUR_STDERR=/dev/null
57 fi
58
59 if [[ -z $STAGED_INSTALL ]]
60 then
61 if ! is_castfs_installed
62 then
63 export STAGED_INSTALL=off
64 else
65 export STAGED_INSTALL=on
66 fi
67 fi
68
69 if [[ $STAGED_INSTALL == on ]] && ! run_castfs_sanity
70 then
71 message "${PROBLEM_COLOR}CastFS failed the sanity check, staging disabled!"
72 message -n "$DEFAULT_COLOR"
73 export STAGED_INSTALL=off
74 fi
75
76 local PROTECT_SORCERY=yes
77 local rs
78 (
79 run_pre_build">run_pre_build || return 1
80 run_config_loc || return 2
81 (
82 run_build">run_build &&
83 run_pre_install &&
84 if [[ $STAGED_INSTALL == off ]]
85 then
86 invoke_installwatch
87 fi &&
88 if [[ $OVERRIDE_GRIMOIRES ]]; then
89 delve -g "$OVERRIDE_GRIMOIRES" $SPELL INSTALL &&
90 delve -g "$OVERRIDE_GRIMOIRES" $SPELL INSTALL_EXTRAS
91 else
92 delve $SPELL INSTALL &&
93 delve $SPELL INSTALL_EXTRAS
94 fi &&
95 run_post_install">run_post_install || return 2
96 run_transfer &&
97 devoke_installwatch &&
98 STAGED_INSTALL=off &&
99 run_final | append_to_notice_log || return 3
100 ) 3> >(tee -a $C_LOG >> /dev/stdout) \
101 2> >(tee -a $C_LOG 1>&2 >> $VOYEUR_STDERR) \
102 > >(tee -a $C_LOG >> $VOYEUR_STDOUT) \
103 )
104 rs=$?
105 unset __DELVE_IN_CAST
106 if [[ $SCREEN_NAME ]] && [ $rs -gt 0 ] ; then
107 screen_move_window "$SCREEN_NAME" $SCREEN_CAST_WIN $SCREEN_LAST_FAILED_CAST_WIN
108 screen_name_window "$SCREEN_NAME" $SCREEN_LAST_FAILED_CAST_WIN "Failed $SPELL"
109 screen_kill_window "$SCREEN_NAME" $SCREEN_CAST_WIN
110 screen_notify "$SCREEN_NAME" "Last failed cast at $SCREEN_LAST_FAILED_CAST_WIN"
111 elif [[ $SCREEN_NAME ]] ; then
112 screen_kill_window "$SCREEN_NAME" $SCREEN_CAST_WIN
113 fi
114
115 # triggers don't run in the window
116 [ $rs -gt 0 ] && return $rs
117
118 run_triggers || return 4
119
120 return 0
121 }
122
123 #---------------------------------------------------------------------
124 ## This phase of casting involves unpacking the source into the
125 ## source directories. If a PRE_BUILD file exists in SCRIPT_DIRECTORY
126 ## and is executable it is run in preference to the default_pre_build.
127 #---------------------------------------------------------------------
128 function run_pre_build">run_pre_build() {
129
130 debug "build_api/api2" "run_pre_build">run_pre_build()"
131 message "${MESSAGE_COLOR}Preparing" \
132 "${SPELL_COLOR}${SPELL}${DEFAULT_COLOR}"
133
134 rm_source_dir || return 1
135 mkdir -p $BUILD_DIRECTORY
136 cd "$BUILD_DIRECTORY"
137
138 verify_sources &&
139 run_spell_file PRE_BUILD pre_build
140 }
141
142
143 #---------------------------------------------------------------------
144 ## Starts up the compile logs, turns on the various environment
145 ## settings that need to be on, eventually gets around to running
146 ## BUILD or default_build.
147 #---------------------------------------------------------------------
148 function run_build">run_build() {
149
150 debug "build_api/api2" "Starting run_compile()"
151
152 echo "Compile log for $SPELL $VERSION Built on `date -u`" > $C_LOG
153 echo "Using gcc version: `gcc -dumpversion`" >> $C_LOG
154 message "${MESSAGE_COLOR}Building" \
155 "${SPELL_COLOR}${SPELL}${DEFAULT_COLOR}" >&3
156
157 if [ -d "$SOURCE_DIRECTORY" ] ; then
158 cd "$SOURCE_DIRECTORY"
159 else
160 cd "$BUILD_DIRECTORY"
161 fi &&
162
163 invoke_build_dir
164 invoke_gcc
165
166 message -n "Building in dir: "
167 pwd
168 message "$SPELL $VERSION"
169 message
170
171 run_spell_file BUILD build optimize
172
173 if [ "$?" != 0 ]; then
174 message "${PROBLEM_COLOR}" \
175 "! Problem Detected !" \
176 "${DEFAULT_COLOR}"
177 return 1
178 fi
179 pwd > $S_PWD
180 }
181
182
183 #---------------------------------------------------------------------
184 ## Turns all the various logs back on that were turned off from after
185 ## run_build">run_build finished, then runs PRE_INSTALL or default_pre_install
186 #---------------------------------------------------------------------
187 function run_pre_install() {
188 debug "build_api/api2" "Starting run_pre_install()"
189
190 if [ -f $S_PWD ] ; then
191 cd "`cat $S_PWD`"
192 elif [ -d $SOURCE_DIRECTORY ] ; then
193 cd "$SOURCE_DIRECTORY"
194 else
195 cd "$BUILD_DIRECTORY"
196 fi
197
198 run_spell_file PRE_INSTALL pre_install
199 local rc=$?
200 echo "Compile log for $SPELL $VERSION Completed Build on `date -u`" >> $C_LOG
201 pwd > $S_PWD
202 return $rc
203 }
204
205
206 #---------------------------------------------------------------------
207 ## load persistent vars, then runs INSTALL or default_install
208 ## Along with other stuff that needs to be transplanted elsewhere.
209 ## NOTE: this function is run from delve so installwatch can be invoked
210 ## around an execed bash shell, this is needed for installwatch to
211 ## stage root properly
212 #---------------------------------------------------------------------
213 function run_install() {
214 debug "build_api/api2" "Starting run_install()"
215
216 if [[ $STAGED_INSTALL == on ]]; then
217 message "${MESSAGE_COLOR}Installing" \
218 "${SPELL_COLOR}${SPELL}${MESSAGE_COLOR}" \
219 "into the stage${DEFAULT_COLOR}" >&3
220 else
221 message "${MESSAGE_COLOR}Installing" \
222 "${SPELL_COLOR}${SPELL}${DEFAULT_COLOR}" >&3
223 fi
224
225 if [ -f $S_PWD ] ; then
226 cd "`cat $S_PWD`"
227 elif [ -d $SOURCE_DIRECTORY ] ; then
228 cd "$SOURCE_DIRECTORY"
229 else
230 cd "$BUILD_DIRECTORY"
231 fi
232
233 run_spell_file INSTALL install
234
235 if [ "$?" != 0 ]; then
236 message "${PROBLEM_COLOR}" \
237 "Problem Detected!" \
238 "${DEFAULT_COLOR}"
239 false
240 fi
241 }
242
243 function run_install_extras() {
244
245 debug "build_api/api2" "Starting run_install_extras()"
246 run_spell_file INSTALL_EXTRAS install_extras
247 }
248
249 #---------------------------------------------------------------------
250 ## Checks for a POST_BUILD file in SCRIPT_DIRECTORY, and if it is
251 ## executable, runs it. This file is run after INSTALL and before
252 ## FINAL. Its purpose is to manipulate the installed files in the stage
253 ## root and install other tracked files.
254 ## NOTE: this function is run from delve so installwatch can be invoked
255 ## around an execed bash shell, this is needed for installwatch to
256 ## stage root properly
257 #---------------------------------------------------------------------
258 function run_post_install">run_post_install() {
259 debug "build_api/api2" "Starting run_post_install">run_post_install()"
260 persistent_load &&
261 if [[ $STAGED_INSTALL != off ]]
262 then
263 cd "$STAGE_DIRECTORY/"
264 else
265 cd "${INSTALL_ROOT:-/}"
266 fi &&
267 run_spell_file POST_INSTALL post_install
268 unlock_resources "libgrimoire" "install"
269 }
270
271 #--------------------------------------------------------------------
272 ## Checks against STAGED_INSTALL and installs the staged spell
273 ## accordingly
274 #--------------------------------------------------------------------
275 function run_transfer() {
276 if [[ "$STAGED_INSTALL" != "off" ]]
277 then
278 message "${MESSAGE_COLOR}Installing" \
279 "${SPELL_COLOR}${SPELL}${MESSAGE_COLOR}" \
280 "into the system${DEFAULT_COLOR}" >&3
281 run_spell_file TRANSFER transfer
282 fi
283 }
284
285 #---------------------------------------------------------------------
286 ## Checks for a FINAL file in SCRIPT_DIRECTORY, and if it is
287 ## executable, runs it. This file is used for extra files that need
288 ## to be installed, but not tracked by installwatch.
289 #---------------------------------------------------------------------
290 function run_final() {
291
292 debug "build_api/api2" "Starting run_final()"
293 run_spell_file FINAL final
294 }
295
296 #---------------------------------------------------------------------
297 ## @Type API
298 ## Creates the source directory and unpacks the source package into it.
299 ## Used if no PRE_BUILD script is found for a spell.
300 ##
301 #---------------------------------------------------------------------
302 function real_default_sorcery_pre_build">real_default_sorcery_pre_build() {
303
304 debug "libgrimoire" "default_pre_build() - SOURCE=$SOURCE SOURCE_DIRECTORY=$SOURCE_DIRECTORY"
305 mk_source_dir $SOURCE_DIRECTORY &&
306 unpack_file
307
308 }
309
310
311 #---------------------------------------------------------------------
312 ## @Type API
313 ## Used if no BUILD script is found
314 ## Default build is:
315 ## <pre>
316 ## ./configure --build=$BUILD \
317 ## --prefix=/usr \
318 ## --sysconfdir=/etc \
319 ## --localstatedir=/var \
320 ## $OPTS &&
321 ## make
322 ## </pre>
323 ##
324 #---------------------------------------------------------------------
325 function real_default_sorcery_build">real_default_sorcery_build() {
326 debug "build_api/api2" "real_default_sorcery_build">real_default_sorcery_build"
327
328 OPTS="$OPTS --build=${BUILD}"
329 #If these switches are used, they _may_ stop distcc and ccache from working
330 # for some spells (bug 3798)
331 # We could write wrappers for all of the possible binaries
332 [[ $CROSS_INSTALL == on ]] && OPTS="$OPTS --host=${HOST}"
333
334 ./configure --prefix=${INSTALL_ROOT}/usr \
335 --sysconfdir=${INSTALL_ROOT}/etc \
336 --localstatedir=${INSTALL_ROOT}/var \
337 --mandir=${INSTALL_ROOT}/usr/share/man \
338 --infodir=${INSTALL_ROOT}/usr/share/info \
339 $OPTS &&
340 make
341
342 }
343
344 #---------------------------------------------------------------------
345 ## @Type API
346 ## Used if no PRE_INSTALL script is found
347 ## Default pre_install is:
348 ## <pre>
349 ## prepare_install
350 ## </pre>
351 ##
352 #---------------------------------------------------------------------
353 function real_default_sorcery_pre_install() {
354 debug "build_api/api2" "Starting real_default_sorcery_pre_install"
355 prepare_install >&3
356 }
357
358 #---------------------------------------------------------------------
359 ## @Type API
360 ## Used if no INSTALL script is found
361 ## Default install is:
362 ## <pre>
363 ## make install
364 ## </pre>
365 ##
366 #---------------------------------------------------------------------
367 function real_default_sorcery_install() {
368 debug "build_api/api2" "Starting real_default_sorcery_install"
369 make install
370 }
371
372
373 #---------------------------------------------------------------------
374 ## @Type API
375 ## Installs configuration files and documentation. Stops installwatch.
376 ## Used if no POST_INSTALL script is found for a spell.
377 ##
378 ## This is identical to api1's post_build
379 #---------------------------------------------------------------------
380 function real_default_sorcery_install_extras() {
381
382 debug "build_api/api2" "Starting real_default_sorcery_install_extras"
383 install_xinetd
384 install_initd
385 install_pam_confs
386 install_desktop_files
387 gather_docs
388 init_post_install
389 [[ $STAGED_INSTALL == off ]] && ldconfig
390 # release_saved_libraries
391 cd /
392
393 }
394
395 function real_default_sorcery_transfer() {
396
397 debug "build_api/api2" "Starting real_default_sorcery_transfer"
398 transfer_staged_spell
399 }
400
401 #---------------------------------------------------------------------
402 ## @License
403 ##
404 ## This software is free software; you can redistribute it and/or modify
405 ## it under the terms of the GNU General Public License as published by
406 ## the Free Software Foundation; either version 2 of the License, or
407 ## (at your option) any later version.
408 ##
409 ## This software is distributed in the hope that it will be useful,
410 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
411 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
412 ## GNU General Public License for more details.
413 ##
414 ## You should have received a copy of the GNU General Public License
415 ## along with this software; if not, write to the Free Software
416 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
417 ##
418 #---------------------------------------------------------------------