/var/lib/sorcery/modules/build_api/api1
1 #---------------------------------------------------------------------
2 ##
3 ##=head1 SYNOPSIS
4 ##
5 ## Functions for dealing with the actual compiling/installation of spells
6 ## and walking through casts 'pass 4' pipeline. If BUILD_API is '1'
7 ##
8 ##=head1 DESCRIPTION
9 ##
10 ## Contains functions for the build api version 1
11 ## which has the following steps:
12 ## PRE_BUILD -> BUILD -> POST_BUILD -> POST_INSTALL -> TRIGGERS
13 ##
14 ##=head1 COPYRIGHT
15 ##
16 ## Copyright (C) 2004 The Source Mage Team <http://www.sourcemage.org>
17 ##
18 ##=head1 FUNCTIONS
19 #---------------------------------------------------------------------
20
21 #---------------------------------------------------------------------
22 ## This runs through the phase 4 pipeline of building and installing
23 ## a spell for BUILD_API 1.
24 #---------------------------------------------------------------------
25 function run_build_spell">run_build_spell() {
26 debug "build_api/api1" "run_build_spell">run_build_spell"
27 C_LOG=$TMP_DIR/$SPELL.compile.log
28 C_FIFO=/dev/stdout
29 STAGED_INSTALL=off
30 rm -f $C_LOG
31 touch $C_LOG
32 if [[ $SCREEN_NAME ]] ; then
33 screen_new_window "$SCREEN_NAME" $SCREEN_CAST_WIN "cast $SPELL" \
34 tail -f -s 0.1 $C_LOG
35 screen_switch_window "$SCREEN_NAME" $SCREEN_MAIN_WIN
36
37 VOYEUR_STDOUT=/dev/null
38 VOYEUR_STDERR=/dev/null
39 elif [ "$VOYEUR" == "on" -a -z "$SILENT" ] ; then
40 VOYEUR_STDOUT=/dev/stdout
41 VOYEUR_STDERR=/dev/stderr
42 else
43 VOYEUR_STDOUT=/dev/null
44 VOYEUR_STDERR=/dev/null
45 fi
46 # should OPTS get set here?
47
48 local PROTECT_SORCERY=yes
49 local rs
50
51 # This is an experiment, If we have actual interesting return codes
52 # from here, the caller can figure out what to do
53 # as opposed to trying to cram it all in here
54 (
55 run_pre_build">run_pre_build || return 1
56 run_build">run_build || return 2
57 run_post_build &&
58 run_post_install">run_post_install || return 3
59 )
60 rs=$?
61
62 if [[ $SCREEN_NAME ]] && [ $rs -gt 0 ] ; then
63 screen_move_window "$SCREEN_NAME" $SCREEN_CAST_WIN $SCREEN_LAST_FAILED_CAST_WIN
64 screen_name_window "$SCREEN_NAME" $SCREEN_LAST_FAILED_CAST_WIN "Failed $SPELL"
65 screen_kill_window "$SCREEN_NAME" $SCREEN_CAST_WIN
66 screen_notify "$SCREEN_NAME" "Last failed cast at $SCREEN_LAST_FAILED_CAST_WIN"
67 elif [[ $SCREEN_NAME ]] ; then
68 screen_kill_window "$SCREEN_NAME" $SCREEN_CAST_WIN
69 fi
70
71 # Triggers don't run in the window
72 [ $rs -gt 0 ] && return $rs
73 run_triggers || return 4
74
75 return $rs
76 }
77
78 #---------------------------------------------------------------------
79 ## This phase of casting involves unpacking the source into the
80 ## source directories. If a PRE_BUILD file exists in SCRIPT_DIRECTORY
81 ## and is executable it is run in preference to the default_pre_build.
82 #---------------------------------------------------------------------
83 function run_pre_build">run_pre_build() {
84
85 debug "build_api/api1" "run_pre_build">run_pre_build()"
86 message "${MESSAGE_COLOR}Building" \
87 "${SPELL_COLOR}${SPELL}" \
88 "${DEFAULT_COLOR}"
89
90 rm_source_dir
91 mkdir -p $BUILD_DIRECTORY
92 cd $BUILD_DIRECTORY
93
94 run_spell_file PRE_BUILD pre_build
95 }
96
97
98 #---------------------------------------------------------------------
99 ## Starts up the compile logs, turns on the various environment
100 ## settings that need to be on, eventually gets around to running
101 ## BUILD or default_build, then does other things it shouldn't do.
102 #---------------------------------------------------------------------
103 function run_build">run_build() {
104
105 debug "build_api/api1" "Starting run_build">run_build()"
106
107 echo "Compile log for $SPELL $VERSION Built on `date -u`" > $C_LOG
108 echo "Using gcc version: `gcc -dumpversion`" >> $C_LOG
109
110 # slight bug here if SOURCE_DIRECTORY doesnt exist
111 [ -d "$SOURCE_DIRECTORY" ] &&
112 cd $SOURCE_DIRECTORY
113
114 invoke_build_dir
115 invoke_gcc
116 optimize
117 invoke_installwatch
118
119 message -n "Installing in dir: "
120 pwd
121 message "$SPELL $VERSION"
122
123 run_config_loc
124 (
125 run_spell_file BUILD build
126 ) 2> >(tee -a $C_LOG 1>&2 >> $VOYEUR_STDERR) \
127 > >(tee -a $C_LOG >> $VOYEUR_STDOUT) # see bug 7201
128
129 if [ "$?" != 0 ]; then
130 message "${PROBLEM_COLOR}" \
131 "! Problem Detected !" \
132 "${DEFAULT_COLOR}"
133 return 1
134 fi
135 echo "Compile log for $SPELL $VERSION Completed Build on `date -u`" >> $C_LOG
136
137 }
138
139
140 #---------------------------------------------------------------------
141 ## Checks for a POST_BUILD file in SCRIPT_DIRECTORY, and if it is
142 ## executable, runs it. This file is run after BUILD and before
143 ## POST_INSTALL. Its purpose is to bookend BUILD and shutoff installwatch.
144 #---------------------------------------------------------------------
145 function run_post_build() {
146
147 debug "build_api/api1" "Starting run_post_build()"
148 run_spell_file POST_BUILD post_build
149
150 # Lock made in prepare_install
151 unlock_resources "libgrimoire" "install"
152
153 }
154
155
156 #---------------------------------------------------------------------
157 ## Checks for a POST_INSTALL file in SCRIPT_DIRECTORY, and if it is
158 ## executable, runs it. This file is used for extra files that need
159 ## to be installed, but not tracked by installwatch.
160 #---------------------------------------------------------------------
161 function run_post_install">run_post_install() {
162
163 debug "build_api/api1" "Starting run_post_install">run_post_install()"
164 run_spell_file INSTALL install
165 }
166
167
168 #---------------------------------------------------------------------
169 ## @Type API
170 ## Creates the source directory and unpacks the source package into it.
171 ## Used if no PRE_BUILD script is found for a spell.
172 #---------------------------------------------------------------------
173 function real_default_sorcery_pre_build">real_default_sorcery_pre_build() {
174
175 debug "build_api/api1" "Starting real_default_sorcery_pre_build">real_default_sorcery_pre_build() - SOURCE=$SOURCE SOURCE_DIRECTORY=$SOURCE_DIRECTORY"
176 mk_source_dir $SOURCE_DIRECTORY &&
177 unpack_file
178
179 }
180
181
182
183
184 #---------------------------------------------------------------------
185 ## @Type API
186 ## Used if no BUILD script is found for a spell
187 ## Default build is:
188 ## <pre>
189 ## ./configure --build=$BUILD \
190 ## --prefix=/usr \
191 ## --sysconfdir=/etc \
192 ## --localstatedir=/var \
193 ## $OPTS &&
194 ## make &&
195 ## prepare_install &&
196 ## make install
197 ## </pre>
198 ##
199 #---------------------------------------------------------------------
200 function real_default_sorcery_build">real_default_sorcery_build() {
201
202 debug "build_api/api1" "Starting real_default_sorcery_build">real_default_sorcery_build()"
203 OPTS="$OPTS --build=${BUILD}"
204 #If this switches are used, they _may_ stop distcc and ccache from working
205 # for some spells (bug 3798)
206 # We could write wrappers for all of the possible binaries
207 [[ $CROSS_INSTALL == on ]] && OPTS="$OPTS --host=${HOST}"
208
209 ./configure --prefix=${INSTALL_ROOT}/usr \
210 --sysconfdir=${INSTALL_ROOT}/etc \
211 --localstatedir=${INSTALL_ROOT}/var \
212 --mandir=${INSTALL_ROOT}/usr/share/man \
213 --infodir=${INSTALL_ROOT}/usr/share/info \
214 $OPTS &&
215 make &&
216 prepare_install &&
217 make install
218
219 }
220
221
222
223 #---------------------------------------------------------------------
224 ## @Type API
225 ## Installs configuration files and documentation. Stops installwatch.
226 ## Used if no POST_BUILD script is found for a spell.
227 ##
228 #---------------------------------------------------------------------
229 function real_default_sorcery_post_build() {
230
231 debug "build_api/api1" "Starting real_default_sorcery_post_build()"
232
233 install_xinetd
234 install_initd
235 install_pam_confs
236 install_desktop_files
237 gather_docs
238 devoke_installwatch
239 init_post_install
240 ldconfig
241 # release_saved_libraries
242 cd /
243
244 }
245
246 #---------------------------------------------------------------------
247 ## @License
248 ##
249 ## This software is free software; you can redistribute it and/or modify
250 ## it under the terms of the GNU General Public License as published by
251 ## the Free Software Foundation; either version 2 of the License, or
252 ## (at your option) any later version.
253 ##
254 ## This software is distributed in the hope that it will be useful,
255 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
256 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
257 ## GNU General Public License for more details.
258 ##
259 ## You should have received a copy of the GNU General Public License
260 ## along with this software; if not, write to the Free Software
261 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
262 ##
263 #---------------------------------------------------------------------