Magellan Linux

Contents of /trunk/mage/usr/lib/mage/smage2.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 79 - (show annotations) (download) (as text)
Wed Jun 1 15:49:20 2005 UTC (18 years, 11 months ago) by niro
File MIME type: application/x-sh
File size: 14293 byte(s)
added functions for stripping bins and libs

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.10 2005-06-01 15:49:20 niro Exp $
8
9 #01.10.2004
10 # added ccache support
11 # added distcc support
12
13 ## setup ##
14 SMAGEVERSION=0.3.6-r15
15 PKGSUFFIX="mpk"
16 SMAGENAME="$1"
17 SMAGESUFFIX="smage2"
18 #SOURCEDIR="/bootstrap/sources"
19 #SMAGESCRIPTSDIR="/bootstrap/smage2-install-scripts"
20 #SMAGE2RSYNC="rsync://192.168.0.2/smage2-scripts"
21 MLIBDIR=/usr/lib/mage
22
23 source /etc/mage.rc
24
25 showversion() {
26 echo -en "Magellan Source Install v${SMAGEVERSION} "
27 echo -e "-- Niels Rogalla (niro@magellan-linux.de)"
28 }
29
30 die() {
31 xtitleclean
32 echo "SMAGE failed: $@"
33 exit 1
34 }
35
36 xtitle() {
37 if [ ${TERM} == "xterm" ]
38 then
39 echo -ne "\033]0;[sMage: $@]\007"
40 fi
41 return 0
42 }
43
44 xtitleclean() {
45 if [ ${TERM} == "xterm" ]
46 then
47 echo -ne "\033]0;\007"
48 fi
49 return 0
50 }
51
52 syncsmage2() {
53 xtitle "Updating smage2-script tree ..."
54 local i
55 for i in ${SMAGE2RSYNC}
56 do
57 rsync \
58 --recursive \
59 --links \
60 --perms \
61 --times \
62 --devices \
63 --timeout=600 \
64 --verbose \
65 --compress \
66 --progress \
67 --stats \
68 --delete \
69 --delete-after \
70 ${i} ${SMAGESCRIPTSDIR}
71
72 if [ "$?" == "0" ]
73 then
74 break
75 else
76 continue
77 fi
78
79 done
80
81 #clean up backup files (foo~)
82 find ${SMAGESCRIPTSDIR} -name *~ -exec rm '{}' ';'
83
84 xtitleclean
85 }
86
87 # $1 filename
88 get_db_md5_sum() {
89 local DB_FILE
90 local MD5_FILE
91 local i
92
93 DB_ENTRY="$(basename $1)"
94 MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} ${SMAGESUFFIX})"
95
96 i="$(cat ${MD5_FILE}| grep ${DB_ENTRY} | cut -d' ' -f1)"
97
98 echo "${i}"
99 }
100
101 download_sources() {
102
103 [ -z "${SRC_URI}" ] && echo -e "\nNothing declared to download.\n" && return 0
104
105 local EOA=${#SRC_URI[*]}
106 local my_SRC_URI
107 local my_SRC_URI_DEST
108 local my_SRC_URI_MIRROR
109 local my_SOURCEDIR
110 local DB_MD5_SUM_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5"
111 local FETCHING
112 local i mirror
113
114
115 #install SRCDIR/PNAME if not exist
116 [ ! -d ${SOURCEDIR}/${PNAME} ] && install -d ${SOURCEDIR}/${PNAME}
117
118 # check if FETCHING is needed
119 ( cd ${SOURCEDIR}/${PNAME}; md5sum --check ${DB_MD5_SUM_FILE} &> /dev/null )
120 if [[ $? == 0 ]]
121 then
122 # md5's ok, not fetching needed
123 FETCHING=false
124 else
125 FETCHING=true
126 fi
127
128 for ((i=0; i < EOA; i++))
129 do
130 # url to file
131 my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)"
132
133 # subdir in sources dir; the my_SRCI_URI file goes to there
134 my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)"
135
136 # if my_src_uri_dest is not equal my_src_uri; than an other dir is used
137 if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]]
138 then
139 my_SOURCEDIR="${SOURCEDIR}/${PNAME}/${my_SRC_URI_DEST}"
140 else
141 my_SOURCEDIR="${SOURCEDIR}/${PNAME}"
142 fi
143
144 # if an mirrored file than replace first the mirror uri
145 if [ -n "$(echo ${my_SRC_URI} | grep 'mirror://')" ]
146 then
147 for mirror in ${MIRRORS}
148 do
149 my_SRC_URI_MIRROR="$(echo ${my_SRC_URI} | sed "s|mirror:/|${mirror}/sources|g")"
150
151 #echo "DEBUG: ${MY_SRC_URI}"
152 if [[ ${FETCHING} == true ]]
153 then
154 echo "==> fetching ${my_SRC_URI_MIRROR}"
155 wget \
156 --passive-ftp \
157 --tries 3 \
158 --continue \
159 --progress bar \
160 --directory-prefix="${my_SOURCEDIR}" \
161 "${my_SRC_URI_MIRROR}"
162 if [ "$?" == "0" ]
163 then
164 break
165 else
166 continue
167 fi
168 fi
169 done
170 else
171 #echo "DEBUG: ${SRC_URI[${i}]}"
172 if [[ ${FETCHING} == true ]]
173 then
174 echo "==> fetching ${my_SRC_URI}"
175 wget \
176 --passive-ftp \
177 --tries 3 \
178 --continue \
179 --progress bar \
180 --directory-prefix="${my_SOURCEDIR}" \
181 "${my_SRC_URI}"
182 if [ "$?" == "0" ]
183 then
184 break
185 else
186 continue
187 fi
188 fi
189 fi
190
191 # unset them to be shure
192 unset my_SRC_URI
193 unset my_SRC_URI_DEST
194 unset my_SRC_URI_MIRROR
195 unset my_SOURCEDIR
196 done
197
198 # recheck md5 sums
199 echo
200 echo ">== Checking MD5 sums:"
201 ( cd ${SOURCEDIR}/${PNAME}; md5sum --check ${DB_MD5_SUM_FILE} ) || die "md5 failed"
202 echo
203
204 # not needed anymore
205 unset SRC_URI
206 }
207
208 # dummy function, used if that not exist in smage file
209 src_prepare() {
210 echo "no src_prepare defined"
211 sleep 2
212 return 0
213 }
214
215 # dummy function, used if that not exist in smage file
216 src_compile() {
217 echo "no src_compile defined"
218 sleep 2
219 return 0
220 }
221
222 # dummy function, used if that not exist in smage file
223 src_install() {
224 echo "no src_install defined"
225 sleep 2
226 return 0
227 }
228
229
230 build_mage_script() {
231 return 0
232 }
233
234 mconfigure() {
235 if [ -x ./configure ]
236 then
237 ./configure \
238 --prefix=/usr \
239 --host=${CHOST} \
240 --mandir=/usr/share/man \
241 --infodir=/usr/share/info \
242 --datadir=/usr/share \
243 --sysconfdir=/etc \
244 --localstatedir=/var/lib \
245 "$@" || die "mconfigure failed"
246 else
247 echo "configure is not an executable ..."
248 exit 1
249 fi
250 }
251
252 minstall() {
253 if [ -f ./[mM]akefile -o -f ./GNUmakefile ] ; then
254 make prefix=${BINDIR}/usr \
255 datadir=${BINDIR}/usr/share \
256 infodir=${BINDIR}/usr/share/info \
257 localstatedir=${BINDIR}/var/lib \
258 mandir=${BINDIR}/usr/share/man \
259 sysconfdir=${BINDIR}/etc \
260 "$@" install || die "minstall failed"
261 else
262 die "no Makefile found"
263 fi
264 }
265
266 mmake() {
267 make ${MAKEOPTS} ${EXTRA_EMAKE} "$@"
268 }
269
270 munpack() {
271 local SRCFILE
272 local IFTAR
273 local DEST
274
275 SRCFILE=$1
276
277 if [ -z "$2" ]
278 then
279 DEST=${BUILDDIR}
280 else
281 DEST=$2
282 fi
283
284 case "${SRCFILE##*.}" in
285 bz2)
286 IFTAR="$(basename $SRCFILE .bz2)"
287 IFTAR="${IFTAR##*.}"
288 if [ "${IFTAR}" == "tar" ]
289 then
290 tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST}
291 fi
292 ;;
293 gz)
294 IFTAR="$(basename $SRCFILE .gz)"
295 IFTAR="${IFTAR##*.}"
296 if [ "${IFTAR}" == "tar" ]
297 then
298 tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST}
299 fi
300 ;;
301 tbz2)
302 tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST}
303 ;;
304 tgz)
305 tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST}
306 ;;
307 *)
308 die "munpack failed"
309 ;;
310 esac
311 }
312
313 mpatch() {
314 local PATCHOPTS
315 local PATCHFILE
316
317 PATCHOPTS=$1
318 PATCHFILE=$2
319
320 patch "${PATCHOPTS}" -i ${SOURCEDIR}/${PNAME}/${PATCHFILE}
321 }
322
323
324 minstalldocs() {
325 local docfiles
326
327 docfiles="$@"
328
329 if [ ! -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} ]
330 then
331 install -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "creating doc dirs."
332 fi
333
334 for i in ${docfiles}
335 do
336 cat ${i} | gzip -9c > ${i}.gz || die "gzipping docs."
337 install -m 0644 ${SRCDIR}/${i}.gz \
338 ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "coping docs."
339 done
340 }
341
342 mstriplibs() {
343 local stripdir="$@"
344
345 [ -z "${stripdir}" ] && stripdir=${BINDIR}
346 find ${stripdir} | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
347 }
348
349 mstripbins() {
350 local stripdir="$@"
351
352 [ -z "${stripdir}" ] && stripdir=${BINDIR}
353 find ${stripdir} | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
354 }
355
356 setup_distcc_environment(){
357 if [ -x /usr/bin/distcc ]
358 then
359 echo "Using DistCC for compilation ..."
360 export PATH=/usr/lib/distcc/bin:${PATH} || die "distcc: could not export new $PATH"
361
362 #export distcc as compiler
363 # export CC="distcc"
364 # export CXX=distcc
365
366 export DISTCC_DIR="${DISTCC_DIR}" || die "distcc_dir export failed"
367
368
369 #ccache + distcc together
370 if [ "${SMAGE_USE_CCACHE}" == "true" ]
371 then
372 if [ -x /usr/bin/ccache ]
373 then
374 echo "Preparing DistCC to work together with CCache ..."
375 #export CCACHE_PREFIX="distcc" || die "distcc: could not set ccach_prefix"
376 # export CC="ccache distcc"
377 # export CXX="ccache distcc"
378 fi
379 fi
380
381 #creating distcc tempdir
382 install -o distcc -g daemon -d ${DISTCC_DIR}
383 chmod 1777 ${DISTCC_DIR}
384 fi
385 }
386
387 setup_ccache_environment(){
388 if [ -x /usr/bin/ccache ]
389 then
390 echo "Using CCache for compilation ..."
391 export PATH=/usr/lib/ccache/bin:${PATH} || die "ccache: could not export new $PATH"
392 #unset CC CXX
393 fi
394 }
395
396 # print out our version
397 showversion
398 echo
399
400 if [ -z "$1" ]
401 then
402 echo "No .smage2 file given. Exiting."
403 echo
404 exit 1
405 fi
406
407 #updating smage2-scripts
408 if [ "$1" == "update" ]
409 then
410 if [ ! -d ${SOURCEDIR} ]
411 then
412 install -d ${SOURCEDIR}
413 fi
414 syncsmage2
415 exit 0
416 fi
417
418 #creates md5sums for smages to given dir
419 if [ "$1" == "calcmd5" ]
420 then
421 if [ $# -ge 3 ]
422 then
423 SMAGENAME="$2"
424 MD5DIR="$3"
425 source ${SMAGENAME} || die "download source failed"
426
427 # overridable sourcedir; must be declared after source of the smage2
428 CALC_SOURCEDIR="${CALC_SOURCEDIR:="${SOURCEDIR}/${PNAME}"}"
429
430 [ -z "${SRC_URI}" ] && die "Nothing declared to calculate."
431
432 # end of array
433 EOA=${#SRC_URI[*]}
434
435 [ ! -d ${MD5DIR} ] && install -d ${MD5DIR}
436
437 # clear md5sum file
438 MY_MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5"
439 echo -n > ${MY_MD5_FILE}
440
441 for ((i=0; i < EOA; i++))
442 do
443 # url to file
444 my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)"
445
446 # subdir in sources dir; the my_SRCI_URI file goes to there
447 my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)"
448
449 # if my_src_uri_dest is not equal my_src_uri; than an other dir is used
450 if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]]
451 then
452 MY_SRC_FILE="${my_SRC_URI_DEST}/$(basename ${SRC_URI[${i}]})"
453 else
454 MY_SRC_FILE="$(basename ${SRC_URI[${i}]})"
455 fi
456
457 if [ -e "${CALC_SOURCEDIR}/${MY_SRC_FILE}" ]
458 then
459 echo "calculating $(basename ${MY_SRC_FILE}) ..."
460 ( cd ${CALC_SOURCEDIR}; md5sum "${MY_SRC_FILE}" ) >> ${MY_MD5_FILE}
461 else
462 echo "WARNING: File '$(basename ${MY_SRC_FILE}) not found in ${CALC_SOURCEDIR}."
463 fi
464
465 # unset them to be shure
466 unset my_SRC_URI
467 unset my_SRC_URI_DEST
468 unset my_SRC_URI_MIRROR
469 unset my_SOURCEDIR
470 done
471
472 echo
473 echo "Calculating of md5 sums for '$(basename ${SMAGENAME} .${SMAGESUFFIX})' done."
474 echo
475 else
476 echo "Usage: Calculating MD5 Sums:"
477 echo " $(basename $0) calcmd5 /path/to/SMAGENAME /path/to/MD5DIR"
478 echo
479 echo
480 echo "Export the CALC_SOURCEDIR variable to override current SOURCEDIRs."
481 echo
482 exit 1
483 fi
484
485 exit 0
486 fi
487
488 #download sources
489 if [ "$1" == "download" -a -n "$2" ]
490 then
491 showversion
492 if [ ! -d ${SMAGESCRIPTSDIR} ]
493 then
494 install -d ${SMAGESCRIPTSDIR}
495 fi
496
497 # get smage
498 SMAGENAME="$2"
499 MD5DIR="$(dirname ${SMAGENAME})/md5"
500 source ${SMAGENAME} || die "download source failed"
501
502 download_sources
503 exit 0
504 fi
505
506 if [ ! -e ${MLIBDIR}/pkgbuild_dir.sh ]
507 then
508 die "Error: ${MLIBDIR}/pkgbuild_dir.sh not found. Aborting."
509 fi
510
511 if [ -z "`basename ${SMAGENAME}|grep .${SMAGESUFFIX}`" ]
512 then
513 die "File '`basename ${SMAGENAME}`' is not a sMage v${SMAGEVERSION} file. Aborting."
514 fi
515
516 if [ -z "${SOURCEDIR}" ]
517 then
518 die "\$SOURCEDIR not found. Please setup your mage.rc correctly."
519 fi
520
521 if [ -z "${SMAGESCRIPTSDIR}" ]
522 then
523 die "\$SMAGESCRIPTSDIR not found. Please setup your mage.rc correctly."
524 fi
525
526 if [ -z "${SMAGE2RSYNC}" ]
527 then
528 echo "\$SMAGE2RSYNC not found. Please setup your mage.rc correctly."
529 exit 1
530 fi
531
532 if [ -z "${BINDIR}" ]
533 then
534 die "no BINDIR variable found in /etc/mage.rc"
535 fi
536
537 if [ -z "${CHOST}" ]
538 then
539 die "no CHOST variable found in /etc/mage.rc"
540 fi
541
542 if [ -z "${CFLAGS}" ]
543 then
544 die "no CFLAGS variable found in /etc/mage.rc"
545 fi
546
547 if [ -z "${CXXFLAGS}" ]
548 then
549 die "no CXXFLAGS variable found in /etc/mage.rc"
550 fi
551
552
553 source ${SMAGENAME} || die "source failed"
554 PKGNAME="${PNAME}-${PVER}-${CHOST%%-*}-${PBUILD}"
555 MD5DIR="$(dirname ${SMAGENAME})/md5"
556
557 xtitle "Compiling ${PKGNAME}"
558 echo "Compiling ${PKGNAME}"
559
560 #download sources
561 download_sources
562
563 #fixes some issues with these functions
564 export -f src_prepare || die "src_prepare export failed"
565 export -f src_compile || die "src_compile export failed"
566 export -f src_install || die "src_install export failed"
567
568 #fixes some compile issues
569 export CHOST="${CHOST}" || die "CHOST export failed"
570 export CFLAGS="${CFLAGS}" || die "CFLAGS export failed"
571 export CXXFLAGS="${CFLAGS}" || die "CXXFLAGS export failed"
572 export BINDIR="${BINDIR}" || die "BINDIR export failed"
573 export MAKEOPTS="${MAKEOPTS}" || die "MAKEOPTS export failed"
574
575
576 #setup distcc
577 #distcc mus be setup *before* ccache, as ccache need to be before distcc in path
578 if [ "${SMAGE_USE_DISTCC}" == "true" ]
579 then
580 setup_distcc_environment
581 fi
582
583 #setup ccache
584 if [ "${SMAGE_USE_CCACHE}" == "true" ]
585 then
586 setup_ccache_environment
587 fi
588
589
590 # small sleep to show our settings
591 sleep 1
592
593 #debug
594 #echo "CC=${CC}"
595 #echo "CXX=${CXX}"
596 #echo "DISTCC_DIR=${DISTCC_DIR}"
597 #echo "PATH: ${PATH}"
598 #echo "--------------------------------------"
599 #env
600 #echo "--------------------------------------"
601 #read
602 #debug end
603
604 #cleans up build if a previously one exists
605 if [ -d ${BUILDDIR} ]
606 then
607 rm -rf ${BUILDDIR}/* || die "couldn't cleanup \$BUILDDIR."
608 fi
609 install -d ${BUILDDIR} || die "couldn't create \$BUILDDIR."
610
611 #cleans up srcdir if a previously unpacked one exists
612 if [ -d ${SRCDIR} ]
613 then
614 rm -rf ${SRCDIR}
615 fi
616
617 #cleans up bindir if a previous build exists or creates a new one
618 if [ -d ${BINDIR} ]
619 then
620 rm -rf ${BINDIR}
621 fi
622 install -d ${BINDIR} || die "couldn't create \$BINDIR."
623
624 #cleans up package temp dir if a previous build exists
625 if [ -d ${BUILDDIR}/${PKGNAME} ]
626 then
627 rm -rf ${BUILDDIR}/${PKGNAME}
628 fi
629
630 #cleans up timestamp if one exists
631 if [ -f /var/tmp/timestamp ]
632 then
633 mage rmstamp
634 fi
635
636 src_prepare || die "src_prepare failed"
637 src_compile || die "src_compile failed"
638 src_install || die "src_install failed"
639
640
641 #compressing doc, info & man files
642 echo -e "Compressing man-pages ..."
643 if [ -d ${BUILDDIR}/builded/usr/share/man ]
644 then
645 ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/man
646 fi
647
648 echo -e "Compressing info-pages ..."
649 if [ -d ${BUILDDIR}/builded/usr/share/info ]
650 then
651 ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/info
652 fi
653
654 # stripping all bins and libs
655 case ${NOSTRIP} in
656 true|TRUE|yes|y)
657 echo -e "NOSTRIP=true detected; Package will not be stripped ..."
658 ;;
659 *)
660 echo -e "Stripping binaries ..."
661 mstripbins ${BINDIR}
662 echo -e "Stripping libraries ..."
663 mstriplibs ${BINDIR}
664 ;;
665 esac
666
667 #the new buildpkg command
668 case ${NOPKGBUILD} in
669 true|TRUE|yes|y)
670 echo -e "NOPGKBUILD=true detected; Package will not be build ..."
671 ;;
672 *)
673 ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed"
674 echo -e "\nPackage ${PKGNAME} successfully builded.\n"
675 ;;
676 esac
677
678 #for sure
679 unset NOPKGBUILD
680
681 xtitleclean
682 #echo -e "\nPackage ${PKGNAME} successfully builded.\n"

Properties

Name Value
svn:executable *