Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.196  
changed lines
  Added in v.1630