Magellan Linux

Annotation of /branches/mage-next/src/smage2.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1580 - (hide annotations) (download) (as text)
Wed Dec 28 11:58:28 2011 UTC (12 years, 4 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/smage2.sh
File MIME type: application/x-sh
File size: 39891 byte(s)
-added mpurgetargets and mstriplibtoolarchive
1 niro 24 #!/bin/bash
2 niro 1571 # $Id$
3 niro 24
4     # compiles/installs .smage2 source install scripts
5     # needs pkgbuild_dir (mage)
6    
7 niro 1571 # TODO: record dynlib, gz | xz database
8 niro 24
9    
10 niro 419 # set default user mage.rc
11     : ${MAGERC="/etc/mage.rc"}
12    
13 niro 24 ## setup ##
14     SMAGENAME="$1"
15 niro 186 SMAGEVERSION="$( < ${MLIBDIR}/version)"
16 niro 24
17 niro 169 # export default C locale
18     export LC_ALL=C
19    
20 niro 439 source /etc/mage.rc.global
21 niro 419 source ${MAGERC}
22 niro 1273 source ${MLIBDIR}/mage4.functions.sh
23 niro 24
24 niro 347 # set PKGDIR and BUILDDIR and BINDIR to MROOT
25     if [[ -n ${MROOT} ]]
26     then
27     export PKGDIR=${MROOT}/${PKGDIR}
28     export BUILDDIR=${MROOT}/${BUILDDIR}
29     export BINDIR=${MROOT}/${BINDIR}
30     fi
31    
32 niro 1346 # sources the smage file and uses state from distribution file if exist
33     # may helpful for repository support later on
34     smagesource()
35     {
36     local file="$1"
37     local mystate
38     local mycodename
39    
40     source ${file}
41    
42     [[ -n ${STATE} ]] && mystate="${STATE}"
43 niro 1349
44     # do not overide if local state was broken or disabled!
45     case ${STATE} in
46     broken) return ;;
47     disabled) return ;;
48     esac
49    
50 niro 1346 if [ -f ${SMAGESCRIPTSDIR}/distribution ]
51     then
52     source ${SMAGESCRIPTSDIR}/distribution
53     [[ -n ${STATE} ]] && mystate="${STATE}"
54     fi
55     # now switch state and export it
56     STATE="${mystate}"
57     }
58    
59 niro 306 showversion()
60     {
61 niro 24 echo -en "Magellan Source Install v${SMAGEVERSION} "
62     echo -e "-- Niels Rogalla (niro@magellan-linux.de)"
63     }
64    
65 niro 306 die()
66     {
67 niro 24 xtitleclean
68 niro 413 echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT}
69 niro 24 echo "SMAGE failed: $@"
70     exit 1
71     }
72    
73 niro 941 die_pipestatus()
74     {
75 niro 943 # the status change if we do any parameter declarations!!
76     # dont do this anymore, keep this in mind!
77     #
78     # local pos="$1"
79     # local comment="$2"
80     #
81     # [ ${PIPESTATUS[${pos}]} -ne 0 ] && die "${comment}"
82     #
83     [ ${PIPESTATUS[$1]} -ne 0 ] && die "$2"
84 niro 941 }
85    
86 niro 306 xtitle()
87     {
88     if [[ ${TERM} = xterm ]]
89 niro 24 then
90     echo -ne "\033]0;[sMage: $@]\007"
91     fi
92     return 0
93     }
94    
95 niro 306 xtitleclean()
96     {
97     if [[ ${TERM} = xterm ]]
98 niro 24 then
99     echo -ne "\033]0;\007"
100     fi
101     return 0
102     }
103    
104 niro 306 syncsmage2()
105     {
106 niro 24 xtitle "Updating smage2-script tree ..."
107     local i
108     for i in ${SMAGE2RSYNC}
109     do
110 niro 386 rsync ${RSYNC_FETCH_OPTIONS} ${i} ${SMAGESCRIPTSDIR}
111 niro 306 if [[ $? = 0 ]]
112 niro 24 then
113     break
114     else
115     continue
116     fi
117     done
118 niro 306
119     # clean up backup files (foo~)
120 niro 24 find ${SMAGESCRIPTSDIR} -name *~ -exec rm '{}' ';'
121 niro 306
122 niro 24 xtitleclean
123     }
124    
125 niro 59 # $1 filename
126 niro 306 get_db_md5_sum()
127     {
128 niro 59 local DB_FILE
129     local MD5_FILE
130     local i
131    
132     DB_ENTRY="$(basename $1)"
133     MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} ${SMAGESUFFIX})"
134    
135     i="$(cat ${MD5_FILE}| grep ${DB_ENTRY} | cut -d' ' -f1)"
136    
137     echo "${i}"
138     }
139    
140 niro 306 download_sources()
141     {
142 niro 61 [ -z "${SRC_URI}" ] && echo -e "\nNothing declared to download.\n" && return 0
143 niro 59
144 niro 1580 local count=${#SRC_URI[*]}
145     local uri
146     local subdir
147     local outputdir
148     local db_md5_file="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5"
149     local fetching
150     local i
151 niro 59
152     # check if FETCHING is needed
153 niro 1580 if mchecksum --rundir "${SOURCEDIR}/${PNAME}" --file "${db_md5_file}" --method md5
154 niro 59 then
155 niro 439 # md5's ok, no fetching needed
156 niro 1580 fetching=false
157 niro 59 else
158 niro 1580 fetching=true
159 niro 59 fi
160 niro 306
161 niro 1580 if [[ ${fetching} = true ]]
162     then
163     for ((i=0; i < count; i++))
164     do
165     # url to file
166     uri="${SRC_URI[${i}]%%' '*}"
167 niro 59
168 niro 1580 # subdir in sources dir; the my_SRCI_URI file goes to there
169     subdir="${SRC_URI[${i}]##*' '}"
170 niro 66
171 niro 1580 # if $subdir is not equal with $uri then an other dir is used
172     if [[ ${uri} != ${subdir} ]]
173 niro 59 then
174 niro 1580 outputdir="${SOURCEDIR}/${PNAME}/${subdir}"
175     else
176     outputdir="${SOURCEDIR}/${PNAME}"
177 niro 59 fi
178 niro 306
179 niro 1580 echo -e "${COLBLUE}==>${COLGREEN} fetching ${uri}${COLDEFAULT}"
180     mdownload --uri "${uri}" --dir "${outputdir}" || die "Could not download '${uri}'"
181 niro 59
182 niro 1580 # unset them to be sure
183     unset uri
184     unset subdir
185     unset outputdir
186     done
187 niro 59
188 niro 1580 # recheck md5 sums after download
189     echo
190     echo -e "${COLBLUE}===${COLGREEN} Checking MD5 sums:${COLDEFAULT}"
191     mchecksum --rundir "${SOURCEDIR}/${PNAME}" --file "${db_md5_file}" --method md5 || die "md5 failed"
192     echo
193     else
194     echo -e "${COLBLUE}===${COLGREEN} All sources already fetched, nothing to do${COLDEFAULT}"
195     fi
196    
197 niro 59 # not needed anymore
198     unset SRC_URI
199     }
200    
201 niro 1573 # dummy function, used if that does not exist in smage file
202 niro 306 src_prepare()
203     {
204 niro 24 echo "no src_prepare defined"
205     return 0
206     }
207    
208 niro 1573 # dummy function, used if that does not exist in smage file
209 niro 1577 src_compile()
210 niro 1575 {
211 niro 1577 echo "no src_compile defined"
212 niro 1575 return 0
213     }
214    
215     # dummy function, used if that does not exist in smage file
216 niro 1577 src_check()
217 niro 306 {
218 niro 1577 echo "no src_check defined"
219 niro 24 return 0
220     }
221    
222 niro 1573 # dummy function, used if that does not exist in smage file
223 niro 306 src_install()
224     {
225 niro 24 echo "no src_install defined"
226     return 0
227     }
228    
229 niro 351 mlibdir()
230     {
231     local libdir=lib
232     [[ ${ARCH} = x86_64 ]] && libdir=lib64
233    
234     echo "${libdir}"
235     }
236    
237 niro 306 mconfigure()
238     {
239 niro 24 if [ -x ./configure ]
240     then
241 niro 306 ./configure \
242     --prefix=/usr \
243     --host=${CHOST} \
244 niro 833 --build=${CHOST} \
245 niro 306 --mandir=/usr/share/man \
246     --infodir=/usr/share/info \
247     --datadir=/usr/share \
248     --sysconfdir=/etc \
249     --localstatedir=/var/lib \
250 niro 351 --libdir=/usr/$(mlibdir) \
251 niro 306 "$@" || die "mconfigure failed"
252 niro 24 else
253     echo "configure is not an executable ..."
254     exit 1
255     fi
256     }
257    
258 niro 306 minstall()
259     {
260     if [ -f ./[mM]akefile -o -f ./GNUmakefile ]
261     then
262 niro 24 make prefix=${BINDIR}/usr \
263     datadir=${BINDIR}/usr/share \
264     infodir=${BINDIR}/usr/share/info \
265     localstatedir=${BINDIR}/var/lib \
266     mandir=${BINDIR}/usr/share/man \
267     sysconfdir=${BINDIR}/etc \
268 niro 351 libdir=${BINDIR}/usr/$(mlibdir) \
269 niro 24 "$@" install || die "minstall failed"
270     else
271     die "no Makefile found"
272     fi
273     }
274    
275 niro 306 mmake()
276     {
277 niro 24 make ${MAKEOPTS} ${EXTRA_EMAKE} "$@"
278     }
279    
280 niro 306 munpack()
281     {
282 niro 24 local SRCFILE
283     local IFTAR
284     local DEST
285    
286     SRCFILE=$1
287 niro 306
288 niro 597 if [[ -z $2 ]]
289 niro 24 then
290     DEST=${BUILDDIR}
291     else
292     DEST=$2
293     fi
294 niro 306
295 niro 411 [[ ! -d ${DEST} ]] && install -d ${DEST}
296    
297 niro 24 case "${SRCFILE##*.}" in
298     bz2)
299     IFTAR="$(basename $SRCFILE .bz2)"
300     IFTAR="${IFTAR##*.}"
301 niro 306 if [[ ${IFTAR} = tar ]]
302 niro 24 then
303 niro 597 tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tar.bz2 unpack failed."
304     else
305     pushd ${DEST} > /dev/null
306     bzcat ${SOURCEDIR}/${PNAME}/${SRCFILE} > ${DEST}/$(basename ${SRCFILE} .bz2) || die ".bz2 unpack failed."
307     popd > /dev/null
308 niro 24 fi
309     ;;
310     gz)
311     IFTAR="$(basename $SRCFILE .gz)"
312     IFTAR="${IFTAR##*.}"
313 niro 306 if [[ ${IFTAR} = tar ]]
314 niro 24 then
315 niro 597 tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tar.gz unpack failed."
316     else
317     pushd ${DEST} > /dev/null
318     zcat ${SOURCEDIR}/${PNAME}/${SRCFILE} > ${DEST}/$(basename ${SRCFILE} .gz) || die ".gz unpack failed."
319     popd > /dev/null
320 niro 24 fi
321     ;;
322 niro 1351 xz)
323     IFTAR="$(basename $SRCFILE .xz)"
324     IFTAR="${IFTAR##*.}"
325     if [[ ${IFTAR} = tar ]]
326     then
327     tar --no-same-owner -xvJf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tar.xz unpack failed."
328     else
329     pushd ${DEST} > /dev/null
330     xzcat ${SOURCEDIR}/${PNAME}/${SRCFILE} > ${DEST}/$(basename ${SRCFILE} .xz) || die ".xz unpack failed."
331     popd > /dev/null
332     fi
333     ;;
334 niro 600 tbz2|mpks|mpk)
335 niro 597 tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tbz2 unpack failed."
336 niro 24 ;;
337     tgz)
338 niro 597 tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tgz unpack failed."
339 niro 24 ;;
340 niro 1351 txz|mpkzs|mpkz)
341     tar --no-same-owner -xvJf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".txz unpack failed."
342     ;;
343 niro 597 rar)
344     unrar x ${SOURCEDIR}/${PNAME}/${SRCFILE} ${DEST} || die ".rar unpack failed."
345     ;;
346 niro 600 zip|xpi)
347 niro 597 unzip ${SOURCEDIR}/${PNAME}/${SRCFILE} -d ${DEST} || die ".zip unpack failed."
348     ;;
349     rpm)
350 niro 635 pushd ${DEST} > /dev/null
351 niro 597 rpm2targz ${SOURCEDIR}/${PNAME}/${SRCFILE} || die "rpm2targz: .rpm unpack failed."
352 niro 602 tar --no-same-owner -xvzf ${SRCFILE/.rpm/.tar.gz} || die "tar: .rpm unpack failed."
353 niro 635 if [[ -f ${DEST}/${SRCFILE/.rpm/.tar.gz} ]]
354 niro 602 then
355 niro 635 rm ${DEST}/${SRCFILE/.rpm/.tar.gz}
356 niro 602 fi
357 niro 597 ;;
358 niro 24 *)
359     die "munpack failed"
360     ;;
361     esac
362     }
363    
364 niro 306 mpatch()
365     {
366 niro 24 local PATCHOPTS
367     local PATCHFILE
368 niro 447 local i
369 niro 24
370     PATCHOPTS=$1
371     PATCHFILE=$2
372    
373 niro 447 if [[ -z $2 ]]
374     then
375     PATCHFILE=$1
376    
377     ## patch level auto-detection, get patch level
378     for ((i=0; i < 10; i++))
379     do
380     patch --dry-run -Np${i} -i ${SOURCEDIR}/${PNAME}/${PATCHFILE} > /dev/null
381     if [[ $? = 0 ]]
382     then
383     PATCHOPTS="-Np${i}"
384     break
385     fi
386     done
387     fi
388    
389 niro 384 echo -e "${COLBLUE}*** ${COLGREEN}Applying patch '${PATCHFILE}'${COLDEFAULT}"
390 niro 24 patch "${PATCHOPTS}" -i ${SOURCEDIR}/${PNAME}/${PATCHFILE}
391     }
392    
393 niro 497 mlibtoolize()
394     {
395     local opts="$@"
396 niro 1435 [[ -z ${opts} ]] && opts="--verbose --install --force"
397 niro 24
398 niro 497 libtoolize ${opts} || die "running: mlibtoolize ${opts}"
399     }
400    
401 niro 1291 mautoreconf()
402     {
403     local opts="$@"
404     [[ -z ${opts} ]] && opts="--verbose --install --force"
405    
406     autoreconf ${opts} || die "running: mautoreconf ${opts}"
407     }
408    
409 niro 306 minstalldocs()
410     {
411 niro 24 local docfiles
412     docfiles="$@"
413 niro 306
414 niro 24 if [ ! -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} ]
415     then
416     install -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "creating doc dirs."
417     fi
418 niro 306
419 niro 953 local i
420 niro 24 for i in ${docfiles}
421     do
422 niro 953 if [ -f ${i} ]
423     then
424     cat ${i} | gzip -9c > ${i}.gz || die "gzipping docs."
425     install -m 0644 ${SRCDIR}/${i}.gz \
426     ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "coping docs."
427     fi
428 niro 24 done
429     }
430    
431 niro 306 mstriplibs()
432     {
433 niro 79 local stripdir="$@"
434    
435 niro 1578 [[ -z ${stripdir} ]] && stripdir="${BINDIR}"
436     [[ -z ${STRIP_DYN_LIB} ]] && STRIP_DYN_LIB="--strip-debug"
437     find ${stripdir} ! -type d | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_DYN_LIB} 2> /dev/null
438 niro 79 }
439    
440 niro 306 mstripbins()
441     {
442 niro 79 local stripdir="$@"
443    
444 niro 1578 [[ -z ${stripdir} ]] && stripdir="${BINDIR}"
445     [[ -z ${STRIP_DYN_BIN} ]] && STRIP_DYN_BIN="--strip-debug"
446     find ${stripdir} ! -type d | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_DYN_BIN} 2> /dev/null
447 niro 79 }
448    
449 niro 1543 mstripstatic()
450     {
451     local stripdir="$@"
452    
453 niro 1578 [[ -z ${stripdir} ]] && stripdir="${BINDIR}"
454     [[ -z ${STRIP_STATIC_LIB} ]] && STRIP_STATIC_LIB="--strip-debug"
455     find ${stripdir} ! -type d | xargs file | grep "ar archive" | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_STATIC_LIB} 2> /dev/null
456 niro 1543 }
457    
458 niro 1580 mstriplibtoolarchive()
459     {
460     local stripdir="$@"
461    
462     [[ -z ${stripdir} ]] && stripdir="${BINDIR}"
463     find ${stripdir} ! -type d -name \*.la | xargs file | grep "libtool library" | cut -f 1 -d : | xargs --no-run-if-empty rm -f -- 2> /dev/null
464     }
465    
466     mpurgetargets()
467     {
468     local stripdir="$@"
469     local target
470    
471     [[ -z ${stripdir} ]] && stripdir=${BINDIR}
472     # nothing to do in this case
473     [[ -z ${PURGE_TARGETS[*]} ]] && return
474    
475     for target in ${PURGE_TARGETS[*]}
476     do
477     # check if target is a regex pattern without any slashes
478     if [[ ${target} = ${target//\/} ]]
479     then
480     find ${BINDIR} -type f -name "${target}" | xargs --no-run-if-empty rm -f -- 2> /dev/null
481     else
482     rm -f -- ${target} 2> /dev/null
483     fi
484     done
485     }
486    
487 niro 943 mcompressdocs()
488     {
489     local bindir="$@"
490    
491     if [ -d ${bindir}/usr/share/man ]
492     then
493     echo -e "${COLBLUE}===${COLGREEN} compressing man-pages ...${COLDEFAULT}"
494     ${MLIBDIR}/compressdoc -g -9 ${bindir}/usr/share/man
495     fi
496    
497     if [ -d ${bindir}/usr/share/info ]
498     then
499     echo -e "${COLBLUE}===${COLGREEN} compressing info-pages ...${COLDEFAULT}"
500     ${MLIBDIR}/compressdoc -g -9 ${bindir}/usr/share/info
501     fi
502     }
503    
504 niro 306 sminclude()
505     {
506 niro 172 local i
507    
508 niro 183 if [[ -n "$@" ]]
509 niro 172 then
510     for i in $@
511     do
512 niro 175 echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
513 niro 172 source ${SMAGESCRIPTSDIR}/include/${i}.sminc
514     done
515 niro 177 echo
516 niro 172 fi
517     }
518    
519 niro 306 setup_distcc_environment()
520     {
521 niro 24 if [ -x /usr/bin/distcc ]
522     then
523 niro 441 echo -e "${COLBLUE}---${COLGREEN} Using DistCC for compilation ...${COLDEFAULT}"
524 niro 351 export PATH=/usr/$(mlibdir)/distcc/bin:${PATH} || die "distcc: could not export new $PATH"
525 niro 24
526     export DISTCC_DIR="${DISTCC_DIR}" || die "distcc_dir export failed"
527    
528 niro 306 # creating distcc tempdir
529 niro 24 install -o distcc -g daemon -d ${DISTCC_DIR}
530     chmod 1777 ${DISTCC_DIR}
531     fi
532     }
533    
534 niro 306 setup_ccache_environment()
535     {
536 niro 24 if [ -x /usr/bin/ccache ]
537     then
538 niro 441 echo -e "${COLBLUE}---${COLGREEN} Using CCache for compilation ...${COLDEFAULT}"
539 niro 351 export PATH=/usr/$(mlibdir)/ccache/bin:${PATH} || die "ccache: could not export new $PATH"
540 niro 24 fi
541     }
542    
543 niro 193
544     # fixes given dependencies to match a MAGE_TARGET
545 niro 198 # fix_mage_deps -target s/depend # <-- note -target !
546 niro 306 fix_mage_deps()
547     {
548 niro 193 local target="$1"
549     local depend="$2"
550     local NDEPEND
551     local sym dep cat pver pname
552    
553     # deps and provides are special
554     # they must be fixed to match the target
555    
556     # run this only if target and depend is not empty
557     if [ -n "${target}" ] && [ -n "${depend}" ]
558     then
559     # fix DEPEND
560     while read sym dep
561     do
562 niro 427 # ignore empty lines
563     [[ -z ${dep} ]] && continue
564    
565 niro 193 cat="$(dirname ${dep})"
566 niro 199 # change if not virtual
567 niro 200 if [[ ${cat} = virtual ]]
568 niro 199 then
569 niro 200 pname="$(basename ${dep})"
570     else
571 niro 199 # fix pver to target-pver
572     # to get pname-target-pver
573 niro 193
574 niro 199 # doing it backwards !
575     pver="${dep##*-}"
576 niro 200 # full pver
577     pname="$(basename ${dep/-${pver}/})${target}-${pver}"
578 niro 199 fi
579 niro 193
580     # do not add empty lines
581     if [ -z "${NDEPEND}" ]
582     then
583 niro 200 NDEPEND="${sym} ${cat}/${pname}"
584 niro 193 else
585     NDEPEND="${NDEPEND}
586 niro 201 ${sym} ${cat}/${pname}"
587 niro 193 fi
588    
589     unset cat pname pver
590     done << EOF
591     ${depend}
592     EOF
593     # set NDEPEND to DEPEND
594     depend="${NDEPEND}"
595     fi
596    
597     echo "${depend}"
598     }
599    
600 niro 192 # build_mage_script(): helper functions for regen_mage_tree()
601 niro 191 # generates an mage file with given information in smage file
602     # needs at least:
603     # PNAME name of pkg
604     # PVER version
605     # PBUILD revision
606     # PCATEGORIE categorie of the pkg
607     # STATE state of pkg stable|unstable|old
608     # DESCRIPTION va short description (opt)
609     # HOMEPAGE homepage (opt)
610     # DEPEND runtime dependencies (opt)
611     # SDEPEND add. needed deps to build the pkg (opt)
612     # PROVIDE provides a virtual (opt)
613     #
614     # special tags:
615     # PKGTYPE type of pkg
616     # INHERITS which functions get included
617 niro 832 # SPECIAL_FUNCTIONS special functions which should also be added
618 niro 191 # warning: they get killed before the build starts !
619 niro 943 # SPLIT_PACKAGES names of all subpackages which are splitted from parent
620     # SPLIT_PACKAGE_BASE base package name for splitpackages
621     # (only in the resulting magefile}
622 niro 191 #
623     # MAGE_TREE_DEST target destination of the generated tree
624     # REGEN_MAGE_TREE set to 'true' to enable this
625 niro 193 #
626 niro 195 # gets called with build_mage_script target
627 niro 192 build_mage_script()
628 niro 191 {
629     local magefile
630     local dest
631 niro 193 local target
632 niro 943 local split_pkg_base
633 niro 191 local sym
634     local depname
635    
636     # if MAGE_TREE_DEST not set use BUILDDIR
637     : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
638    
639     # determinate which suffix this mage file should get, if any
640 niro 943 [[ $1 = --target ]] && shift && target="-$1"
641 niro 191
642 niro 943 # mark package as splitpackage
643     [[ $1 = --split-pkg-base ]] && shift && split_pkg_base="$1"
644    
645 niro 191 # name of magefile
646 niro 193 magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage"
647 niro 191
648     # destination to magefile
649 niro 193 dest="${MAGE_TREE_DEST}/${PCATEGORIE}/${PNAME}${target}/${magefile}"
650 niro 191
651     # show what we are doing
652 niro 439 echo -e "${COLBLUE}===${COLGREEN} generating mage file:${COLDEFAULT}"
653     echo "${dest}"
654 niro 191
655     install -d "$(dirname ${dest})"
656     # now build the mage file
657     > ${dest}
658    
659     # pgkname and state
660 niro 193 echo "PKGNAME=\"${PNAME}${target}-${PVER}-\${ARCH}-${PBUILD}\"" >> ${dest}
661 niro 191 echo "STATE=\"${STATE}\"" >> ${dest}
662    
663     # description and homepage
664     echo "DESCRIPTION=\"${DESCRIPTION}\"" >> ${dest}
665     echo "HOMEPAGE=\"${HOMEPAGE}\"" >> ${dest}
666    
667 niro 196 # special tags and vars
668 niro 191 echo "PKGTYPE=\"${PKGTYPE}\"" >> ${dest}
669 niro 214
670     # echo MAGE_TARGETS ## note -target is needed !
671     echo "MAGE_TARGETS=\"${target}\"" >> ${dest}
672    
673 niro 943 # split package base
674     echo "SPLIT_PACKAGE_BASE=\"${split_pkg_base}\"" >> ${dest}
675    
676 niro 197 # add special vars
677     if [ -n "${SPECIAL_VARS}" ]
678 niro 191 then
679     local i
680 niro 197 for i in ${SPECIAL_VARS}
681 niro 191 do
682 niro 197 # being tricky here :)
683     echo "${i}=\"$(eval echo \$${i})\"" >> ${dest}
684 niro 191 done
685     fi
686 niro 214
687 niro 197 # add at least all includes
688     if [ -n "${INHERITS}" ]
689 niro 196 then
690 niro 197 echo -n "minclude" >> ${dest}
691 niro 196 local i
692 niro 197 for i in ${INHERITS}
693 niro 196 do
694 niro 197 echo -n " ${i}" >> ${dest}
695 niro 196 done
696 niro 1351 # a CRLF is needed here!
697     echo >> ${dest}
698 niro 196 fi
699    
700 niro 191 # deps and provides
701 niro 193 echo "DEPEND=\"$(fix_mage_deps "${target}" "${DEPEND}")\"" >> ${dest}
702     echo "SDEPEND=\"$(fix_mage_deps "${target}" "${SDEPEND}")\"" >> ${dest}
703 niro 191 echo "PROVIDE=\"${PROVIDE}\"" >> ${dest}
704    
705     # add special functions
706     if [ -n "${SPECIAL_FUNCTIONS}" ]
707     then
708     local i
709     for i in ${SPECIAL_FUNCTIONS}
710     do
711     # add to mage (quotes needed !)
712     typeset -f "${i}" >> ${dest}
713     # unset to be safe (quotes needed !)
714 niro 192 #unset "${i}" <-- later to get every target built
715 niro 191 done
716     fi
717    
718     # pre|post-install|removes
719     typeset -f preinstall >> ${dest}
720     typeset -f postinstall >> ${dest}
721     typeset -f preremove >> ${dest}
722     typeset -f postremove >> ${dest}
723     }
724    
725     regen_mage_tree()
726     {
727 niro 1436 local subpackage
728 niro 191
729     # build them only if requested
730     if [[ ${REGEN_MAGE_TREE} = true ]]
731     then
732 niro 195 # run it without targets
733 niro 943 if [[ -n ${MAGE_TARGETS} ]]
734 niro 195 then
735 niro 943 # build for each target a mage file
736     # run it with several targets
737 niro 191 echo
738 niro 1436 for subpackage in ${MAGE_TARGETS}
739 niro 943 do
740 niro 1436 build_mage_script --target "${subpackage}"
741 niro 943 done
742 niro 191 echo
743 niro 195
744 niro 943 # run it for splitpackages
745     elif [[ -n ${SPLIT_PACKAGES} ]]
746     then
747     local split_pkg_base="${PNAME}"
748     # save smage environment
749     split_save_variables
750     # build for each subpackage a mage file
751 niro 195 # run it with several targets
752 niro 943 echo
753 niro 1436 for subpackage in ${SPLIT_PACKAGES}
754 niro 195 do
755 niro 943 # get the right variables for the split
756 niro 1436 export PNAME="${subpackage}"
757     split_info_${subpackage}
758     # get the preinstall etc
759     split_export_inherits ${subpackage}
760 niro 943 build_mage_script --split-pkg-base "${split_pkg_base}"
761 niro 1436 # delete split preinstall etc
762     split_delete_inherits ${subpackage}
763 niro 951 # restore smage environment
764     split_restore_variables
765 niro 195 done
766 niro 943 echo
767 niro 951 # unset all saved smage variables
768     split_unset_variables
769 niro 943
770     else
771     echo
772     build_mage_script
773     echo
774 niro 195 fi
775 niro 191 fi
776    
777     # now unset all uneeded vars to be safe
778 niro 192 # unset PKGNAME <-- don't do that; smage needs this var
779     # unset to be safe (quotes needed !)
780 niro 477 # for i in ${SPECIAL_FUNCTIONS}
781     # do
782     # unset "${i}"
783     # done
784 niro 192 unset SPECIAL_FUNCTIONS
785 niro 477 # for i in ${SPECIAL_VARS}
786     # do
787     # unset "${i}"
788     # done
789 niro 194 unset SPECIAL_VARS
790 niro 191 unset STATE
791     unset DESCRIPTION
792     unset HOMEPAGE
793     unset PKGTYPE
794     unset INHERITS
795     unset DEPEND
796     unset SDEPEND
797     unset PROVIDE
798     unset preinstall
799     unset postinstall
800     unset preremove
801     unset postremove
802     }
803    
804 niro 943 split_save_variables()
805     {
806     export SAVED_PNAME="${PNAME}"
807     export SAVED_PVER="${PVER}"
808     export SAVED_PBUILD="${PBUILD}"
809     export SAVED_PCATEGORIE="${PCATEGORIE}"
810     export SAVED_DESCRIPTION="${DESCRIPTION}"
811     export SAVED_HOMEPAGE="${HOMEPAGE}"
812     export SAVED_SPECIAL_VARS="${SPECIAL_VARS}"
813     export SAVED_STATE="${STATE}"
814     export SAVED_PKGTYPE="${PKGTYPE}"
815     export SAVED_INHERITS="${INHERITS}"
816     export SAVED_DEPEND="${DEPEND}"
817     export SAVED_SDEPEND="${SDEPEND}"
818     export SAVED_PROVIDE="${PROVIDE}"
819 niro 945 export SAVED_NOPKGBUILD="${NOPKGBUILD}"
820 niro 943
821 niro 945 # bindir too
822     export SAVED_BINDIR="${BINDIR}"
823    
824     # export the SPLIT_PACKAGE_BASE
825     export SPLIT_PACKAGE_BASE="${SAVED_PNAME}"
826    
827 niro 943 # functions
828     if [[ ! -z $(typeset -f preinstall) ]]
829     then
830     # rename the old one
831     local saved_preinstall
832     saved_preinstall=SAVED_$(typeset -f preinstall)
833     eval "${saved_preinstall}"
834     export -f SAVED_preinstall
835     fi
836    
837     if [[ ! -z $(typeset -f postinstall) ]]
838     then
839     # rename the old one
840     local saved_postinstall
841     saved_postinstall=SAVED_$(typeset -f postinstall)
842     eval "${saved_postinstall}"
843     export -f SAVED_postinstall
844     fi
845    
846     if [[ ! -z $(typeset -f preremove) ]]
847     then
848     # rename the old one
849     local saved_preremove
850     saved_preremove=SAVED_$(typeset -f preremove)
851     eval "${saved_preremove}"
852     export -f SAVED_preremove
853     fi
854    
855     if [[ ! -z $(typeset -f postremove) ]]
856     then
857     # rename the old one
858     local saved_postremove
859     saved_postremove=SAVED_$(typeset -f postremove)
860     eval "${saved_postremove}"
861     export -f SAVED_postremove
862     fi
863     }
864    
865     split_restore_variables()
866     {
867     export PNAME="${SAVED_PNAME}"
868     export PVER="${SAVED_PVER}"
869     export PBUILD="${SAVED_PBUILD}"
870     export PCATEGORIE="${SAVED_PCATEGORIE}"
871     export DESCRIPTION="${SAVED_DESCRIPTION}"
872     export HOMEPAGE="${SAVED_HOMEPAGE}"
873     export SPECIAL_VARS="${SAVED_SPECIAL_VARS}"
874     export STATE="${SAVED_STATE}"
875     export PKGTYPE="${SAVED_PKGTYPE}"
876     export INHERITS="${SAVED_INHERITS}"
877     export DEPEND="${SAVED_DEPEND}"
878     export SDEPEND="${SAVED_SDEPEND}"
879     export PROVIDE="${SAVED_PROVIDE}"
880 niro 945 export NOPKGBUILD="${SAVED_NOPKGBUILD}"
881 niro 943
882 niro 945 # bindir too
883     export BINDIR="${SAVED_BINDIR}"
884    
885 niro 943 # functions
886     if [[ ! -z $(typeset -f SAVED_preinstall) ]]
887     then
888     # rename the old one
889     local saved_preinstall
890     saved_preinstall=$(typeset -f SAVED_preinstall)
891     eval "${saved_preinstall/SAVED_/}"
892     export -f preinstall
893     fi
894    
895     if [[ ! -z $(typeset -f SAVED_postinstall) ]]
896     then
897     # rename the old one
898     local saved_postinstall
899     saved_postinstall=$(typeset -f SAVED_postinstall)
900     eval "${saved_postinstall/SAVED_/}"
901     export -f postinstall
902     fi
903    
904     if [[ ! -z $(typeset -f SAVED_preremove) ]]
905     then
906     # rename the old one
907     local saved_preremove
908     saved_preremove=$(typeset -f SAVED_preremove)
909     eval "${saved_preremove/SAVED_/}"
910     export -f preremove
911     fi
912    
913     if [[ ! -z $(typeset -f SAVED_postremove) ]]
914     then
915     # rename the old one
916     local saved_postremove
917     saved_postremove=$(typeset -f SAVED_postremove)
918     eval "${saved_postremove/SAVED_/}"
919     export -f postremove
920     fi
921 niro 951 }
922 niro 943
923 niro 951 split_unset_variables()
924     {
925 niro 943 # unset saved vars; not needed anymore
926     unset SAVED_PNAME
927     unset SAVED_PVER
928     unset SAVED_PBUILD
929     unset SAVED_PCATEGORIE
930     unset SAVED_DESCRIPTION
931     unset SAVED_HOMEPAGE
932     unset SAVED_SPECIAL_VARS
933     unset SAVED_STATE
934     unset SAVED_PKGTYPE
935     unset SAVED_INHERITS
936     unset SAVED_DEPEND
937     unset SAVED_SDEPEND
938     unset SAVED_PROVIDE
939 niro 945 unset SAVED_BINDIR
940     unset SAVED_NOPKGBUILD
941     unset SPLIT_PACKAGE_BASE
942 niro 943 unset -f SAVED_preinstall
943     unset -f SAVED_postinstall
944     unset -f SAVED_preremove
945     unset -f SAVED_postremove
946     }
947    
948 niro 1436 split_export_inherits()
949     {
950     local subpackage="$1"
951     local func
952     local newfunc
953    
954     for func in preinstall postinstall preremove postremove
955     do
956     if [[ ! -z $(typeset -f ${func}_${subpackage}) ]]
957     then
958     newfunc=$(typeset -f ${func}_${subpackage})
959     newfunc="${newfunc/_${subpackage} (/ (}"
960     eval "${newfunc}"
961     fi
962     done
963     }
964    
965     split_delete_inherits()
966     {
967     local subpackage="$1"
968     local func
969    
970     for func in preinstall postinstall preremove postremove
971     do
972     if [[ ! -z $(typeset -f ${func}_${subpackage}) ]]
973     then
974     unset -f ${func}
975     fi
976     done
977     }
978    
979 niro 253 export_inherits()
980     {
981     local include="$1"
982     shift
983    
984     while [ "$1" ]
985     do
986     local functions="$1"
987    
988     # sanity checks
989     [ -z "${include}" ] && die "export_inherits(): \$include not given."
990     [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
991    
992     eval "${functions}() { ${include}_${functions} ; }"
993    
994     # debug
995     [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"
996    
997     shift
998     done
999     }
1000    
1001 niro 255 generate_package_md5sum()
1002     {
1003     local dest
1004     local pcat
1005     local pname
1006     local pver
1007     local pbuild
1008     local parch
1009     local target
1010     local pkgname
1011    
1012     # very basic getops
1013     for i in $*
1014     do
1015     case $1 in
1016     --pcat|-c) shift; pcat="$1" ;;
1017     --pname|-n) shift; pname="$1" ;;
1018     --pver|-v) shift; pver="$1" ;;
1019     --pbuild|-b) shift; pbuild="$1" ;;
1020     --parch|a) shift; parch="$1" ;;
1021     --target|t) shift; target="$1" ;;
1022     esac
1023     shift
1024     done
1025    
1026     # sanity checks; abort if not given
1027     [ -z "${pcat}" ] && die "generate_package_md5sum() \$pcat not given."
1028     [ -z "${pname}" ] && die "generate_package_md5sum() \$pname not given."
1029     [ -z "${pver}" ] && die "generate_package_md5sum() \$pver not given."
1030     [ -z "${pbuild}" ] && die "generate_package_md5sum() \$pbuild not given."
1031     [ -z "${parch}" ] && die "generate_package_md5sum() \$parch not given."
1032    
1033     # check needed global vars
1034     [ -z "${PKGDIR}" ] && die "generate_package_md5sum() \$PKGDIR not set."
1035     [ -z "${PKGSUFFIX}" ] && die "generate_package_md5sum() \$PKGSUFFIX not set."
1036    
1037     # fix target as it may be empty !
1038     [ -n "${target}" ] && target="-${target}"
1039    
1040 niro 890
1041 niro 255 # build pkgname
1042     pkgname="${pname}${target}-${pver}-${parch}-${pbuild}"
1043    
1044     # build pkg-md5-sum only if requested
1045     if [[ ${REGEN_MAGE_TREE} = true ]]
1046     then
1047 niro 439 echo -ne "${COLBLUE}===${COLGREEN} generating md5's for ${pkgname}.${PKGSUFFIX} ... ${COLDEFAULT}"
1048 niro 255
1049     # abort if not exist
1050     if [ ! -f ${PKGDIR}/${pkgname}.${PKGSUFFIX} ]
1051     then
1052 niro 439 echo -e "${COLRED}! exists${COLDEFAULT}"
1053 niro 255 return 0
1054     fi
1055    
1056     # if MAGE_TREE_DEST not set use BUILDDIR
1057     : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
1058    
1059     # setup md5 dir
1060 niro 891 dest="${MAGE_TREE_DEST}/${pcat}/${pname}${target}/md5"
1061 niro 255 install -d ${dest}
1062    
1063     # gen md5sum
1064     ( cd ${PKGDIR}; md5sum "${pkgname}.${PKGSUFFIX}" ) \
1065 niro 256 > ${dest}/${pkgname}.md5
1066 niro 439 echo -e "${COLGREEN}done${COLDEFAULT}"
1067 niro 255 fi
1068     }
1069    
1070 niro 403 source_pkg_build()
1071     {
1072     if [[ ${PKGTYPE} = virtual ]]
1073     then
1074     echo "Virtual package detected; src-pkg-tarball not necessary ..."
1075     return 0
1076     fi
1077    
1078     if [[ ! -d ${SOURCEDIR}/${PNAME} ]]
1079     then
1080     echo "No SRC_URI defined; src-pkg-tarball not necessary ..."
1081     return 0
1082     fi
1083    
1084 niro 419 [ -z "${SRCPKGDIR}" ] && die "\$SRCPKGDIR not found. Please setup your ${MAGERC} correctly."
1085 niro 406
1086 niro 403 echo -e "${COLGREEN}Creating source package tarball ... ${COLDEFAULT}"
1087 niro 412
1088     # include the smage2 file
1089     cp ${SMAGENAME} ${SOURCEDIR}/${PNAME}
1090    
1091 niro 403 ( cd ${SOURCEDIR}; tar cvjf ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${PNAME}; )
1092 niro 406 [[ ! -d ${SRCPKGDIR} ]] && install -d ${SRCPKGDIR}
1093     mv ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${SRCPKGDIR}/${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX}
1094 niro 403
1095     echo -e "${COLGREEN}Source package ${COLBLUE}${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX} ${COLGREEN}successfully builded.${COLDEFAULT}"
1096     }
1097    
1098 niro 859 step_by_step()
1099     {
1100     if [[ ${STEP_BY_STEP} = true ]]
1101     then
1102 niro 945 echo -e "${COLRED}Step-by-step enabled! Paused after $1.${COLDEFAULT}"
1103 niro 859 echo "Press [enter] to continue"
1104     read
1105     fi
1106     }
1107 niro 403
1108 niro 859
1109 niro 59 # print out our version
1110     showversion
1111     echo
1112    
1113 niro 24 if [ -z "$1" ]
1114     then
1115     echo "No .smage2 file given. Exiting."
1116     echo
1117     exit 1
1118     fi
1119    
1120 niro 192 # updating smage2-scripts
1121 niro 306 if [[ $1 = update ]]
1122 niro 24 then
1123 niro 59 if [ ! -d ${SOURCEDIR} ]
1124     then
1125     install -d ${SOURCEDIR}
1126     fi
1127     syncsmage2
1128     exit 0
1129     fi
1130    
1131 niro 192 # creates md5sums for smages to given dir
1132 niro 306 if [[ $1 = calcmd5 ]]
1133 niro 59 then
1134 niro 1207 if [ $# -ge 2 ]
1135 niro 59 then
1136     SMAGENAME="$2"
1137     MD5DIR="$3"
1138 niro 1207 [[ -z ${MD5DIR} ]] && MD5DIR="$(dirname ${SMAGENAME})/md5"
1139    
1140 niro 1346 smagesource ${SMAGENAME} || die "download source failed"
1141 niro 59
1142 niro 66 # overridable sourcedir; must be declared after source of the smage2
1143     CALC_SOURCEDIR="${CALC_SOURCEDIR:="${SOURCEDIR}/${PNAME}"}"
1144    
1145 niro 59 [ -z "${SRC_URI}" ] && die "Nothing declared to calculate."
1146    
1147     # end of array
1148     EOA=${#SRC_URI[*]}
1149    
1150     [ ! -d ${MD5DIR} ] && install -d ${MD5DIR}
1151    
1152     # clear md5sum file
1153     MY_MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5"
1154     echo -n > ${MY_MD5_FILE}
1155    
1156     for ((i=0; i < EOA; i++))
1157     do
1158 niro 66 # url to file
1159     my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)"
1160    
1161     # subdir in sources dir; the my_SRCI_URI file goes to there
1162     my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)"
1163    
1164     # if my_src_uri_dest is not equal my_src_uri; than an other dir is used
1165     if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]]
1166     then
1167     MY_SRC_FILE="${my_SRC_URI_DEST}/$(basename ${SRC_URI[${i}]})"
1168     else
1169     MY_SRC_FILE="$(basename ${SRC_URI[${i}]})"
1170     fi
1171    
1172 niro 59 if [ -e "${CALC_SOURCEDIR}/${MY_SRC_FILE}" ]
1173     then
1174     echo "calculating $(basename ${MY_SRC_FILE}) ..."
1175     ( cd ${CALC_SOURCEDIR}; md5sum "${MY_SRC_FILE}" ) >> ${MY_MD5_FILE}
1176     else
1177     echo "WARNING: File '$(basename ${MY_SRC_FILE}) not found in ${CALC_SOURCEDIR}."
1178     fi
1179 niro 66
1180     # unset them to be shure
1181     unset my_SRC_URI
1182     unset my_SRC_URI_DEST
1183     unset my_SRC_URI_MIRROR
1184     unset my_SOURCEDIR
1185 niro 59 done
1186 niro 306
1187 niro 59 echo
1188     echo "Calculating of md5 sums for '$(basename ${SMAGENAME} .${SMAGESUFFIX})' done."
1189     echo
1190     else
1191     echo "Usage: Calculating MD5 Sums:"
1192 niro 1207 echo " $(basename $0) calcmd5 /path/to/SMAGENAME [/path/to/MD5DIR]"
1193 niro 59 echo
1194     echo
1195     echo "Export the CALC_SOURCEDIR variable to override current SOURCEDIRs."
1196     echo
1197     exit 1
1198     fi
1199 niro 306
1200 niro 59 exit 0
1201     fi
1202    
1203 niro 192 # download sources
1204 niro 59 if [ "$1" == "download" -a -n "$2" ]
1205     then
1206 niro 24 if [ ! -d ${SMAGESCRIPTSDIR} ]
1207     then
1208     install -d ${SMAGESCRIPTSDIR}
1209     fi
1210 niro 59
1211     # get smage
1212     SMAGENAME="$2"
1213     MD5DIR="$(dirname ${SMAGENAME})/md5"
1214 niro 1346 smagesource ${SMAGENAME} || die "download source failed"
1215 niro 59
1216     download_sources
1217 niro 24 exit 0
1218     fi
1219    
1220 niro 202 # regen-mage-tree
1221     if [ "$1" == "only-regen-tree" -a -n "$2" ]
1222     then
1223     # set correct SMAGENAME
1224     SMAGENAME="$2"
1225     MD5DIR="$(dirname ${SMAGENAME})/md5"
1226 niro 1346 smagesource ${SMAGENAME} || die "regen: smage2 not found"
1227 niro 202
1228     regen_mage_tree
1229 niro 255
1230 niro 890 # build several targets
1231 niro 943 if [[ -n ${MAGE_TARGETS} ]]
1232 niro 890 then
1233     for target in ${MAGE_TARGETS}
1234     do
1235     # build md5sum for existing packages
1236     generate_package_md5sum \
1237     --pcat "${PCATEGORIE}" \
1238     --pname "${PNAME}" \
1239     --pver "${PVER}" \
1240     --pbuild "${PBUILD}" \
1241     --parch "${ARCH}" \
1242     --target "${target}"
1243     done
1244 niro 943
1245     # build several subpackages
1246     elif [[ -n ${SPLIT_PACKAGES} ]]
1247     then
1248     split_save_variables
1249 niro 964 for subpackage in ${SPLIT_PACKAGES}
1250 niro 943 do
1251     # get the right variables for the split
1252     export PNAME="${subpackage}"
1253     split_info_${subpackage}
1254     # build md5sum for existing packages
1255     generate_package_md5sum \
1256     --pcat "${PCATEGORIE}" \
1257     --pname "${PNAME}" \
1258     --pver "${PVER}" \
1259     --pbuild "${PBUILD}" \
1260     --parch "${ARCH}"
1261 niro 951 # restore smage environment
1262     split_restore_variables
1263 niro 943 done
1264 niro 951 # unset all saved smage variables
1265     split_unset_variables
1266 niro 943
1267 niro 890 else
1268     # build md5sum for existing packages
1269     generate_package_md5sum \
1270     --pcat "${PCATEGORIE}" \
1271     --pname "${PNAME}" \
1272     --pver "${PVER}" \
1273     --pbuild "${PBUILD}" \
1274 niro 943 --parch "${ARCH}"
1275 niro 890 fi
1276 niro 255
1277 niro 202 exit 0
1278     fi
1279    
1280 niro 412 if [ "$1" == "--create-src-tarball" -a -n "$2" ]
1281 niro 403 then
1282     # set correct SMAGENAME
1283     SMAGENAME="$2"
1284     MD5DIR="$(dirname ${SMAGENAME})/md5"
1285    
1286 niro 412 echo -e "${COLGREEN}create-src-tarball called for ${COLBLUE}${SMAGENAME}${COLGREEN} ...${COLDEFAULT}"
1287 niro 403
1288 niro 1346 smagesource ${SMAGENAME} || die "regen: smage2 not found"
1289 niro 403
1290     if [[ -d ${SOURCEDIR}/${PNAME} ]]
1291     then
1292     echo -e "${COLGREEN}Deleting old sourcefiles ${COLBLUE}${SOURCEDIR}/${PNAME}${COLGREEN} ...${COLDEFAULT}"
1293     rm -rf ${SOURCEDIR}/${PKGNAME}
1294     fi
1295    
1296     download_sources
1297     source_pkg_build ${SMAGENAME}
1298     exit 0
1299     fi
1300    
1301 niro 406 if [ "$1" == "--src-tarball" -a -n "$2" ] || [ "$1" == "-st" -a -n "$2" ]
1302 niro 403 then
1303 niro 412 SRCPKGTARBALL="${2}"
1304 niro 403 USE_SRC_PKG_TARBALL=true
1305    
1306 niro 412 # abort if given file is not a source pkg
1307     [[ ${SRCPKGTARBALL##*.} != ${SRCPKGSUFFIX} ]] && die "${SRCPKGTARBALL} is not a valid src-pkg file."
1308    
1309     # set correct SMAGENAME; use the one that the src_pkg provide
1310     # /path/to/SOURCEDIR/PNAME/SMAGENAME
1311     SMAGENAME="${SOURCEDIR}/$(basename ${SRCPKGTARBALL%-*-*})/$(basename ${SRCPKGTARBALL} .${SRCPKGSUFFIX}).${SMAGESUFFIX}"
1312    
1313 niro 403 echo -e "${COLGREEN}Using src-tarball ${COLBLUE}${SRCPKGTARBALL}${COLGREEN} ...${COLDEFAULT}"
1314    
1315     [[ ! -d ${SOURCEDIR} ]] && install -d ${SOURCEDIR}
1316    
1317     # unpack srctarball
1318     [[ ! -f ${SRCPKGTARBALL} ]] && die "Error: ${SRCPKGTARBALL} does not exist. Aborting."
1319    
1320     tar xvjf ${SRCPKGTARBALL} -C ${SOURCEDIR} || die "Error unpackung src-tarball ${SRCPKGTARBALL}"
1321 niro 412
1322     [[ ! -f ${SMAGENAME} ]] && die "Included smage2 file in src-tarball not found: ${SMAGENAME}"
1323 niro 403 fi
1324    
1325    
1326 niro 306 [ ! -e ${MLIBDIR}/pkgbuild_dir.sh ] && die "Error: ${MLIBDIR}/pkgbuild_dir.sh not found. Aborting."
1327     [ -z "$(basename ${SMAGENAME} | grep .${SMAGESUFFIX})" ] &&
1328     die "File '$(basename ${SMAGENAME})' is not a sMage v${SMAGEVERSION} file. Aborting."
1329 niro 419 [ -z "${SOURCEDIR}" ] && die "\$SOURCEDIR not found. Please setup your ${MAGERC} correctly."
1330     [ -z "${SMAGESCRIPTSDIR}" ] && die "\$SMAGESCRIPTSDIR not found. Please setup your ${MAGERC} correctly."
1331     [ -z "${SMAGE2RSYNC}" ] && die "\$SMAGE2RSYNC not found. Please setup your ${MAGERC} correctly."
1332     [ -z "${BINDIR}" ] && die "no BINDIR variable found in ${MAGERC}"
1333     [ -z "${CHOST}" ] && die "no CHOST variable found in ${MAGERC}"
1334     [ -z "${CFLAGS}" ] && die "no CFLAGS variable found in ${MAGERC}"
1335     [ -z "${CXXFLAGS}" ] && die "no CXXFLAGS variable found in ${MAGERC}"
1336 niro 24
1337 niro 1346 smagesource ${SMAGENAME} || die "source failed"
1338 niro 255 PKGNAME="${PNAME}-${PVER}-${ARCH}-${PBUILD}"
1339 niro 59 MD5DIR="$(dirname ${SMAGENAME})/md5"
1340 niro 941 SMAGE_LOG_CMD="tee -a /var/log/smage/${PKGNAME}.log"
1341 niro 24
1342     xtitle "Compiling ${PKGNAME}"
1343 niro 439 echo -e "${COLGREEN}Compiling ${PKGNAME}${COLDEFAULT}"
1344 niro 59
1345 niro 191 # auto regen mage tree if requested
1346     regen_mage_tree
1347    
1348 niro 403 if [[ ${CREATE_SRC_PKG_TARBALL} = true ]]
1349     then
1350     if [[ -d ${SOURCEDIR}/${PNAME} ]]
1351     then
1352 niro 441 echo -e "${COLBLUE}===${COLGREEN} deleting old sourcefiles ${COLBLUE}${SOURCEDIR}/${PNAME}${COLGREEN} ...${COLDEFAULT}"
1353 niro 408 rm -rf ${SOURCEDIR}/${PNAME}
1354 niro 403 fi
1355     fi
1356    
1357 niro 192 # download sources
1358 niro 403 [[ ${USE_SRC_PKG_TARBALL} != true ]] && download_sources
1359 niro 59
1360 niro 192 # fixes some issues with these functions
1361 niro 24 export -f src_prepare || die "src_prepare export failed"
1362     export -f src_compile || die "src_compile export failed"
1363 niro 1575 export -f src_check || die "src_check export failed"
1364 niro 24 export -f src_install || die "src_install export failed"
1365    
1366 niro 192 # fixes some compile issues
1367 niro 24 export CHOST="${CHOST}" || die "CHOST export failed"
1368     export CFLAGS="${CFLAGS}" || die "CFLAGS export failed"
1369     export CXXFLAGS="${CFLAGS}" || die "CXXFLAGS export failed"
1370     export BINDIR="${BINDIR}" || die "BINDIR export failed"
1371     export MAKEOPTS="${MAKEOPTS}" || die "MAKEOPTS export failed"
1372    
1373    
1374 niro 192 # setup distcc
1375 niro 351 # setup for distcc goes *before* ccache, so ccache comes before distcc in path
1376 niro 306 [[ ${SMAGE_USE_DISTCC} = true ]] && setup_distcc_environment
1377 niro 24
1378 niro 192 # setup ccache
1379 niro 306 [[ ${SMAGE_USE_CCACHE} = true ]] && setup_ccache_environment
1380 niro 24
1381 niro 1573 # clean up builddir if a previously one exist
1382 niro 24 if [ -d ${BUILDDIR} ]
1383     then
1384     rm -rf ${BUILDDIR}/* || die "couldn't cleanup \$BUILDDIR."
1385     fi
1386     install -d ${BUILDDIR} || die "couldn't create \$BUILDDIR."
1387    
1388 niro 1573 # clean up srcdir if a previously unpacked one exist
1389 niro 24 if [ -d ${SRCDIR} ]
1390     then
1391     rm -rf ${SRCDIR}
1392     fi
1393    
1394 niro 1573 # clean up bindir if a previous build exist or create a new one
1395 niro 24 if [ -d ${BINDIR} ]
1396     then
1397     rm -rf ${BINDIR}
1398     fi
1399     install -d ${BINDIR} || die "couldn't create \$BINDIR."
1400    
1401 niro 1579 # clean up package temp dir if a previous build exist
1402 niro 24 if [ -d ${BUILDDIR}/${PKGNAME} ]
1403     then
1404     rm -rf ${BUILDDIR}/${PKGNAME}
1405     fi
1406    
1407 niro 1573 # setup build logging
1408 niro 875 [[ ! -d /var/log/smage ]] && install -d /var/log/smage
1409     echo -e "### Build started on $(date) ###\n" > /var/log/smage/${PKGNAME}.log
1410    
1411 niro 941 src_prepare | ${SMAGE_LOG_CMD}
1412     die_pipestatus 0 "src_prepare failed"
1413 niro 859 step_by_step $_
1414 niro 941
1415     src_compile | ${SMAGE_LOG_CMD}
1416     die_pipestatus 0 "src_compile failed"
1417 niro 859 step_by_step $_
1418 niro 941
1419 niro 1575 # only run checks if requested
1420     if [[ ${MAGE_CHECK} != true ]]
1421     then
1422     echo "MAGE_CHECK not requested; src_check() will not be run!" | ${SMAGE_LOG_CMD}
1423     step_by_step src_check
1424     else
1425     src_check | ${SMAGE_LOG_CMD}
1426     die_pipestatus 0 "src_check failed"
1427     step_by_step $_
1428     fi
1429    
1430 niro 943 # build several subpackages
1431     if [[ -n ${SPLIT_PACKAGES} ]]
1432     then
1433 niro 945 # save bindir & pname
1434     split_save_variables
1435 niro 943 export SAVED_BINDIR="${BINDIR}"
1436     for subpackage in ${SPLIT_PACKAGES}
1437     do
1438     if typeset -f src_install_${subpackage} > /dev/null
1439     then
1440     # export subpackage bindir
1441     export BINDIR="${SAVED_BINDIR}_${subpackage}"
1442 niro 945 # export PNAME, several internal function and include
1443     # rely on this variable
1444     export PNAME="${subpackage}"
1445    
1446     echo
1447     echo -en "${COLBLUE}*** ${COLDEFAULT}"
1448     echo -en " Running ${COLGREEN}split src_install()${COLDEFAULT}"
1449     echo -en " for subpkg: ${COLBLUE}${PNAME}${COLDEFAULT}"
1450     echo -e " - basepkg: ${COLBLUE}${SPLIT_PACKAGE_BASE}${COLDEFAULT} ..."
1451    
1452 niro 943 src_install_${subpackage} | ${SMAGE_LOG_CMD}
1453     die_pipestatus 0 "src_install_${subpackage} failed"
1454     step_by_step $_
1455     fi
1456     done
1457 niro 945 # restore bindir & pname
1458     split_restore_variables
1459 niro 951 # unset all saved smage variables
1460     split_unset_variables
1461 niro 943 else
1462     src_install | ${SMAGE_LOG_CMD}
1463     die_pipestatus 0 "src_install failed"
1464     step_by_step $_
1465     fi
1466 niro 24
1467 niro 192 # compressing doc, info & man files
1468 niro 943 if [[ -n ${SPLIT_PACKAGES} ]]
1469 niro 24 then
1470 niro 964 for subpackage in ${SPLIT_PACKAGES}
1471 niro 943 do
1472     mcompressdocs ${BINDIR}_${subpackage}
1473     done
1474     else
1475     mcompressdocs ${BINDIR}
1476 niro 24 fi
1477    
1478 niro 1580 if [[ ${SMAGE_STRIP_LIBTOOL} = true ]]
1479     then
1480     if [[ -n ${SPLIT_PACKAGES} ]]
1481     then
1482     for subpackage in ${SPLIT_PACKAGES}
1483     do
1484     echo -e "${COLBLUE}===${COLGREEN} stripping libtool archives for '${subpackage}' ...${COLDEFAULT}"
1485     mstriplibtoolarchive ${BINDIR}_${subpackage}
1486     done
1487     else
1488     echo -e "${COLBLUE}===${COLGREEN} stripping libtool archives ...${COLDEFAULT}"
1489     mstriplibtoolarchive ${BINDIR}
1490     fi
1491     fi
1492 niro 24
1493 niro 1580 if [[ ${SMAGE_PURGE} = true ]]
1494     then
1495     if [[ -n ${SPLIT_PACKAGES} ]]
1496     then
1497     for subpackage in ${SPLIT_PACKAGES}
1498     do
1499     echo -e "${COLBLUE}===${COLGREEN} purging all purge targets in '${subpackage}' ...${COLDEFAULT}"
1500     mpurgetargets ${BINDIR}_${subpackage}
1501     done
1502     else
1503     echo -e "${COLBLUE}===${COLGREEN} purging all purge targets ...${COLDEFAULT}"
1504     mpurgetargets ${BINDIR}
1505     fi
1506     fi
1507    
1508 niro 79 # stripping all bins and libs
1509     case ${NOSTRIP} in
1510     true|TRUE|yes|y)
1511     echo -e "NOSTRIP=true detected; Package will not be stripped ..."
1512     ;;
1513     *)
1514 niro 943 if [[ -n ${SPLIT_PACKAGES} ]]
1515     then
1516 niro 964 for subpackage in ${SPLIT_PACKAGES}
1517 niro 943 do
1518 niro 1082 echo -e "${COLBLUE}===${COLGREEN} stripping binaries for '${subpackage}' ...${COLDEFAULT}"
1519 niro 943 mstripbins ${BINDIR}_${subpackage}
1520 niro 1543 echo -e "${COLBLUE}===${COLGREEN} stripping dynamic libraries for '${subpackage}' ...${COLDEFAULT}"
1521 niro 943 mstriplibs ${BINDIR}_${subpackage}
1522 niro 1543 echo -e "${COLBLUE}===${COLGREEN} stripping static libraries for '${subpackage}' ...${COLDEFAULT}"
1523     mstripstatic ${BINDIR}_${subpackage}
1524 niro 943 done
1525     else
1526     echo -e "${COLBLUE}===${COLGREEN} stripping binaries ...${COLDEFAULT}"
1527     mstripbins ${BINDIR}
1528 niro 1543 echo -e "${COLBLUE}===${COLGREEN} stripping dynamic libraries ...${COLDEFAULT}"
1529 niro 943 mstriplibs ${BINDIR}
1530 niro 1543 echo -e "${COLBLUE}===${COLGREEN} stripping static libraries ...${COLDEFAULT}"
1531     mstripstatic ${BINDIR}
1532 niro 943 fi
1533 niro 79 ;;
1534     esac
1535    
1536 niro 192 # the new buildpkg command
1537 niro 24 case ${NOPKGBUILD} in
1538     true|TRUE|yes|y)
1539     echo -e "NOPGKBUILD=true detected; Package will not be build ..."
1540     ;;
1541 niro 192 *)
1542 niro 306 # build several targets
1543 niro 943 if [[ -n ${MAGE_TARGETS} ]]
1544 niro 192 then
1545     for target in ${MAGE_TARGETS}
1546     do
1547 niro 1573 # check if a special target_pkgbuild exists
1548 niro 192 if typeset -f ${target}_pkgbuild > /dev/null
1549     then
1550     # run it
1551     ${target}_pkgbuild
1552     fi
1553     # now create the target package
1554     ${MLIBDIR}/pkgbuild_dir.sh \
1555 niro 255 "${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD}" \
1556 niro 192 ${BINDIR} || die "target: ${target} package-build failed"
1557 niro 255
1558     # build pkg-md5-sum if requested
1559     generate_package_md5sum \
1560     --pcat "${PCATEGORIE}" \
1561     --pname "${PNAME}" \
1562     --pver "${PVER}" \
1563     --pbuild "${PBUILD}" \
1564     --parch "${ARCH}" \
1565     --target "${target}"
1566    
1567 niro 439 echo -e "${COLGREEN}\nPackage ${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n${COLDEFAULT}"
1568 niro 192 done
1569 niro 943
1570     # build several subpackages
1571     elif [[ -n ${SPLIT_PACKAGES} ]]
1572     then
1573     split_save_variables
1574     for subpackage in ${SPLIT_PACKAGES}
1575     do
1576     # get the right variables for the split
1577     export PNAME="${subpackage}"
1578     split_info_${PNAME}
1579    
1580 niro 947 # jump to next one if NOPKGBUILD is set in split_info
1581     case ${NOPKGBUILD} in
1582     true|TRUE|yes|y) continue ;;
1583     esac
1584    
1585 niro 943 # check if an special subpackage_pkgbuild exists
1586     if typeset -f ${PNAME}_pkgbuild > /dev/null
1587     then
1588     # run it
1589     ${PNAME}_pkgbuild
1590     fi
1591     # now create the target package
1592     ${MLIBDIR}/pkgbuild_dir.sh \
1593     "${PNAME}-${PVER}-${ARCH}-${PBUILD}" \
1594     "${BINDIR}_${PNAME}" || die "split_package: ${PNAME} package-build failed"
1595    
1596     # build pkg-md5-sum if requested
1597     generate_package_md5sum \
1598     --pcat "${PCATEGORIE}" \
1599     --pname "${PNAME}" \
1600     --pver "${PVER}" \
1601     --pbuild "${PBUILD}" \
1602     --parch "${ARCH}"
1603    
1604     echo -e "${COLGREEN}\nPackage ${PNAME}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n${COLDEFAULT}"
1605 niro 951
1606     # restore smage environment
1607     split_restore_variables
1608 niro 943 done
1609 niro 951 # unset all saved smage variables
1610     split_unset_variables
1611 niro 943
1612 niro 192 else
1613     ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed"
1614 niro 255
1615     # build pkg-md5-sum if requested
1616     generate_package_md5sum \
1617     --pcat "${PCATEGORIE}" \
1618     --pname "${PNAME}" \
1619     --pver "${PVER}" \
1620     --pbuild "${PBUILD}" \
1621     --parch "${ARCH}"
1622    
1623 niro 439 echo -e "${COLGREEN}\nPackage ${PKGNAME} successfully builded.\n${COLDEFAULT}"
1624 niro 192 fi
1625 niro 403
1626     # build src-pkg-tarball if requested
1627     [[ ${CREATE_SRC_PKG_TARBALL} = true ]] && source_pkg_build ${SMAGENAME}
1628 niro 24 ;;
1629     esac
1630    
1631 niro 875 if [[ ${SMAGE_BUILD_LOGGING} != false ]]
1632     then
1633     bzip2 -9f /var/log/smage/${PKGNAME}.log
1634     else
1635     [[ -f /var/log/smage/${PKGNAME}.log ]] && rm /var/log/smage/${PKGNAME}.log
1636     fi
1637    
1638 niro 192 # for sure
1639 niro 24 unset NOPKGBUILD
1640 niro 85 unset NOSTRIP
1641 niro 351
1642 niro 24 xtitleclean

Properties

Name Value
svn:executable *