Contents of /trunk/mage/usr/lib/mage/smage2.sh
Parent Directory | Revision Log
Revision 192 -
(show annotations)
(download)
(as text)
Fri Aug 19 03:43:56 2005 UTC (19 years, 1 month ago) by niro
File MIME type: application/x-sh
File size: 18810 byte(s)
Fri Aug 19 03:43:56 2005 UTC (19 years, 1 month ago) by niro
File MIME type: application/x-sh
File size: 18810 byte(s)
- fixed whitespaces - do not unset PKGNAME in regen_mage_tree - renamed helper function to build_mage_srcipt - added MAGE_TARGETS support for pkgbuild
1 | #!/bin/bash |
2 | |
3 | # compiles/installs .smage2 source install scripts |
4 | # needs pkgbuild_dir (mage) |
5 | |
6 | # SMAGE2 |
7 | # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.23 2005-08-19 03:43:56 niro Exp $ |
8 | |
9 | #01.10.2004 |
10 | # added ccache support |
11 | # added distcc support |
12 | |
13 | ## setup ## |
14 | PKGSUFFIX="mpk" |
15 | SMAGENAME="$1" |
16 | SMAGESUFFIX="smage2" |
17 | #SOURCEDIR="/bootstrap/sources" |
18 | #SMAGESCRIPTSDIR="/bootstrap/smage2-install-scripts" |
19 | #SMAGE2RSYNC="rsync://192.168.0.2/smage2-scripts" |
20 | MLIBDIR=/usr/lib/mage |
21 | SMAGEVERSION="$( < ${MLIBDIR}/version)" |
22 | |
23 | # export default C locale |
24 | export LC_ALL=C |
25 | |
26 | source /etc/mage.rc |
27 | |
28 | showversion() { |
29 | echo -en "Magellan Source Install v${SMAGEVERSION} " |
30 | echo -e "-- Niels Rogalla (niro@magellan-linux.de)" |
31 | } |
32 | |
33 | die() { |
34 | xtitleclean |
35 | echo "SMAGE failed: $@" |
36 | exit 1 |
37 | } |
38 | |
39 | xtitle() { |
40 | if [ ${TERM} == "xterm" ] |
41 | then |
42 | echo -ne "\033]0;[sMage: $@]\007" |
43 | fi |
44 | return 0 |
45 | } |
46 | |
47 | xtitleclean() { |
48 | if [ ${TERM} == "xterm" ] |
49 | then |
50 | echo -ne "\033]0;\007" |
51 | fi |
52 | return 0 |
53 | } |
54 | |
55 | syncsmage2() { |
56 | xtitle "Updating smage2-script tree ..." |
57 | local i |
58 | for i in ${SMAGE2RSYNC} |
59 | do |
60 | rsync \ |
61 | --recursive \ |
62 | --links \ |
63 | --perms \ |
64 | --times \ |
65 | --devices \ |
66 | --timeout=600 \ |
67 | --verbose \ |
68 | --compress \ |
69 | --progress \ |
70 | --stats \ |
71 | --delete \ |
72 | --delete-after \ |
73 | ${i} ${SMAGESCRIPTSDIR} |
74 | |
75 | if [ "$?" == "0" ] |
76 | then |
77 | break |
78 | else |
79 | continue |
80 | fi |
81 | |
82 | done |
83 | |
84 | #clean up backup files (foo~) |
85 | find ${SMAGESCRIPTSDIR} -name *~ -exec rm '{}' ';' |
86 | |
87 | xtitleclean |
88 | } |
89 | |
90 | # $1 filename |
91 | get_db_md5_sum() { |
92 | local DB_FILE |
93 | local MD5_FILE |
94 | local i |
95 | |
96 | DB_ENTRY="$(basename $1)" |
97 | MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} ${SMAGESUFFIX})" |
98 | |
99 | i="$(cat ${MD5_FILE}| grep ${DB_ENTRY} | cut -d' ' -f1)" |
100 | |
101 | echo "${i}" |
102 | } |
103 | |
104 | download_sources() { |
105 | |
106 | [ -z "${SRC_URI}" ] && echo -e "\nNothing declared to download.\n" && return 0 |
107 | |
108 | local EOA=${#SRC_URI[*]} |
109 | local my_SRC_URI |
110 | local my_SRC_URI_DEST |
111 | local my_SRC_URI_MIRROR |
112 | local my_SOURCEDIR |
113 | local DB_MD5_SUM_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5" |
114 | local FETCHING |
115 | local i mirror |
116 | |
117 | |
118 | #install SRCDIR/PNAME if not exist |
119 | [ ! -d ${SOURCEDIR}/${PNAME} ] && install -d ${SOURCEDIR}/${PNAME} |
120 | |
121 | # check if FETCHING is needed |
122 | ( cd ${SOURCEDIR}/${PNAME}; md5sum --check ${DB_MD5_SUM_FILE} &> /dev/null ) |
123 | if [[ $? == 0 ]] |
124 | then |
125 | # md5's ok, not fetching needed |
126 | FETCHING=false |
127 | else |
128 | FETCHING=true |
129 | fi |
130 | |
131 | for ((i=0; i < EOA; i++)) |
132 | do |
133 | # url to file |
134 | my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)" |
135 | |
136 | # subdir in sources dir; the my_SRCI_URI file goes to there |
137 | my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)" |
138 | |
139 | # if my_src_uri_dest is not equal my_src_uri; than an other dir is used |
140 | if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]] |
141 | then |
142 | my_SOURCEDIR="${SOURCEDIR}/${PNAME}/${my_SRC_URI_DEST}" |
143 | else |
144 | my_SOURCEDIR="${SOURCEDIR}/${PNAME}" |
145 | fi |
146 | |
147 | # if an mirrored file than replace first the mirror uri |
148 | if [ -n "$(echo ${my_SRC_URI} | grep 'mirror://')" ] |
149 | then |
150 | for mirror in ${MIRRORS} |
151 | do |
152 | my_SRC_URI_MIRROR="$(echo ${my_SRC_URI} | sed "s|mirror:/|${mirror}/sources|g")" |
153 | |
154 | #echo "DEBUG: ${MY_SRC_URI}" |
155 | if [[ ${FETCHING} == true ]] |
156 | then |
157 | echo "==> fetching ${my_SRC_URI_MIRROR}" |
158 | wget \ |
159 | --passive-ftp \ |
160 | --tries 3 \ |
161 | --continue \ |
162 | --progress bar \ |
163 | --directory-prefix="${my_SOURCEDIR}" \ |
164 | "${my_SRC_URI_MIRROR}" |
165 | if [ "$?" == "0" ] |
166 | then |
167 | break |
168 | else |
169 | continue |
170 | fi |
171 | fi |
172 | done |
173 | else |
174 | #echo "DEBUG: ${SRC_URI[${i}]}" |
175 | if [[ ${FETCHING} == true ]] |
176 | then |
177 | echo "==> fetching ${my_SRC_URI}" |
178 | wget \ |
179 | --passive-ftp \ |
180 | --tries 3 \ |
181 | --continue \ |
182 | --progress bar \ |
183 | --directory-prefix="${my_SOURCEDIR}" \ |
184 | "${my_SRC_URI}" |
185 | # only needed to run through a list of mirrors |
186 | # if [ "$?" == "0" ] |
187 | # then |
188 | # break |
189 | # else |
190 | # continue |
191 | # fi |
192 | fi |
193 | fi |
194 | |
195 | # unset them to be shure |
196 | unset my_SRC_URI |
197 | unset my_SRC_URI_DEST |
198 | unset my_SRC_URI_MIRROR |
199 | unset my_SOURCEDIR |
200 | done |
201 | |
202 | # recheck md5 sums |
203 | echo |
204 | echo ">== Checking MD5 sums:" |
205 | ( cd ${SOURCEDIR}/${PNAME}; md5sum --check ${DB_MD5_SUM_FILE} ) || die "md5 failed" |
206 | echo |
207 | |
208 | # not needed anymore |
209 | unset SRC_URI |
210 | } |
211 | |
212 | # dummy function, used if that not exist in smage file |
213 | src_prepare() { |
214 | echo "no src_prepare defined" |
215 | sleep 2 |
216 | return 0 |
217 | } |
218 | |
219 | # dummy function, used if that not exist in smage file |
220 | src_compile() { |
221 | echo "no src_compile defined" |
222 | sleep 2 |
223 | return 0 |
224 | } |
225 | |
226 | # dummy function, used if that not exist in smage file |
227 | src_install() { |
228 | echo "no src_install defined" |
229 | sleep 2 |
230 | return 0 |
231 | } |
232 | |
233 | mconfigure() { |
234 | if [ -x ./configure ] |
235 | then |
236 | ./configure \ |
237 | --prefix=/usr \ |
238 | --host=${CHOST} \ |
239 | --mandir=/usr/share/man \ |
240 | --infodir=/usr/share/info \ |
241 | --datadir=/usr/share \ |
242 | --sysconfdir=/etc \ |
243 | --localstatedir=/var/lib \ |
244 | "$@" || die "mconfigure failed" |
245 | else |
246 | echo "configure is not an executable ..." |
247 | exit 1 |
248 | fi |
249 | } |
250 | |
251 | minstall() { |
252 | if [ -f ./[mM]akefile -o -f ./GNUmakefile ] ; then |
253 | make prefix=${BINDIR}/usr \ |
254 | datadir=${BINDIR}/usr/share \ |
255 | infodir=${BINDIR}/usr/share/info \ |
256 | localstatedir=${BINDIR}/var/lib \ |
257 | mandir=${BINDIR}/usr/share/man \ |
258 | sysconfdir=${BINDIR}/etc \ |
259 | "$@" install || die "minstall failed" |
260 | else |
261 | die "no Makefile found" |
262 | fi |
263 | } |
264 | |
265 | mmake() { |
266 | make ${MAKEOPTS} ${EXTRA_EMAKE} "$@" |
267 | } |
268 | |
269 | munpack() { |
270 | local SRCFILE |
271 | local IFTAR |
272 | local DEST |
273 | |
274 | SRCFILE=$1 |
275 | |
276 | if [ -z "$2" ] |
277 | then |
278 | DEST=${BUILDDIR} |
279 | else |
280 | DEST=$2 |
281 | fi |
282 | |
283 | case "${SRCFILE##*.}" in |
284 | bz2) |
285 | IFTAR="$(basename $SRCFILE .bz2)" |
286 | IFTAR="${IFTAR##*.}" |
287 | if [ "${IFTAR}" == "tar" ] |
288 | then |
289 | tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} |
290 | fi |
291 | ;; |
292 | gz) |
293 | IFTAR="$(basename $SRCFILE .gz)" |
294 | IFTAR="${IFTAR##*.}" |
295 | if [ "${IFTAR}" == "tar" ] |
296 | then |
297 | tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} |
298 | fi |
299 | ;; |
300 | tbz2) |
301 | tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} |
302 | ;; |
303 | tgz) |
304 | tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} |
305 | ;; |
306 | *) |
307 | die "munpack failed" |
308 | ;; |
309 | esac |
310 | } |
311 | |
312 | mpatch() { |
313 | local PATCHOPTS |
314 | local PATCHFILE |
315 | |
316 | PATCHOPTS=$1 |
317 | PATCHFILE=$2 |
318 | |
319 | patch "${PATCHOPTS}" -i ${SOURCEDIR}/${PNAME}/${PATCHFILE} |
320 | } |
321 | |
322 | |
323 | minstalldocs() { |
324 | local docfiles |
325 | |
326 | docfiles="$@" |
327 | |
328 | if [ ! -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} ] |
329 | then |
330 | install -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "creating doc dirs." |
331 | fi |
332 | |
333 | for i in ${docfiles} |
334 | do |
335 | cat ${i} | gzip -9c > ${i}.gz || die "gzipping docs." |
336 | install -m 0644 ${SRCDIR}/${i}.gz \ |
337 | ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "coping docs." |
338 | done |
339 | } |
340 | |
341 | mstriplibs() { |
342 | local stripdir="$@" |
343 | |
344 | [ -z "${stripdir}" ] && stripdir=${BINDIR} |
345 | find ${stripdir} | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null |
346 | } |
347 | |
348 | mstripbins() { |
349 | local stripdir="$@" |
350 | |
351 | [ -z "${stripdir}" ] && stripdir=${BINDIR} |
352 | find ${stripdir} | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null |
353 | } |
354 | |
355 | sminclude() { |
356 | local i |
357 | |
358 | if [[ -n "$@" ]] |
359 | then |
360 | for i in $@ |
361 | do |
362 | echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc" |
363 | source ${SMAGESCRIPTSDIR}/include/${i}.sminc |
364 | done |
365 | echo |
366 | fi |
367 | } |
368 | |
369 | setup_distcc_environment(){ |
370 | if [ -x /usr/bin/distcc ] |
371 | then |
372 | echo "Using DistCC for compilation ..." |
373 | export PATH=/usr/lib/distcc/bin:${PATH} || die "distcc: could not export new $PATH" |
374 | |
375 | #export distcc as compiler |
376 | # export CC="distcc" |
377 | # export CXX=distcc |
378 | |
379 | export DISTCC_DIR="${DISTCC_DIR}" || die "distcc_dir export failed" |
380 | |
381 | |
382 | #ccache + distcc together |
383 | if [ "${SMAGE_USE_CCACHE}" == "true" ] |
384 | then |
385 | if [ -x /usr/bin/ccache ] |
386 | then |
387 | echo "Preparing DistCC to work together with CCache ..." |
388 | #export CCACHE_PREFIX="distcc" || die "distcc: could not set ccach_prefix" |
389 | # export CC="ccache distcc" |
390 | # export CXX="ccache distcc" |
391 | fi |
392 | fi |
393 | |
394 | #creating distcc tempdir |
395 | install -o distcc -g daemon -d ${DISTCC_DIR} |
396 | chmod 1777 ${DISTCC_DIR} |
397 | fi |
398 | } |
399 | |
400 | setup_ccache_environment(){ |
401 | if [ -x /usr/bin/ccache ] |
402 | then |
403 | echo "Using CCache for compilation ..." |
404 | export PATH=/usr/lib/ccache/bin:${PATH} || die "ccache: could not export new $PATH" |
405 | #unset CC CXX |
406 | fi |
407 | } |
408 | |
409 | # build_mage_script(): helper functions for regen_mage_tree() |
410 | # generates an mage file with given information in smage file |
411 | # needs at least: |
412 | # PNAME name of pkg |
413 | # PVER version |
414 | # PBUILD revision |
415 | # PCATEGORIE categorie of the pkg |
416 | # STATE state of pkg stable|unstable|old |
417 | # DESCRIPTION va short description (opt) |
418 | # HOMEPAGE homepage (opt) |
419 | # DEPEND runtime dependencies (opt) |
420 | # SDEPEND add. needed deps to build the pkg (opt) |
421 | # PROVIDE provides a virtual (opt) |
422 | # |
423 | # special tags: |
424 | # PKGTYPE type of pkg |
425 | # INHERITS which functions get included |
426 | # SPECIAL_FUNCTIONS special functions wich should also be added |
427 | # warning: they get killed before the build starts ! |
428 | # |
429 | # MAGE_TREE_DEST target destination of the generated tree |
430 | # REGEN_MAGE_TREE set to 'true' to enable this |
431 | build_mage_script() |
432 | { |
433 | local magefile |
434 | local dest |
435 | local suffix |
436 | local sym |
437 | local depname |
438 | |
439 | # if MAGE_TREE_DEST not set use BUILDDIR |
440 | : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree} |
441 | |
442 | # determinate which suffix this mage file should get, if any |
443 | suffix="$1" |
444 | |
445 | # name of magefile |
446 | magefile="${PNAME}${suffix}-${PVER}-${PBUILD}.mage" |
447 | |
448 | # destination to magefile |
449 | dest="${MAGE_TREE_DEST}/${PCATEGORIE}/${PNAME}${suffix}/${magefile}" |
450 | |
451 | # show what we are doing |
452 | echo "Generating Mage file:" |
453 | echo " ${dest}" |
454 | |
455 | install -d "$(dirname ${dest})" |
456 | # now build the mage file |
457 | > ${dest} |
458 | |
459 | # header |
460 | echo '# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.23 2005-08-19 03:43:56 niro Exp $' >> ${dest} |
461 | echo >> ${dest} |
462 | |
463 | # pgkname and state |
464 | echo "PKGNAME=\"${PNAME}${suffix}-${PVER}-\${ARCH}-${PBUILD}\"" >> ${dest} |
465 | echo "STATE=\"${STATE}\"" >> ${dest} |
466 | echo >> ${dest} |
467 | |
468 | # description and homepage |
469 | echo "DESCRIPTION=\"${DESCRIPTION}\"" >> ${dest} |
470 | echo "HOMEPAGE=\"${HOMEPAGE}\"" >> ${dest} |
471 | echo >> ${dest} |
472 | |
473 | # special tags |
474 | echo "PKGTYPE=\"${PKGTYPE}\"" >> ${dest} |
475 | if [ -n "${INHERITS}" ] |
476 | then |
477 | echo -n "minclude" >> ${dest} |
478 | local i |
479 | for i in ${INHERITS} |
480 | do |
481 | echo -n " ${i}" >> ${dest} |
482 | done |
483 | echo >> ${dest} |
484 | fi |
485 | echo >> ${dest} |
486 | |
487 | # deps and provides |
488 | echo "DEPEND=\"${DEPEND}\"" >> ${dest} |
489 | echo "SDEPEND=\"${SDEPEND}\"" >> ${dest} |
490 | echo "PROVIDE=\"${PROVIDE}\"" >> ${dest} |
491 | echo >> ${dest} |
492 | |
493 | # add special functions |
494 | if [ -n "${SPECIAL_FUNCTIONS}" ] |
495 | then |
496 | local i |
497 | for i in ${SPECIAL_FUNCTIONS} |
498 | do |
499 | # add to mage (quotes needed !) |
500 | typeset -f "${i}" >> ${dest} |
501 | # unset to be safe (quotes needed !) |
502 | #unset "${i}" <-- later to get every target built |
503 | done |
504 | fi |
505 | |
506 | # pre|post-install|removes |
507 | typeset -f preinstall >> ${dest} |
508 | echo >> ${dest} |
509 | typeset -f postinstall >> ${dest} |
510 | echo >> ${dest} |
511 | typeset -f preremove >> ${dest} |
512 | echo >> ${dest} |
513 | typeset -f postremove >> ${dest} |
514 | echo >> ${dest} |
515 | } |
516 | |
517 | regen_mage_tree() |
518 | { |
519 | local i |
520 | |
521 | # build them only if requested |
522 | if [[ ${REGEN_MAGE_TREE} = true ]] |
523 | then |
524 | # build for each target an mage file |
525 | for i in ${MAGE_TARGETS} |
526 | do |
527 | echo |
528 | build_mage_script "${i}" |
529 | echo |
530 | done |
531 | fi |
532 | |
533 | # now unset all uneeded vars to be safe |
534 | # unset PKGNAME <-- don't do that; smage needs this var |
535 | # unset to be safe (quotes needed !) |
536 | for i in ${SPECIAL_FUNCTIONS} |
537 | do |
538 | unset "${i}" |
539 | done |
540 | unset SPECIAL_FUNCTIONS |
541 | unset STATE |
542 | unset DESCRIPTION |
543 | unset HOMEPAGE |
544 | unset PKGTYPE |
545 | unset INHERITS |
546 | unset DEPEND |
547 | unset SDEPEND |
548 | unset PROVIDE |
549 | unset preinstall |
550 | unset postinstall |
551 | unset preremove |
552 | unset postremove |
553 | } |
554 | |
555 | # print out our version |
556 | showversion |
557 | echo |
558 | |
559 | if [ -z "$1" ] |
560 | then |
561 | echo "No .smage2 file given. Exiting." |
562 | echo |
563 | exit 1 |
564 | fi |
565 | |
566 | # updating smage2-scripts |
567 | if [ "$1" == "update" ] |
568 | then |
569 | if [ ! -d ${SOURCEDIR} ] |
570 | then |
571 | install -d ${SOURCEDIR} |
572 | fi |
573 | syncsmage2 |
574 | exit 0 |
575 | fi |
576 | |
577 | # creates md5sums for smages to given dir |
578 | if [ "$1" == "calcmd5" ] |
579 | then |
580 | if [ $# -ge 3 ] |
581 | then |
582 | SMAGENAME="$2" |
583 | MD5DIR="$3" |
584 | source ${SMAGENAME} || die "download source failed" |
585 | |
586 | # overridable sourcedir; must be declared after source of the smage2 |
587 | CALC_SOURCEDIR="${CALC_SOURCEDIR:="${SOURCEDIR}/${PNAME}"}" |
588 | |
589 | [ -z "${SRC_URI}" ] && die "Nothing declared to calculate." |
590 | |
591 | # end of array |
592 | EOA=${#SRC_URI[*]} |
593 | |
594 | [ ! -d ${MD5DIR} ] && install -d ${MD5DIR} |
595 | |
596 | # clear md5sum file |
597 | MY_MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5" |
598 | echo -n > ${MY_MD5_FILE} |
599 | |
600 | for ((i=0; i < EOA; i++)) |
601 | do |
602 | # url to file |
603 | my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)" |
604 | |
605 | # subdir in sources dir; the my_SRCI_URI file goes to there |
606 | my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)" |
607 | |
608 | # if my_src_uri_dest is not equal my_src_uri; than an other dir is used |
609 | if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]] |
610 | then |
611 | MY_SRC_FILE="${my_SRC_URI_DEST}/$(basename ${SRC_URI[${i}]})" |
612 | else |
613 | MY_SRC_FILE="$(basename ${SRC_URI[${i}]})" |
614 | fi |
615 | |
616 | if [ -e "${CALC_SOURCEDIR}/${MY_SRC_FILE}" ] |
617 | then |
618 | echo "calculating $(basename ${MY_SRC_FILE}) ..." |
619 | ( cd ${CALC_SOURCEDIR}; md5sum "${MY_SRC_FILE}" ) >> ${MY_MD5_FILE} |
620 | else |
621 | echo "WARNING: File '$(basename ${MY_SRC_FILE}) not found in ${CALC_SOURCEDIR}." |
622 | fi |
623 | |
624 | # unset them to be shure |
625 | unset my_SRC_URI |
626 | unset my_SRC_URI_DEST |
627 | unset my_SRC_URI_MIRROR |
628 | unset my_SOURCEDIR |
629 | done |
630 | |
631 | echo |
632 | echo "Calculating of md5 sums for '$(basename ${SMAGENAME} .${SMAGESUFFIX})' done." |
633 | echo |
634 | else |
635 | echo "Usage: Calculating MD5 Sums:" |
636 | echo " $(basename $0) calcmd5 /path/to/SMAGENAME /path/to/MD5DIR" |
637 | echo |
638 | echo |
639 | echo "Export the CALC_SOURCEDIR variable to override current SOURCEDIRs." |
640 | echo |
641 | exit 1 |
642 | fi |
643 | |
644 | exit 0 |
645 | fi |
646 | |
647 | # download sources |
648 | if [ "$1" == "download" -a -n "$2" ] |
649 | then |
650 | if [ ! -d ${SMAGESCRIPTSDIR} ] |
651 | then |
652 | install -d ${SMAGESCRIPTSDIR} |
653 | fi |
654 | |
655 | # get smage |
656 | SMAGENAME="$2" |
657 | MD5DIR="$(dirname ${SMAGENAME})/md5" |
658 | source ${SMAGENAME} || die "download source failed" |
659 | |
660 | download_sources |
661 | exit 0 |
662 | fi |
663 | |
664 | if [ ! -e ${MLIBDIR}/pkgbuild_dir.sh ] |
665 | then |
666 | die "Error: ${MLIBDIR}/pkgbuild_dir.sh not found. Aborting." |
667 | fi |
668 | |
669 | if [ -z "`basename ${SMAGENAME}|grep .${SMAGESUFFIX}`" ] |
670 | then |
671 | die "File '`basename ${SMAGENAME}`' is not a sMage v${SMAGEVERSION} file. Aborting." |
672 | fi |
673 | |
674 | if [ -z "${SOURCEDIR}" ] |
675 | then |
676 | die "\$SOURCEDIR not found. Please setup your mage.rc correctly." |
677 | fi |
678 | |
679 | if [ -z "${SMAGESCRIPTSDIR}" ] |
680 | then |
681 | die "\$SMAGESCRIPTSDIR not found. Please setup your mage.rc correctly." |
682 | fi |
683 | |
684 | if [ -z "${SMAGE2RSYNC}" ] |
685 | then |
686 | echo "\$SMAGE2RSYNC not found. Please setup your mage.rc correctly." |
687 | exit 1 |
688 | fi |
689 | |
690 | if [ -z "${BINDIR}" ] |
691 | then |
692 | die "no BINDIR variable found in /etc/mage.rc" |
693 | fi |
694 | |
695 | if [ -z "${CHOST}" ] |
696 | then |
697 | die "no CHOST variable found in /etc/mage.rc" |
698 | fi |
699 | |
700 | if [ -z "${CFLAGS}" ] |
701 | then |
702 | die "no CFLAGS variable found in /etc/mage.rc" |
703 | fi |
704 | |
705 | if [ -z "${CXXFLAGS}" ] |
706 | then |
707 | die "no CXXFLAGS variable found in /etc/mage.rc" |
708 | fi |
709 | |
710 | |
711 | source ${SMAGENAME} || die "source failed" |
712 | PKGNAME="${PNAME}-${PVER}-${CHOST%%-*}-${PBUILD}" |
713 | MD5DIR="$(dirname ${SMAGENAME})/md5" |
714 | |
715 | xtitle "Compiling ${PKGNAME}" |
716 | echo "Compiling ${PKGNAME}" |
717 | |
718 | # auto regen mage tree if requested |
719 | regen_mage_tree |
720 | |
721 | # download sources |
722 | download_sources |
723 | |
724 | # fixes some issues with these functions |
725 | export -f src_prepare || die "src_prepare export failed" |
726 | export -f src_compile || die "src_compile export failed" |
727 | export -f src_install || die "src_install export failed" |
728 | |
729 | # fixes some compile issues |
730 | export CHOST="${CHOST}" || die "CHOST export failed" |
731 | export CFLAGS="${CFLAGS}" || die "CFLAGS export failed" |
732 | export CXXFLAGS="${CFLAGS}" || die "CXXFLAGS export failed" |
733 | export BINDIR="${BINDIR}" || die "BINDIR export failed" |
734 | export MAKEOPTS="${MAKEOPTS}" || die "MAKEOPTS export failed" |
735 | |
736 | |
737 | # setup distcc |
738 | # distcc mus be setup *before* ccache, as ccache need to be before distcc in path |
739 | if [ "${SMAGE_USE_DISTCC}" == "true" ] |
740 | then |
741 | setup_distcc_environment |
742 | fi |
743 | |
744 | # setup ccache |
745 | if [ "${SMAGE_USE_CCACHE}" == "true" ] |
746 | then |
747 | setup_ccache_environment |
748 | fi |
749 | |
750 | |
751 | # small sleep to show our settings |
752 | sleep 1 |
753 | |
754 | #debug |
755 | #echo "CC=${CC}" |
756 | #echo "CXX=${CXX}" |
757 | #echo "DISTCC_DIR=${DISTCC_DIR}" |
758 | #echo "PATH: ${PATH}" |
759 | #echo "--------------------------------------" |
760 | #env |
761 | #echo "--------------------------------------" |
762 | #read |
763 | #debug end |
764 | |
765 | # cleans up build if a previously one exists |
766 | if [ -d ${BUILDDIR} ] |
767 | then |
768 | rm -rf ${BUILDDIR}/* || die "couldn't cleanup \$BUILDDIR." |
769 | fi |
770 | install -d ${BUILDDIR} || die "couldn't create \$BUILDDIR." |
771 | |
772 | # cleans up srcdir if a previously unpacked one exists |
773 | if [ -d ${SRCDIR} ] |
774 | then |
775 | rm -rf ${SRCDIR} |
776 | fi |
777 | |
778 | # cleans up bindir if a previous build exists or creates a new one |
779 | if [ -d ${BINDIR} ] |
780 | then |
781 | rm -rf ${BINDIR} |
782 | fi |
783 | install -d ${BINDIR} || die "couldn't create \$BINDIR." |
784 | |
785 | # cleans up package temp dir if a previous build exists |
786 | if [ -d ${BUILDDIR}/${PKGNAME} ] |
787 | then |
788 | rm -rf ${BUILDDIR}/${PKGNAME} |
789 | fi |
790 | |
791 | # cleans up timestamp if one exists |
792 | if [ -f /var/tmp/timestamp ] |
793 | then |
794 | mage rmstamp |
795 | fi |
796 | |
797 | src_prepare || die "src_prepare failed" |
798 | src_compile || die "src_compile failed" |
799 | src_install || die "src_install failed" |
800 | |
801 | |
802 | # compressing doc, info & man files |
803 | echo -e "Compressing man-pages ..." |
804 | if [ -d ${BUILDDIR}/builded/usr/share/man ] |
805 | then |
806 | ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/man |
807 | fi |
808 | |
809 | echo -e "Compressing info-pages ..." |
810 | if [ -d ${BUILDDIR}/builded/usr/share/info ] |
811 | then |
812 | ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/info |
813 | fi |
814 | |
815 | # stripping all bins and libs |
816 | case ${NOSTRIP} in |
817 | true|TRUE|yes|y) |
818 | echo -e "NOSTRIP=true detected; Package will not be stripped ..." |
819 | ;; |
820 | *) |
821 | echo -e "Stripping binaries ..." |
822 | mstripbins ${BINDIR} |
823 | echo -e "Stripping libraries ..." |
824 | mstriplibs ${BINDIR} |
825 | ;; |
826 | esac |
827 | |
828 | # the new buildpkg command |
829 | case ${NOPKGBUILD} in |
830 | true|TRUE|yes|y) |
831 | echo -e "NOPGKBUILD=true detected; Package will not be build ..." |
832 | ;; |
833 | *) |
834 | # build serveral targets |
835 | if [ -n "${MAGE_TARGETS}" ] |
836 | then |
837 | for target in ${MAGE_TARGETS} |
838 | do |
839 | # check if an special target_pkgbuild exists |
840 | if typeset -f ${target}_pkgbuild > /dev/null |
841 | then |
842 | # run it |
843 | ${target}_pkgbuild |
844 | fi |
845 | # now create the target package |
846 | ${MLIBDIR}/pkgbuild_dir.sh \ |
847 | "${PNAME}-${target}-${PVER}-${CHOST%%-*}-${PBUILD}" \ |
848 | ${BINDIR} || die "target: ${target} package-build failed" |
849 | echo -e "\nPackage ${PNAME}-${target}-${PVER}-${CHOST%%-*}-${PBUILD} successfully builded.\n" |
850 | done |
851 | else |
852 | ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed" |
853 | echo -e "\nPackage ${PKGNAME} successfully builded.\n" |
854 | fi |
855 | ;; |
856 | esac |
857 | |
858 | # for sure |
859 | unset NOPKGBUILD |
860 | unset NOSTRIP |
861 | |
862 | xtitleclean |
863 | #echo -e "\nPackage ${PKGNAME} successfully builded.\n" |
Properties
Name | Value |
---|---|
svn:executable | * |