3 # ==========================================================================
4 # Based on Cygwin generic package build script, customized for nmh.
5 # Relies on nmh VERSION file.
7 # This script is incompatible with directory names that contain spaces, etc.
8 # To fix that, a whole bunch of shell variables need to be wrapped with "".
9 # ==========================================================================
11 # Generic package build script
13 # $Id: generic-build-script,v 1.47 2006/02/01 14:01:14 igor Exp $
15 # Package maintainers: if the original source is not distributed as a
16 # (possibly compressed) tarball, set the value of ${src_orig_pkg_name},
17 # and redefine the unpack() helper function appropriately.
18 # Also, if the Makefile rule to run the test suite is not "check", change
19 # the definition of ${test_rule} below.
21 # find out where the build script is located
22 tdir=`echo "$0" | sed 's%[\\/][^\\/][^\\/]*$%%'`
23 test "x$tdir" = "x$0" && tdir=.
24 scriptdir=`cd $tdir; pwd`
26 # If scriptdir ends in SPECS, then topdir is $scriptdir/..
27 # If scriptdir ends in CYGWIN-PATCHES, then topdir is $scriptdir/../..
28 # Otherwise, we assume that topdir = scriptdir
29 topdir1=`echo ${scriptdir} | sed 's%/SPECS$%%'`
30 topdir2=`echo ${scriptdir} | sed 's%/CYGWIN-PATCHES$%%'`
31 if [ "x$topdir1" != "x$scriptdir" ] ; then # SPECS
32 topdir=`cd ${scriptdir}/..; pwd`
34 if [ "x$topdir2" != "x$scriptdir" ] ; then # CYGWIN-PATCHES
35 topdir=`cd ${scriptdir}/../..; pwd`
37 topdir=`cd ${scriptdir}; pwd`
41 # Change from generic-build-script: save pwd for later use.
44 # Change from generic-build-script: base version on contents of
45 # VERSION instead of script name. Looks first for VERSION in
46 # current directory, then in $topdir.
47 test -e VERSION && version=VERSION || version="${topdir}/VERSION"
48 if ! test -e "${version}"; then
49 echo "$0: need VERSION file"
53 tscriptname=nmh-`cat "${version}"`
54 # Change from generic-build-script: allow + in addition to - between
55 # VER and REL, e.g., 1.5+dev.
56 export PKG=`echo $tscriptname | sed -e 's/\-[^\-]*[+-][^+-]*$//'`
57 export VER=`echo $tscriptname | sed -e "s/${PKG}\-//" -e 's/[+-][^+-]*$//'`
58 export REL=`echo $tscriptname | sed -e "s/${PKG}\-${VER}\([+-]\)/\1/"`
59 # BASEPKG refers to the upstream base package
60 # SHORTPKG refers to the Cygwin package
61 # Normally, these are identical, but if the Cygwin package name is different
62 # from the upstream package name, you will want to redefine BASEPKG.
63 # Example: For Apache 2, BASEPKG=httpd-2.x.xx but SHORTPKG=apache2-2.x.xx
65 # Change from generic-build-script: added DISABLE_SETGID_MAIL=1 so that
66 # install will not try to chgrp/chmod bin/inc.
67 export DISABLE_SETGID_MAIL=1
68 # Change from generic-build-script: added -${REL} to BASEPKG.
69 export BASEPKG=${PKG}-${VER}${REL}
70 export SHORTPKG=${PKG}-${VER}
71 export FULLPKG=${SHORTPKG}${REL}
73 # determine correct decompression option and tarball filename
74 export src_orig_pkg_name=
75 if [ -e "${src_orig_pkg_name}" ] ; then
76 export opt_decomp=? # Make sure tar punts if unpack() is not redefined
77 elif [ -e ${BASEPKG}.tar.bz2 ] ; then
79 export src_orig_pkg_name=${BASEPKG}.tar.bz2
80 elif [ -e ${BASEPKG}.tar.gz ] ; then
82 export src_orig_pkg_name=${BASEPKG}.tar.gz
83 elif [ -e ${BASEPKG}.tgz ] ; then
85 export src_orig_pkg_name=${BASEPKG}.tgz
86 elif [ -e ${BASEPKG}.tar ] ; then
88 export src_orig_pkg_name=${BASEPKG}.tar
90 # Change from generic-build-script: build the tarball if it doesn't exist.
91 (cd "${topdir}" && make dist)
92 if [ -e "${topdir}/${BASEPKG}.tar.gz" ] ; then
94 export src_orig_pkg_name=${BASEPKG}.tar.gz
96 echo "Cannot find PKG:${PKG} VER:${VER} REL:${REL}. Rename $0 to"
97 echo "something more appropriate, and try again."
102 export src_orig_pkg=${topdir}/${src_orig_pkg_name}
104 # determine correct names for generated files
105 export src_pkg_name=${FULLPKG}-src.tar.bz2
106 export src_patch_name=${FULLPKG}.patch
107 export bin_pkg_name=${FULLPKG}.tar.bz2
108 export log_pkg_name=${FULLPKG}-BUILDLOGS.tar.bz2
110 export configurelogname=${FULLPKG}-CONFIGURE.LOG
111 export makelogname=${FULLPKG}-MAKE.LOG
112 export checklogname=${FULLPKG}-CHECK.LOG
113 export installlogname=${FULLPKG}-INSTALL.LOG
115 # Change from generic-build-script: put src_pkg and bin_pkg in current
117 export src_pkg=${pwd}/${src_pkg_name}
118 export src_patch="${topdir}"/${src_patch_name}
119 export bin_pkg=${pwd}/${bin_pkg_name}
120 export srcdir="${topdir}"/${BASEPKG}
121 export objdir=${srcdir}/.build
122 export instdir=${srcdir}/.inst
123 export srcinstdir=${srcdir}/.sinst
124 export buildlogdir=${srcdir}/.buildlogs
125 export configurelogfile=${srcinstdir}/${configurelogname}
126 export makelogfile=${srcinstdir}/${makelogname}
127 export checklogfile=${srcinstdir}/${checklogname}
128 export installlogfile=${srcinstdir}/${installlogname}
133 if [ -z "$MY_CFLAGS" ]; then
136 if [ -z "$MY_LDFLAGS" ]; then
140 # Change from generic-build-script: removed ChangeLog because the nmh
141 # Makefile installs it.
142 export install_docs="\
168 export install_docs="`for i in ${install_docs}; do echo $i; done | sort -u`"
169 export test_rule=check
170 if [ -z "$SIG" ]; then
171 export SIG=0 # set to 1 to turn on signing by default
173 # Sort in POSIX order.
181 This is the cygwin packaging script for ${FULLPKG}.
182 Usage: $0 [<option>...] <action>...
184 help, --help Print this message
185 version, --version Print the version message
186 with_logs, --logs Create logs of remaining steps
188 prep Unpack and patch into ${srcdir}
189 mkdirs Make hidden directories needed during build
190 conf, configure Configure the package (./configure)
191 reconf Rerun configure
192 build, make Build the package (make)
193 check, test Run the testsuite (make ${test_rule})
194 clean Remove built files (make clean)
195 install Install package to staging area (make install)
196 list List package contents
197 depend List package dependencies
198 strip Strip package executables
199 pkg, package Prepare the binary package ${bin_pkg_name}
200 mkpatch Prepare the patch file ${src_patch_name}
201 acceptpatch Copy patch file ${src_patch_name} to ${topdir}
202 spkg, src-package Prepare the source package ${src_pkg_name}
203 finish Remove source directory ${srcdir}
204 checksig Validate GPG signatures (requires gpg)
205 first Full run for spkg (mkdirs, spkg, finish)
206 almostall Full run for bin pkg, except for finish
207 all Full run for bin pkg
211 # Provide version of generic-build-script modified to make this script.
213 vers=`echo '$Revision: 1.47 $' | sed -e 's/Revision: //' -e 's/ *\\$//g'`
214 echo "$0 based on generic-build-script $vers"
217 # Unpacks the original package source archive into ./${BASEPKG}/.
218 # Change this if the original package was not tarred
219 # or if it doesn't unpack to a correct directory.
221 tar xv${opt_decomp}f "$1"
224 # Make the hidden directories used by this script.
227 rm -fr ${objdir} ${instdir} ${srcinstdir} && \
228 mkdir -p ${objdir} && \
229 mkdir -p ${instdir} && \
230 mkdir -p ${srcinstdir} )
235 rm -fr ${buildlogdir} && \
236 mkdir -p ${buildlogdir} )
239 # Unpack the original tarball, and get everything set up for this script.
242 unpack ${src_orig_pkg} && \
244 if [ -f ${src_patch} ] ; then \
245 patch -Z -p0 < ${src_patch} ;\
252 if [ -f ${topdir}/${log_pkg_name} ] ; then \
253 # Change from generic-build-script: do the following in subshell
254 # so that cd isn't permanent.
255 (cd ${buildlogdir} && \
256 tar xvjf "${topdir}"/${log_pkg_name})
260 # Configure the package.
263 CFLAGS="${MY_CFLAGS}" LDFLAGS="${MY_LDFLAGS}" \
264 ${srcdir}/configure \
265 --srcdir=${srcdir} --prefix="${prefix}" \
266 --exec-prefix='${prefix}' --sysconfdir="${sysconfdir}" \
267 --libdir='${prefix}/lib' --includedir='${prefix}/include' \
268 --mandir='${prefix}/share/man' --infodir='${prefix}/share/info' \
269 --libexecdir='${sbindir}' --localstatedir="${localstatedir}" \
270 --datadir='${prefix}/share' )
273 conf "$@" 2>&1 | tee ${configurelogfile}
274 return ${PIPESTATUS[0]}
277 # Rerun configure to pick up changes in the environment.
280 rm -fr ${objdir} && \
281 mkdir -p ${objdir} && \
285 reconf "$@" 2>&1 | tee ${configurelogfile}
286 return ${PIPESTATUS[0]}
292 make CFLAGS="${MY_CFLAGS}" )
295 build "$@" 2>&1 | tee ${makelogfile}
296 return ${PIPESTATUS[0]}
299 # Run the package testsuite.
302 make -k ${test_rule} )
305 check "$@" 2>&1 | tee ${checklogfile}
306 return ${PIPESTATUS[0]}
309 # Remove files created by configure and make.
315 # Install the package, with DESTDIR set to '.inst'.
316 # Change from generic-build-script: added ":;" after "find ... | gzip"
317 # because it returns non-zero status.
320 rm -fr ${instdir}/* && \
321 make install DESTDIR=${instdir} && \
322 for f in ${prefix}/share/info/dir ${prefix}/info/dir ; do \
323 if [ -f ${instdir}${f} ] ; then \
324 rm -f ${instdir}${f} ; \
327 for d in ${prefix}/share/doc/${SHORTPKG} ${prefix}/share/doc/Cygwin ; do \
328 if [ ! -d ${instdir}${d} ] ; then \
329 mkdir -p ${instdir}${d} ;\
332 if [ -d ${instdir}${prefix}/share/info ] ; then \
333 find ${instdir}${prefix}/share/info -name "*.info" | xargs -r gzip -q ; \
335 if [ -d ${instdir}${prefix}/share/man ] ; then \
336 find ${instdir}${prefix}/share/man -name "*.1" -o -name "*.3" -o \
337 -name "*.3x" -o -name "*.3pm" -o -name "*.5" -o -name "*.6" -o \
338 -name "*.7" -o -name "*.8" | xargs -r gzip -q ; :; \
341 for fp in ${install_docs} ; do \
343 */) templist="$templist `find ${srcdir}/$fp -type f`" ;;
344 *) for f in ${srcdir}/$fp ; do \
345 if [ -f $f ] ; then \
346 templist="$templist $f"; \
351 if [ ! "x$templist" = "x" ]; then \
352 /usr/bin/install -m 644 $templist \
353 ${instdir}${prefix}/share/doc/${SHORTPKG} ; \
355 if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}.README ]; then \
356 /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/${PKG}.README \
357 ${instdir}${prefix}/share/doc/Cygwin/${SHORTPKG}.README ; \
358 elif [ -f ${srcdir}/CYGWIN-PATCHES/README ] ; then \
359 /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/README \
360 ${instdir}${prefix}/share/doc/Cygwin/${SHORTPKG}.README ; \
362 if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}.sh ] ; then \
363 if [ ! -d ${instdir}${sysconfdir}/postinstall ]; then \
364 mkdir -p ${instdir}${sysconfdir}/postinstall ; \
366 /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/${PKG}.sh \
367 ${instdir}${sysconfdir}/postinstall/${PKG}.sh ; \
368 elif [ -f ${srcdir}/CYGWIN-PATCHES/postinstall.sh ] ; then \
369 if [ ! -d ${instdir}${sysconfdir}/postinstall ]; then \
370 mkdir -p ${instdir}${sysconfdir}/postinstall ; \
372 /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/postinstall.sh \
373 ${instdir}${sysconfdir}/postinstall/${PKG}.sh ; \
375 if [ -f ${srcdir}/CYGWIN-PATCHES/preremove.sh ] ; then \
376 if [ ! -d ${instdir}${sysconfdir}/preremove ]; then \
377 mkdir -p ${instdir}${sysconfdir}/preremove ; \
379 /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/preremove.sh \
380 ${instdir}${sysconfdir}/preremove/${PKG}.sh ; \
382 if [ -f ${srcdir}/CYGWIN-PATCHES/manifest.lst ] ; then
383 if [ ! -d ${instdir}${sysconfdir}/preremove ]; then
384 mkdir -p ${instdir}${sysconfdir}/preremove ;
386 /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/manifest.lst \
387 ${instdir}${sysconfdir}/preremove/${PKG}-manifest.lst ;
391 install "$@" 2>&1 | tee ${installlogfile}
392 return ${PIPESTATUS[0]}
395 # Strip all binaries.
398 find . -name "*.dll" -or -name "*.exe" | xargs -r strip 2>&1 ; \
402 # List all non-hidden files that belong to the package.
405 find . -name "*" ! -type d | sed 's%^\.% %' | sort ; \
409 # List the static .dll dependencies of the package. This does not pick up
410 # dynamic dependencies (whether or not libtool was used), nor does it pick
411 # up program dependencies, such as system() depending on /bin/sh.
414 find ${instdir} -name "*.exe" -o -name "*.dll" | xargs -r cygcheck | \
415 sed -ne '/^ [^ ]/ s,\\,/,gp' | sort -bu | \
416 xargs -r -n1 cygpath -u | xargs -r cygcheck -f | sed 's%^% %' | sort -u ; \
420 # Build the binary package tarball.
423 tar cvjf ${bin_pkg} * )
426 # Compare the original tarball against cygwin modifications.
429 find . -name "autom4te.cache" | xargs -r rm -rf ; \
430 unpack ${src_orig_pkg} && \
431 mv ${BASEPKG} ../${BASEPKG}-orig && \
433 diff -urN -x '.build' -x '.inst' -x '.sinst' -x '.buildlogs' \
434 ${BASEPKG}-orig ${BASEPKG} > \
435 ${srcinstdir}/${src_patch_name} ; \
436 rm -rf ${BASEPKG}-orig )
439 # Note: maintainer-only functionality
441 cp --backup=numbered ${srcinstdir}/${src_patch_name} ${topdir}
444 # Build the source tarball.
445 # Change from generic-build-script: added VERSION file.
448 if [ "${SIG}" -eq 1 ] ; then \
449 name=${srcinstdir}/${src_patch_name} text="PATCH" sigfile ; \
451 cp ${src_orig_pkg} ${srcinstdir}/${src_orig_pkg_name} && \
452 if [ -e ${src_orig_pkg}.sig ] ; then \
453 cp ${src_orig_pkg}.sig ${srcinstdir}/ ; \
455 cp $0 ${srcinstdir}/`basename $0` && \
456 name=$0 text="SCRIPT" sigfile && \
457 if [ "${SIG}" -eq 1 ] ; then \
458 cp $0.sig ${srcinstdir}/ ; \
460 cp "${version}" "${srcinstdir}" && \
461 cd ${srcinstdir} && \
462 tar cvjf ${src_pkg} * )
466 (cd ${srcinstdir} && \
467 if [ -e ${configurelogname} -o -e ${makelogname} -o \
468 -e ${checklogname} -o -e ${installlogname} ]; then
469 tar --ignore-failed-read -cvjf ${log_pkg_name} \
470 ${configurelogname} ${makelogname} ${checklogname} ${installlogname} && \
472 ${configurelogname} ${makelogname} ${checklogname} ${installlogname} ; \
474 tar uvjf ${src_pkg} * )
477 # Clean up everything.
482 # Generate GPG signatures.
484 if [ \( "${SIG}" -eq 1 \) -a \( -e $name \) -a \( \( ! -e $name.sig \) -o \( $name -nt $name.sig \) \) ]; then \
485 if [ -x /usr/bin/gpg ]; then \
486 echo "$text signature need to be updated"; \
488 /usr/bin/gpg --detach-sign $name; \
490 echo "You need the gnupg package installed in order to make signatures."; \
495 # Validate GPG signatures.
497 if [ -x /usr/bin/gpg ]; then \
498 if [ -e ${src_orig_pkg}.sig ]; then \
499 echo "ORIGINAL PACKAGE signature follows:"; \
500 /usr/bin/gpg --verify ${src_orig_pkg}.sig ${src_orig_pkg}; \
502 echo "ORIGINAL PACKAGE signature missing."; \
504 if [ -e $0.sig ]; then \
505 echo "SCRIPT signature follows:"; \
506 /usr/bin/gpg --verify $0.sig $0; \
508 echo "SCRIPT signature missing."; \
510 if [ -e ${src_patch}.sig ]; then \
511 echo "PATCH signature follows:"; \
512 /usr/bin/gpg --verify ${src_patch}.sig ${src_patch}; \
514 echo "PATCH signature missing."; \
517 echo "You need the gnupg package installed in order to check signatures." ; \
531 f_mkdirs=mkdirs_log && \
534 f_reconf=reconf_log && \
535 f_build=build_log && \
536 f_check=check_log && \
537 f_install=install_log && \
541 while test -n "$1" ; do
543 help|--help) help ; STATUS=$? ;;
544 version|--version) version ; STATUS=$? ;;
545 with_logs|--logs) enablelogging ; STATUS=$? ;;
546 prep) $f_prep ; STATUS=$? ;;
547 mkdirs) $f_mkdirs ; STATUS=$? ;;
548 conf) $f_conf ; STATUS=$? ;;
549 configure) $f_conf ; STATUS=$? ;;
550 reconf) $f_reconf ; STATUS=$? ;;
551 build) $f_build ; STATUS=$? ;;
552 make) $f_build ; STATUS=$? ;;
553 check) $f_check ; STATUS=$? ;;
554 test) $f_check ; STATUS=$? ;;
555 clean) $f_clean ; STATUS=$? ;;
556 install) $f_install ; STATUS=$? ;;
557 list) list ; STATUS=$? ;;
558 depend) depend ; STATUS=$? ;;
559 strip) strip ; STATUS=$? ;;
560 package) pkg ; STATUS=$? ;;
561 pkg) pkg ; STATUS=$? ;;
562 mkpatch) mkpatch ; STATUS=$? ;;
563 acceptpatch) acceptpatch ; STATUS=$? ;;
564 src-package) $f_spkg ; STATUS=$? ;;
565 spkg) $f_spkg ; STATUS=$? ;;
566 finish) finish ; STATUS=$? ;;
567 checksig) checksig ; STATUS=$? ;;
568 first) $f_mkdirs && $f_spkg && finish ; STATUS=$? ;;
569 almostall) checksig && $f_prep && $f_conf && $f_build && \
570 $f_install && strip && pkg && $f_spkg ; STATUS=$? ;;
571 all) checksig && $f_prep && $f_conf && $f_build && \
572 $f_install && strip && pkg && $f_spkg && finish ; \
574 *) echo "Error: bad arguments" ; exit 1 ;;
576 ( exit ${STATUS} ) || exit ${STATUS}