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