3 # ==========================================================================
4 # Change from generic-build-script: added this comment block.
5 # Based on Cygwin generic package build script, customized for nmh.
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 tscriptname=`basename $0 .sh`
42 export PKG=`echo $tscriptname | sed -e 's/\-[^\-]*\-[^\-]*$//'`
43 export VER=`echo $tscriptname | sed -e "s/${PKG}\-//" -e 's/\-[^\-]*$//'`
44 export REL=`echo $tscriptname | sed -e "s/${PKG}\-${VER}\-//"`
45 # BASEPKG refers to the upstream base package
46 # SHORTPKG refers to the Cygwin package
47 # Normally, these are identical, but if the Cygwin package name is different
48 # from the upstream package name, you will want to redefine BASEPKG.
49 # Example: For Apache 2, BASEPKG=httpd-2.x.xx but SHORTPKG=apache2-2.x.xx
50 export BASEPKG=${PKG}-${VER}
51 # Change from generic-build-script: redefined BASEPKG.
52 export BASEPKG=${PKG}-${VER}-RC2
53 export SHORTPKG=${PKG}-${VER}
54 export FULLPKG=${SHORTPKG}-${REL}
56 # determine correct decompression option and tarball filename
57 # Change from generic-build-script: set scr_orig_pkg_name here.
58 export src_orig_pkg_name=nmh-1.5-RC2.tar.gz
59 if [ -e "${src_orig_pkg_name}" ] ; then
60 # Change from generic-build-script: don't need the following line, use
62 # export opt_decomp=? # Make sure tar punts if unpack() is not redefined
64 elif [ -e ${BASEPKG}.tar.bz2 ] ; then
66 export src_orig_pkg_name=${BASEPKG}.tar.bz2
67 elif [ -e ${BASEPKG}.tar.gz ] ; then
69 export src_orig_pkg_name=${BASEPKG}.tar.gz
70 elif [ -e ${BASEPKG}.tgz ] ; then
72 export src_orig_pkg_name=${BASEPKG}.tgz
73 elif [ -e ${BASEPKG}.tar ] ; then
75 export src_orig_pkg_name=${BASEPKG}.tar
77 echo "Cannot find PKG:${PKG} VER:${VER} REL:${REL}. Rename $0 to"
78 echo "something more appropriate, and try again."
82 export src_orig_pkg=${topdir}/${src_orig_pkg_name}
84 # determine correct names for generated files
85 export src_pkg_name=${FULLPKG}-src.tar.bz2
86 export src_patch_name=${FULLPKG}.patch
87 export bin_pkg_name=${FULLPKG}.tar.bz2
88 export log_pkg_name=${FULLPKG}-BUILDLOGS.tar.bz2
90 export configurelogname=${FULLPKG}-CONFIGURE.LOG
91 export makelogname=${FULLPKG}-MAKE.LOG
92 export checklogname=${FULLPKG}-CHECK.LOG
93 export installlogname=${FULLPKG}-INSTALL.LOG
95 export src_pkg=${topdir}/${src_pkg_name}
96 export src_patch=${topdir}/${src_patch_name}
97 export bin_pkg=${topdir}/${bin_pkg_name}
98 export srcdir=${topdir}/${BASEPKG}
99 export objdir=${srcdir}/.build
100 export instdir=${srcdir}/.inst
101 export srcinstdir=${srcdir}/.sinst
102 export buildlogdir=${srcdir}/.buildlogs
103 export configurelogfile=${srcinstdir}/${configurelogname}
104 export makelogfile=${srcinstdir}/${makelogname}
105 export checklogfile=${srcinstdir}/${checklogname}
106 export installlogfile=${srcinstdir}/${installlogname}
111 if [ -z "$MY_CFLAGS" ]; then
114 if [ -z "$MY_LDFLAGS" ]; then
118 # Change from generic-build-script: removed ChangeLog because the nmh
119 # Makefile installs it.
120 export install_docs="\
146 export install_docs="`for i in ${install_docs}; do echo $i; done | sort -u`"
147 export test_rule=check
148 if [ -z "$SIG" ]; then
149 export SIG=0 # set to 1 to turn on signing by default
151 # Sort in POSIX order.
159 This is the cygwin packaging script for ${FULLPKG}.
160 Usage: $0 [<option>...] <action>...
162 help, --help Print this message
163 version, --version Print the version message
164 with_logs, --logs Create logs of remaining steps
166 prep Unpack and patch into ${srcdir}
167 mkdirs Make hidden directories needed during build
168 conf, configure Configure the package (./configure)
169 reconf Rerun configure
170 build, make Build the package (make)
171 check, test Run the testsuite (make ${test_rule})
172 clean Remove built files (make clean)
173 install Install package to staging area (make install)
174 list List package contents
175 depend List package dependencies
176 strip Strip package executables
177 pkg, package Prepare the binary package ${bin_pkg_name}
178 mkpatch Prepare the patch file ${src_patch_name}
179 acceptpatch Copy patch file ${src_patch_name} to ${topdir}
180 spkg, src-package Prepare the source package ${src_pkg_name}
181 finish Remove source directory ${srcdir}
182 checksig Validate GPG signatures (requires gpg)
183 first Full run for spkg (mkdirs, spkg, finish)
184 almostall Full run for bin pkg, except for finish
185 all Full run for bin pkg
189 # Provide version of generic-build-script modified to make this script.
191 vers=`echo '$Revision: 1.47 $' | sed -e 's/Revision: //' -e 's/ *\\$//g'`
192 echo "$0 based on generic-build-script $vers"
195 # Unpacks the original package source archive into ./${BASEPKG}/.
196 # Change this if the original package was not tarred
197 # or if it doesn't unpack to a correct directory.
199 tar xv${opt_decomp}f "$1"
202 # Make the hidden directories used by this script.
205 rm -fr ${objdir} ${instdir} ${srcinstdir} && \
206 mkdir -p ${objdir} && \
207 mkdir -p ${instdir} && \
208 mkdir -p ${srcinstdir} )
213 rm -fr ${buildlogdir} && \
214 mkdir -p ${buildlogdir} )
217 # Unpack the original tarball, and get everything set up for this script.
220 unpack ${src_orig_pkg} && \
222 if [ -f ${src_patch} ] ; then \
223 patch -Z -p0 < ${src_patch} ;\
230 if [ -f ${topdir}/${log_pkg_name} ] ; then \
231 # Change from generic-build-script: do the following in subshell
232 # so that cd isn't permanent.
233 (cd ${buildlogdir} && \
234 tar xvjf "${topdir}"/${log_pkg_name})
238 # Configure the package.
241 CFLAGS="${MY_CFLAGS}" LDFLAGS="${MY_LDFLAGS}" \
242 ${srcdir}/configure \
243 --srcdir=${srcdir} --prefix="${prefix}" \
244 --exec-prefix='${prefix}' --sysconfdir="${sysconfdir}" \
245 --libdir='${prefix}/lib' --includedir='${prefix}/include' \
246 --mandir='${prefix}/share/man' --infodir='${prefix}/share/info' \
247 --libexecdir='${sbindir}' --localstatedir="${localstatedir}" \
248 --datadir='${prefix}/share' )
251 conf "$@" 2>&1 | tee ${configurelogfile}
252 return ${PIPESTATUS[0]}
255 # Rerun configure to pick up changes in the environment.
258 rm -fr ${objdir} && \
259 mkdir -p ${objdir} && \
263 reconf "$@" 2>&1 | tee ${configurelogfile}
264 return ${PIPESTATUS[0]}
270 make CFLAGS="${MY_CFLAGS}" )
273 build "$@" 2>&1 | tee ${makelogfile}
274 return ${PIPESTATUS[0]}
277 # Run the package testsuite.
280 make -k ${test_rule} )
283 check "$@" 2>&1 | tee ${checklogfile}
284 return ${PIPESTATUS[0]}
287 # Remove files created by configure and make.
293 # Install the package, with DESTDIR set to '.inst'.
294 # Change from generic-build-script: added ":;" after "find ... | gzip"
295 # because it returns non-zero status.
298 rm -fr ${instdir}/* && \
299 make install DESTDIR=${instdir} && \
300 for f in ${prefix}/share/info/dir ${prefix}/info/dir ; do \
301 if [ -f ${instdir}${f} ] ; then \
302 rm -f ${instdir}${f} ; \
305 for d in ${prefix}/share/doc/${SHORTPKG} ${prefix}/share/doc/Cygwin ; do \
306 if [ ! -d ${instdir}${d} ] ; then \
307 mkdir -p ${instdir}${d} ;\
310 if [ -d ${instdir}${prefix}/share/info ] ; then \
311 find ${instdir}${prefix}/share/info -name "*.info" | xargs -r gzip -q ; \
313 if [ -d ${instdir}${prefix}/share/man ] ; then \
314 find ${instdir}${prefix}/share/man -name "*.1" -o -name "*.3" -o \
315 -name "*.3x" -o -name "*.3pm" -o -name "*.5" -o -name "*.6" -o \
316 -name "*.7" -o -name "*.8" | xargs -r gzip -q ; :; \
319 for fp in ${install_docs} ; do \
321 */) templist="$templist `find ${srcdir}/$fp -type f`" ;;
322 *) for f in ${srcdir}/$fp ; do \
323 if [ -f $f ] ; then \
324 templist="$templist $f"; \
329 if [ ! "x$templist" = "x" ]; then \
330 /usr/bin/install -m 644 $templist \
331 ${instdir}${prefix}/share/doc/${SHORTPKG} ; \
333 if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}.README ]; then \
334 /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/${PKG}.README \
335 ${instdir}${prefix}/share/doc/Cygwin/${SHORTPKG}.README ; \
336 elif [ -f ${srcdir}/CYGWIN-PATCHES/README ] ; then \
337 /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/README \
338 ${instdir}${prefix}/share/doc/Cygwin/${SHORTPKG}.README ; \
340 if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}.sh ] ; then \
341 if [ ! -d ${instdir}${sysconfdir}/postinstall ]; then \
342 mkdir -p ${instdir}${sysconfdir}/postinstall ; \
344 /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/${PKG}.sh \
345 ${instdir}${sysconfdir}/postinstall/${PKG}.sh ; \
346 elif [ -f ${srcdir}/CYGWIN-PATCHES/postinstall.sh ] ; then \
347 if [ ! -d ${instdir}${sysconfdir}/postinstall ]; then \
348 mkdir -p ${instdir}${sysconfdir}/postinstall ; \
350 /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/postinstall.sh \
351 ${instdir}${sysconfdir}/postinstall/${PKG}.sh ; \
353 if [ -f ${srcdir}/CYGWIN-PATCHES/preremove.sh ] ; then \
354 if [ ! -d ${instdir}${sysconfdir}/preremove ]; then \
355 mkdir -p ${instdir}${sysconfdir}/preremove ; \
357 /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/preremove.sh \
358 ${instdir}${sysconfdir}/preremove/${PKG}.sh ; \
360 if [ -f ${srcdir}/CYGWIN-PATCHES/manifest.lst ] ; then
361 if [ ! -d ${instdir}${sysconfdir}/preremove ]; then
362 mkdir -p ${instdir}${sysconfdir}/preremove ;
364 /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/manifest.lst \
365 ${instdir}${sysconfdir}/preremove/${PKG}-manifest.lst ;
369 install "$@" 2>&1 | tee ${installlogfile}
370 return ${PIPESTATUS[0]}
373 # Strip all binaries.
376 find . -name "*.dll" -or -name "*.exe" | xargs -r strip 2>&1 ; \
380 # List all non-hidden files that belong to the package.
383 find . -name "*" ! -type d | sed 's%^\.% %' | sort ; \
387 # List the static .dll dependencies of the package. This does not pick up
388 # dynamic dependencies (whether or not libtool was used), nor does it pick
389 # up program dependencies, such as system() depending on /bin/sh.
392 find ${instdir} -name "*.exe" -o -name "*.dll" | xargs -r cygcheck | \
393 sed -ne '/^ [^ ]/ s,\\,/,gp' | sort -bu | \
394 xargs -r -n1 cygpath -u | xargs -r cygcheck -f | sed 's%^% %' | sort -u ; \
398 # Build the binary package tarball.
401 tar cvjf ${bin_pkg} * )
404 # Compare the original tarball against cygwin modifications.
407 find . -name "autom4te.cache" | xargs -r rm -rf ; \
408 unpack ${src_orig_pkg} && \
409 mv ${BASEPKG} ../${BASEPKG}-orig && \
411 diff -urN -x '.build' -x '.inst' -x '.sinst' -x '.buildlogs' \
412 ${BASEPKG}-orig ${BASEPKG} > \
413 ${srcinstdir}/${src_patch_name} ; \
414 rm -rf ${BASEPKG}-orig )
417 # Note: maintainer-only functionality
419 cp --backup=numbered ${srcinstdir}/${src_patch_name} ${topdir}
422 # Build the source tarball.
425 if [ "${SIG}" -eq 1 ] ; then \
426 name=${srcinstdir}/${src_patch_name} text="PATCH" sigfile ; \
428 cp ${src_orig_pkg} ${srcinstdir}/${src_orig_pkg_name} && \
429 if [ -e ${src_orig_pkg}.sig ] ; then \
430 cp ${src_orig_pkg}.sig ${srcinstdir}/ ; \
432 cp $0 ${srcinstdir}/`basename $0` && \
433 name=$0 text="SCRIPT" sigfile && \
434 if [ "${SIG}" -eq 1 ] ; then \
435 cp $0.sig ${srcinstdir}/ ; \
437 cd ${srcinstdir} && \
438 tar cvjf ${src_pkg} * )
442 (cd ${srcinstdir} && \
443 if [ -e ${configurelogname} -o -e ${makelogname} -o \
444 -e ${checklogname} -o -e ${installlogname} ]; then
445 tar --ignore-failed-read -cvjf ${log_pkg_name} \
446 ${configurelogname} ${makelogname} ${checklogname} ${installlogname} && \
448 ${configurelogname} ${makelogname} ${checklogname} ${installlogname} ; \
450 tar uvjf ${src_pkg} * )
453 # Clean up everything.
458 # Generate GPG signatures.
460 if [ \( "${SIG}" -eq 1 \) -a \( -e $name \) -a \( \( ! -e $name.sig \) -o \( $name -nt $name.sig \) \) ]; then \
461 if [ -x /usr/bin/gpg ]; then \
462 echo "$text signature need to be updated"; \
464 /usr/bin/gpg --detach-sign $name; \
466 echo "You need the gnupg package installed in order to make signatures."; \
471 # Validate GPG signatures.
473 if [ -x /usr/bin/gpg ]; then \
474 if [ -e ${src_orig_pkg}.sig ]; then \
475 echo "ORIGINAL PACKAGE signature follows:"; \
476 /usr/bin/gpg --verify ${src_orig_pkg}.sig ${src_orig_pkg}; \
478 echo "ORIGINAL PACKAGE signature missing."; \
480 if [ -e $0.sig ]; then \
481 echo "SCRIPT signature follows:"; \
482 /usr/bin/gpg --verify $0.sig $0; \
484 echo "SCRIPT signature missing."; \
486 if [ -e ${src_patch}.sig ]; then \
487 echo "PATCH signature follows:"; \
488 /usr/bin/gpg --verify ${src_patch}.sig ${src_patch}; \
490 echo "PATCH signature missing."; \
493 echo "You need the gnupg package installed in order to check signatures." ; \
507 f_mkdirs=mkdirs_log && \
510 f_reconf=reconf_log && \
511 f_build=build_log && \
512 f_check=check_log && \
513 f_install=install_log && \
517 while test -n "$1" ; do
519 help|--help) help ; STATUS=$? ;;
520 version|--version) version ; STATUS=$? ;;
521 with_logs|--logs) enablelogging ; STATUS=$? ;;
522 prep) $f_prep ; STATUS=$? ;;
523 mkdirs) $f_mkdirs ; STATUS=$? ;;
524 conf) $f_conf ; STATUS=$? ;;
525 configure) $f_conf ; STATUS=$? ;;
526 reconf) $f_reconf ; STATUS=$? ;;
527 build) $f_build ; STATUS=$? ;;
528 make) $f_build ; STATUS=$? ;;
529 check) $f_check ; STATUS=$? ;;
530 test) $f_check ; STATUS=$? ;;
531 clean) $f_clean ; STATUS=$? ;;
532 install) $f_install ; STATUS=$? ;;
533 list) list ; STATUS=$? ;;
534 depend) depend ; STATUS=$? ;;
535 strip) strip ; STATUS=$? ;;
536 package) pkg ; STATUS=$? ;;
537 pkg) pkg ; STATUS=$? ;;
538 mkpatch) mkpatch ; STATUS=$? ;;
539 acceptpatch) acceptpatch ; STATUS=$? ;;
540 src-package) $f_spkg ; STATUS=$? ;;
541 spkg) $f_spkg ; STATUS=$? ;;
542 finish) finish ; STATUS=$? ;;
543 checksig) checksig ; STATUS=$? ;;
544 first) $f_mkdirs && $f_spkg && finish ; STATUS=$? ;;
545 almostall) checksig && $f_prep && $f_conf && $f_build && \
546 $f_install && strip && pkg && $f_spkg ; STATUS=$? ;;
547 all) checksig && $f_prep && $f_conf && $f_build && \
548 $f_install && strip && pkg && $f_spkg && finish ; \
550 *) echo "Error: bad arguments" ; exit 1 ;;
552 ( exit ${STATUS} ) || exit ${STATUS}