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