3 # Generic package build script
5 # $Id: generic-build-script,v 1.47 2006/02/01 14:01:14 igor Exp $
7 # Package maintainers: if the original source is not distributed as a
8 # (possibly compressed) tarball, set the value of ${src_orig_pkg_name},
9 # and redefine the unpack() helper function appropriately.
10 # Also, if the Makefile rule to run the test suite is not "check", change
11 # the definition of ${test_rule} below.
13 # find out where the build script is located
14 tdir=`echo "$0" | sed 's%[\\/][^\\/][^\\/]*$%%'`
15 test "x$tdir" = "x$0" && tdir=.
16 scriptdir=`cd $tdir; pwd`
18 # If scriptdir ends in SPECS, then topdir is $scriptdir/..
19 # If scriptdir ends in CYGWIN-PATCHES, then topdir is $scriptdir/../..
20 # Otherwise, we assume that topdir = scriptdir
21 topdir1=`echo ${scriptdir} | sed 's%/SPECS$%%'`
22 topdir2=`echo ${scriptdir} | sed 's%/CYGWIN-PATCHES$%%'`
23 if [ "x$topdir1" != "x$scriptdir" ] ; then # SPECS
24 topdir=`cd ${scriptdir}/..; pwd`
26 if [ "x$topdir2" != "x$scriptdir" ] ; then # CYGWIN-PATCHES
27 topdir=`cd ${scriptdir}/../..; pwd`
29 topdir=`cd ${scriptdir}; pwd`
33 tscriptname=`basename $0 .sh`
34 export PKG=`echo $tscriptname | sed -e 's/\-[^\-]*\-[^\-]*$//'`
35 export VER=`echo $tscriptname | sed -e "s/${PKG}\-//" -e 's/\-[^\-]*$//'`
36 export REL=`echo $tscriptname | sed -e "s/${PKG}\-${VER}\-//"`
37 # BASEPKG refers to the upstream base package
38 # SHORTPKG refers to the Cygwin package
39 # Normally, these are identical, but if the Cygwin package name is different
40 # from the upstream package name, you will want to redefine BASEPKG.
41 # Example: For Apache 2, BASEPKG=httpd-2.x.xx but SHORTPKG=apache2-2.x.xx
42 export BASEPKG=${PKG}-${VER}
43 export SHORTPKG=${PKG}-${VER}
44 export FULLPKG=${SHORTPKG}-${REL}
46 # determine correct decompression option and tarball filename
47 export src_orig_pkg_name=
48 if [ -e "${src_orig_pkg_name}" ] ; then
49 export opt_decomp=? # Make sure tar punts if unpack() is not redefined
50 elif [ -e ${BASEPKG}.tar.bz2 ] ; then
52 export src_orig_pkg_name=${BASEPKG}.tar.bz2
53 elif [ -e ${BASEPKG}.tar.gz ] ; then
55 export src_orig_pkg_name=${BASEPKG}.tar.gz
56 elif [ -e ${BASEPKG}.tgz ] ; then
58 export src_orig_pkg_name=${BASEPKG}.tgz
59 elif [ -e ${BASEPKG}.tar ] ; then
61 export src_orig_pkg_name=${BASEPKG}.tar
63 echo "Cannot find PKG:${PKG} VER:${VER} REL:${REL}. Rename $0 to"
64 echo "something more appropriate, and try again."
68 export src_orig_pkg=${topdir}/${src_orig_pkg_name}
70 # determine correct names for generated files
71 export src_pkg_name=${FULLPKG}-src.tar.bz2
72 export src_patch_name=${FULLPKG}.patch
73 export bin_pkg_name=${FULLPKG}.tar.bz2
74 export log_pkg_name=${FULLPKG}-BUILDLOGS.tar.bz2
76 export configurelogname=${FULLPKG}-CONFIGURE.LOG
77 export makelogname=${FULLPKG}-MAKE.LOG
78 export checklogname=${FULLPKG}-CHECK.LOG
79 export installlogname=${FULLPKG}-INSTALL.LOG
81 export src_pkg=${topdir}/${src_pkg_name}
82 export src_patch=${topdir}/${src_patch_name}
83 export bin_pkg=${topdir}/${bin_pkg_name}
84 export srcdir=${topdir}/${BASEPKG}
85 export objdir=${srcdir}/.build
86 export instdir=${srcdir}/.inst
87 export srcinstdir=${srcdir}/.sinst
88 export buildlogdir=${srcdir}/.buildlogs
89 export configurelogfile=${srcinstdir}/${configurelogname}
90 export makelogfile=${srcinstdir}/${makelogname}
91 export checklogfile=${srcinstdir}/${checklogname}
92 export installlogfile=${srcinstdir}/${installlogname}
97 if [ -z "$MY_CFLAGS" ]; then
100 if [ -z "$MY_LDFLAGS" ]; then
104 export install_docs="\
131 export install_docs="`for i in ${install_docs}; do echo $i; done | sort -u`"
132 export test_rule=check
133 if [ -z "$SIG" ]; then
134 export SIG=0 # set to 1 to turn on signing by default
136 # Sort in POSIX order.
144 This is the cygwin packaging script for ${FULLPKG}.
145 Usage: $0 [<option>...] <action>...
147 help, --help Print this message
148 version, --version Print the version message
149 with_logs, --logs Create logs of remaining steps
151 prep Unpack and patch into ${srcdir}
152 mkdirs Make hidden directories needed during build
153 conf, configure Configure the package (./configure)
154 reconf Rerun configure
155 build, make Build the package (make)
156 check, test Run the testsuite (make ${test_rule})
157 clean Remove built files (make clean)
158 install Install package to staging area (make install)
159 list List package contents
160 depend List package dependencies
161 strip Strip package executables
162 pkg, package Prepare the binary package ${bin_pkg_name}
163 mkpatch Prepare the patch file ${src_patch_name}
164 acceptpatch Copy patch file ${src_patch_name} to ${topdir}
165 spkg, src-package Prepare the source package ${src_pkg_name}
166 finish Remove source directory ${srcdir}
167 checksig Validate GPG signatures (requires gpg)
168 first Full run for spkg (mkdirs, spkg, finish)
169 almostall Full run for bin pkg, except for finish
170 all Full run for bin pkg
174 # Provide version of generic-build-script modified to make this script.
176 vers=`echo '$Revision: 1.47 $' | sed -e 's/Revision: //' -e 's/ *\\$//g'`
177 echo "$0 based on generic-build-script $vers"
180 # Unpacks the original package source archive into ./${BASEPKG}/.
181 # Change this if the original package was not tarred
182 # or if it doesn't unpack to a correct directory.
184 tar xv${opt_decomp}f "$1"
187 # Make the hidden directories used by this script.
190 rm -fr ${objdir} ${instdir} ${srcinstdir} && \
191 mkdir -p ${objdir} && \
192 mkdir -p ${instdir} && \
193 mkdir -p ${srcinstdir} )
198 rm -fr ${buildlogdir} && \
199 mkdir -p ${buildlogdir} )
202 # Unpack the original tarball, and get everything set up for this script.
205 unpack ${src_orig_pkg} && \
207 if [ -f ${src_patch} ] ; then \
208 patch -Z -p0 < ${src_patch} ;\
215 if [ -f ${topdir}/${log_pkg_name} ] ; then \
216 cd ${buildlogdir} && \
217 tar xvjf ${topdir}/${log_pkg_name}
221 # Configure the package.
224 CFLAGS="${MY_CFLAGS}" LDFLAGS="${MY_LDFLAGS}" \
225 ${srcdir}/configure \
226 --srcdir=${srcdir} --prefix="${prefix}" \
227 --exec-prefix='${prefix}' --sysconfdir="${sysconfdir}" \
228 --libdir='${prefix}/lib' --includedir='${prefix}/include' \
229 --mandir='${prefix}/share/man' --infodir='${prefix}/share/info' \
230 --libexecdir='${sbindir}' --localstatedir="${localstatedir}" \
231 --datadir='${prefix}/share' )
234 conf "$@" 2>&1 | tee ${configurelogfile}
235 return ${PIPESTATUS[0]}
238 # Rerun configure to pick up changes in the environment.
241 rm -fr ${objdir} && \
242 mkdir -p ${objdir} && \
246 reconf "$@" 2>&1 | tee ${configurelogfile}
247 return ${PIPESTATUS[0]}
253 make CFLAGS="${MY_CFLAGS}" )
256 build "$@" 2>&1 | tee ${makelogfile}
257 return ${PIPESTATUS[0]}
260 # Run the package testsuite.
263 make -k ${test_rule} )
266 check "$@" 2>&1 | tee ${checklogfile}
267 return ${PIPESTATUS[0]}
270 # Remove files created by configure and make.
276 # Install the package, with DESTDIR set to '.inst'.
279 rm -fr ${instdir}/* && \
280 make install DESTDIR=${instdir} && \
281 for f in ${prefix}/share/info/dir ${prefix}/info/dir ; do \
282 if [ -f ${instdir}${f} ] ; then \
283 rm -f ${instdir}${f} ; \
286 for d in ${prefix}/share/doc/${SHORTPKG} ${prefix}/share/doc/Cygwin ; do \
287 if [ ! -d ${instdir}${d} ] ; then \
288 mkdir -p ${instdir}${d} ;\
291 if [ -d ${instdir}${prefix}/share/info ] ; then \
292 find ${instdir}${prefix}/share/info -name "*.info" | xargs -r gzip -q ; \
294 if [ -d ${instdir}${prefix}/share/man ] ; then \
295 find ${instdir}${prefix}/share/man -name "*.1" -o -name "*.3" -o \
296 -name "*.3x" -o -name "*.3pm" -o -name "*.5" -o -name "*.6" -o \
297 -name "*.7" -o -name "*.8" | xargs -r gzip -q ; \
300 for fp in ${install_docs} ; do \
302 */) templist="$templist `find ${srcdir}/$fp -type f`" ;;
303 *) for f in ${srcdir}/$fp ; do \
304 if [ -f $f ] ; then \
305 templist="$templist $f"; \
310 if [ ! "x$templist" = "x" ]; then \
311 /usr/bin/install -m 644 $templist \
312 ${instdir}${prefix}/share/doc/${SHORTPKG} ; \
314 if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}.README ]; then \
315 /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/${PKG}.README \
316 ${instdir}${prefix}/share/doc/Cygwin/${SHORTPKG}.README ; \
317 elif [ -f ${srcdir}/CYGWIN-PATCHES/README ] ; then \
318 /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/README \
319 ${instdir}${prefix}/share/doc/Cygwin/${SHORTPKG}.README ; \
321 if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}.sh ] ; then \
322 if [ ! -d ${instdir}${sysconfdir}/postinstall ]; then \
323 mkdir -p ${instdir}${sysconfdir}/postinstall ; \
325 /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/${PKG}.sh \
326 ${instdir}${sysconfdir}/postinstall/${PKG}.sh ; \
327 elif [ -f ${srcdir}/CYGWIN-PATCHES/postinstall.sh ] ; then \
328 if [ ! -d ${instdir}${sysconfdir}/postinstall ]; then \
329 mkdir -p ${instdir}${sysconfdir}/postinstall ; \
331 /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/postinstall.sh \
332 ${instdir}${sysconfdir}/postinstall/${PKG}.sh ; \
334 if [ -f ${srcdir}/CYGWIN-PATCHES/preremove.sh ] ; then \
335 if [ ! -d ${instdir}${sysconfdir}/preremove ]; then \
336 mkdir -p ${instdir}${sysconfdir}/preremove ; \
338 /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/preremove.sh \
339 ${instdir}${sysconfdir}/preremove/${PKG}.sh ; \
341 if [ -f ${srcdir}/CYGWIN-PATCHES/manifest.lst ] ; then
342 if [ ! -d ${instdir}${sysconfdir}/preremove ]; then
343 mkdir -p ${instdir}${sysconfdir}/preremove ;
345 /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/manifest.lst \
346 ${instdir}${sysconfdir}/preremove/${PKG}-manifest.lst ;
350 install "$@" 2>&1 | tee ${installlogfile}
351 return ${PIPESTATUS[0]}
354 # Strip all binaries.
357 find . -name "*.dll" -or -name "*.exe" | xargs -r strip 2>&1 ; \
361 # List all non-hidden files that belong to the package.
364 find . -name "*" ! -type d | sed 's%^\.% %' | sort ; \
368 # List the static .dll dependencies of the package. This does not pick up
369 # dynamic dependencies (whether or not libtool was used), nor does it pick
370 # up program dependencies, such as system() depending on /bin/sh.
373 find ${instdir} -name "*.exe" -o -name "*.dll" | xargs -r cygcheck | \
374 sed -ne '/^ [^ ]/ s,\\,/,gp' | sort -bu | \
375 xargs -r -n1 cygpath -u | xargs -r cygcheck -f | sed 's%^% %' | sort -u ; \
379 # Build the binary package tarball.
382 tar cvjf ${bin_pkg} * )
385 # Compare the original tarball against cygwin modifications.
388 find . -name "autom4te.cache" | xargs -r rm -rf ; \
389 unpack ${src_orig_pkg} && \
390 mv ${BASEPKG} ../${BASEPKG}-orig && \
392 diff -urN -x '.build' -x '.inst' -x '.sinst' -x '.buildlogs' \
393 ${BASEPKG}-orig ${BASEPKG} > \
394 ${srcinstdir}/${src_patch_name} ; \
395 rm -rf ${BASEPKG}-orig )
398 # Note: maintainer-only functionality
400 cp --backup=numbered ${srcinstdir}/${src_patch_name} ${topdir}
403 # Build the source tarball.
406 if [ "${SIG}" -eq 1 ] ; then \
407 name=${srcinstdir}/${src_patch_name} text="PATCH" sigfile ; \
409 cp ${src_orig_pkg} ${srcinstdir}/${src_orig_pkg_name} && \
410 if [ -e ${src_orig_pkg}.sig ] ; then \
411 cp ${src_orig_pkg}.sig ${srcinstdir}/ ; \
413 cp $0 ${srcinstdir}/`basename $0` && \
414 name=$0 text="SCRIPT" sigfile && \
415 if [ "${SIG}" -eq 1 ] ; then \
416 cp $0.sig ${srcinstdir}/ ; \
418 cd ${srcinstdir} && \
419 tar cvjf ${src_pkg} * )
423 (cd ${srcinstdir} && \
424 if [ -e ${configurelogname} -o -e ${makelogname} -o \
425 -e ${checklogname} -o -e ${installlogname} ]; then
426 tar --ignore-failed-read -cvjf ${log_pkg_name} \
427 ${configurelogname} ${makelogname} ${checklogname} ${installlogname} && \
429 ${configurelogname} ${makelogname} ${checklogname} ${installlogname} ; \
431 tar uvjf ${src_pkg} * )
434 # Clean up everything.
439 # Generate GPG signatures.
441 if [ \( "${SIG}" -eq 1 \) -a \( -e $name \) -a \( \( ! -e $name.sig \) -o \( $name -nt $name.sig \) \) ]; then \
442 if [ -x /usr/bin/gpg ]; then \
443 echo "$text signature need to be updated"; \
445 /usr/bin/gpg --detach-sign $name; \
447 echo "You need the gnupg package installed in order to make signatures."; \
452 # Validate GPG signatures.
454 if [ -x /usr/bin/gpg ]; then \
455 if [ -e ${src_orig_pkg}.sig ]; then \
456 echo "ORIGINAL PACKAGE signature follows:"; \
457 /usr/bin/gpg --verify ${src_orig_pkg}.sig ${src_orig_pkg}; \
459 echo "ORIGINAL PACKAGE signature missing."; \
461 if [ -e $0.sig ]; then \
462 echo "SCRIPT signature follows:"; \
463 /usr/bin/gpg --verify $0.sig $0; \
465 echo "SCRIPT signature missing."; \
467 if [ -e ${src_patch}.sig ]; then \
468 echo "PATCH signature follows:"; \
469 /usr/bin/gpg --verify ${src_patch}.sig ${src_patch}; \
471 echo "PATCH signature missing."; \
474 echo "You need the gnupg package installed in order to check signatures." ; \
488 f_mkdirs=mkdirs_log && \
491 f_reconf=reconf_log && \
492 f_build=build_log && \
493 f_check=check_log && \
494 f_install=install_log && \
498 while test -n "$1" ; do
500 help|--help) help ; STATUS=$? ;;
501 version|--version) version ; STATUS=$? ;;
502 with_logs|--logs) enablelogging ; STATUS=$? ;;
503 prep) $f_prep ; STATUS=$? ;;
504 mkdirs) $f_mkdirs ; STATUS=$? ;;
505 conf) $f_conf ; STATUS=$? ;;
506 configure) $f_conf ; STATUS=$? ;;
507 reconf) $f_reconf ; STATUS=$? ;;
508 build) $f_build ; STATUS=$? ;;
509 make) $f_build ; STATUS=$? ;;
510 check) $f_check ; STATUS=$? ;;
511 test) $f_check ; STATUS=$? ;;
512 clean) $f_clean ; STATUS=$? ;;
513 install) $f_install ; STATUS=$? ;;
514 list) list ; STATUS=$? ;;
515 depend) depend ; STATUS=$? ;;
516 strip) strip ; STATUS=$? ;;
517 package) pkg ; STATUS=$? ;;
518 pkg) pkg ; STATUS=$? ;;
519 mkpatch) mkpatch ; STATUS=$? ;;
520 acceptpatch) acceptpatch ; STATUS=$? ;;
521 src-package) $f_spkg ; STATUS=$? ;;
522 spkg) $f_spkg ; STATUS=$? ;;
523 finish) finish ; STATUS=$? ;;
524 checksig) checksig ; STATUS=$? ;;
525 first) $f_mkdirs && $f_spkg && finish ; STATUS=$? ;;
526 almostall) checksig && $f_prep && $f_conf && $f_build && \
527 $f_install && strip && pkg && $f_spkg ; STATUS=$? ;;
528 all) checksig && $f_prep && $f_conf && $f_build && \
529 $f_install && strip && pkg && $f_spkg && finish ; \
531 *) echo "Error: bad arguments" ; exit 1 ;;
533 ( exit ${STATUS} ) || exit ${STATUS}