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