Contents of /trunk/mage/usr/lib/mage/smage2.functions.sh
Parent Directory | Revision Log
Revision 1640 -
(show annotations)
(download)
(as text)
Fri Jan 13 18:29:52 2012 UTC (12 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 27241 byte(s)
Fri Jan 13 18:29:52 2012 UTC (12 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 27241 byte(s)
-split of smage2-functions into an extra include
1 | #!/bin/bash |
2 | # smage2 releated functions |
3 | # $Id$ |
4 | |
5 | # sources the smage file and uses state from distribution file if exist |
6 | # may helpful for repository support later on |
7 | smagesource() |
8 | { |
9 | local file="$1" |
10 | local mystate |
11 | local mycodename |
12 | |
13 | source ${file} |
14 | |
15 | [[ -n ${STATE} ]] && mystate="${STATE}" |
16 | |
17 | # do not overide if local state was broken or disabled! |
18 | case ${STATE} in |
19 | broken) return ;; |
20 | disabled) return ;; |
21 | esac |
22 | |
23 | if [ -f ${SMAGESCRIPTSDIR}/distribution ] |
24 | then |
25 | source ${SMAGESCRIPTSDIR}/distribution |
26 | [[ -n ${STATE} ]] && mystate="${STATE}" |
27 | fi |
28 | # now switch state and export it |
29 | STATE="${mystate}" |
30 | } |
31 | |
32 | showversion() |
33 | { |
34 | echo -en "Magellan Source Install v${SMAGEVERSION} " |
35 | echo -e "-- Niels Rogalla (niro@magellan-linux.de)" |
36 | } |
37 | |
38 | die() |
39 | { |
40 | xtitleclean |
41 | echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT} |
42 | echo "SMAGE failed: $@" |
43 | exit 1 |
44 | } |
45 | |
46 | die_pipestatus() |
47 | { |
48 | # the status change if we do any parameter declarations!! |
49 | # dont do this anymore, keep this in mind! |
50 | # |
51 | # local pos="$1" |
52 | # local comment="$2" |
53 | # |
54 | # [ ${PIPESTATUS[${pos}]} -ne 0 ] && die "${comment}" |
55 | # |
56 | [ ${PIPESTATUS[$1]} -ne 0 ] && die "$2" |
57 | } |
58 | |
59 | xtitle() |
60 | { |
61 | if [[ ${TERM} = xterm ]] |
62 | then |
63 | echo -ne "\033]0;[sMage: $@]\007" |
64 | fi |
65 | return 0 |
66 | } |
67 | |
68 | xtitleclean() |
69 | { |
70 | if [[ ${TERM} = xterm ]] |
71 | then |
72 | echo -ne "\033]0;\007" |
73 | fi |
74 | return 0 |
75 | } |
76 | |
77 | syncsmage2() |
78 | { |
79 | xtitle "Updating smage2-script tree ..." |
80 | local i |
81 | for i in ${SMAGE2RSYNC} |
82 | do |
83 | rsync ${RSYNC_FETCH_OPTIONS} ${i} ${SMAGESCRIPTSDIR} |
84 | if [[ $? = 0 ]] |
85 | then |
86 | break |
87 | else |
88 | continue |
89 | fi |
90 | done |
91 | |
92 | # clean up backup files (foo~) |
93 | find ${SMAGESCRIPTSDIR} -name *~ -exec rm '{}' ';' |
94 | |
95 | xtitleclean |
96 | } |
97 | |
98 | # $1 filename |
99 | get_db_md5_sum() |
100 | { |
101 | local DB_FILE |
102 | local MD5_FILE |
103 | local i |
104 | |
105 | DB_ENTRY="$(basename $1)" |
106 | MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} ${SMAGESUFFIX})" |
107 | |
108 | i="$(cat ${MD5_FILE}| grep ${DB_ENTRY} | cut -d' ' -f1)" |
109 | |
110 | echo "${i}" |
111 | } |
112 | |
113 | download_sources() |
114 | { |
115 | [ -z "${SRC_URI}" ] && echo -e "\nNothing declared to download.\n" && return 0 |
116 | |
117 | local count=${#SRC_URI[*]} |
118 | local uri |
119 | local subdir |
120 | local outputdir |
121 | local db_md5_file="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5" |
122 | local fetching |
123 | local i |
124 | |
125 | # check if FETCHING is needed |
126 | if mchecksum --rundir "${SOURCEDIR}/${PNAME}" --file "${db_md5_file}" --method md5 |
127 | then |
128 | # md5's ok, no fetching needed |
129 | fetching=false |
130 | else |
131 | fetching=true |
132 | fi |
133 | |
134 | if [[ ${fetching} = true ]] |
135 | then |
136 | for ((i=0; i < count; i++)) |
137 | do |
138 | # url to file |
139 | uri="${SRC_URI[${i}]%%' '*}" |
140 | |
141 | # subdir in sources dir; the my_SRCI_URI file goes to there |
142 | subdir="${SRC_URI[${i}]##*' '}" |
143 | |
144 | # if $subdir is not equal with $uri then an other dir is used |
145 | if [[ ${uri} != ${subdir} ]] |
146 | then |
147 | outputdir="${SOURCEDIR}/${PNAME}/${subdir}" |
148 | else |
149 | outputdir="${SOURCEDIR}/${PNAME}" |
150 | fi |
151 | |
152 | echo -e "${COLBLUE}==>${COLGREEN} fetching ${uri}${COLDEFAULT}" |
153 | # always use verbose mode for source downloads |
154 | FVERBOSE=off msetfeature "verbose" |
155 | # do not die here, mchecksum catches download errors |
156 | mdownload --uri "${uri}" --dir "${outputdir}" |
157 | |
158 | # unset them to be sure |
159 | unset uri |
160 | unset subdir |
161 | unset outputdir |
162 | done |
163 | |
164 | # recheck md5 sums after download |
165 | echo |
166 | echo -e "${COLBLUE}===${COLGREEN} Checking MD5 sums:${COLDEFAULT}" |
167 | mchecksum --rundir "${SOURCEDIR}/${PNAME}" --file "${db_md5_file}" --method md5 || die "md5 failed" |
168 | echo |
169 | else |
170 | echo -e "${COLBLUE}===${COLGREEN} All sources already fetched, nothing to do${COLDEFAULT}" |
171 | fi |
172 | |
173 | # not needed anymore |
174 | unset SRC_URI |
175 | } |
176 | |
177 | # dummy function, used if that does not exist in smage file |
178 | src_prepare() |
179 | { |
180 | echo "no src_prepare defined; doing nothing ..." |
181 | return 0 |
182 | } |
183 | |
184 | # dummy function, used if that does not exist in smage file |
185 | src_compile() |
186 | { |
187 | echo "no src_compile defined; doing nothing ..." |
188 | return 0 |
189 | } |
190 | |
191 | # dummy function, used if that does not exist in smage file |
192 | src_check() |
193 | { |
194 | echo "no src_check defined; doing nothing ..." |
195 | return 0 |
196 | } |
197 | |
198 | # dummy function, used if that does not exist in smage file |
199 | src_install() |
200 | { |
201 | echo "no src_install defined; doing nothing ..." |
202 | return 0 |
203 | } |
204 | |
205 | mlibdir() |
206 | { |
207 | local libdir=lib |
208 | [[ ${ARCH} = x86_64 ]] && libdir=lib64 |
209 | |
210 | echo "${libdir}" |
211 | } |
212 | |
213 | mconfigure() |
214 | { |
215 | local myopts |
216 | if [[ ! -z ${CTARGET} ]] |
217 | then |
218 | myopts+=" --target=${CTARGET}" |
219 | fi |
220 | |
221 | if [ -x ./configure ] |
222 | then |
223 | # if requested disable-static |
224 | if [[ ! -z $(./configure --help | grep -- '--.*able-static') ]] |
225 | then |
226 | if mqueryfeature '!static' |
227 | then |
228 | myopts+=" --disable-static" |
229 | else |
230 | myopts+=" --enable-static" |
231 | fi |
232 | fi |
233 | |
234 | # always enable shared by default |
235 | if [[ ! -z $(./configure --help | grep -- '--.*able-shared') ]] |
236 | then |
237 | myopts+=" --enable-shared" |
238 | fi |
239 | |
240 | ./configure \ |
241 | --prefix=/usr \ |
242 | --host=${CHOST} \ |
243 | --build=${CHOST} \ |
244 | --mandir=/usr/share/man \ |
245 | --infodir=/usr/share/info \ |
246 | --datadir=/usr/share \ |
247 | --sysconfdir=/etc \ |
248 | --localstatedir=/var/lib \ |
249 | --libdir=/usr/$(mlibdir) \ |
250 | ${myopts} \ |
251 | "$@" || die "mconfigure failed" |
252 | else |
253 | echo "configure is not an executable ..." |
254 | exit 1 |
255 | fi |
256 | } |
257 | |
258 | minstall() |
259 | { |
260 | if [ -f ./[mM]akefile -o -f ./GNUmakefile ] |
261 | then |
262 | make prefix=${BINDIR}/usr \ |
263 | datadir=${BINDIR}/usr/share \ |
264 | infodir=${BINDIR}/usr/share/info \ |
265 | localstatedir=${BINDIR}/var/lib \ |
266 | mandir=${BINDIR}/usr/share/man \ |
267 | sysconfdir=${BINDIR}/etc \ |
268 | libdir=${BINDIR}/usr/$(mlibdir) \ |
269 | "$@" install || die "minstall failed" |
270 | else |
271 | die "no Makefile found" |
272 | fi |
273 | } |
274 | |
275 | mmake() |
276 | { |
277 | make ${MAKEOPTS} ${EXTRA_EMAKE} "$@" |
278 | } |
279 | |
280 | munpack() |
281 | { |
282 | local SRCFILE |
283 | local IFTAR |
284 | local DEST |
285 | |
286 | SRCFILE=$1 |
287 | |
288 | if [[ -z $2 ]] |
289 | then |
290 | DEST=${BUILDDIR} |
291 | else |
292 | DEST=$2 |
293 | fi |
294 | |
295 | [[ ! -d ${DEST} ]] && install -d ${DEST} |
296 | |
297 | case "${SRCFILE##*.}" in |
298 | bz2) |
299 | IFTAR="$(basename $SRCFILE .bz2)" |
300 | IFTAR="${IFTAR##*.}" |
301 | if [[ ${IFTAR} = tar ]] |
302 | then |
303 | tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tar.bz2 unpack failed." |
304 | else |
305 | pushd ${DEST} > /dev/null |
306 | bzcat ${SOURCEDIR}/${PNAME}/${SRCFILE} > ${DEST}/$(basename ${SRCFILE} .bz2) || die ".bz2 unpack failed." |
307 | popd > /dev/null |
308 | fi |
309 | ;; |
310 | gz) |
311 | IFTAR="$(basename $SRCFILE .gz)" |
312 | IFTAR="${IFTAR##*.}" |
313 | if [[ ${IFTAR} = tar ]] |
314 | then |
315 | tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tar.gz unpack failed." |
316 | else |
317 | pushd ${DEST} > /dev/null |
318 | zcat ${SOURCEDIR}/${PNAME}/${SRCFILE} > ${DEST}/$(basename ${SRCFILE} .gz) || die ".gz unpack failed." |
319 | popd > /dev/null |
320 | fi |
321 | ;; |
322 | xz) |
323 | IFTAR="$(basename $SRCFILE .xz)" |
324 | IFTAR="${IFTAR##*.}" |
325 | if [[ ${IFTAR} = tar ]] |
326 | then |
327 | tar --no-same-owner -xvJf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tar.xz unpack failed." |
328 | else |
329 | pushd ${DEST} > /dev/null |
330 | xzcat ${SOURCEDIR}/${PNAME}/${SRCFILE} > ${DEST}/$(basename ${SRCFILE} .xz) || die ".xz unpack failed." |
331 | popd > /dev/null |
332 | fi |
333 | ;; |
334 | tbz2|mpks|mpk) |
335 | tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tbz2 unpack failed." |
336 | ;; |
337 | tgz) |
338 | tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tgz unpack failed." |
339 | ;; |
340 | txz|mpkzs|mpkz) |
341 | tar --no-same-owner -xvJf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".txz unpack failed." |
342 | ;; |
343 | rar) |
344 | unrar x ${SOURCEDIR}/${PNAME}/${SRCFILE} ${DEST} || die ".rar unpack failed." |
345 | ;; |
346 | zip|xpi|jar) |
347 | unzip ${SOURCEDIR}/${PNAME}/${SRCFILE} -d ${DEST} || die ".zip unpack failed." |
348 | ;; |
349 | rpm) |
350 | pushd ${DEST} > /dev/null |
351 | rpm2targz ${SOURCEDIR}/${PNAME}/${SRCFILE} || die "rpm2targz: .rpm unpack failed." |
352 | tar --no-same-owner -xvzf ${SRCFILE/.rpm/.tar.gz} || die "tar: .rpm unpack failed." |
353 | if [[ -f ${DEST}/${SRCFILE/.rpm/.tar.gz} ]] |
354 | then |
355 | rm ${DEST}/${SRCFILE/.rpm/.tar.gz} |
356 | fi |
357 | ;; |
358 | *) |
359 | die "munpack failed" |
360 | ;; |
361 | esac |
362 | } |
363 | |
364 | mpatch() |
365 | { |
366 | local PATCHOPTS |
367 | local PATCHFILE |
368 | local i |
369 | |
370 | PATCHOPTS=$1 |
371 | PATCHFILE=$2 |
372 | |
373 | if [[ -z $2 ]] |
374 | then |
375 | PATCHFILE=$1 |
376 | |
377 | ## patch level auto-detection, get patch level |
378 | for ((i=0; i < 10; i++)) |
379 | do |
380 | patch --dry-run -Np${i} -i ${SOURCEDIR}/${PNAME}/${PATCHFILE} > /dev/null |
381 | if [[ $? = 0 ]] |
382 | then |
383 | PATCHOPTS="-Np${i}" |
384 | break |
385 | fi |
386 | done |
387 | fi |
388 | |
389 | echo -e "${COLBLUE}*** ${COLGREEN}Applying patch '${PATCHFILE}'${COLDEFAULT}" |
390 | patch "${PATCHOPTS}" -i ${SOURCEDIR}/${PNAME}/${PATCHFILE} |
391 | } |
392 | |
393 | mlibtoolize() |
394 | { |
395 | local opts="$@" |
396 | [[ -z ${opts} ]] && opts="--verbose --install --force" |
397 | |
398 | libtoolize ${opts} || die "running: mlibtoolize ${opts}" |
399 | } |
400 | |
401 | mautoreconf() |
402 | { |
403 | local opts="$@" |
404 | [[ -z ${opts} ]] && opts="--verbose --install --force" |
405 | |
406 | autoreconf ${opts} || die "running: mautoreconf ${opts}" |
407 | } |
408 | |
409 | minstalldocs() |
410 | { |
411 | local docfiles |
412 | local doc |
413 | docfiles="$@" |
414 | |
415 | if [ ! -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} ] |
416 | then |
417 | install -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "creating doc dirs." |
418 | fi |
419 | |
420 | for doc in ${docfiles} |
421 | do |
422 | if [ -f ${doc} ] |
423 | then |
424 | if mqueryfeature "compressdoc" |
425 | then |
426 | cat ${doc} | gzip -9c > ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/$(basename ${doc}).gz || die "gzipping +installing ${doc}." |
427 | chmod 0644 ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/$(basename ${doc}).gz || die "fixing permissions of ${doc}." |
428 | else |
429 | install -m 0644 ${doc} ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "installing ${doc}." |
430 | fi |
431 | fi |
432 | done |
433 | } |
434 | |
435 | mstriplibs() |
436 | { |
437 | local stripdir="$@" |
438 | |
439 | [[ -z ${stripdir} ]] && stripdir="${BINDIR}" |
440 | [[ -z ${STRIP_DYN_LIB} ]] && STRIP_DYN_LIB="--strip-debug" |
441 | find ${stripdir} ! -type d | xargs --no-run-if-empty file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_DYN_LIB} 2> /dev/null |
442 | } |
443 | |
444 | mstripbins() |
445 | { |
446 | local stripdir="$@" |
447 | |
448 | [[ -z ${stripdir} ]] && stripdir="${BINDIR}" |
449 | [[ -z ${STRIP_DYN_BIN} ]] && STRIP_DYN_BIN="--strip-debug" |
450 | find ${stripdir} ! -type d | xargs --no-run-if-empty file | grep "executable" | grep ELF | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_DYN_BIN} 2> /dev/null |
451 | } |
452 | |
453 | mstripstatic() |
454 | { |
455 | local stripdir="$@" |
456 | |
457 | [[ -z ${stripdir} ]] && stripdir="${BINDIR}" |
458 | [[ -z ${STRIP_STATIC_LIB} ]] && STRIP_STATIC_LIB="--strip-debug" |
459 | find ${stripdir} ! -type d | xargs --no-run-if-empty file | grep "ar archive" | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_STATIC_LIB} 2> /dev/null |
460 | } |
461 | |
462 | mstriplibtoolarchive() |
463 | { |
464 | local stripdir="$@" |
465 | |
466 | [[ -z ${stripdir} ]] && stripdir="${BINDIR}" |
467 | find ${stripdir} ! -type d -name \*.la | xargs --no-run-if-empty file | grep "libtool library" | cut -f 1 -d : | xargs --no-run-if-empty rm -f -- 2> /dev/null |
468 | } |
469 | |
470 | mpurgetargets() |
471 | { |
472 | local stripdir="$@" |
473 | local target |
474 | |
475 | [[ -z ${stripdir} ]] && stripdir=${BINDIR} |
476 | # nothing to do in this case |
477 | [[ -z ${PURGE_TARGETS[*]} ]] && return |
478 | |
479 | for target in ${PURGE_TARGETS[*]} |
480 | do |
481 | # check if target is a regex pattern without any slashes |
482 | if [[ ${target} = ${target//\/} ]] |
483 | then |
484 | find ${BINDIR} -type f -name "${target}" | xargs --no-run-if-empty rm -f -- 2> /dev/null |
485 | else |
486 | rm -f -- ${target} 2> /dev/null |
487 | fi |
488 | done |
489 | } |
490 | |
491 | mcompressdocs() |
492 | { |
493 | local bindir="$@" |
494 | |
495 | if [ -d ${bindir}/usr/share/man ] |
496 | then |
497 | echo -e "${COLBLUE}===${COLGREEN} compressing man-pages ...${COLDEFAULT}" |
498 | ${MLIBDIR}/compressdoc -g -9 ${bindir}/usr/share/man |
499 | fi |
500 | |
501 | if [ -d ${bindir}/usr/share/info ] |
502 | then |
503 | echo -e "${COLBLUE}===${COLGREEN} compressing info-pages ...${COLDEFAULT}" |
504 | ${MLIBDIR}/compressdoc -g -9 ${bindir}/usr/share/info |
505 | fi |
506 | } |
507 | |
508 | sminclude() |
509 | { |
510 | local i |
511 | |
512 | if [[ -n "$@" ]] |
513 | then |
514 | for i in $@ |
515 | do |
516 | echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc" |
517 | source ${SMAGESCRIPTSDIR}/include/${i}.sminc |
518 | done |
519 | echo |
520 | fi |
521 | } |
522 | |
523 | setup_distcc_environment() |
524 | { |
525 | if [ -x /usr/bin/distcc ] |
526 | then |
527 | echo -e "${COLBLUE}---${COLGREEN} Using DistCC for compilation ...${COLDEFAULT}" |
528 | export PATH=/usr/$(mlibdir)/distcc/bin:${PATH} || die "distcc: could not export new $PATH" |
529 | |
530 | export DISTCC_DIR="${DISTCC_DIR}" || die "distcc_dir export failed" |
531 | |
532 | # creating distcc tempdir |
533 | install -o distcc -g daemon -d ${DISTCC_DIR} |
534 | chmod 1777 ${DISTCC_DIR} |
535 | fi |
536 | } |
537 | |
538 | setup_ccache_environment() |
539 | { |
540 | if [ -x /usr/bin/ccache ] |
541 | then |
542 | echo -e "${COLBLUE}---${COLGREEN} Using CCache for compilation ...${COLDEFAULT}" |
543 | export PATH=/usr/$(mlibdir)/ccache/bin:${PATH} || die "ccache: could not export new $PATH" |
544 | fi |
545 | } |
546 | |
547 | # fixes given dependencies to match a MAGE_TARGET |
548 | # fix_mage_deps -target s/depend # <-- note -target ! |
549 | fix_mage_deps() |
550 | { |
551 | local target="$1" |
552 | local depend="$2" |
553 | local NDEPEND |
554 | local sym dep cat pver pname |
555 | |
556 | # deps and provides are special |
557 | # they must be fixed to match the target |
558 | |
559 | # run this only if target and depend is not empty |
560 | if [ -n "${target}" ] && [ -n "${depend}" ] |
561 | then |
562 | # fix DEPEND |
563 | while read sym dep |
564 | do |
565 | # ignore empty lines |
566 | [[ -z ${dep} ]] && continue |
567 | |
568 | cat="$(dirname ${dep})" |
569 | # change if not virtual |
570 | if [[ ${cat} = virtual ]] |
571 | then |
572 | pname="$(basename ${dep})" |
573 | else |
574 | # fix pver to target-pver |
575 | # to get pname-target-pver |
576 | |
577 | # doing it backwards ! |
578 | pver="${dep##*-}" |
579 | # full pver |
580 | pname="$(basename ${dep/-${pver}/})${target}-${pver}" |
581 | fi |
582 | |
583 | # do not add empty lines |
584 | if [ -z "${NDEPEND}" ] |
585 | then |
586 | NDEPEND="${sym} ${cat}/${pname}" |
587 | else |
588 | NDEPEND="${NDEPEND} |
589 | ${sym} ${cat}/${pname}" |
590 | fi |
591 | |
592 | unset cat pname pver |
593 | done << EOF |
594 | ${depend} |
595 | EOF |
596 | # set NDEPEND to DEPEND |
597 | depend="${NDEPEND}" |
598 | fi |
599 | |
600 | echo "${depend}" |
601 | } |
602 | |
603 | # build_mage_script(): helper functions for regen_mage_tree() |
604 | # generates an mage file with given information in smage file |
605 | # needs at least: |
606 | # PNAME name of pkg |
607 | # PVER version |
608 | # PBUILD revision |
609 | # PCATEGORIE category of the pkg |
610 | # STATE state of pkg stable|unstable|old |
611 | # DESCRIPTION a short description (opt) |
612 | # HOMEPAGE homepage (opt) |
613 | # DEPEND runtime dependencies (opt) |
614 | # SDEPEND adds needed deps to build the pkg (opt) |
615 | # PROVIDE provides a virtual (opt) |
616 | # |
617 | # special tags: |
618 | # PKGTYPE type of pkg |
619 | # INHERITS which functions get included |
620 | # SPECIAL_FUNCTIONS special functions which should also be added |
621 | # warning: they get killed before the build starts ! |
622 | # SPLIT_PACKAGES names of all subpackages which are splitted from parent |
623 | # SPLIT_PACKAGE_BASE base package name for splitpackages |
624 | # (only in the resulting magefile} |
625 | # |
626 | # MAGE_TREE_DEST target destination of the generated tree |
627 | # REGEN_MAGE_TREE set to 'true' to enable this |
628 | # |
629 | # gets called with build_mage_script target |
630 | build_mage_script() |
631 | { |
632 | local magefile |
633 | local dest |
634 | local target |
635 | local split_pkg_base |
636 | local sym |
637 | local depname |
638 | |
639 | # if MAGE_TREE_DEST not set use BUILDDIR |
640 | : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree} |
641 | |
642 | # determinate which suffix this mage file should get, if any |
643 | [[ $1 = --target ]] && shift && target="-$1" |
644 | |
645 | # mark package as splitpackage |
646 | [[ $1 = --split-pkg-base ]] && shift && split_pkg_base="$1" |
647 | |
648 | # name of magefile |
649 | magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage" |
650 | |
651 | # destination to magefile |
652 | dest="${MAGE_TREE_DEST}/${PCATEGORIE}/${PNAME}${target}/${magefile}" |
653 | |
654 | # show what we are doing |
655 | echo -e "${COLBLUE}===${COLGREEN} generating mage file:${COLDEFAULT}" |
656 | echo "${dest}" |
657 | |
658 | install -d "$(dirname ${dest})" |
659 | # now build the mage file |
660 | > ${dest} |
661 | |
662 | # pgkname and state |
663 | echo "PKGNAME=\"${PNAME}${target}-${PVER}-\${ARCH}-${PBUILD}\"" >> ${dest} |
664 | echo "STATE=\"${STATE}\"" >> ${dest} |
665 | |
666 | # description and homepage |
667 | echo "DESCRIPTION=\"${DESCRIPTION}\"" >> ${dest} |
668 | echo "HOMEPAGE=\"${HOMEPAGE}\"" >> ${dest} |
669 | |
670 | # special tags and vars |
671 | echo "PKGTYPE=\"${PKGTYPE}\"" >> ${dest} |
672 | |
673 | # echo MAGE_TARGETS ## note -target is needed ! |
674 | echo "MAGE_TARGETS=\"${target}\"" >> ${dest} |
675 | |
676 | # split package base |
677 | echo "SPLIT_PACKAGE_BASE=\"${split_pkg_base}\"" >> ${dest} |
678 | |
679 | # add special vars |
680 | if [ -n "${SPECIAL_VARS}" ] |
681 | then |
682 | local i |
683 | for i in ${SPECIAL_VARS} |
684 | do |
685 | # being tricky here :) |
686 | echo "${i}=\"$(eval echo \$${i})\"" >> ${dest} |
687 | done |
688 | fi |
689 | |
690 | # add at least all includes |
691 | if [ -n "${INHERITS}" ] |
692 | then |
693 | echo -n "minclude" >> ${dest} |
694 | local i |
695 | for i in ${INHERITS} |
696 | do |
697 | echo -n " ${i}" >> ${dest} |
698 | done |
699 | # a CRLF is needed here! |
700 | echo >> ${dest} |
701 | fi |
702 | |
703 | # deps and provides |
704 | echo "DEPEND=\"$(fix_mage_deps "${target}" "${DEPEND}")\"" >> ${dest} |
705 | echo "SDEPEND=\"$(fix_mage_deps "${target}" "${SDEPEND}")\"" >> ${dest} |
706 | echo "PROVIDE=\"${PROVIDE}\"" >> ${dest} |
707 | |
708 | # add special functions |
709 | if [ -n "${SPECIAL_FUNCTIONS}" ] |
710 | then |
711 | local i |
712 | for i in ${SPECIAL_FUNCTIONS} |
713 | do |
714 | # add to mage (quotes needed !) |
715 | typeset -f "${i}" >> ${dest} |
716 | # unset to be safe (quotes needed !) |
717 | #unset "${i}" <-- later to get every target built |
718 | done |
719 | fi |
720 | |
721 | # pre|post-install|removes |
722 | typeset -f preinstall >> ${dest} |
723 | typeset -f postinstall >> ${dest} |
724 | typeset -f preremove >> ${dest} |
725 | typeset -f postremove >> ${dest} |
726 | } |
727 | |
728 | regen_mage_tree() |
729 | { |
730 | local subpackage |
731 | |
732 | # build them only if requested |
733 | if mqueryfeature regentree |
734 | then |
735 | # run it without targets |
736 | if [[ -n ${MAGE_TARGETS} ]] |
737 | then |
738 | # build for each target a mage file |
739 | # run it with several targets |
740 | echo |
741 | for subpackage in ${MAGE_TARGETS} |
742 | do |
743 | build_mage_script --target "${subpackage}" |
744 | done |
745 | echo |
746 | |
747 | # run it for splitpackages |
748 | elif [[ -n ${SPLIT_PACKAGES} ]] |
749 | then |
750 | local split_pkg_base="${PNAME}" |
751 | # save smage environment |
752 | split_save_variables |
753 | # build for each subpackage a mage file |
754 | # run it with several targets |
755 | echo |
756 | for subpackage in ${SPLIT_PACKAGES} |
757 | do |
758 | # get the right variables for the split |
759 | export PNAME="${subpackage}" |
760 | split_info_${subpackage} |
761 | # get the preinstall etc |
762 | split_export_inherits ${subpackage} |
763 | build_mage_script --split-pkg-base "${split_pkg_base}" |
764 | # delete split preinstall etc |
765 | split_delete_inherits ${subpackage} |
766 | # restore smage environment |
767 | split_restore_variables |
768 | done |
769 | echo |
770 | # unset all saved smage variables |
771 | split_unset_variables |
772 | |
773 | else |
774 | echo |
775 | build_mage_script |
776 | echo |
777 | fi |
778 | fi |
779 | |
780 | # now unset all uneeded vars to be safe |
781 | # unset PKGNAME <-- don't do that; smage needs this var |
782 | # unset to be safe (quotes needed !) |
783 | # for i in ${SPECIAL_FUNCTIONS} |
784 | # do |
785 | # unset "${i}" |
786 | # done |
787 | unset SPECIAL_FUNCTIONS |
788 | # for i in ${SPECIAL_VARS} |
789 | # do |
790 | # unset "${i}" |
791 | # done |
792 | unset SPECIAL_VARS |
793 | unset STATE |
794 | unset DESCRIPTION |
795 | unset HOMEPAGE |
796 | # unset PKGTYPE <-- don't do that either; smage needs this var |
797 | unset INHERITS |
798 | unset DEPEND |
799 | unset SDEPEND |
800 | unset PROVIDE |
801 | unset preinstall |
802 | unset postinstall |
803 | unset preremove |
804 | unset postremove |
805 | } |
806 | |
807 | split_save_variables() |
808 | { |
809 | export SAVED_PNAME="${PNAME}" |
810 | export SAVED_PVER="${PVER}" |
811 | export SAVED_PBUILD="${PBUILD}" |
812 | export SAVED_PCATEGORIE="${PCATEGORIE}" |
813 | export SAVED_DESCRIPTION="${DESCRIPTION}" |
814 | export SAVED_HOMEPAGE="${HOMEPAGE}" |
815 | export SAVED_SPECIAL_VARS="${SPECIAL_VARS}" |
816 | export SAVED_STATE="${STATE}" |
817 | export SAVED_PKGTYPE="${PKGTYPE}" |
818 | export SAVED_INHERITS="${INHERITS}" |
819 | export SAVED_DEPEND="${DEPEND}" |
820 | export SAVED_SDEPEND="${SDEPEND}" |
821 | export SAVED_PROVIDE="${PROVIDE}" |
822 | export SAVED_PKGTYPE="${PKGTYPE}" |
823 | |
824 | # special handling needed for mage features |
825 | # pkgbuild |
826 | mqueryfeature "pkgbuild" && export SAVED_FEATURE_PKGBUILD="pkgbuild" |
827 | mqueryfeature "!pkgbuild" && export SAVED_FEATURE_PKGBUILD="!pkgbuild" |
828 | # strip |
829 | mqueryfeature "strip" && export SAVED_FEATURE_STRIP="strip" |
830 | mqueryfeature "!strip" && export SAVED_FEATURE_STRIP="!strip" |
831 | # libtool |
832 | mqueryfeature "libtool" && export SAVED_FEATURE_LIBTOOL="libtool" |
833 | mqueryfeature "!libtool" && export SAVED_FEATURE_LIBTOOL="!libtool" |
834 | # compressdoc |
835 | mqueryfeature "compressdoc" && export SAVED_FEATURE_COMPRESSDOC="compressdoc" |
836 | mqueryfeature "!compressdoc" && export SAVED_FEATURE_COMPRESSDOC="!compressdoc" |
837 | |
838 | # bindir too |
839 | export SAVED_BINDIR="${BINDIR}" |
840 | |
841 | # export the SPLIT_PACKAGE_BASE |
842 | export SPLIT_PACKAGE_BASE="${SAVED_PNAME}" |
843 | |
844 | # functions |
845 | if [[ ! -z $(typeset -f preinstall) ]] |
846 | then |
847 | # rename the old one |
848 | local saved_preinstall |
849 | saved_preinstall=SAVED_$(typeset -f preinstall) |
850 | eval "${saved_preinstall}" |
851 | export -f SAVED_preinstall |
852 | fi |
853 | |
854 | if [[ ! -z $(typeset -f postinstall) ]] |
855 | then |
856 | # rename the old one |
857 | local saved_postinstall |
858 | saved_postinstall=SAVED_$(typeset -f postinstall) |
859 | eval "${saved_postinstall}" |
860 | export -f SAVED_postinstall |
861 | fi |
862 | |
863 | if [[ ! -z $(typeset -f preremove) ]] |
864 | then |
865 | # rename the old one |
866 | local saved_preremove |
867 | saved_preremove=SAVED_$(typeset -f preremove) |
868 | eval "${saved_preremove}" |
869 | export -f SAVED_preremove |
870 | fi |
871 | |
872 | if [[ ! -z $(typeset -f postremove) ]] |
873 | then |
874 | # rename the old one |
875 | local saved_postremove |
876 | saved_postremove=SAVED_$(typeset -f postremove) |
877 | eval "${saved_postremove}" |
878 | export -f SAVED_postremove |
879 | fi |
880 | } |
881 | |
882 | split_restore_variables() |
883 | { |
884 | export PNAME="${SAVED_PNAME}" |
885 | export PVER="${SAVED_PVER}" |
886 | export PBUILD="${SAVED_PBUILD}" |
887 | export PCATEGORIE="${SAVED_PCATEGORIE}" |
888 | export DESCRIPTION="${SAVED_DESCRIPTION}" |
889 | export HOMEPAGE="${SAVED_HOMEPAGE}" |
890 | export SPECIAL_VARS="${SAVED_SPECIAL_VARS}" |
891 | export STATE="${SAVED_STATE}" |
892 | export PKGTYPE="${SAVED_PKGTYPE}" |
893 | export INHERITS="${SAVED_INHERITS}" |
894 | export DEPEND="${SAVED_DEPEND}" |
895 | export SDEPEND="${SAVED_SDEPEND}" |
896 | export PROVIDE="${SAVED_PROVIDE}" |
897 | export PKGTYPE="${SAVED_PKGTYPE}" |
898 | |
899 | # special handling needed for mage features |
900 | # pkgbuild |
901 | FVERBOSE=off msetfeature "${SAVED_FEATURE_PKGBUILD}" |
902 | # strip |
903 | FVERBOSE=off msetfeature "${SAVED_FEATURE_STRIP}" |
904 | # libtool |
905 | FVERBOSE=off msetfeature "${SAVED_FEATURE_LIBTOOL}" |
906 | # compressdoc |
907 | FVERBOSE=off msetfeature "${SAVED_FEATURE_COMPRESSDOC}" |
908 | |
909 | # bindir too |
910 | export BINDIR="${SAVED_BINDIR}" |
911 | |
912 | # functions |
913 | if [[ ! -z $(typeset -f SAVED_preinstall) ]] |
914 | then |
915 | # rename the old one |
916 | local saved_preinstall |
917 | saved_preinstall=$(typeset -f SAVED_preinstall) |
918 | eval "${saved_preinstall/SAVED_/}" |
919 | export -f preinstall |
920 | fi |
921 | |
922 | if [[ ! -z $(typeset -f SAVED_postinstall) ]] |
923 | then |
924 | # rename the old one |
925 | local saved_postinstall |
926 | saved_postinstall=$(typeset -f SAVED_postinstall) |
927 | eval "${saved_postinstall/SAVED_/}" |
928 | export -f postinstall |
929 | fi |
930 | |
931 | if [[ ! -z $(typeset -f SAVED_preremove) ]] |
932 | then |
933 | # rename the old one |
934 | local saved_preremove |
935 | saved_preremove=$(typeset -f SAVED_preremove) |
936 | eval "${saved_preremove/SAVED_/}" |
937 | export -f preremove |
938 | fi |
939 | |
940 | if [[ ! -z $(typeset -f SAVED_postremove) ]] |
941 | then |
942 | # rename the old one |
943 | local saved_postremove |
944 | saved_postremove=$(typeset -f SAVED_postremove) |
945 | eval "${saved_postremove/SAVED_/}" |
946 | export -f postremove |
947 | fi |
948 | } |
949 | |
950 | split_unset_variables() |
951 | { |
952 | # unset saved vars; not needed anymore |
953 | unset SAVED_PNAME |
954 | unset SAVED_PVER |
955 | unset SAVED_PBUILD |
956 | unset SAVED_PCATEGORIE |
957 | unset SAVED_DESCRIPTION |
958 | unset SAVED_HOMEPAGE |
959 | unset SAVED_SPECIAL_VARS |
960 | unset SAVED_STATE |
961 | unset SAVED_PKGTYPE |
962 | unset SAVED_INHERITS |
963 | unset SAVED_DEPEND |
964 | unset SAVED_SDEPEND |
965 | unset SAVED_PROVIDE |
966 | unset SAVED_BINDIR |
967 | unset SAVED_PKGTYPE |
968 | unset SAVED_FEATURE_PKGBUILD |
969 | unset SAVED_FEATURE_STRIP |
970 | unset SAVED_FEATURE_LIBTOOL |
971 | unset SAVED_FEATURE_COMPRESSDOC |
972 | unset SPLIT_PACKAGE_BASE |
973 | unset -f SAVED_preinstall |
974 | unset -f SAVED_postinstall |
975 | unset -f SAVED_preremove |
976 | unset -f SAVED_postremove |
977 | } |
978 | |
979 | split_export_inherits() |
980 | { |
981 | local subpackage="$1" |
982 | local func |
983 | local newfunc |
984 | |
985 | for func in preinstall postinstall preremove postremove |
986 | do |
987 | if [[ ! -z $(typeset -f ${func}_${subpackage}) ]] |
988 | then |
989 | newfunc=$(typeset -f ${func}_${subpackage}) |
990 | newfunc="${newfunc/_${subpackage} (/ (}" |
991 | eval "${newfunc}" |
992 | fi |
993 | done |
994 | } |
995 | |
996 | split_delete_inherits() |
997 | { |
998 | local subpackage="$1" |
999 | local func |
1000 | |
1001 | for func in preinstall postinstall preremove postremove |
1002 | do |
1003 | if [[ ! -z $(typeset -f ${func}_${subpackage}) ]] |
1004 | then |
1005 | unset -f ${func} |
1006 | fi |
1007 | done |
1008 | } |
1009 | |
1010 | export_inherits() |
1011 | { |
1012 | local include="$1" |
1013 | shift |
1014 | |
1015 | while [ "$1" ] |
1016 | do |
1017 | local functions="$1" |
1018 | |
1019 | # sanity checks |
1020 | [ -z "${include}" ] && die "export_inherits(): \$include not given." |
1021 | [ -z "${functions}" ] && die "export_inherits(): \$functions not given." |
1022 | |
1023 | eval "${functions}() { ${include}_${functions} ; }" |
1024 | |
1025 | # debug |
1026 | [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}" |
1027 | |
1028 | shift |
1029 | done |
1030 | } |
1031 | |
1032 | generate_package_md5sum() |
1033 | { |
1034 | local dest |
1035 | local pcat |
1036 | local pname |
1037 | local pver |
1038 | local pbuild |
1039 | local parch |
1040 | local target |
1041 | local pkgname |
1042 | |
1043 | # very basic getops |
1044 | for i in $* |
1045 | do |
1046 | case $1 in |
1047 | --pcat|-c) shift; pcat="$1" ;; |
1048 | --pname|-n) shift; pname="$1" ;; |
1049 | --pver|-v) shift; pver="$1" ;; |
1050 | --pbuild|-b) shift; pbuild="$1" ;; |
1051 | --parch|a) shift; parch="$1" ;; |
1052 | --target|t) shift; target="$1" ;; |
1053 | esac |
1054 | shift |
1055 | done |
1056 | |
1057 | # sanity checks; abort if not given |
1058 | [ -z "${pcat}" ] && die "generate_package_md5sum() \$pcat not given." |
1059 | [ -z "${pname}" ] && die "generate_package_md5sum() \$pname not given." |
1060 | [ -z "${pver}" ] && die "generate_package_md5sum() \$pver not given." |
1061 | [ -z "${pbuild}" ] && die "generate_package_md5sum() \$pbuild not given." |
1062 | [ -z "${parch}" ] && die "generate_package_md5sum() \$parch not given." |
1063 | |
1064 | # check needed global vars |
1065 | [ -z "${PKGDIR}" ] && die "generate_package_md5sum() \$PKGDIR not set." |
1066 | [ -z "${PKGSUFFIX}" ] && die "generate_package_md5sum() \$PKGSUFFIX not set." |
1067 | |
1068 | # fix target as it may be empty ! |
1069 | [ -n "${target}" ] && target="-${target}" |
1070 | |
1071 | # build pkgname |
1072 | pkgname="${pname}${target}-${pver}-${parch}-${pbuild}" |
1073 | |
1074 | # build pkg-md5-sum only if requested |
1075 | if mqueryfeature regentree |
1076 | then |
1077 | echo -ne "${COLBLUE}===${COLGREEN} generating md5's for ${pkgname}.${PKGSUFFIX} ... ${COLDEFAULT}" |
1078 | |
1079 | # abort if not exist |
1080 | if [ ! -f ${PKGDIR}/${pkgname}.${PKGSUFFIX} ] |
1081 | then |
1082 | echo -e "${COLRED}! exists${COLDEFAULT}" |
1083 | return 0 |
1084 | fi |
1085 | |
1086 | # if MAGE_TREE_DEST not set use BUILDDIR |
1087 | : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree} |
1088 | |
1089 | # setup md5 dir |
1090 | dest="${MAGE_TREE_DEST}/${pcat}/${pname}${target}/md5" |
1091 | install -d ${dest} |
1092 | |
1093 | # gen md5sum |
1094 | ( cd ${PKGDIR}; md5sum "${pkgname}.${PKGSUFFIX}" ) \ |
1095 | > ${dest}/${pkgname}.md5 |
1096 | echo -e "${COLGREEN}done${COLDEFAULT}" |
1097 | fi |
1098 | } |
1099 | |
1100 | source_pkg_build() |
1101 | { |
1102 | if [[ ${PKGTYPE} = virtual ]] |
1103 | then |
1104 | echo "Virtual package detected; src-pkg-tarball not necessary ..." |
1105 | return 0 |
1106 | fi |
1107 | |
1108 | if [[ ! -d ${SOURCEDIR}/${PNAME} ]] |
1109 | then |
1110 | echo "No SRC_URI defined; src-pkg-tarball not necessary ..." |
1111 | return 0 |
1112 | fi |
1113 | |
1114 | [ -z "${SRCPKGDIR}" ] && die "\$SRCPKGDIR not found. Please setup your ${MAGERC} correctly." |
1115 | |
1116 | echo -e "${COLGREEN}Creating source package tarball ... ${COLDEFAULT}" |
1117 | |
1118 | # include the smage2 file |
1119 | cp ${SMAGENAME} ${SOURCEDIR}/${PNAME} |
1120 | |
1121 | ( cd ${SOURCEDIR}; tar cvjf ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${PNAME}; ) |
1122 | [[ ! -d ${SRCPKGDIR} ]] && install -d ${SRCPKGDIR} |
1123 | mv ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${SRCPKGDIR}/${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX} |
1124 | |
1125 | echo -e "${COLGREEN}Source package ${COLBLUE}${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX} ${COLGREEN}successfully builded.${COLDEFAULT}" |
1126 | } |
1127 | |
1128 | step_by_step() |
1129 | { |
1130 | if mqueryfeature stepbystep |
1131 | then |
1132 | echo -e "${COLRED}Step-by-step enabled! Paused after $1.${COLDEFAULT}" |
1133 | echo "Press [enter] to continue" |
1134 | read |
1135 | fi |
1136 | } |
1137 | |
1138 | resume_stamp() |
1139 | { |
1140 | local step="$1" |
1141 | [[ ! -d ${BUILDDIR}/.stamps ]] && install -d ${BUILDDIR}/.stamps |
1142 | touch ${BUILDDIR}/.stamps/smage-${PKGNAME}-${step} |
1143 | } |
1144 | |
1145 | run_resume() |
1146 | { |
1147 | local step="$1" |
1148 | |
1149 | if mqueryfeature "resume" && [[ -f ${BUILDDIR}/.stamps/smage-${PKGNAME}-${step} ]] |
1150 | then |
1151 | echo -e "${COLMAGENTA}${step} already processed; doing nothing${COLDEFAULT}" |
1152 | return 0 |
1153 | else |
1154 | return 1 |
1155 | fi |
1156 | } |