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 -${REL} to BASEPKG.
66 export BASEPKG=${PKG}-${VER}${REL}
67 export SHORTPKG=${PKG}-${VER}
68 export FULLPKG=${SHORTPKG}${REL}
70 # determine correct decompression option and tarball filename
71 export src_orig_pkg_name=
72 if [ -e "${src_orig_pkg_name}" ] ; then
73 export opt_decomp=? # Make sure tar punts if unpack() is not redefined
74 elif [ -e ${BASEPKG}.tar.bz2 ] ; then
76 export src_orig_pkg_name=${BASEPKG}.tar.bz2
77 elif [ -e ${BASEPKG}.tar.gz ] ; then
79 export src_orig_pkg_name=${BASEPKG}.tar.gz
80 elif [ -e ${BASEPKG}.tgz ] ; then
82 export src_orig_pkg_name=${BASEPKG}.tgz
83 elif [ -e ${BASEPKG}.tar ] ; then
85 export src_orig_pkg_name=${BASEPKG}.tar
87 # Change from generic-build-script: build the tarball if it doesn't exist.
88 (cd "${topdir}" && make dist)
89 if [ -e "${topdir}/${BASEPKG}.tar.gz" ] ; then
91 export src_orig_pkg_name=${BASEPKG}.tar.gz
93 echo "Cannot find PKG:${PKG} VER:${VER} REL:${REL}. Rename $0 to"
94 echo "something more appropriate, and try again."
99 export src_orig_pkg=${topdir}/${src_orig_pkg_name}
101 # determine correct names for generated files
102 export src_pkg_name=${FULLPKG}-src.tar.bz2
103 export src_patch_name=${FULLPKG}.patch
104 export bin_pkg_name=${FULLPKG}.tar.bz2
105 export log_pkg_name=${FULLPKG}-BUILDLOGS.tar.bz2
107 export configurelogname=${FULLPKG}-CONFIGURE.LOG
108 export makelogname=${FULLPKG}-MAKE.LOG
109 export checklogname=${FULLPKG}-CHECK.LOG
110 export installlogname=${FULLPKG}-INSTALL.LOG
112 # Change from generic-build-script: put src_pkg and bin_pkg in current
114 export src_pkg=${pwd}/${src_pkg_name}
115 export src_patch="${topdir}"/${src_patch_name}
116 export bin_pkg=${pwd}/${bin_pkg_name}
117 export srcdir="${topdir}"/${BASEPKG}
118 export objdir=${srcdir}/.build
119 export instdir=${srcdir}/.inst
120 export srcinstdir=${srcdir}/.sinst
121 export buildlogdir=${srcdir}/.buildlogs
122 export configurelogfile=${srcinstdir}/${configurelogname}
123 export makelogfile=${srcinstdir}/${makelogname}
124 export checklogfile=${srcinstdir}/${checklogname}
125 export installlogfile=${srcinstdir}/${installlogname}
130 if [ -z "$MY_CFLAGS" ]; then
133 if [ -z "$MY_LDFLAGS" ]; then
137 # Change from generic-build-script: removed ChangeLog because the nmh
138 # Makefile installs it.
139 export install_docs="\
165 export install_docs="`for i in ${install_docs}; do echo $i; done | sort -u`"
166 export test_rule=check
167 if [ -z "$SIG" ]; then
168 export SIG=0 # set to 1 to turn on signing by default
170 # Sort in POSIX order.
178 This is the cygwin packaging script for ${FULLPKG}.
179 Usage: $0 [<option>...] <action>...
181 help, --help Print this message
182 version, --version Print the version message
183 with_logs, --logs Create logs of remaining steps
185 prep Unpack and patch into ${srcdir}
186 mkdirs Make hidden directories needed during build
187 conf, configure Configure the package (./configure)
188 reconf Rerun configure
189 build, make Build the package (make)
190 check, test Run the testsuite (make ${test_rule})
191 clean Remove built files (make clean)
192 install Install package to staging area (make install)
193 list List package contents
194 depend List package dependencies
195 strip Strip package executables
196 pkg, package Prepare the binary package ${bin_pkg_name}
197 mkpatch Prepare the patch file ${src_patch_name}
198 acceptpatch Copy patch file ${src_patch_name} to ${topdir}
199 spkg, src-package Prepare the source package ${src_pkg_name}
200 finish Remove source directory ${srcdir}
201 checksig Validate GPG signatures (requires gpg)
202 first Full run for spkg (mkdirs, spkg, finish)
203 almostall Full run for bin pkg, except for finish
204 all Full run for bin pkg
208 # Provide version of generic-build-script modified to make this script.
210 vers=`echo '$Revision: 1.47 $' | sed -e 's/Revision: //' -e 's/ *\\$//g'`
211 echo "$0 based on generic-build-script $vers"
214 # Unpacks the original package source archive into ./${BASEPKG}/.
215 # Change this if the original package was not tarred
216 # or if it doesn't unpack to a correct directory.
218 tar xv${opt_decomp}f "$1"
221 # Make the hidden directories used by this script.
224 rm -fr ${objdir} ${instdir} ${srcinstdir} && \
225 mkdir -p ${objdir} && \
226 mkdir -p ${instdir} && \
227 mkdir -p ${srcinstdir} )
232 rm -fr ${buildlogdir} && \
233 mkdir -p ${buildlogdir} )
236 # Unpack the original tarball, and get everything set up for this script.
239 unpack ${src_orig_pkg} && \
241 if [ -f ${src_patch} ] ; then \
242 patch -Z -p0 < ${src_patch} ;\
249 if [ -f ${topdir}/${log_pkg_name} ] ; then \
250 # Change from generic-build-script: do the following in subshell
251 # so that cd isn't permanent.
252 (cd ${buildlogdir} && \
253 tar xvjf "${topdir}"/${log_pkg_name})
257 # Configure the package.
260 CFLAGS="${MY_CFLAGS}" LDFLAGS="${MY_LDFLAGS}" \
261 ${srcdir}/configure \
262 --srcdir=${srcdir} --prefix="${prefix}" \
263 --exec-prefix='${prefix}' --sysconfdir="${sysconfdir}" \
264 --libdir='${prefix}/lib' --includedir='${prefix}/include' \
265 --mandir='${prefix}/share/man' --infodir='${prefix}/share/info' \
266 --libexecdir='${sbindir}' --localstatedir="${localstatedir}" \
267 --datadir='${prefix}/share' )
270 conf "$@" 2>&1 | tee ${configurelogfile}
271 return ${PIPESTATUS[0]}
274 # Rerun configure to pick up changes in the environment.
277 rm -fr ${objdir} && \
278 mkdir -p ${objdir} && \
282 reconf "$@" 2>&1 | tee ${configurelogfile}
283 return ${PIPESTATUS[0]}
289 make CFLAGS="${MY_CFLAGS}" )
292 build "$@" 2>&1 | tee ${makelogfile}
293 return ${PIPESTATUS[0]}
296 # Run the package testsuite.
299 make -k ${test_rule} )
302 check "$@" 2>&1 | tee ${checklogfile}
303 return ${PIPESTATUS[0]}
306 # Remove files created by configure and make.
312 # Install the package, with DESTDIR set to '.inst'.
313 # Change from generic-build-script: added ":;" after "find ... | gzip"
314 # because it returns non-zero status.
317 rm -fr ${instdir}/* && \
318 make install DESTDIR=${instdir} && \
319 for f in ${prefix}/share/info/dir ${prefix}/info/dir ; do \
320 if [ -f ${instdir}${f} ] ; then \
321 rm -f ${instdir}${f} ; \
324 for d in ${prefix}/share/doc/${SHORTPKG} ${prefix}/share/doc/Cygwin ; do \
325 if [ ! -d ${instdir}${d} ] ; then \
326 mkdir -p ${instdir}${d} ;\
329 if [ -d ${instdir}${prefix}/share/info ] ; then \
330 find ${instdir}${prefix}/share/info -name "*.info" | xargs -r gzip -q ; \
332 if [ -d ${instdir}${prefix}/share/man ] ; then \
333 find ${instdir}${prefix}/share/man -name "*.1" -o -name "*.3" -o \
334 -name "*.3x" -o -name "*.3pm" -o -name "*.5" -o -name "*.6" -o \
335 -name "*.7" -o -name "*.8" | xargs -r gzip -q ; :; \
338 for fp in ${install_docs} ; do \
340 */) templist="$templist `find ${srcdir}/$fp -type f`" ;;
341 *) for f in ${srcdir}/$fp ; do \
342 if [ -f $f ] ; then \
343 templist="$templist $f"; \
348 if [ ! "x$templist" = "x" ]; then \
349 /usr/bin/install -m 644 $templist \
350 ${instdir}${prefix}/share/doc/${SHORTPKG} ; \
352 if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}.README ]; then \
353 /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/${PKG}.README \
354 ${instdir}${prefix}/share/doc/Cygwin/${SHORTPKG}.README ; \
355 elif [ -f ${srcdir}/CYGWIN-PATCHES/README ] ; then \
356 /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/README \
357 ${instdir}${prefix}/share/doc/Cygwin/${SHORTPKG}.README ; \
359 if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}.sh ] ; then \
360 if [ ! -d ${instdir}${sysconfdir}/postinstall ]; then \
361 mkdir -p ${instdir}${sysconfdir}/postinstall ; \
363 /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/${PKG}.sh \
364 ${instdir}${sysconfdir}/postinstall/${PKG}.sh ; \
365 elif [ -f ${srcdir}/CYGWIN-PATCHES/postinstall.sh ] ; then \
366 if [ ! -d ${instdir}${sysconfdir}/postinstall ]; then \
367 mkdir -p ${instdir}${sysconfdir}/postinstall ; \
369 /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/postinstall.sh \
370 ${instdir}${sysconfdir}/postinstall/${PKG}.sh ; \
372 if [ -f ${srcdir}/CYGWIN-PATCHES/preremove.sh ] ; then \
373 if [ ! -d ${instdir}${sysconfdir}/preremove ]; then \
374 mkdir -p ${instdir}${sysconfdir}/preremove ; \
376 /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/preremove.sh \
377 ${instdir}${sysconfdir}/preremove/${PKG}.sh ; \
379 if [ -f ${srcdir}/CYGWIN-PATCHES/manifest.lst ] ; then
380 if [ ! -d ${instdir}${sysconfdir}/preremove ]; then
381 mkdir -p ${instdir}${sysconfdir}/preremove ;
383 /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/manifest.lst \
384 ${instdir}${sysconfdir}/preremove/${PKG}-manifest.lst ;
388 install "$@" 2>&1 | tee ${installlogfile}
389 return ${PIPESTATUS[0]}
392 # Strip all binaries.
395 find . -name "*.dll" -or -name "*.exe" | xargs -r strip 2>&1 ; \
399 # List all non-hidden files that belong to the package.
402 find . -name "*" ! -type d | sed 's%^\.% %' | sort ; \
406 # List the static .dll dependencies of the package. This does not pick up
407 # dynamic dependencies (whether or not libtool was used), nor does it pick
408 # up program dependencies, such as system() depending on /bin/sh.
411 find ${instdir} -name "*.exe" -o -name "*.dll" | xargs -r cygcheck | \
412 sed -ne '/^ [^ ]/ s,\\,/,gp' | sort -bu | \
413 xargs -r -n1 cygpath -u | xargs -r cygcheck -f | sed 's%^% %' | sort -u ; \
417 # Build the binary package tarball.
420 tar cvjf ${bin_pkg} * )
423 # Compare the original tarball against cygwin modifications.
426 find . -name "autom4te.cache" | xargs -r rm -rf ; \
427 unpack ${src_orig_pkg} && \
428 mv ${BASEPKG} ../${BASEPKG}-orig && \
430 diff -urN -x '.build' -x '.inst' -x '.sinst' -x '.buildlogs' \
431 ${BASEPKG}-orig ${BASEPKG} > \
432 ${srcinstdir}/${src_patch_name} ; \
433 rm -rf ${BASEPKG}-orig )
436 # Note: maintainer-only functionality
438 cp --backup=numbered ${srcinstdir}/${src_patch_name} ${topdir}
441 # Build the source tarball.
442 # Change from generic-build-script: added VERSION file.
445 if [ "${SIG}" -eq 1 ] ; then \
446 name=${srcinstdir}/${src_patch_name} text="PATCH" sigfile ; \
448 cp ${src_orig_pkg} ${srcinstdir}/${src_orig_pkg_name} && \
449 if [ -e ${src_orig_pkg}.sig ] ; then \
450 cp ${src_orig_pkg}.sig ${srcinstdir}/ ; \
452 cp $0 ${srcinstdir}/`basename $0` && \
453 name=$0 text="SCRIPT" sigfile && \
454 if [ "${SIG}" -eq 1 ] ; then \
455 cp $0.sig ${srcinstdir}/ ; \
457 cp "${version}" "${srcinstdir}" && \
458 cd ${srcinstdir} && \
459 tar cvjf ${src_pkg} * )
463 (cd ${srcinstdir} && \
464 if [ -e ${configurelogname} -o -e ${makelogname} -o \
465 -e ${checklogname} -o -e ${installlogname} ]; then
466 tar --ignore-failed-read -cvjf ${log_pkg_name} \
467 ${configurelogname} ${makelogname} ${checklogname} ${installlogname} && \
469 ${configurelogname} ${makelogname} ${checklogname} ${installlogname} ; \
471 tar uvjf ${src_pkg} * )
474 # Clean up everything.
479 # Generate GPG signatures.
481 if [ \( "${SIG}" -eq 1 \) -a \( -e $name \) -a \( \( ! -e $name.sig \) -o \( $name -nt $name.sig \) \) ]; then \
482 if [ -x /usr/bin/gpg ]; then \
483 echo "$text signature need to be updated"; \
485 /usr/bin/gpg --detach-sign $name; \
487 echo "You need the gnupg package installed in order to make signatures."; \
492 # Validate GPG signatures.
494 if [ -x /usr/bin/gpg ]; then \
495 if [ -e ${src_orig_pkg}.sig ]; then \
496 echo "ORIGINAL PACKAGE signature follows:"; \
497 /usr/bin/gpg --verify ${src_orig_pkg}.sig ${src_orig_pkg}; \
499 echo "ORIGINAL PACKAGE signature missing."; \
501 if [ -e $0.sig ]; then \
502 echo "SCRIPT signature follows:"; \
503 /usr/bin/gpg --verify $0.sig $0; \
505 echo "SCRIPT signature missing."; \
507 if [ -e ${src_patch}.sig ]; then \
508 echo "PATCH signature follows:"; \
509 /usr/bin/gpg --verify ${src_patch}.sig ${src_patch}; \
511 echo "PATCH signature missing."; \
514 echo "You need the gnupg package installed in order to check signatures." ; \
528 f_mkdirs=mkdirs_log && \
531 f_reconf=reconf_log && \
532 f_build=build_log && \
533 f_check=check_log && \
534 f_install=install_log && \
538 while test -n "$1" ; do
540 help|--help) help ; STATUS=$? ;;
541 version|--version) version ; STATUS=$? ;;
542 with_logs|--logs) enablelogging ; STATUS=$? ;;
543 prep) $f_prep ; STATUS=$? ;;
544 mkdirs) $f_mkdirs ; STATUS=$? ;;
545 conf) $f_conf ; STATUS=$? ;;
546 configure) $f_conf ; STATUS=$? ;;
547 reconf) $f_reconf ; STATUS=$? ;;
548 build) $f_build ; STATUS=$? ;;
549 make) $f_build ; STATUS=$? ;;
550 check) $f_check ; STATUS=$? ;;
551 test) $f_check ; STATUS=$? ;;
552 clean) $f_clean ; STATUS=$? ;;
553 install) $f_install ; STATUS=$? ;;
554 list) list ; STATUS=$? ;;
555 depend) depend ; STATUS=$? ;;
556 strip) strip ; STATUS=$? ;;
557 package) pkg ; STATUS=$? ;;
558 pkg) pkg ; STATUS=$? ;;
559 mkpatch) mkpatch ; STATUS=$? ;;
560 acceptpatch) acceptpatch ; STATUS=$? ;;
561 src-package) $f_spkg ; STATUS=$? ;;
562 spkg) $f_spkg ; STATUS=$? ;;
563 finish) finish ; STATUS=$? ;;
564 checksig) checksig ; STATUS=$? ;;
565 first) $f_mkdirs && $f_spkg && finish ; STATUS=$? ;;
566 almostall) checksig && $f_prep && $f_conf && $f_build && \
567 $f_install && strip && pkg && $f_spkg ; STATUS=$? ;;
568 all) checksig && $f_prep && $f_conf && $f_build && \
569 $f_install && strip && pkg && $f_spkg && finish ; \
571 *) echo "Error: bad arguments" ; exit 1 ;;
573 ( exit ${STATUS} ) || exit ${STATUS}