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