Magellan Linux

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

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

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

Legend:
Removed from v.24  
changed lines
  Added in v.1640