Annotation of /trunk/mage/usr/lib/mage/smage2.sh
Parent Directory | Revision Log
Revision 1631 -
(hide annotations)
(download)
(as text)
Fri Jan 13 13:20:22 2012 UTC (12 years, 4 months ago) by niro
File MIME type: application/x-sh
File size: 45399 byte(s)
Fri Jan 13 13:20:22 2012 UTC (12 years, 4 months ago) by niro
File MIME type: application/x-sh
File size: 45399 byte(s)
-let mage-features decide to build static libs and always enable shared libs
1 | niro | 24 | #!/bin/bash |
2 | niro | 1571 | # $Id$ |
3 | niro | 24 | |
4 | # compiles/installs .smage2 source install scripts | ||
5 | # needs pkgbuild_dir (mage) | ||
6 | |||
7 | niro | 1571 | # TODO: record dynlib, gz | xz database |
8 | niro | 24 | |
9 | |||
10 | niro | 419 | # set default user mage.rc |
11 | : ${MAGERC="/etc/mage.rc"} | ||
12 | |||
13 | niro | 169 | # export default C locale |
14 | export LC_ALL=C | ||
15 | |||
16 | niro | 439 | source /etc/mage.rc.global |
17 | niro | 419 | source ${MAGERC} |
18 | niro | 1273 | source ${MLIBDIR}/mage4.functions.sh |
19 | niro | 24 | |
20 | niro | 1589 | ## setup ## |
21 | SMAGENAME="$1" | ||
22 | SMAGEVERSION="$(< ${MLIBDIR}/version)" | ||
23 | |||
24 | niro | 347 | # set PKGDIR and BUILDDIR and BINDIR to MROOT |
25 | if [[ -n ${MROOT} ]] | ||
26 | then | ||
27 | export PKGDIR=${MROOT}/${PKGDIR} | ||
28 | export BUILDDIR=${MROOT}/${BUILDDIR} | ||
29 | export BINDIR=${MROOT}/${BINDIR} | ||
30 | fi | ||
31 | |||
32 | niro | 1346 | # sources the smage file and uses state from distribution file if exist |
33 | # may helpful for repository support later on | ||
34 | smagesource() | ||
35 | { | ||
36 | local file="$1" | ||
37 | local mystate | ||
38 | local mycodename | ||
39 | |||
40 | source ${file} | ||
41 | |||
42 | [[ -n ${STATE} ]] && mystate="${STATE}" | ||
43 | niro | 1349 | |
44 | # do not overide if local state was broken or disabled! | ||
45 | case ${STATE} in | ||
46 | broken) return ;; | ||
47 | disabled) return ;; | ||
48 | esac | ||
49 | |||
50 | niro | 1346 | if [ -f ${SMAGESCRIPTSDIR}/distribution ] |
51 | then | ||
52 | source ${SMAGESCRIPTSDIR}/distribution | ||
53 | [[ -n ${STATE} ]] && mystate="${STATE}" | ||
54 | fi | ||
55 | # now switch state and export it | ||
56 | STATE="${mystate}" | ||
57 | } | ||
58 | |||
59 | niro | 306 | showversion() |
60 | { | ||
61 | niro | 24 | echo -en "Magellan Source Install v${SMAGEVERSION} " |
62 | echo -e "-- Niels Rogalla (niro@magellan-linux.de)" | ||
63 | } | ||
64 | |||
65 | niro | 306 | die() |
66 | { | ||
67 | niro | 24 | xtitleclean |
68 | niro | 413 | echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT} |
69 | niro | 24 | echo "SMAGE failed: $@" |
70 | exit 1 | ||
71 | } | ||
72 | |||
73 | niro | 941 | die_pipestatus() |
74 | { | ||
75 | niro | 943 | # the status change if we do any parameter declarations!! |
76 | # dont do this anymore, keep this in mind! | ||
77 | # | ||
78 | # local pos="$1" | ||
79 | # local comment="$2" | ||
80 | # | ||
81 | # [ ${PIPESTATUS[${pos}]} -ne 0 ] && die "${comment}" | ||
82 | # | ||
83 | [ ${PIPESTATUS[$1]} -ne 0 ] && die "$2" | ||
84 | niro | 941 | } |
85 | |||
86 | niro | 306 | xtitle() |
87 | { | ||
88 | if [[ ${TERM} = xterm ]] | ||
89 | niro | 24 | then |
90 | echo -ne "\033]0;[sMage: $@]\007" | ||
91 | fi | ||
92 | return 0 | ||
93 | } | ||
94 | |||
95 | niro | 306 | xtitleclean() |
96 | { | ||
97 | if [[ ${TERM} = xterm ]] | ||
98 | niro | 24 | then |
99 | echo -ne "\033]0;\007" | ||
100 | fi | ||
101 | return 0 | ||
102 | } | ||
103 | |||
104 | niro | 306 | syncsmage2() |
105 | { | ||
106 | niro | 24 | xtitle "Updating smage2-script tree ..." |
107 | local i | ||
108 | for i in ${SMAGE2RSYNC} | ||
109 | do | ||
110 | niro | 386 | rsync ${RSYNC_FETCH_OPTIONS} ${i} ${SMAGESCRIPTSDIR} |
111 | niro | 306 | if [[ $? = 0 ]] |
112 | niro | 24 | then |
113 | break | ||
114 | else | ||
115 | continue | ||
116 | fi | ||
117 | done | ||
118 | niro | 306 | |
119 | # clean up backup files (foo~) | ||
120 | niro | 24 | find ${SMAGESCRIPTSDIR} -name *~ -exec rm '{}' ';' |
121 | niro | 306 | |
122 | niro | 24 | xtitleclean |
123 | } | ||
124 | |||
125 | niro | 59 | # $1 filename |
126 | niro | 306 | get_db_md5_sum() |
127 | { | ||
128 | niro | 59 | local DB_FILE |
129 | local MD5_FILE | ||
130 | local i | ||
131 | |||
132 | DB_ENTRY="$(basename $1)" | ||
133 | MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} ${SMAGESUFFIX})" | ||
134 | |||
135 | i="$(cat ${MD5_FILE}| grep ${DB_ENTRY} | cut -d' ' -f1)" | ||
136 | |||
137 | echo "${i}" | ||
138 | } | ||
139 | |||
140 | niro | 306 | download_sources() |
141 | { | ||
142 | niro | 61 | [ -z "${SRC_URI}" ] && echo -e "\nNothing declared to download.\n" && return 0 |
143 | niro | 59 | |
144 | niro | 1580 | local count=${#SRC_URI[*]} |
145 | local uri | ||
146 | local subdir | ||
147 | local outputdir | ||
148 | local db_md5_file="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5" | ||
149 | local fetching | ||
150 | local i | ||
151 | niro | 59 | |
152 | # check if FETCHING is needed | ||
153 | niro | 1580 | if mchecksum --rundir "${SOURCEDIR}/${PNAME}" --file "${db_md5_file}" --method md5 |
154 | niro | 59 | then |
155 | niro | 439 | # md5's ok, no fetching needed |
156 | niro | 1580 | fetching=false |
157 | niro | 59 | else |
158 | niro | 1580 | fetching=true |
159 | niro | 59 | fi |
160 | niro | 306 | |
161 | niro | 1580 | if [[ ${fetching} = true ]] |
162 | then | ||
163 | for ((i=0; i < count; i++)) | ||
164 | do | ||
165 | # url to file | ||
166 | uri="${SRC_URI[${i}]%%' '*}" | ||
167 | niro | 59 | |
168 | niro | 1580 | # subdir in sources dir; the my_SRCI_URI file goes to there |
169 | subdir="${SRC_URI[${i}]##*' '}" | ||
170 | niro | 66 | |
171 | niro | 1580 | # if $subdir is not equal with $uri then an other dir is used |
172 | if [[ ${uri} != ${subdir} ]] | ||
173 | niro | 59 | then |
174 | niro | 1580 | outputdir="${SOURCEDIR}/${PNAME}/${subdir}" |
175 | else | ||
176 | outputdir="${SOURCEDIR}/${PNAME}" | ||
177 | niro | 59 | fi |
178 | niro | 306 | |
179 | niro | 1580 | echo -e "${COLBLUE}==>${COLGREEN} fetching ${uri}${COLDEFAULT}" |
180 | niro | 1630 | # always use verbose mode for source downloads |
181 | FVERBOSE=off msetfeature "verbose" | ||
182 | niro | 1600 | # do not die here, mchecksum catches download errors |
183 | mdownload --uri "${uri}" --dir "${outputdir}" | ||
184 | niro | 59 | |
185 | niro | 1580 | # unset them to be sure |
186 | unset uri | ||
187 | unset subdir | ||
188 | unset outputdir | ||
189 | done | ||
190 | niro | 59 | |
191 | niro | 1580 | # recheck md5 sums after download |
192 | echo | ||
193 | echo -e "${COLBLUE}===${COLGREEN} Checking MD5 sums:${COLDEFAULT}" | ||
194 | mchecksum --rundir "${SOURCEDIR}/${PNAME}" --file "${db_md5_file}" --method md5 || die "md5 failed" | ||
195 | echo | ||
196 | else | ||
197 | echo -e "${COLBLUE}===${COLGREEN} All sources already fetched, nothing to do${COLDEFAULT}" | ||
198 | fi | ||
199 | |||
200 | niro | 59 | # not needed anymore |
201 | unset SRC_URI | ||
202 | } | ||
203 | |||
204 | niro | 1573 | # dummy function, used if that does not exist in smage file |
205 | niro | 306 | src_prepare() |
206 | { | ||
207 | niro | 1592 | echo "no src_prepare defined; doing nothing ..." |
208 | niro | 24 | return 0 |
209 | } | ||
210 | |||
211 | niro | 1573 | # dummy function, used if that does not exist in smage file |
212 | niro | 1577 | src_compile() |
213 | niro | 1575 | { |
214 | niro | 1591 | echo "no src_compile defined; doing nothing ..." |
215 | niro | 1575 | return 0 |
216 | } | ||
217 | |||
218 | # dummy function, used if that does not exist in smage file | ||
219 | niro | 1577 | src_check() |
220 | niro | 306 | { |
221 | niro | 1591 | echo "no src_check defined; doing nothing ..." |
222 | niro | 24 | return 0 |
223 | } | ||
224 | |||
225 | niro | 1573 | # dummy function, used if that does not exist in smage file |
226 | niro | 306 | src_install() |
227 | { | ||
228 | niro | 1591 | echo "no src_install defined; doing nothing ..." |
229 | niro | 24 | return 0 |
230 | } | ||
231 | |||
232 | niro | 351 | mlibdir() |
233 | { | ||
234 | local libdir=lib | ||
235 | [[ ${ARCH} = x86_64 ]] && libdir=lib64 | ||
236 | |||
237 | echo "${libdir}" | ||
238 | } | ||
239 | |||
240 | niro | 306 | mconfigure() |
241 | { | ||
242 | niro | 1613 | local myopts |
243 | if [[ ! -z ${CTARGET} ]] | ||
244 | then | ||
245 | niro | 1631 | myopts+=" --target=${CTARGET}" |
246 | niro | 1613 | fi |
247 | niro | 1631 | # if requested disable-static |
248 | if [[ ! -z $(./configure --help | grep -- '--.*able-static') ]] | ||
249 | then | ||
250 | if mqueryfeature '!static' | ||
251 | then | ||
252 | myopts+=" --disable-static" | ||
253 | else | ||
254 | myopts+=" --enable-static" | ||
255 | fi | ||
256 | fi | ||
257 | niro | 1613 | |
258 | niro | 1631 | # always enable shared by default |
259 | if [[ ! -z $(./configure --help | grep -- '--.*able-shared') ]] | ||
260 | then | ||
261 | myopts+=" --enable-shared" | ||
262 | fi | ||
263 | |||
264 | niro | 24 | if [ -x ./configure ] |
265 | then | ||
266 | niro | 306 | ./configure \ |
267 | --prefix=/usr \ | ||
268 | --host=${CHOST} \ | ||
269 | niro | 833 | --build=${CHOST} \ |
270 | niro | 306 | --mandir=/usr/share/man \ |
271 | --infodir=/usr/share/info \ | ||
272 | --datadir=/usr/share \ | ||
273 | --sysconfdir=/etc \ | ||
274 | --localstatedir=/var/lib \ | ||
275 | niro | 351 | --libdir=/usr/$(mlibdir) \ |
276 | niro | 1613 | ${myopts} \ |
277 | niro | 306 | "$@" || die "mconfigure failed" |
278 | niro | 24 | else |
279 | echo "configure is not an executable ..." | ||
280 | exit 1 | ||
281 | fi | ||
282 | } | ||
283 | |||
284 | niro | 306 | minstall() |
285 | { | ||
286 | if [ -f ./[mM]akefile -o -f ./GNUmakefile ] | ||
287 | then | ||
288 | niro | 24 | make prefix=${BINDIR}/usr \ |
289 | datadir=${BINDIR}/usr/share \ | ||
290 | infodir=${BINDIR}/usr/share/info \ | ||
291 | localstatedir=${BINDIR}/var/lib \ | ||
292 | mandir=${BINDIR}/usr/share/man \ | ||
293 | sysconfdir=${BINDIR}/etc \ | ||
294 | niro | 351 | libdir=${BINDIR}/usr/$(mlibdir) \ |
295 | niro | 24 | "$@" install || die "minstall failed" |
296 | else | ||
297 | die "no Makefile found" | ||
298 | fi | ||
299 | } | ||
300 | |||
301 | niro | 306 | mmake() |
302 | { | ||
303 | niro | 24 | make ${MAKEOPTS} ${EXTRA_EMAKE} "$@" |
304 | } | ||
305 | |||
306 | niro | 306 | munpack() |
307 | { | ||
308 | niro | 24 | local SRCFILE |
309 | local IFTAR | ||
310 | local DEST | ||
311 | |||
312 | SRCFILE=$1 | ||
313 | niro | 306 | |
314 | niro | 597 | if [[ -z $2 ]] |
315 | niro | 24 | then |
316 | DEST=${BUILDDIR} | ||
317 | else | ||
318 | DEST=$2 | ||
319 | fi | ||
320 | niro | 306 | |
321 | niro | 411 | [[ ! -d ${DEST} ]] && install -d ${DEST} |
322 | |||
323 | niro | 24 | case "${SRCFILE##*.}" in |
324 | bz2) | ||
325 | IFTAR="$(basename $SRCFILE .bz2)" | ||
326 | IFTAR="${IFTAR##*.}" | ||
327 | niro | 306 | if [[ ${IFTAR} = tar ]] |
328 | niro | 24 | then |
329 | niro | 597 | tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tar.bz2 unpack failed." |
330 | else | ||
331 | pushd ${DEST} > /dev/null | ||
332 | bzcat ${SOURCEDIR}/${PNAME}/${SRCFILE} > ${DEST}/$(basename ${SRCFILE} .bz2) || die ".bz2 unpack failed." | ||
333 | popd > /dev/null | ||
334 | niro | 24 | fi |
335 | ;; | ||
336 | gz) | ||
337 | IFTAR="$(basename $SRCFILE .gz)" | ||
338 | IFTAR="${IFTAR##*.}" | ||
339 | niro | 306 | if [[ ${IFTAR} = tar ]] |
340 | niro | 24 | then |
341 | niro | 597 | tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tar.gz unpack failed." |
342 | else | ||
343 | pushd ${DEST} > /dev/null | ||
344 | zcat ${SOURCEDIR}/${PNAME}/${SRCFILE} > ${DEST}/$(basename ${SRCFILE} .gz) || die ".gz unpack failed." | ||
345 | popd > /dev/null | ||
346 | niro | 24 | fi |
347 | ;; | ||
348 | niro | 1351 | xz) |
349 | IFTAR="$(basename $SRCFILE .xz)" | ||
350 | IFTAR="${IFTAR##*.}" | ||
351 | if [[ ${IFTAR} = tar ]] | ||
352 | then | ||
353 | tar --no-same-owner -xvJf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tar.xz unpack failed." | ||
354 | else | ||
355 | pushd ${DEST} > /dev/null | ||
356 | xzcat ${SOURCEDIR}/${PNAME}/${SRCFILE} > ${DEST}/$(basename ${SRCFILE} .xz) || die ".xz unpack failed." | ||
357 | popd > /dev/null | ||
358 | fi | ||
359 | ;; | ||
360 | niro | 600 | tbz2|mpks|mpk) |
361 | niro | 597 | tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tbz2 unpack failed." |
362 | niro | 24 | ;; |
363 | tgz) | ||
364 | niro | 597 | tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tgz unpack failed." |
365 | niro | 24 | ;; |
366 | niro | 1351 | txz|mpkzs|mpkz) |
367 | tar --no-same-owner -xvJf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".txz unpack failed." | ||
368 | ;; | ||
369 | niro | 597 | rar) |
370 | unrar x ${SOURCEDIR}/${PNAME}/${SRCFILE} ${DEST} || die ".rar unpack failed." | ||
371 | ;; | ||
372 | niro | 1604 | zip|xpi|jar) |
373 | niro | 597 | unzip ${SOURCEDIR}/${PNAME}/${SRCFILE} -d ${DEST} || die ".zip unpack failed." |
374 | ;; | ||
375 | rpm) | ||
376 | niro | 635 | pushd ${DEST} > /dev/null |
377 | niro | 597 | rpm2targz ${SOURCEDIR}/${PNAME}/${SRCFILE} || die "rpm2targz: .rpm unpack failed." |
378 | niro | 602 | tar --no-same-owner -xvzf ${SRCFILE/.rpm/.tar.gz} || die "tar: .rpm unpack failed." |
379 | niro | 635 | if [[ -f ${DEST}/${SRCFILE/.rpm/.tar.gz} ]] |
380 | niro | 602 | then |
381 | niro | 635 | rm ${DEST}/${SRCFILE/.rpm/.tar.gz} |
382 | niro | 602 | fi |
383 | niro | 597 | ;; |
384 | niro | 24 | *) |
385 | die "munpack failed" | ||
386 | ;; | ||
387 | esac | ||
388 | } | ||
389 | |||
390 | niro | 306 | mpatch() |
391 | { | ||
392 | niro | 24 | local PATCHOPTS |
393 | local PATCHFILE | ||
394 | niro | 447 | local i |
395 | niro | 24 | |
396 | PATCHOPTS=$1 | ||
397 | PATCHFILE=$2 | ||
398 | |||
399 | niro | 447 | if [[ -z $2 ]] |
400 | then | ||
401 | PATCHFILE=$1 | ||
402 | |||
403 | ## patch level auto-detection, get patch level | ||
404 | for ((i=0; i < 10; i++)) | ||
405 | do | ||
406 | patch --dry-run -Np${i} -i ${SOURCEDIR}/${PNAME}/${PATCHFILE} > /dev/null | ||
407 | if [[ $? = 0 ]] | ||
408 | then | ||
409 | PATCHOPTS="-Np${i}" | ||
410 | break | ||
411 | fi | ||
412 | done | ||
413 | fi | ||
414 | |||
415 | niro | 384 | echo -e "${COLBLUE}*** ${COLGREEN}Applying patch '${PATCHFILE}'${COLDEFAULT}" |
416 | niro | 24 | patch "${PATCHOPTS}" -i ${SOURCEDIR}/${PNAME}/${PATCHFILE} |
417 | } | ||
418 | |||
419 | niro | 497 | mlibtoolize() |
420 | { | ||
421 | local opts="$@" | ||
422 | niro | 1435 | [[ -z ${opts} ]] && opts="--verbose --install --force" |
423 | niro | 24 | |
424 | niro | 497 | libtoolize ${opts} || die "running: mlibtoolize ${opts}" |
425 | } | ||
426 | |||
427 | niro | 1291 | mautoreconf() |
428 | { | ||
429 | local opts="$@" | ||
430 | [[ -z ${opts} ]] && opts="--verbose --install --force" | ||
431 | |||
432 | autoreconf ${opts} || die "running: mautoreconf ${opts}" | ||
433 | } | ||
434 | |||
435 | niro | 306 | minstalldocs() |
436 | { | ||
437 | niro | 24 | local docfiles |
438 | niro | 1581 | local doc |
439 | niro | 24 | docfiles="$@" |
440 | niro | 306 | |
441 | niro | 24 | if [ ! -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} ] |
442 | then | ||
443 | install -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "creating doc dirs." | ||
444 | fi | ||
445 | niro | 306 | |
446 | niro | 1581 | for doc in ${docfiles} |
447 | niro | 24 | do |
448 | niro | 1581 | if [ -f ${doc} ] |
449 | niro | 953 | then |
450 | niro | 1584 | if mqueryfeature "compressdoc" |
451 | niro | 1581 | then |
452 | niro | 1615 | cat ${doc} | gzip -9c > ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/$(basename ${doc}).gz || die "gzipping +installing ${doc}." |
453 | chmod 0644 ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/$(basename ${doc}).gz || die "fixing permissions of ${doc}." | ||
454 | niro | 1581 | else |
455 | install -m 0644 ${SRCDIR}/${i} ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "installing ${doc}." | ||
456 | fi | ||
457 | niro | 953 | fi |
458 | niro | 24 | done |
459 | } | ||
460 | |||
461 | niro | 306 | mstriplibs() |
462 | { | ||
463 | niro | 79 | local stripdir="$@" |
464 | |||
465 | niro | 1578 | [[ -z ${stripdir} ]] && stripdir="${BINDIR}" |
466 | [[ -z ${STRIP_DYN_LIB} ]] && STRIP_DYN_LIB="--strip-debug" | ||
467 | find ${stripdir} ! -type d | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_DYN_LIB} 2> /dev/null | ||
468 | niro | 79 | } |
469 | |||
470 | niro | 306 | mstripbins() |
471 | { | ||
472 | niro | 79 | local stripdir="$@" |
473 | |||
474 | niro | 1578 | [[ -z ${stripdir} ]] && stripdir="${BINDIR}" |
475 | [[ -z ${STRIP_DYN_BIN} ]] && STRIP_DYN_BIN="--strip-debug" | ||
476 | find ${stripdir} ! -type d | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_DYN_BIN} 2> /dev/null | ||
477 | niro | 79 | } |
478 | |||
479 | niro | 1543 | mstripstatic() |
480 | { | ||
481 | local stripdir="$@" | ||
482 | |||
483 | niro | 1578 | [[ -z ${stripdir} ]] && stripdir="${BINDIR}" |
484 | [[ -z ${STRIP_STATIC_LIB} ]] && STRIP_STATIC_LIB="--strip-debug" | ||
485 | find ${stripdir} ! -type d | xargs file | grep "ar archive" | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_STATIC_LIB} 2> /dev/null | ||
486 | niro | 1543 | } |
487 | |||
488 | niro | 1580 | mstriplibtoolarchive() |
489 | { | ||
490 | local stripdir="$@" | ||
491 | |||
492 | [[ -z ${stripdir} ]] && stripdir="${BINDIR}" | ||
493 | niro | 1601 | find ${stripdir} ! -type d -name \*.la | xargs | grep "libtool library" | cut -f 1 -d : | xargs --no-run-if-empty rm -f -- 2> /dev/null |
494 | niro | 1580 | } |
495 | |||
496 | mpurgetargets() | ||
497 | { | ||
498 | local stripdir="$@" | ||
499 | local target | ||
500 | |||
501 | [[ -z ${stripdir} ]] && stripdir=${BINDIR} | ||
502 | # nothing to do in this case | ||
503 | [[ -z ${PURGE_TARGETS[*]} ]] && return | ||
504 | |||
505 | for target in ${PURGE_TARGETS[*]} | ||
506 | do | ||
507 | # check if target is a regex pattern without any slashes | ||
508 | if [[ ${target} = ${target//\/} ]] | ||
509 | then | ||
510 | find ${BINDIR} -type f -name "${target}" | xargs --no-run-if-empty rm -f -- 2> /dev/null | ||
511 | else | ||
512 | rm -f -- ${target} 2> /dev/null | ||
513 | fi | ||
514 | done | ||
515 | } | ||
516 | |||
517 | niro | 943 | mcompressdocs() |
518 | { | ||
519 | local bindir="$@" | ||
520 | |||
521 | if [ -d ${bindir}/usr/share/man ] | ||
522 | then | ||
523 | echo -e "${COLBLUE}===${COLGREEN} compressing man-pages ...${COLDEFAULT}" | ||
524 | ${MLIBDIR}/compressdoc -g -9 ${bindir}/usr/share/man | ||
525 | fi | ||
526 | |||
527 | if [ -d ${bindir}/usr/share/info ] | ||
528 | then | ||
529 | echo -e "${COLBLUE}===${COLGREEN} compressing info-pages ...${COLDEFAULT}" | ||
530 | ${MLIBDIR}/compressdoc -g -9 ${bindir}/usr/share/info | ||
531 | fi | ||
532 | } | ||
533 | |||
534 | niro | 306 | sminclude() |
535 | { | ||
536 | niro | 172 | local i |
537 | |||
538 | niro | 183 | if [[ -n "$@" ]] |
539 | niro | 172 | then |
540 | for i in $@ | ||
541 | do | ||
542 | niro | 175 | echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc" |
543 | niro | 172 | source ${SMAGESCRIPTSDIR}/include/${i}.sminc |
544 | done | ||
545 | niro | 177 | echo |
546 | niro | 172 | fi |
547 | } | ||
548 | |||
549 | niro | 306 | setup_distcc_environment() |
550 | { | ||
551 | niro | 24 | if [ -x /usr/bin/distcc ] |
552 | then | ||
553 | niro | 441 | echo -e "${COLBLUE}---${COLGREEN} Using DistCC for compilation ...${COLDEFAULT}" |
554 | niro | 351 | export PATH=/usr/$(mlibdir)/distcc/bin:${PATH} || die "distcc: could not export new $PATH" |
555 | niro | 24 | |
556 | export DISTCC_DIR="${DISTCC_DIR}" || die "distcc_dir export failed" | ||
557 | |||
558 | niro | 306 | # creating distcc tempdir |
559 | niro | 24 | install -o distcc -g daemon -d ${DISTCC_DIR} |
560 | chmod 1777 ${DISTCC_DIR} | ||
561 | fi | ||
562 | } | ||
563 | |||
564 | niro | 306 | setup_ccache_environment() |
565 | { | ||
566 | niro | 24 | if [ -x /usr/bin/ccache ] |
567 | then | ||
568 | niro | 441 | echo -e "${COLBLUE}---${COLGREEN} Using CCache for compilation ...${COLDEFAULT}" |
569 | niro | 351 | export PATH=/usr/$(mlibdir)/ccache/bin:${PATH} || die "ccache: could not export new $PATH" |
570 | niro | 24 | fi |
571 | } | ||
572 | |||
573 | niro | 193 | # fixes given dependencies to match a MAGE_TARGET |
574 | niro | 198 | # fix_mage_deps -target s/depend # <-- note -target ! |
575 | niro | 306 | fix_mage_deps() |
576 | { | ||
577 | niro | 193 | local target="$1" |
578 | local depend="$2" | ||
579 | local NDEPEND | ||
580 | local sym dep cat pver pname | ||
581 | |||
582 | # deps and provides are special | ||
583 | # they must be fixed to match the target | ||
584 | |||
585 | # run this only if target and depend is not empty | ||
586 | if [ -n "${target}" ] && [ -n "${depend}" ] | ||
587 | then | ||
588 | # fix DEPEND | ||
589 | while read sym dep | ||
590 | do | ||
591 | niro | 427 | # ignore empty lines |
592 | [[ -z ${dep} ]] && continue | ||
593 | |||
594 | niro | 193 | cat="$(dirname ${dep})" |
595 | niro | 199 | # change if not virtual |
596 | niro | 200 | if [[ ${cat} = virtual ]] |
597 | niro | 199 | then |
598 | niro | 200 | pname="$(basename ${dep})" |
599 | else | ||
600 | niro | 199 | # fix pver to target-pver |
601 | # to get pname-target-pver | ||
602 | niro | 193 | |
603 | niro | 199 | # doing it backwards ! |
604 | pver="${dep##*-}" | ||
605 | niro | 200 | # full pver |
606 | pname="$(basename ${dep/-${pver}/})${target}-${pver}" | ||
607 | niro | 199 | fi |
608 | niro | 193 | |
609 | # do not add empty lines | ||
610 | if [ -z "${NDEPEND}" ] | ||
611 | then | ||
612 | niro | 200 | NDEPEND="${sym} ${cat}/${pname}" |
613 | niro | 193 | else |
614 | NDEPEND="${NDEPEND} | ||
615 | niro | 201 | ${sym} ${cat}/${pname}" |
616 | niro | 193 | fi |
617 | |||
618 | unset cat pname pver | ||
619 | done << EOF | ||
620 | ${depend} | ||
621 | EOF | ||
622 | # set NDEPEND to DEPEND | ||
623 | depend="${NDEPEND}" | ||
624 | fi | ||
625 | |||
626 | echo "${depend}" | ||
627 | } | ||
628 | |||
629 | niro | 192 | # build_mage_script(): helper functions for regen_mage_tree() |
630 | niro | 191 | # generates an mage file with given information in smage file |
631 | # needs at least: | ||
632 | # PNAME name of pkg | ||
633 | # PVER version | ||
634 | # PBUILD revision | ||
635 | # PCATEGORIE categorie of the pkg | ||
636 | # STATE state of pkg stable|unstable|old | ||
637 | # DESCRIPTION va short description (opt) | ||
638 | # HOMEPAGE homepage (opt) | ||
639 | # DEPEND runtime dependencies (opt) | ||
640 | # SDEPEND add. needed deps to build the pkg (opt) | ||
641 | # PROVIDE provides a virtual (opt) | ||
642 | # | ||
643 | # special tags: | ||
644 | # PKGTYPE type of pkg | ||
645 | # INHERITS which functions get included | ||
646 | niro | 832 | # SPECIAL_FUNCTIONS special functions which should also be added |
647 | niro | 191 | # warning: they get killed before the build starts ! |
648 | niro | 943 | # SPLIT_PACKAGES names of all subpackages which are splitted from parent |
649 | # SPLIT_PACKAGE_BASE base package name for splitpackages | ||
650 | # (only in the resulting magefile} | ||
651 | niro | 191 | # |
652 | # MAGE_TREE_DEST target destination of the generated tree | ||
653 | # REGEN_MAGE_TREE set to 'true' to enable this | ||
654 | niro | 193 | # |
655 | niro | 195 | # gets called with build_mage_script target |
656 | niro | 192 | build_mage_script() |
657 | niro | 191 | { |
658 | local magefile | ||
659 | local dest | ||
660 | niro | 193 | local target |
661 | niro | 943 | local split_pkg_base |
662 | niro | 191 | local sym |
663 | local depname | ||
664 | |||
665 | # if MAGE_TREE_DEST not set use BUILDDIR | ||
666 | : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree} | ||
667 | |||
668 | # determinate which suffix this mage file should get, if any | ||
669 | niro | 943 | [[ $1 = --target ]] && shift && target="-$1" |
670 | niro | 191 | |
671 | niro | 943 | # mark package as splitpackage |
672 | [[ $1 = --split-pkg-base ]] && shift && split_pkg_base="$1" | ||
673 | |||
674 | niro | 191 | # name of magefile |
675 | niro | 193 | magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage" |
676 | niro | 191 | |
677 | # destination to magefile | ||
678 | niro | 193 | dest="${MAGE_TREE_DEST}/${PCATEGORIE}/${PNAME}${target}/${magefile}" |
679 | niro | 191 | |
680 | # show what we are doing | ||
681 | niro | 439 | echo -e "${COLBLUE}===${COLGREEN} generating mage file:${COLDEFAULT}" |
682 | echo "${dest}" | ||
683 | niro | 191 | |
684 | install -d "$(dirname ${dest})" | ||
685 | # now build the mage file | ||
686 | > ${dest} | ||
687 | |||
688 | # pgkname and state | ||
689 | niro | 193 | echo "PKGNAME=\"${PNAME}${target}-${PVER}-\${ARCH}-${PBUILD}\"" >> ${dest} |
690 | niro | 191 | echo "STATE=\"${STATE}\"" >> ${dest} |
691 | |||
692 | # description and homepage | ||
693 | echo "DESCRIPTION=\"${DESCRIPTION}\"" >> ${dest} | ||
694 | echo "HOMEPAGE=\"${HOMEPAGE}\"" >> ${dest} | ||
695 | |||
696 | niro | 196 | # special tags and vars |
697 | niro | 191 | echo "PKGTYPE=\"${PKGTYPE}\"" >> ${dest} |
698 | niro | 214 | |
699 | # echo MAGE_TARGETS ## note -target is needed ! | ||
700 | echo "MAGE_TARGETS=\"${target}\"" >> ${dest} | ||
701 | |||
702 | niro | 943 | # split package base |
703 | echo "SPLIT_PACKAGE_BASE=\"${split_pkg_base}\"" >> ${dest} | ||
704 | |||
705 | niro | 197 | # add special vars |
706 | if [ -n "${SPECIAL_VARS}" ] | ||
707 | niro | 191 | then |
708 | local i | ||
709 | niro | 197 | for i in ${SPECIAL_VARS} |
710 | niro | 191 | do |
711 | niro | 197 | # being tricky here :) |
712 | echo "${i}=\"$(eval echo \$${i})\"" >> ${dest} | ||
713 | niro | 191 | done |
714 | fi | ||
715 | niro | 214 | |
716 | niro | 197 | # add at least all includes |
717 | if [ -n "${INHERITS}" ] | ||
718 | niro | 196 | then |
719 | niro | 197 | echo -n "minclude" >> ${dest} |
720 | niro | 196 | local i |
721 | niro | 197 | for i in ${INHERITS} |
722 | niro | 196 | do |
723 | niro | 197 | echo -n " ${i}" >> ${dest} |
724 | niro | 196 | done |
725 | niro | 1351 | # a CRLF is needed here! |
726 | echo >> ${dest} | ||
727 | niro | 196 | fi |
728 | |||
729 | niro | 191 | # deps and provides |
730 | niro | 193 | echo "DEPEND=\"$(fix_mage_deps "${target}" "${DEPEND}")\"" >> ${dest} |
731 | echo "SDEPEND=\"$(fix_mage_deps "${target}" "${SDEPEND}")\"" >> ${dest} | ||
732 | niro | 191 | echo "PROVIDE=\"${PROVIDE}\"" >> ${dest} |
733 | |||
734 | # add special functions | ||
735 | if [ -n "${SPECIAL_FUNCTIONS}" ] | ||
736 | then | ||
737 | local i | ||
738 | for i in ${SPECIAL_FUNCTIONS} | ||
739 | do | ||
740 | # add to mage (quotes needed !) | ||
741 | typeset -f "${i}" >> ${dest} | ||
742 | # unset to be safe (quotes needed !) | ||
743 | niro | 192 | #unset "${i}" <-- later to get every target built |
744 | niro | 191 | done |
745 | fi | ||
746 | |||
747 | # pre|post-install|removes | ||
748 | typeset -f preinstall >> ${dest} | ||
749 | typeset -f postinstall >> ${dest} | ||
750 | typeset -f preremove >> ${dest} | ||
751 | typeset -f postremove >> ${dest} | ||
752 | } | ||
753 | |||
754 | regen_mage_tree() | ||
755 | { | ||
756 | niro | 1436 | local subpackage |
757 | niro | 191 | |
758 | # build them only if requested | ||
759 | niro | 1584 | if mqueryfeature regentree |
760 | niro | 191 | then |
761 | niro | 195 | # run it without targets |
762 | niro | 943 | if [[ -n ${MAGE_TARGETS} ]] |
763 | niro | 195 | then |
764 | niro | 943 | # build for each target a mage file |
765 | # run it with several targets | ||
766 | niro | 191 | echo |
767 | niro | 1436 | for subpackage in ${MAGE_TARGETS} |
768 | niro | 943 | do |
769 | niro | 1436 | build_mage_script --target "${subpackage}" |
770 | niro | 943 | done |
771 | niro | 191 | echo |
772 | niro | 195 | |
773 | niro | 943 | # run it for splitpackages |
774 | elif [[ -n ${SPLIT_PACKAGES} ]] | ||
775 | then | ||
776 | local split_pkg_base="${PNAME}" | ||
777 | # save smage environment | ||
778 | split_save_variables | ||
779 | # build for each subpackage a mage file | ||
780 | niro | 195 | # run it with several targets |
781 | niro | 943 | echo |
782 | niro | 1436 | for subpackage in ${SPLIT_PACKAGES} |
783 | niro | 195 | do |
784 | niro | 943 | # get the right variables for the split |
785 | niro | 1436 | export PNAME="${subpackage}" |
786 | split_info_${subpackage} | ||
787 | # get the preinstall etc | ||
788 | split_export_inherits ${subpackage} | ||
789 | niro | 943 | build_mage_script --split-pkg-base "${split_pkg_base}" |
790 | niro | 1436 | # delete split preinstall etc |
791 | split_delete_inherits ${subpackage} | ||
792 | niro | 951 | # restore smage environment |
793 | split_restore_variables | ||
794 | niro | 195 | done |
795 | niro | 943 | echo |
796 | niro | 951 | # unset all saved smage variables |
797 | split_unset_variables | ||
798 | niro | 943 | |
799 | else | ||
800 | echo | ||
801 | build_mage_script | ||
802 | echo | ||
803 | niro | 195 | fi |
804 | niro | 191 | fi |
805 | |||
806 | # now unset all uneeded vars to be safe | ||
807 | niro | 192 | # unset PKGNAME <-- don't do that; smage needs this var |
808 | # unset to be safe (quotes needed !) | ||
809 | niro | 477 | # for i in ${SPECIAL_FUNCTIONS} |
810 | # do | ||
811 | # unset "${i}" | ||
812 | # done | ||
813 | niro | 192 | unset SPECIAL_FUNCTIONS |
814 | niro | 477 | # for i in ${SPECIAL_VARS} |
815 | # do | ||
816 | # unset "${i}" | ||
817 | # done | ||
818 | niro | 194 | unset SPECIAL_VARS |
819 | niro | 191 | unset STATE |
820 | unset DESCRIPTION | ||
821 | unset HOMEPAGE | ||
822 | niro | 1594 | # unset PKGTYPE <-- don't do that either; smage needs this var |
823 | niro | 191 | unset INHERITS |
824 | unset DEPEND | ||
825 | unset SDEPEND | ||
826 | unset PROVIDE | ||
827 | unset preinstall | ||
828 | unset postinstall | ||
829 | unset preremove | ||
830 | unset postremove | ||
831 | } | ||
832 | |||
833 | niro | 943 | split_save_variables() |
834 | { | ||
835 | export SAVED_PNAME="${PNAME}" | ||
836 | export SAVED_PVER="${PVER}" | ||
837 | export SAVED_PBUILD="${PBUILD}" | ||
838 | export SAVED_PCATEGORIE="${PCATEGORIE}" | ||
839 | export SAVED_DESCRIPTION="${DESCRIPTION}" | ||
840 | export SAVED_HOMEPAGE="${HOMEPAGE}" | ||
841 | export SAVED_SPECIAL_VARS="${SPECIAL_VARS}" | ||
842 | export SAVED_STATE="${STATE}" | ||
843 | export SAVED_PKGTYPE="${PKGTYPE}" | ||
844 | export SAVED_INHERITS="${INHERITS}" | ||
845 | export SAVED_DEPEND="${DEPEND}" | ||
846 | export SAVED_SDEPEND="${SDEPEND}" | ||
847 | export SAVED_PROVIDE="${PROVIDE}" | ||
848 | niro | 1582 | export SAVED_PKGTYPE="${PKGTYPE}" |
849 | niro | 943 | |
850 | niro | 1584 | # special handling needed for mage features |
851 | # pkgbuild | ||
852 | mqueryfeature "pkgbuild" && export SAVED_FEATURE_PKGBUILD="pkgbuild" | ||
853 | mqueryfeature "!pkgbuild" && export SAVED_FEATURE_PKGBUILD="!pkgbuild" | ||
854 | # strip | ||
855 | mqueryfeature "strip" && export SAVED_FEATURE_STRIP="strip" | ||
856 | mqueryfeature "!strip" && export SAVED_FEATURE_STRIP="!strip" | ||
857 | # libtool | ||
858 | mqueryfeature "libtool" && export SAVED_FEATURE_LIBTOOL="libtool" | ||
859 | mqueryfeature "!libtool" && export SAVED_FEATURE_LIBTOOL="!libtool" | ||
860 | # compressdoc | ||
861 | mqueryfeature "compressdoc" && export SAVED_FEATURE_COMPRESSDOC="compressdoc" | ||
862 | mqueryfeature "!compressdoc" && export SAVED_FEATURE_COMPRESSDOC="!compressdoc" | ||
863 | |||
864 | niro | 945 | # bindir too |
865 | export SAVED_BINDIR="${BINDIR}" | ||
866 | |||
867 | # export the SPLIT_PACKAGE_BASE | ||
868 | export SPLIT_PACKAGE_BASE="${SAVED_PNAME}" | ||
869 | |||
870 | niro | 943 | # functions |
871 | if [[ ! -z $(typeset -f preinstall) ]] | ||
872 | then | ||
873 | # rename the old one | ||
874 | local saved_preinstall | ||
875 | saved_preinstall=SAVED_$(typeset -f preinstall) | ||
876 | eval "${saved_preinstall}" | ||
877 | export -f SAVED_preinstall | ||
878 | fi | ||
879 | |||
880 | if [[ ! -z $(typeset -f postinstall) ]] | ||
881 | then | ||
882 | # rename the old one | ||
883 | local saved_postinstall | ||
884 | saved_postinstall=SAVED_$(typeset -f postinstall) | ||
885 | eval "${saved_postinstall}" | ||
886 | export -f SAVED_postinstall | ||
887 | fi | ||
888 | |||
889 | if [[ ! -z $(typeset -f preremove) ]] | ||
890 | then | ||
891 | # rename the old one | ||
892 | local saved_preremove | ||
893 | saved_preremove=SAVED_$(typeset -f preremove) | ||
894 | eval "${saved_preremove}" | ||
895 | export -f SAVED_preremove | ||
896 | fi | ||
897 | |||
898 | if [[ ! -z $(typeset -f postremove) ]] | ||
899 | then | ||
900 | # rename the old one | ||
901 | local saved_postremove | ||
902 | saved_postremove=SAVED_$(typeset -f postremove) | ||
903 | eval "${saved_postremove}" | ||
904 | export -f SAVED_postremove | ||
905 | fi | ||
906 | } | ||
907 | |||
908 | split_restore_variables() | ||
909 | { | ||
910 | export PNAME="${SAVED_PNAME}" | ||
911 | export PVER="${SAVED_PVER}" | ||
912 | export PBUILD="${SAVED_PBUILD}" | ||
913 | export PCATEGORIE="${SAVED_PCATEGORIE}" | ||
914 | export DESCRIPTION="${SAVED_DESCRIPTION}" | ||
915 | export HOMEPAGE="${SAVED_HOMEPAGE}" | ||
916 | export SPECIAL_VARS="${SAVED_SPECIAL_VARS}" | ||
917 | export STATE="${SAVED_STATE}" | ||
918 | export PKGTYPE="${SAVED_PKGTYPE}" | ||
919 | export INHERITS="${SAVED_INHERITS}" | ||
920 | export DEPEND="${SAVED_DEPEND}" | ||
921 | export SDEPEND="${SAVED_SDEPEND}" | ||
922 | export PROVIDE="${SAVED_PROVIDE}" | ||
923 | niro | 1582 | export PKGTYPE="${SAVED_PKGTYPE}" |
924 | niro | 943 | |
925 | niro | 1584 | # special handling needed for mage features |
926 | # pkgbuild | ||
927 | niro | 1614 | FVERBOSE=off msetfeature "${SAVED_FEATURE_PKGBUILD}" |
928 | niro | 1584 | # strip |
929 | niro | 1614 | FVERBOSE=off msetfeature "${SAVED_FEATURE_STRIP}" |
930 | niro | 1584 | # libtool |
931 | niro | 1614 | FVERBOSE=off msetfeature "${SAVED_FEATURE_LIBTOOL}" |
932 | niro | 1584 | # compressdoc |
933 | niro | 1614 | FVERBOSE=off msetfeature "${SAVED_FEATURE_COMPRESSDOC}" |
934 | niro | 1584 | |
935 | niro | 945 | # bindir too |
936 | export BINDIR="${SAVED_BINDIR}" | ||
937 | |||
938 | niro | 943 | # functions |
939 | if [[ ! -z $(typeset -f SAVED_preinstall) ]] | ||
940 | then | ||
941 | # rename the old one | ||
942 | local saved_preinstall | ||
943 | saved_preinstall=$(typeset -f SAVED_preinstall) | ||
944 | eval "${saved_preinstall/SAVED_/}" | ||
945 | export -f preinstall | ||
946 | fi | ||
947 | |||
948 | if [[ ! -z $(typeset -f SAVED_postinstall) ]] | ||
949 | then | ||
950 | # rename the old one | ||
951 | local saved_postinstall | ||
952 | saved_postinstall=$(typeset -f SAVED_postinstall) | ||
953 | eval "${saved_postinstall/SAVED_/}" | ||
954 | export -f postinstall | ||
955 | fi | ||
956 | |||
957 | if [[ ! -z $(typeset -f SAVED_preremove) ]] | ||
958 | then | ||
959 | # rename the old one | ||
960 | local saved_preremove | ||
961 | saved_preremove=$(typeset -f SAVED_preremove) | ||
962 | eval "${saved_preremove/SAVED_/}" | ||
963 | export -f preremove | ||
964 | fi | ||
965 | |||
966 | if [[ ! -z $(typeset -f SAVED_postremove) ]] | ||
967 | then | ||
968 | # rename the old one | ||
969 | local saved_postremove | ||
970 | saved_postremove=$(typeset -f SAVED_postremove) | ||
971 | eval "${saved_postremove/SAVED_/}" | ||
972 | export -f postremove | ||
973 | fi | ||
974 | niro | 951 | } |
975 | niro | 943 | |
976 | niro | 951 | split_unset_variables() |
977 | { | ||
978 | niro | 943 | # unset saved vars; not needed anymore |
979 | unset SAVED_PNAME | ||
980 | unset SAVED_PVER | ||
981 | unset SAVED_PBUILD | ||
982 | unset SAVED_PCATEGORIE | ||
983 | unset SAVED_DESCRIPTION | ||
984 | unset SAVED_HOMEPAGE | ||
985 | unset SAVED_SPECIAL_VARS | ||
986 | unset SAVED_STATE | ||
987 | unset SAVED_PKGTYPE | ||
988 | unset SAVED_INHERITS | ||
989 | unset SAVED_DEPEND | ||
990 | unset SAVED_SDEPEND | ||
991 | unset SAVED_PROVIDE | ||
992 | niro | 945 | unset SAVED_BINDIR |
993 | niro | 1582 | unset SAVED_PKGTYPE |
994 | niro | 1584 | unset SAVED_FEATURE_PKGBUILD |
995 | unset SAVED_FEATURE_STRIP | ||
996 | unset SAVED_FEATURE_LIBTOOL | ||
997 | unset SAVED_FEATURE_COMPRESSDOC | ||
998 | niro | 945 | unset SPLIT_PACKAGE_BASE |
999 | niro | 943 | unset -f SAVED_preinstall |
1000 | unset -f SAVED_postinstall | ||
1001 | unset -f SAVED_preremove | ||
1002 | unset -f SAVED_postremove | ||
1003 | } | ||
1004 | |||
1005 | niro | 1436 | split_export_inherits() |
1006 | { | ||
1007 | local subpackage="$1" | ||
1008 | local func | ||
1009 | local newfunc | ||
1010 | |||
1011 | for func in preinstall postinstall preremove postremove | ||
1012 | do | ||
1013 | if [[ ! -z $(typeset -f ${func}_${subpackage}) ]] | ||
1014 | then | ||
1015 | newfunc=$(typeset -f ${func}_${subpackage}) | ||
1016 | newfunc="${newfunc/_${subpackage} (/ (}" | ||
1017 | eval "${newfunc}" | ||
1018 | fi | ||
1019 | done | ||
1020 | } | ||
1021 | |||
1022 | split_delete_inherits() | ||
1023 | { | ||
1024 | local subpackage="$1" | ||
1025 | local func | ||
1026 | |||
1027 | for func in preinstall postinstall preremove postremove | ||
1028 | do | ||
1029 | if [[ ! -z $(typeset -f ${func}_${subpackage}) ]] | ||
1030 | then | ||
1031 | unset -f ${func} | ||
1032 | fi | ||
1033 | done | ||
1034 | } | ||
1035 | |||
1036 | niro | 253 | export_inherits() |
1037 | { | ||
1038 | local include="$1" | ||
1039 | shift | ||
1040 | |||
1041 | while [ "$1" ] | ||
1042 | do | ||
1043 | local functions="$1" | ||
1044 | |||
1045 | # sanity checks | ||
1046 | [ -z "${include}" ] && die "export_inherits(): \$include not given." | ||
1047 | [ -z "${functions}" ] && die "export_inherits(): \$functions not given." | ||
1048 | |||
1049 | eval "${functions}() { ${include}_${functions} ; }" | ||
1050 | |||
1051 | # debug | ||
1052 | [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}" | ||
1053 | |||
1054 | shift | ||
1055 | done | ||
1056 | } | ||
1057 | |||
1058 | niro | 255 | generate_package_md5sum() |
1059 | { | ||
1060 | local dest | ||
1061 | local pcat | ||
1062 | local pname | ||
1063 | local pver | ||
1064 | local pbuild | ||
1065 | local parch | ||
1066 | local target | ||
1067 | local pkgname | ||
1068 | |||
1069 | # very basic getops | ||
1070 | for i in $* | ||
1071 | do | ||
1072 | case $1 in | ||
1073 | --pcat|-c) shift; pcat="$1" ;; | ||
1074 | --pname|-n) shift; pname="$1" ;; | ||
1075 | --pver|-v) shift; pver="$1" ;; | ||
1076 | --pbuild|-b) shift; pbuild="$1" ;; | ||
1077 | --parch|a) shift; parch="$1" ;; | ||
1078 | --target|t) shift; target="$1" ;; | ||
1079 | esac | ||
1080 | shift | ||
1081 | done | ||
1082 | |||
1083 | # sanity checks; abort if not given | ||
1084 | [ -z "${pcat}" ] && die "generate_package_md5sum() \$pcat not given." | ||
1085 | [ -z "${pname}" ] && die "generate_package_md5sum() \$pname not given." | ||
1086 | [ -z "${pver}" ] && die "generate_package_md5sum() \$pver not given." | ||
1087 | [ -z "${pbuild}" ] && die "generate_package_md5sum() \$pbuild not given." | ||
1088 | [ -z "${parch}" ] && die "generate_package_md5sum() \$parch not given." | ||
1089 | |||
1090 | # check needed global vars | ||
1091 | [ -z "${PKGDIR}" ] && die "generate_package_md5sum() \$PKGDIR not set." | ||
1092 | [ -z "${PKGSUFFIX}" ] && die "generate_package_md5sum() \$PKGSUFFIX not set." | ||
1093 | |||
1094 | # fix target as it may be empty ! | ||
1095 | [ -n "${target}" ] && target="-${target}" | ||
1096 | |||
1097 | # build pkgname | ||
1098 | pkgname="${pname}${target}-${pver}-${parch}-${pbuild}" | ||
1099 | |||
1100 | # build pkg-md5-sum only if requested | ||
1101 | niro | 1584 | if mqueryfeature regentree |
1102 | niro | 255 | then |
1103 | niro | 439 | echo -ne "${COLBLUE}===${COLGREEN} generating md5's for ${pkgname}.${PKGSUFFIX} ... ${COLDEFAULT}" |
1104 | niro | 255 | |
1105 | # abort if not exist | ||
1106 | if [ ! -f ${PKGDIR}/${pkgname}.${PKGSUFFIX} ] | ||
1107 | then | ||
1108 | niro | 439 | echo -e "${COLRED}! exists${COLDEFAULT}" |
1109 | niro | 255 | return 0 |
1110 | fi | ||
1111 | |||
1112 | # if MAGE_TREE_DEST not set use BUILDDIR | ||
1113 | : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree} | ||
1114 | |||
1115 | # setup md5 dir | ||
1116 | niro | 891 | dest="${MAGE_TREE_DEST}/${pcat}/${pname}${target}/md5" |
1117 | niro | 255 | install -d ${dest} |
1118 | |||
1119 | # gen md5sum | ||
1120 | ( cd ${PKGDIR}; md5sum "${pkgname}.${PKGSUFFIX}" ) \ | ||
1121 | niro | 256 | > ${dest}/${pkgname}.md5 |
1122 | niro | 439 | echo -e "${COLGREEN}done${COLDEFAULT}" |
1123 | niro | 255 | fi |
1124 | } | ||
1125 | |||
1126 | niro | 403 | source_pkg_build() |
1127 | { | ||
1128 | if [[ ${PKGTYPE} = virtual ]] | ||
1129 | then | ||
1130 | echo "Virtual package detected; src-pkg-tarball not necessary ..." | ||
1131 | return 0 | ||
1132 | fi | ||
1133 | |||
1134 | if [[ ! -d ${SOURCEDIR}/${PNAME} ]] | ||
1135 | then | ||
1136 | echo "No SRC_URI defined; src-pkg-tarball not necessary ..." | ||
1137 | return 0 | ||
1138 | fi | ||
1139 | |||
1140 | niro | 419 | [ -z "${SRCPKGDIR}" ] && die "\$SRCPKGDIR not found. Please setup your ${MAGERC} correctly." |
1141 | niro | 406 | |
1142 | niro | 403 | echo -e "${COLGREEN}Creating source package tarball ... ${COLDEFAULT}" |
1143 | niro | 412 | |
1144 | # include the smage2 file | ||
1145 | cp ${SMAGENAME} ${SOURCEDIR}/${PNAME} | ||
1146 | |||
1147 | niro | 403 | ( cd ${SOURCEDIR}; tar cvjf ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${PNAME}; ) |
1148 | niro | 406 | [[ ! -d ${SRCPKGDIR} ]] && install -d ${SRCPKGDIR} |
1149 | mv ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${SRCPKGDIR}/${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX} | ||
1150 | niro | 403 | |
1151 | echo -e "${COLGREEN}Source package ${COLBLUE}${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX} ${COLGREEN}successfully builded.${COLDEFAULT}" | ||
1152 | } | ||
1153 | |||
1154 | niro | 859 | step_by_step() |
1155 | { | ||
1156 | niro | 1584 | if mqueryfeature stepbystep |
1157 | niro | 859 | then |
1158 | niro | 945 | echo -e "${COLRED}Step-by-step enabled! Paused after $1.${COLDEFAULT}" |
1159 | niro | 859 | echo "Press [enter] to continue" |
1160 | read | ||
1161 | fi | ||
1162 | } | ||
1163 | niro | 403 | |
1164 | niro | 1617 | resume_stamp() |
1165 | { | ||
1166 | local step="$1" | ||
1167 | niro | 1621 | [[ ! -d ${BUILDDIR}/.stamps ]] && install -d ${BUILDDIR}/.stamps |
1168 | touch ${BUILDDIR}/.stamps/smage-${PKGNAME}-${step} | ||
1169 | niro | 1617 | } |
1170 | niro | 859 | |
1171 | niro | 1617 | run_resume() |
1172 | { | ||
1173 | local step="$1" | ||
1174 | |||
1175 | niro | 1621 | if mqueryfeature "resume" && [[ -f ${BUILDDIR}/.stamps/smage-${PKGNAME}-${step} ]] |
1176 | niro | 1617 | then |
1177 | echo -e "${COLMAGENTA}${step} already processed; doing nothing${COLDEFAULT}" | ||
1178 | return 0 | ||
1179 | else | ||
1180 | return 1 | ||
1181 | fi | ||
1182 | } | ||
1183 | |||
1184 | niro | 59 | # print out our version |
1185 | showversion | ||
1186 | echo | ||
1187 | |||
1188 | niro | 24 | if [ -z "$1" ] |
1189 | then | ||
1190 | echo "No .smage2 file given. Exiting." | ||
1191 | echo | ||
1192 | exit 1 | ||
1193 | fi | ||
1194 | |||
1195 | niro | 1584 | # load supported mage features |
1196 | load_mage_features | ||
1197 | |||
1198 | niro | 192 | # updating smage2-scripts |
1199 | niro | 306 | if [[ $1 = update ]] |
1200 | niro | 24 | then |
1201 | niro | 59 | if [ ! -d ${SOURCEDIR} ] |
1202 | then | ||
1203 | install -d ${SOURCEDIR} | ||
1204 | fi | ||
1205 | syncsmage2 | ||
1206 | exit 0 | ||
1207 | fi | ||
1208 | |||
1209 | niro | 192 | # creates md5sums for smages to given dir |
1210 | niro | 306 | if [[ $1 = calcmd5 ]] |
1211 | niro | 59 | then |
1212 | niro | 1207 | if [ $# -ge 2 ] |
1213 | niro | 59 | then |
1214 | SMAGENAME="$2" | ||
1215 | MD5DIR="$3" | ||
1216 | niro | 1207 | [[ -z ${MD5DIR} ]] && MD5DIR="$(dirname ${SMAGENAME})/md5" |
1217 | |||
1218 | niro | 1346 | smagesource ${SMAGENAME} || die "download source failed" |
1219 | niro | 59 | |
1220 | niro | 66 | # overridable sourcedir; must be declared after source of the smage2 |
1221 | CALC_SOURCEDIR="${CALC_SOURCEDIR:="${SOURCEDIR}/${PNAME}"}" | ||
1222 | |||
1223 | niro | 59 | [ -z "${SRC_URI}" ] && die "Nothing declared to calculate." |
1224 | |||
1225 | # end of array | ||
1226 | EOA=${#SRC_URI[*]} | ||
1227 | |||
1228 | [ ! -d ${MD5DIR} ] && install -d ${MD5DIR} | ||
1229 | |||
1230 | # clear md5sum file | ||
1231 | MY_MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5" | ||
1232 | echo -n > ${MY_MD5_FILE} | ||
1233 | |||
1234 | for ((i=0; i < EOA; i++)) | ||
1235 | do | ||
1236 | niro | 66 | # url to file |
1237 | my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)" | ||
1238 | |||
1239 | # subdir in sources dir; the my_SRCI_URI file goes to there | ||
1240 | my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)" | ||
1241 | |||
1242 | # if my_src_uri_dest is not equal my_src_uri; than an other dir is used | ||
1243 | if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]] | ||
1244 | then | ||
1245 | MY_SRC_FILE="${my_SRC_URI_DEST}/$(basename ${SRC_URI[${i}]})" | ||
1246 | else | ||
1247 | MY_SRC_FILE="$(basename ${SRC_URI[${i}]})" | ||
1248 | fi | ||
1249 | |||
1250 | niro | 59 | if [ -e "${CALC_SOURCEDIR}/${MY_SRC_FILE}" ] |
1251 | then | ||
1252 | echo "calculating $(basename ${MY_SRC_FILE}) ..." | ||
1253 | ( cd ${CALC_SOURCEDIR}; md5sum "${MY_SRC_FILE}" ) >> ${MY_MD5_FILE} | ||
1254 | else | ||
1255 | echo "WARNING: File '$(basename ${MY_SRC_FILE}) not found in ${CALC_SOURCEDIR}." | ||
1256 | fi | ||
1257 | niro | 66 | |
1258 | # unset them to be shure | ||
1259 | unset my_SRC_URI | ||
1260 | unset my_SRC_URI_DEST | ||
1261 | unset my_SRC_URI_MIRROR | ||
1262 | unset my_SOURCEDIR | ||
1263 | niro | 59 | done |
1264 | niro | 306 | |
1265 | niro | 59 | echo |
1266 | echo "Calculating of md5 sums for '$(basename ${SMAGENAME} .${SMAGESUFFIX})' done." | ||
1267 | echo | ||
1268 | else | ||
1269 | echo "Usage: Calculating MD5 Sums:" | ||
1270 | niro | 1207 | echo " $(basename $0) calcmd5 /path/to/SMAGENAME [/path/to/MD5DIR]" |
1271 | niro | 59 | echo |
1272 | echo | ||
1273 | echo "Export the CALC_SOURCEDIR variable to override current SOURCEDIRs." | ||
1274 | echo | ||
1275 | exit 1 | ||
1276 | fi | ||
1277 | niro | 306 | |
1278 | niro | 59 | exit 0 |
1279 | fi | ||
1280 | |||
1281 | niro | 192 | # download sources |
1282 | niro | 59 | if [ "$1" == "download" -a -n "$2" ] |
1283 | then | ||
1284 | niro | 24 | if [ ! -d ${SMAGESCRIPTSDIR} ] |
1285 | then | ||
1286 | install -d ${SMAGESCRIPTSDIR} | ||
1287 | fi | ||
1288 | niro | 59 | |
1289 | # get smage | ||
1290 | SMAGENAME="$2" | ||
1291 | MD5DIR="$(dirname ${SMAGENAME})/md5" | ||
1292 | niro | 1346 | smagesource ${SMAGENAME} || die "download source failed" |
1293 | niro | 59 | |
1294 | download_sources | ||
1295 | niro | 24 | exit 0 |
1296 | fi | ||
1297 | |||
1298 | niro | 202 | # regen-mage-tree |
1299 | if [ "$1" == "only-regen-tree" -a -n "$2" ] | ||
1300 | then | ||
1301 | # set correct SMAGENAME | ||
1302 | SMAGENAME="$2" | ||
1303 | MD5DIR="$(dirname ${SMAGENAME})/md5" | ||
1304 | niro | 1346 | smagesource ${SMAGENAME} || die "regen: smage2 not found" |
1305 | niro | 202 | |
1306 | regen_mage_tree | ||
1307 | niro | 255 | |
1308 | niro | 890 | # build several targets |
1309 | niro | 943 | if [[ -n ${MAGE_TARGETS} ]] |
1310 | niro | 890 | then |
1311 | for target in ${MAGE_TARGETS} | ||
1312 | do | ||
1313 | # build md5sum for existing packages | ||
1314 | generate_package_md5sum \ | ||
1315 | --pcat "${PCATEGORIE}" \ | ||
1316 | --pname "${PNAME}" \ | ||
1317 | --pver "${PVER}" \ | ||
1318 | --pbuild "${PBUILD}" \ | ||
1319 | --parch "${ARCH}" \ | ||
1320 | --target "${target}" | ||
1321 | done | ||
1322 | niro | 943 | |
1323 | # build several subpackages | ||
1324 | elif [[ -n ${SPLIT_PACKAGES} ]] | ||
1325 | then | ||
1326 | split_save_variables | ||
1327 | niro | 964 | for subpackage in ${SPLIT_PACKAGES} |
1328 | niro | 943 | do |
1329 | # get the right variables for the split | ||
1330 | export PNAME="${subpackage}" | ||
1331 | split_info_${subpackage} | ||
1332 | # build md5sum for existing packages | ||
1333 | generate_package_md5sum \ | ||
1334 | --pcat "${PCATEGORIE}" \ | ||
1335 | --pname "${PNAME}" \ | ||
1336 | --pver "${PVER}" \ | ||
1337 | --pbuild "${PBUILD}" \ | ||
1338 | --parch "${ARCH}" | ||
1339 | niro | 951 | # restore smage environment |
1340 | split_restore_variables | ||
1341 | niro | 943 | done |
1342 | niro | 951 | # unset all saved smage variables |
1343 | split_unset_variables | ||
1344 | niro | 943 | |
1345 | niro | 890 | else |
1346 | # build md5sum for existing packages | ||
1347 | generate_package_md5sum \ | ||
1348 | --pcat "${PCATEGORIE}" \ | ||
1349 | --pname "${PNAME}" \ | ||
1350 | --pver "${PVER}" \ | ||
1351 | --pbuild "${PBUILD}" \ | ||
1352 | niro | 943 | --parch "${ARCH}" |
1353 | niro | 890 | fi |
1354 | niro | 255 | |
1355 | niro | 202 | exit 0 |
1356 | fi | ||
1357 | |||
1358 | niro | 412 | if [ "$1" == "--create-src-tarball" -a -n "$2" ] |
1359 | niro | 403 | then |
1360 | # set correct SMAGENAME | ||
1361 | SMAGENAME="$2" | ||
1362 | MD5DIR="$(dirname ${SMAGENAME})/md5" | ||
1363 | |||
1364 | niro | 412 | echo -e "${COLGREEN}create-src-tarball called for ${COLBLUE}${SMAGENAME}${COLGREEN} ...${COLDEFAULT}" |
1365 | niro | 403 | |
1366 | niro | 1346 | smagesource ${SMAGENAME} || die "regen: smage2 not found" |
1367 | niro | 403 | |
1368 | if [[ -d ${SOURCEDIR}/${PNAME} ]] | ||
1369 | then | ||
1370 | echo -e "${COLGREEN}Deleting old sourcefiles ${COLBLUE}${SOURCEDIR}/${PNAME}${COLGREEN} ...${COLDEFAULT}" | ||
1371 | rm -rf ${SOURCEDIR}/${PKGNAME} | ||
1372 | fi | ||
1373 | |||
1374 | download_sources | ||
1375 | source_pkg_build ${SMAGENAME} | ||
1376 | exit 0 | ||
1377 | fi | ||
1378 | |||
1379 | niro | 406 | if [ "$1" == "--src-tarball" -a -n "$2" ] || [ "$1" == "-st" -a -n "$2" ] |
1380 | niro | 403 | then |
1381 | niro | 412 | SRCPKGTARBALL="${2}" |
1382 | niro | 1584 | msetfeature "srcpkgtarball" |
1383 | niro | 403 | |
1384 | niro | 412 | # abort if given file is not a source pkg |
1385 | [[ ${SRCPKGTARBALL##*.} != ${SRCPKGSUFFIX} ]] && die "${SRCPKGTARBALL} is not a valid src-pkg file." | ||
1386 | |||
1387 | # set correct SMAGENAME; use the one that the src_pkg provide | ||
1388 | # /path/to/SOURCEDIR/PNAME/SMAGENAME | ||
1389 | SMAGENAME="${SOURCEDIR}/$(basename ${SRCPKGTARBALL%-*-*})/$(basename ${SRCPKGTARBALL} .${SRCPKGSUFFIX}).${SMAGESUFFIX}" | ||
1390 | |||
1391 | niro | 403 | echo -e "${COLGREEN}Using src-tarball ${COLBLUE}${SRCPKGTARBALL}${COLGREEN} ...${COLDEFAULT}" |
1392 | |||
1393 | [[ ! -d ${SOURCEDIR} ]] && install -d ${SOURCEDIR} | ||
1394 | |||
1395 | # unpack srctarball | ||
1396 | [[ ! -f ${SRCPKGTARBALL} ]] && die "Error: ${SRCPKGTARBALL} does not exist. Aborting." | ||
1397 | |||
1398 | tar xvjf ${SRCPKGTARBALL} -C ${SOURCEDIR} || die "Error unpackung src-tarball ${SRCPKGTARBALL}" | ||
1399 | niro | 412 | |
1400 | [[ ! -f ${SMAGENAME} ]] && die "Included smage2 file in src-tarball not found: ${SMAGENAME}" | ||
1401 | niro | 403 | fi |
1402 | |||
1403 | niro | 1617 | if [ "$1" == "--resume" -a -n "$2" ] |
1404 | then | ||
1405 | msetfeature "resume" | ||
1406 | SMAGENAME="$2" | ||
1407 | fi | ||
1408 | niro | 403 | |
1409 | niro | 306 | [ ! -e ${MLIBDIR}/pkgbuild_dir.sh ] && die "Error: ${MLIBDIR}/pkgbuild_dir.sh not found. Aborting." |
1410 | [ -z "$(basename ${SMAGENAME} | grep .${SMAGESUFFIX})" ] && | ||
1411 | die "File '$(basename ${SMAGENAME})' is not a sMage v${SMAGEVERSION} file. Aborting." | ||
1412 | niro | 419 | [ -z "${SOURCEDIR}" ] && die "\$SOURCEDIR not found. Please setup your ${MAGERC} correctly." |
1413 | [ -z "${SMAGESCRIPTSDIR}" ] && die "\$SMAGESCRIPTSDIR not found. Please setup your ${MAGERC} correctly." | ||
1414 | [ -z "${SMAGE2RSYNC}" ] && die "\$SMAGE2RSYNC not found. Please setup your ${MAGERC} correctly." | ||
1415 | [ -z "${BINDIR}" ] && die "no BINDIR variable found in ${MAGERC}" | ||
1416 | [ -z "${CHOST}" ] && die "no CHOST variable found in ${MAGERC}" | ||
1417 | [ -z "${CFLAGS}" ] && die "no CFLAGS variable found in ${MAGERC}" | ||
1418 | [ -z "${CXXFLAGS}" ] && die "no CXXFLAGS variable found in ${MAGERC}" | ||
1419 | niro | 24 | |
1420 | niro | 1346 | smagesource ${SMAGENAME} || die "source failed" |
1421 | niro | 255 | PKGNAME="${PNAME}-${PVER}-${ARCH}-${PBUILD}" |
1422 | niro | 59 | MD5DIR="$(dirname ${SMAGENAME})/md5" |
1423 | niro | 941 | SMAGE_LOG_CMD="tee -a /var/log/smage/${PKGNAME}.log" |
1424 | niro | 24 | |
1425 | xtitle "Compiling ${PKGNAME}" | ||
1426 | niro | 439 | echo -e "${COLGREEN}Compiling ${PKGNAME}${COLDEFAULT}" |
1427 | niro | 59 | |
1428 | niro | 191 | # auto regen mage tree if requested |
1429 | regen_mage_tree | ||
1430 | |||
1431 | niro | 1584 | if mqueryfeature "srcpkg" |
1432 | niro | 403 | then |
1433 | if [[ -d ${SOURCEDIR}/${PNAME} ]] | ||
1434 | then | ||
1435 | niro | 441 | echo -e "${COLBLUE}===${COLGREEN} deleting old sourcefiles ${COLBLUE}${SOURCEDIR}/${PNAME}${COLGREEN} ...${COLDEFAULT}" |
1436 | niro | 408 | rm -rf ${SOURCEDIR}/${PNAME} |
1437 | niro | 403 | fi |
1438 | fi | ||
1439 | |||
1440 | niro | 192 | # download sources |
1441 | niro | 1584 | mqueryfeature "srcpkgtarball" || download_sources |
1442 | niro | 59 | |
1443 | niro | 192 | # fixes some issues with these functions |
1444 | niro | 24 | export -f src_prepare || die "src_prepare export failed" |
1445 | export -f src_compile || die "src_compile export failed" | ||
1446 | niro | 1575 | export -f src_check || die "src_check export failed" |
1447 | niro | 24 | export -f src_install || die "src_install export failed" |
1448 | |||
1449 | niro | 192 | # fixes some compile issues |
1450 | niro | 24 | export CHOST="${CHOST}" || die "CHOST export failed" |
1451 | export CFLAGS="${CFLAGS}" || die "CFLAGS export failed" | ||
1452 | niro | 1616 | if [[ -z ${CXXFLAGS} ]] |
1453 | then | ||
1454 | export CXXFLAGS="${CFLAGS}" || die "CXXFLAGS export failed" | ||
1455 | else | ||
1456 | export CXXFLAGS="${CXXFLAGS}" || die "CXXFLAGS export failed" | ||
1457 | fi | ||
1458 | export LDFLAGS="${LDFLAGS}" || die "LDFLAGS export failed" | ||
1459 | niro | 24 | export BINDIR="${BINDIR}" || die "BINDIR export failed" |
1460 | export MAKEOPTS="${MAKEOPTS}" || die "MAKEOPTS export failed" | ||
1461 | |||
1462 | niro | 192 | # setup distcc |
1463 | niro | 351 | # setup for distcc goes *before* ccache, so ccache comes before distcc in path |
1464 | niro | 1584 | mqueryfeature "distcc" && setup_distcc_environment |
1465 | niro | 24 | |
1466 | niro | 192 | # setup ccache |
1467 | niro | 1584 | mqueryfeature "ccache" && setup_ccache_environment |
1468 | niro | 24 | |
1469 | niro | 1617 | if mqueryfeature "resume" |
1470 | niro | 24 | then |
1471 | niro | 1617 | echo -e "${COLMAGENTA}Resume requested; continuing previous build${COLDEFAULT}" |
1472 | niro | 24 | |
1473 | niro | 1617 | # setup build logging |
1474 | [[ ! -d /var/log/smage ]] && install -d /var/log/smage | ||
1475 | if [[ -f /var/log/smage/${PKGNAME}.log.bz2 ]] | ||
1476 | then | ||
1477 | bunzip2 -f /var/log/smage/${PKGNAME}.log.bz2 | ||
1478 | fi | ||
1479 | echo -e "### Resume started on $(date) ###\n" >> /var/log/smage/${PKGNAME}.log | ||
1480 | niro | 24 | |
1481 | niro | 1617 | else |
1482 | # clean up builddir if a previously one exist | ||
1483 | if [ -d ${BUILDDIR} ] | ||
1484 | then | ||
1485 | rm -rf ${BUILDDIR}/* || die "couldn't cleanup \$BUILDDIR." | ||
1486 | fi | ||
1487 | install -d ${BUILDDIR} || die "couldn't create \$BUILDDIR." | ||
1488 | niro | 24 | |
1489 | niro | 1617 | # clean up srcdir if a previously unpacked one exist |
1490 | if [ -d ${SRCDIR} ] | ||
1491 | then | ||
1492 | rm -rf ${SRCDIR} | ||
1493 | fi | ||
1494 | |||
1495 | # clean up bindir if a previous build exist or create a new one | ||
1496 | if [ -d ${BINDIR} ] | ||
1497 | then | ||
1498 | rm -rf ${BINDIR} | ||
1499 | fi | ||
1500 | install -d ${BINDIR} || die "couldn't create \$BINDIR." | ||
1501 | |||
1502 | # clean up package temp dir if a previous build exist | ||
1503 | if [ -d ${BUILDDIR}/${PKGNAME} ] | ||
1504 | then | ||
1505 | rm -rf ${BUILDDIR}/${PKGNAME} | ||
1506 | fi | ||
1507 | |||
1508 | niro | 1621 | # clean up stamps dir |
1509 | if [ -d ${BUILDDIR}/.stamps ] | ||
1510 | then | ||
1511 | rm -rf ${BUILDDIR}/.stamps | ||
1512 | fi | ||
1513 | |||
1514 | niro | 1617 | # setup build logging |
1515 | [[ ! -d /var/log/smage ]] && install -d /var/log/smage | ||
1516 | echo -e "### Build started on $(date) ###\n" > /var/log/smage/${PKGNAME}.log | ||
1517 | niro | 24 | fi |
1518 | |||
1519 | niro | 1593 | if [[ ${PKGTYPE} = virtual ]] |
1520 | niro | 1575 | then |
1521 | niro | 1593 | echo "virtual package detected; nothing will be build ..." |
1522 | # automatically set !pkgbuild here too | ||
1523 | msetfeature "!pkgbuild" | ||
1524 | niro | 1575 | else |
1525 | niro | 1617 | ( run_resume src_prepare || src_prepare ) | ${SMAGE_LOG_CMD} |
1526 | niro | 1593 | die_pipestatus 0 "src_prepare failed" |
1527 | niro | 1617 | resume_stamp src_prepare |
1528 | step_by_step src_prepare | ||
1529 | niro | 1575 | |
1530 | niro | 1617 | ( run_resume src_compile || src_compile ) | ${SMAGE_LOG_CMD} |
1531 | niro | 1593 | die_pipestatus 0 "src_compile failed" |
1532 | niro | 1617 | resume_stamp src_compile |
1533 | step_by_step src_compile | ||
1534 | niro | 945 | |
1535 | niro | 1593 | # only run checks if requested |
1536 | if mqueryfeature "!check" | ||
1537 | then | ||
1538 | echo "!check detected; src_check() will not be run!" | ${SMAGE_LOG_CMD} | ||
1539 | else | ||
1540 | niro | 1617 | ( run_resume src_check || src_check ) | ${SMAGE_LOG_CMD} |
1541 | niro | 1593 | die_pipestatus 0 "src_check failed" |
1542 | niro | 1617 | resume_stamp src_check |
1543 | niro | 1593 | fi |
1544 | niro | 1617 | step_by_step src_check |
1545 | niro | 945 | |
1546 | niro | 1593 | # build several subpackages |
1547 | if [[ -n ${SPLIT_PACKAGES} ]] | ||
1548 | then | ||
1549 | # save bindir & pname | ||
1550 | split_save_variables | ||
1551 | export SAVED_BINDIR="${BINDIR}" | ||
1552 | for subpackage in ${SPLIT_PACKAGES} | ||
1553 | do | ||
1554 | if typeset -f src_install_${subpackage} > /dev/null | ||
1555 | then | ||
1556 | # export subpackage bindir | ||
1557 | export BINDIR="${SAVED_BINDIR}_${subpackage}" | ||
1558 | # export PNAME, several internal function and include | ||
1559 | # rely on this variable | ||
1560 | export PNAME="${subpackage}" | ||
1561 | |||
1562 | echo | ||
1563 | echo -en "${COLBLUE}*** ${COLDEFAULT}" | ||
1564 | echo -en " Running ${COLGREEN}split src_install()${COLDEFAULT}" | ||
1565 | echo -en " for subpkg: ${COLBLUE}${PNAME}${COLDEFAULT}" | ||
1566 | echo -e " - basepkg: ${COLBLUE}${SPLIT_PACKAGE_BASE}${COLDEFAULT} ..." | ||
1567 | |||
1568 | niro | 1617 | ( run_resume src_install_${subpackage} || src_install_${subpackage} ) | ${SMAGE_LOG_CMD} |
1569 | niro | 1593 | die_pipestatus 0 "src_install_${subpackage} failed" |
1570 | niro | 1617 | resume_stamp src_install_${subpackage} |
1571 | step_by_step src_install_${subpackage} | ||
1572 | niro | 1593 | fi |
1573 | done | ||
1574 | # restore bindir & pname | ||
1575 | split_restore_variables | ||
1576 | # unset all saved smage variables | ||
1577 | split_unset_variables | ||
1578 | else | ||
1579 | niro | 1617 | ( run_resume src_install || src_install ) | ${SMAGE_LOG_CMD} |
1580 | niro | 1593 | die_pipestatus 0 "src_install failed" |
1581 | niro | 1617 | resume_stamp src_install |
1582 | step_by_step src_install | ||
1583 | niro | 1593 | fi |
1584 | niro | 943 | fi |
1585 | niro | 24 | |
1586 | niro | 1593 | # echo for sake of good-looking |
1587 | echo | ||
1588 | |||
1589 | niro | 1584 | if mqueryfeature "!compressdoc" |
1590 | niro | 24 | then |
1591 | niro | 1584 | echo -e "!compressdoc detected; documentation will not be compressed ..." |
1592 | niro | 1595 | elif mqueryfeature "!pkgbuild" |
1593 | then | ||
1594 | echo "!pkgbuild detected; skipping documentation compression..." | ||
1595 | niro | 943 | else |
1596 | niro | 1584 | # compressing doc, info & man files |
1597 | if [[ -n ${SPLIT_PACKAGES} ]] | ||
1598 | then | ||
1599 | for subpackage in ${SPLIT_PACKAGES} | ||
1600 | do | ||
1601 | niro | 1617 | run_resume mcompressdoc_${subpackage} || mcompressdocs ${BINDIR}_${subpackage} |
1602 | resume_stamp mcompressdoc_${subpackage} | ||
1603 | niro | 1584 | done |
1604 | else | ||
1605 | niro | 1617 | run_resume mcompressdoc || mcompressdocs ${BINDIR} |
1606 | resume_stamp mcompressdoc | ||
1607 | niro | 1584 | fi |
1608 | niro | 24 | fi |
1609 | |||
1610 | niro | 1584 | if mqueryfeature "!libtool" |
1611 | niro | 1580 | then |
1612 | niro | 1595 | if mqueryfeature "!pkgbuild" |
1613 | then | ||
1614 | echo "!pkgbuild detected; skipping libtool archive stripping ..." | ||
1615 | else | ||
1616 | niro | 1580 | if [[ -n ${SPLIT_PACKAGES} ]] |
1617 | then | ||
1618 | for subpackage in ${SPLIT_PACKAGES} | ||
1619 | do | ||
1620 | echo -e "${COLBLUE}===${COLGREEN} stripping libtool archives for '${subpackage}' ...${COLDEFAULT}" | ||
1621 | niro | 1617 | run_resume mstriplibtoolarchive_${subpackage} || mstriplibtoolarchive ${BINDIR}_${subpackage} |
1622 | resume_stamp mstriplibtoolarchive_${subpackage} | ||
1623 | niro | 1580 | done |
1624 | else | ||
1625 | niro | 1617 | echo -e "${COLBLUE}===${COLGREEN} stripping libtool archives ...${COLDEFAULT}" |
1626 | run_resume mstriplibtoolarchive || mstriplibtoolarchive ${BINDIR} | ||
1627 | resume_stamp mstriplibtoolarchive | ||
1628 | niro | 1580 | fi |
1629 | niro | 1595 | fi |
1630 | niro | 1580 | fi |
1631 | niro | 24 | |
1632 | niro | 1584 | if mqueryfeature "purge" |
1633 | niro | 1580 | then |
1634 | niro | 1595 | if mqueryfeature "!pkgbuild" |
1635 | then | ||
1636 | echo "!pkgbuild detected; skipping file purgation..." | ||
1637 | else | ||
1638 | niro | 1580 | if [[ -n ${SPLIT_PACKAGES} ]] |
1639 | then | ||
1640 | for subpackage in ${SPLIT_PACKAGES} | ||
1641 | do | ||
1642 | echo -e "${COLBLUE}===${COLGREEN} purging all purge targets in '${subpackage}' ...${COLDEFAULT}" | ||
1643 | niro | 1617 | run_resume mpurgetargets_${subpackage} || mpurgetargets ${BINDIR}_${subpackage} |
1644 | resume_stamp mpurgetargets_${subpackage} | ||
1645 | niro | 1580 | done |
1646 | else | ||
1647 | niro | 1617 | echo -e "${COLBLUE}===${COLGREEN} purging all purge targets ...${COLDEFAULT}" |
1648 | run_resume mpurgetargets || mpurgetargets ${BINDIR} | ||
1649 | resume_stamp mpurgetargets | ||
1650 | niro | 1580 | fi |
1651 | niro | 1595 | fi |
1652 | niro | 1580 | fi |
1653 | |||
1654 | niro | 79 | # stripping all bins and libs |
1655 | niro | 1584 | if mqueryfeature "!strip" |
1656 | then | ||
1657 | echo -e "!strip detected; Package will not be stripped ..." | ||
1658 | niro | 1595 | elif mqueryfeature "!pkgbuild" |
1659 | then | ||
1660 | echo "!pkgbuild detected; skipping stripping of the package ..." | ||
1661 | niro | 1584 | else |
1662 | niro | 1595 | if [[ -n ${SPLIT_PACKAGES} ]] |
1663 | then | ||
1664 | for subpackage in ${SPLIT_PACKAGES} | ||
1665 | do | ||
1666 | echo -e "${COLBLUE}===${COLGREEN} stripping binaries for '${subpackage}' ...${COLDEFAULT}" | ||
1667 | niro | 1617 | run_resume mstripbins_${subpackage} || mstripbins ${BINDIR}_${subpackage} |
1668 | resume_stamp mstripbins_${subpackage} | ||
1669 | niro | 1595 | echo -e "${COLBLUE}===${COLGREEN} stripping dynamic libraries for '${subpackage}' ...${COLDEFAULT}" |
1670 | niro | 1617 | run_resume mstriplibs_${subpackage} || mstriplibs ${BINDIR}_${subpackage} |
1671 | resume_stamp mstriplibs_${subpackage} | ||
1672 | niro | 1595 | echo -e "${COLBLUE}===${COLGREEN} stripping static libraries for '${subpackage}' ...${COLDEFAULT}" |
1673 | niro | 1617 | run_resume mstripstatic_${subpackage} || mstripstatic ${BINDIR}_${subpackage} |
1674 | resume_stamp mstripstatic_${subpackage} | ||
1675 | niro | 1595 | done |
1676 | else | ||
1677 | echo -e "${COLBLUE}===${COLGREEN} stripping binaries ...${COLDEFAULT}" | ||
1678 | niro | 1617 | run_resume mstripbins || mstripbins ${BINDIR} |
1679 | resume_stamp mstripbins | ||
1680 | niro | 1595 | echo -e "${COLBLUE}===${COLGREEN} stripping dynamic libraries ...${COLDEFAULT}" |
1681 | niro | 1617 | run_resume mstriplibs || mstriplibs ${BINDIR} |
1682 | resume_stamp mstriplibs | ||
1683 | niro | 1595 | echo -e "${COLBLUE}===${COLGREEN} stripping static libraries ...${COLDEFAULT}" |
1684 | niro | 1617 | run_resume mstripstatic || mstripstatic ${BINDIR} |
1685 | resume_stamp mstripstatic | ||
1686 | niro | 1595 | fi |
1687 | niro | 1584 | fi |
1688 | niro | 79 | |
1689 | niro | 1595 | if mqueryfeature "!pkgbuild" |
1690 | niro | 1584 | then |
1691 | niro | 1595 | echo -e "!pkgbuild detected; Package will not be build ..." |
1692 | niro | 1584 | else |
1693 | niro | 306 | # build several targets |
1694 | niro | 943 | if [[ -n ${MAGE_TARGETS} ]] |
1695 | niro | 192 | then |
1696 | for target in ${MAGE_TARGETS} | ||
1697 | do | ||
1698 | niro | 1573 | # check if a special target_pkgbuild exists |
1699 | niro | 192 | if typeset -f ${target}_pkgbuild > /dev/null |
1700 | then | ||
1701 | # run it | ||
1702 | niro | 1617 | run_resume ${target}_pkgbuild || ${target}_pkgbuild |
1703 | resume_stamp ${target}_pkgbuild | ||
1704 | niro | 192 | fi |
1705 | # now create the target package | ||
1706 | niro | 1617 | run_resume pkg_builddir_${target} || ${MLIBDIR}/pkgbuild_dir.sh \ |
1707 | niro | 255 | "${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD}" \ |
1708 | niro | 192 | ${BINDIR} || die "target: ${target} package-build failed" |
1709 | niro | 1617 | resume_stamp pkg_builddir_${target} |
1710 | niro | 255 | |
1711 | # build pkg-md5-sum if requested | ||
1712 | niro | 1617 | run_resume md5sum_${target} || generate_package_md5sum \ |
1713 | niro | 255 | --pcat "${PCATEGORIE}" \ |
1714 | --pname "${PNAME}" \ | ||
1715 | --pver "${PVER}" \ | ||
1716 | --pbuild "${PBUILD}" \ | ||
1717 | --parch "${ARCH}" \ | ||
1718 | --target "${target}" | ||
1719 | niro | 1617 | resume_stamp md5sum_${target} |
1720 | niro | 255 | |
1721 | niro | 439 | echo -e "${COLGREEN}\nPackage ${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n${COLDEFAULT}" |
1722 | niro | 192 | done |
1723 | niro | 943 | |
1724 | # build several subpackages | ||
1725 | elif [[ -n ${SPLIT_PACKAGES} ]] | ||
1726 | then | ||
1727 | split_save_variables | ||
1728 | for subpackage in ${SPLIT_PACKAGES} | ||
1729 | do | ||
1730 | # get the right variables for the split | ||
1731 | export PNAME="${subpackage}" | ||
1732 | split_info_${PNAME} | ||
1733 | |||
1734 | niro | 1595 | # jump to next one if !pkgbuild is set in split_info |
1735 | mqueryfeature "!pkgbuild" && continue | ||
1736 | niro | 947 | |
1737 | niro | 943 | # check if an special subpackage_pkgbuild exists |
1738 | if typeset -f ${PNAME}_pkgbuild > /dev/null | ||
1739 | then | ||
1740 | # run it | ||
1741 | niro | 1617 | run_resume ${PNAME}_pkgbuild || ${PNAME}_pkgbuild |
1742 | resume_stamp ${PNAME}_pkgbuild | ||
1743 | niro | 943 | fi |
1744 | # now create the target package | ||
1745 | niro | 1617 | run_resume pkg_builddir_${PNAME} || ${MLIBDIR}/pkgbuild_dir.sh \ |
1746 | niro | 943 | "${PNAME}-${PVER}-${ARCH}-${PBUILD}" \ |
1747 | "${BINDIR}_${PNAME}" || die "split_package: ${PNAME} package-build failed" | ||
1748 | niro | 1617 | resume_stamp pkg_builddir_${PNAME} |
1749 | niro | 943 | |
1750 | # build pkg-md5-sum if requested | ||
1751 | niro | 1617 | run_resume md5sum_${PNAME} || generate_package_md5sum \ |
1752 | niro | 943 | --pcat "${PCATEGORIE}" \ |
1753 | --pname "${PNAME}" \ | ||
1754 | --pver "${PVER}" \ | ||
1755 | --pbuild "${PBUILD}" \ | ||
1756 | --parch "${ARCH}" | ||
1757 | niro | 1617 | resume_stamp md5sum_${PNAME} |
1758 | niro | 943 | |
1759 | echo -e "${COLGREEN}\nPackage ${PNAME}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n${COLDEFAULT}" | ||
1760 | niro | 951 | |
1761 | # restore smage environment | ||
1762 | split_restore_variables | ||
1763 | niro | 943 | done |
1764 | niro | 951 | # unset all saved smage variables |
1765 | split_unset_variables | ||
1766 | niro | 943 | |
1767 | niro | 192 | else |
1768 | niro | 1617 | run_resume pkg_builddir || ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed" |
1769 | resume_stamp pkg_builddir | ||
1770 | niro | 255 | |
1771 | # build pkg-md5-sum if requested | ||
1772 | niro | 1617 | run_resume md5sum || generate_package_md5sum \ |
1773 | niro | 255 | --pcat "${PCATEGORIE}" \ |
1774 | --pname "${PNAME}" \ | ||
1775 | --pver "${PVER}" \ | ||
1776 | --pbuild "${PBUILD}" \ | ||
1777 | --parch "${ARCH}" | ||
1778 | niro | 1617 | resume_stamp md5sum |
1779 | niro | 255 | |
1780 | niro | 439 | echo -e "${COLGREEN}\nPackage ${PKGNAME} successfully builded.\n${COLDEFAULT}" |
1781 | niro | 192 | fi |
1782 | niro | 403 | |
1783 | # build src-pkg-tarball if requested | ||
1784 | niro | 1617 | if mqueryfeature "srcpkg" |
1785 | then | ||
1786 | niro | 1618 | run_resume srcpkgbuild || source_pkg_build ${SMAGENAME} |
1787 | niro | 1617 | resume_stamp srcpkgbuild |
1788 | fi | ||
1789 | niro | 1584 | fi |
1790 | niro | 24 | |
1791 | niro | 1584 | if mqueryfeature "buildlog" |
1792 | niro | 875 | then |
1793 | bzip2 -9f /var/log/smage/${PKGNAME}.log | ||
1794 | else | ||
1795 | [[ -f /var/log/smage/${PKGNAME}.log ]] && rm /var/log/smage/${PKGNAME}.log | ||
1796 | fi | ||
1797 | |||
1798 | niro | 24 | xtitleclean |
Properties
Name | Value |
---|---|
svn:executable | * |