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}-${REL}
51 export SHORTPKG=${PKG}-${VER}
52 export FULLPKG=${SHORTPKG}-${REL}
54 # determine correct decompression option and tarball filename
55 # Change from generic-build-script: set scr_orig_pkg_name here.
56 export src_orig_pkg_name=nmh-1.5-2.tar.gz
57 if [ -e "${src_orig_pkg_name}" ] ; then
58 # Change from generic-build-script: don't need the following line, use
60 # export opt_decomp=? # Make sure tar punts if unpack() is not redefined
62 elif [ -e ${BASEPKG}.tar.bz2 ] ; then
64 export src_orig_pkg_name=${BASEPKG}.tar.bz2
65 elif [ -e ${BASEPKG}.tar.gz ] ; then
67 export src_orig_pkg_name=${BASEPKG}.tar.gz
68 elif [ -e ${BASEPKG}.tgz ] ; then
70 export src_orig_pkg_name=${BASEPKG}.tgz
71 elif [ -e ${BASEPKG}.tar ] ; then
73 export src_orig_pkg_name=${BASEPKG}.tar
75 echo "Cannot find PKG:${PKG} VER:${VER} REL:${REL}. Rename $0 to"
76 echo "something more appropriate, and try again."
80 export src_orig_pkg=${topdir}/${src_orig_pkg_name}
82 # determine correct names for generated files
83 export src_pkg_name=${FULLPKG}-src.tar.bz2
84 export src_patch_name=${FULLPKG}.patch
85 export bin_pkg_name=${FULLPKG}.tar.bz2
86 export log_pkg_name=${FULLPKG}-BUILDLOGS.tar.bz2
88 export configurelogname=${FULLPKG}-CONFIGURE.LOG
89 export makelogname=${FULLPKG}-MAKE.LOG
90 export checklogname=${FULLPKG}-CHECK.LOG
91 export installlogname=${FULLPKG}-INSTALL.LOG
93 export src_pkg=${topdir}/${src_pkg_name}
94 export src_patch=${topdir}/${src_patch_name}
95 export bin_pkg=${topdir}/${bin_pkg_name}
96 export srcdir=${topdir}/${BASEPKG}
97 export objdir=${srcdir}/.build
98 export instdir=${srcdir}/.inst
99 export srcinstdir=${srcdir}/.sinst
100 export buildlogdir=${srcdir}/.buildlogs
101 export configurelogfile=${srcinstdir}/${configurelogname}
102 export makelogfile=${srcinstdir}/${makelogname}
103 export checklogfile=${srcinstdir}/${checklogname}
104 export installlogfile=${srcinstdir}/${installlogname}
107 # Change from generic-build-script: use /etc/nmh instead of /etc.
110 if [ -z "$MY_CFLAGS" ]; then
113 if [ -z "$MY_LDFLAGS" ]; then
117 # Change from generic-build-script: disabled install_docs because
118 # nmh's make install takes care of it. Though it installs in
119 # /usr/share/doc/nmh/ instead of /usr/share/doc/nmh-<version>/,
120 # that seems to be more common on Cygwin than using the -<version>.
122 #export install_docs="`for i in ${install_docs}; do echo $i; done | sort -u`"
123 export test_rule=check
124 if [ -z "$SIG" ]; then
125 export SIG=0 # set to 1 to turn on signing by default
127 # Sort in POSIX order.
135 This is the cygwin packaging script for ${FULLPKG}.
136 Usage: $0 [<option>...] <action>...
138 help, --help Print this message
139 version, --version Print the version message
140 with_logs, --logs Create logs of remaining steps
142 prep Unpack and patch into ${srcdir}
143 mkdirs Make hidden directories needed during build
144 conf, configure Configure the package (./configure)
145 reconf Rerun configure
146 build, make Build the package (make)
147 check, test Run the testsuite (make ${test_rule})
148 clean Remove built files (make clean)
149 install Install package to staging area (make install)
150 list List package contents
151 depend List package dependencies
152 strip Strip package executables
153 pkg, package Prepare the binary package ${bin_pkg_name}
154 mkpatch Prepare the patch file ${src_patch_name}
155 acceptpatch Copy patch file ${src_patch_name} to ${topdir}
156 spkg, src-package Prepare the source package ${src_pkg_name}
157 finish Remove source directory ${srcdir}
158 checksig Validate GPG signatures (requires gpg)
159 first Full run for spkg (mkdirs, spkg, finish)
160 almostall Full run for bin pkg, except for finish
161 all Full run for bin pkg
165 # Provide version of generic-build-script modified to make this script.
167 vers=`echo '$Revision: 1.47 $' | sed -e 's/Revision: //' -e 's/ *\\$//g'`
168 echo "$0 based on generic-build-script $vers"
171 # Unpacks the original package source archive into ./${BASEPKG}/.
172 # Change this if the original package was not tarred
173 # or if it doesn't unpack to a correct directory.
175 tar xv${opt_decomp}f "$1"
178 # Make the hidden directories used by this script.
181 rm -fr ${objdir} ${instdir} ${srcinstdir} && \
182 mkdir -p ${objdir} && \
183 mkdir -p ${instdir} && \
184 mkdir -p ${srcinstdir} )
189 rm -fr ${buildlogdir} && \
190 mkdir -p ${buildlogdir} )
193 # Unpack the original tarball, and get everything set up for this script.
196 unpack ${src_orig_pkg} && \
198 if [ -f ${src_patch} ] ; then \
199 patch -Z -p0 < ${src_patch} ;\
206 if [ -f ${topdir}/${log_pkg_name} ] ; then \
207 # Change from generic-build-script: do the following in subshell
208 # so that cd isn't permanent.
209 (cd ${buildlogdir} && \
210 tar xvjf "${topdir}"/${log_pkg_name})
214 # Configure the package.
215 # Change from generic-build-script: added following notes:
216 # Could add --with-cyrus-sasl if libsasl2 and libsas2-devel
217 # packages are installed.
218 # Could add --with-tls if libgnutls26 and gnutls-devel
219 # packages are installed.
223 CFLAGS="${MY_CFLAGS}" LDFLAGS="${MY_LDFLAGS}" \
224 ${srcdir}/configure \
225 --srcdir=${srcdir} --prefix="${prefix}" \
226 --exec-prefix='${prefix}' --sysconfdir="${sysconfdir}" \
227 --libdir='${prefix}/lib' --includedir='${prefix}/include' \
228 --mandir='${prefix}/share/man' --infodir='${prefix}/share/info' \
229 --libexecdir='${sbindir}' --localstatedir="${localstatedir}" \
230 --datadir='${prefix}/share' )
233 conf "$@" 2>&1 | tee ${configurelogfile}
234 return ${PIPESTATUS[0]}
237 # Rerun configure to pick up changes in the environment.
240 rm -fr ${objdir} && \
241 mkdir -p ${objdir} && \
245 reconf "$@" 2>&1 | tee ${configurelogfile}
246 return ${PIPESTATUS[0]}
252 make CFLAGS="${MY_CFLAGS}" )
255 build "$@" 2>&1 | tee ${makelogfile}
256 return ${PIPESTATUS[0]}
259 # Run the package testsuite.
262 make -k ${test_rule} )
265 check "$@" 2>&1 | tee ${checklogfile}
266 return ${PIPESTATUS[0]}
269 # Remove files created by configure and make.
275 # Install the package, with DESTDIR set to '.inst'.
276 # Change from generic-build-script: added ":;" after "find ... | gzip"
277 # because it returns non-zero status.
280 rm -fr ${instdir}/* && \
281 make install DESTDIR=${instdir} && \
282 for f in ${prefix}/share/info/dir ${prefix}/info/dir ; do \
283 if [ -f ${instdir}${f} ] ; then \
284 rm -f ${instdir}${f} ; \
287 for d in ${prefix}/share/doc/${SHORTPKG} ${prefix}/share/doc/Cygwin ; do \
288 if [ ! -d ${instdir}${d} ] ; then \
289 mkdir -p ${instdir}${d} ;\
292 if [ -d ${instdir}${prefix}/share/info ] ; then \
293 find ${instdir}${prefix}/share/info -name "*.info" | xargs -r gzip -q ; \
295 if [ -d ${instdir}${prefix}/share/man ] ; then \
296 find ${instdir}${prefix}/share/man -name "*.1" -o -name "*.3" -o \
297 -name "*.3x" -o -name "*.3pm" -o -name "*.5" -o -name "*.6" -o \
298 -name "*.7" -o -name "*.8" | xargs -r gzip -q ; :; \
301 for fp in ${install_docs} ; do \
303 */) templist="$templist `find ${srcdir}/$fp -type f`" ;;
304 *) for f in ${srcdir}/$fp ; do \
305 if [ -f $f ] ; then \
306 templist="$templist $f"; \
311 if [ ! "x$templist" = "x" ]; then \
312 /usr/bin/install -m 644 $templist \
313 ${instdir}${prefix}/share/doc/${SHORTPKG} ; \
315 if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}.README ]; then \
316 /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/${PKG}.README \
317 ${instdir}${prefix}/share/doc/Cygwin/${SHORTPKG}.README ; \
318 elif [ -f ${srcdir}/CYGWIN-PATCHES/README ] ; then \
319 /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/README \
320 ${instdir}${prefix}/share/doc/Cygwin/${SHORTPKG}.README ; \
322 if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}.sh ] ; then \
323 if [ ! -d ${instdir}${sysconfdir}/postinstall ]; then \
324 mkdir -p ${instdir}${sysconfdir}/postinstall ; \
326 /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/${PKG}.sh \
327 ${instdir}${sysconfdir}/postinstall/${PKG}.sh ; \
328 elif [ -f ${srcdir}/CYGWIN-PATCHES/postinstall.sh ] ; then \
329 if [ ! -d ${instdir}${sysconfdir}/postinstall ]; then \
330 mkdir -p ${instdir}${sysconfdir}/postinstall ; \
332 /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/postinstall.sh \
333 ${instdir}${sysconfdir}/postinstall/${PKG}.sh ; \
335 if [ -f ${srcdir}/CYGWIN-PATCHES/preremove.sh ] ; then \
336 if [ ! -d ${instdir}${sysconfdir}/preremove ]; then \
337 mkdir -p ${instdir}${sysconfdir}/preremove ; \
339 /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/preremove.sh \
340 ${instdir}${sysconfdir}/preremove/${PKG}.sh ; \
342 if [ -f ${srcdir}/CYGWIN-PATCHES/manifest.lst ] ; then
343 if [ ! -d ${instdir}${sysconfdir}/preremove ]; then
344 mkdir -p ${instdir}${sysconfdir}/preremove ;
346 /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/manifest.lst \
347 ${instdir}${sysconfdir}/preremove/${PKG}-manifest.lst ;
351 install "$@" 2>&1 | tee ${installlogfile}
352 return ${PIPESTATUS[0]}
355 # Strip all binaries.
358 find . -name "*.dll" -or -name "*.exe" | xargs -r strip 2>&1 ; \
362 # List all non-hidden files that belong to the package.
365 find . -name "*" ! -type d | sed 's%^\.% %' | sort ; \
369 # List the static .dll dependencies of the package. This does not pick up
370 # dynamic dependencies (whether or not libtool was used), nor does it pick
371 # up program dependencies, such as system() depending on /bin/sh.
374 find ${instdir} -name "*.exe" -o -name "*.dll" | xargs -r cygcheck | \
375 sed -ne '/^ [^ ]/ s,\\,/,gp' | sort -bu | \
376 xargs -r -n1 cygpath -u | xargs -r cygcheck -f | sed 's%^% %' | sort -u ; \
380 # Build the binary package tarball.
383 tar cvjf ${bin_pkg} * )
386 # Compare the original tarball against cygwin modifications.
389 find . -name "autom4te.cache" | xargs -r rm -rf ; \
390 unpack ${src_orig_pkg} && \
391 mv ${BASEPKG} ../${BASEPKG}-orig && \
393 diff -urN -x '.build' -x '.inst' -x '.sinst' -x '.buildlogs' \
394 ${BASEPKG}-orig ${BASEPKG} > \
395 ${srcinstdir}/${src_patch_name} ; \
396 rm -rf ${BASEPKG}-orig )
399 # Note: maintainer-only functionality
401 cp --backup=numbered ${srcinstdir}/${src_patch_name} ${topdir}
404 # Build the source tarball.
407 if [ "${SIG}" -eq 1 ] ; then \
408 name=${srcinstdir}/${src_patch_name} text="PATCH" sigfile ; \
410 cp ${src_orig_pkg} ${srcinstdir}/${src_orig_pkg_name} && \
411 if [ -e ${src_orig_pkg}.sig ] ; then \
412 cp ${src_orig_pkg}.sig ${srcinstdir}/ ; \
414 cp $0 ${srcinstdir}/`basename $0` && \
415 name=$0 text="SCRIPT" sigfile && \
416 if [ "${SIG}" -eq 1 ] ; then \
417 cp $0.sig ${srcinstdir}/ ; \
419 cd ${srcinstdir} && \
420 tar cvjf ${src_pkg} * )
424 (cd ${srcinstdir} && \
425 if [ -e ${configurelogname} -o -e ${makelogname} -o \
426 -e ${checklogname} -o -e ${installlogname} ]; then
427 tar --ignore-failed-read -cvjf ${log_pkg_name} \
428 ${configurelogname} ${makelogname} ${checklogname} ${installlogname} && \
430 ${configurelogname} ${makelogname} ${checklogname} ${installlogname} ; \
432 tar uvjf ${src_pkg} * )
435 # Clean up everything.
440 # Generate GPG signatures.
442 if [ \( "${SIG}" -eq 1 \) -a \( -e $name \) -a \( \( ! -e $name.sig \) -o \( $name -nt $name.sig \) \) ]; then \
443 if [ -x /usr/bin/gpg ]; then \
444 echo "$text signature need to be updated"; \
446 /usr/bin/gpg --detach-sign $name; \
448 echo "You need the gnupg package installed in order to make signatures."; \
453 # Validate GPG signatures.
455 if [ -x /usr/bin/gpg ]; then \
456 if [ -e ${src_orig_pkg}.sig ]; then \
457 echo "ORIGINAL PACKAGE signature follows:"; \
458 /usr/bin/gpg --verify ${src_orig_pkg}.sig ${src_orig_pkg}; \
460 echo "ORIGINAL PACKAGE signature missing."; \
462 if [ -e $0.sig ]; then \
463 echo "SCRIPT signature follows:"; \
464 /usr/bin/gpg --verify $0.sig $0; \
466 echo "SCRIPT signature missing."; \
468 if [ -e ${src_patch}.sig ]; then \
469 echo "PATCH signature follows:"; \
470 /usr/bin/gpg --verify ${src_patch}.sig ${src_patch}; \
472 echo "PATCH signature missing."; \
475 echo "You need the gnupg package installed in order to check signatures." ; \
489 f_mkdirs=mkdirs_log && \
492 f_reconf=reconf_log && \
493 f_build=build_log && \
494 f_check=check_log && \
495 f_install=install_log && \
499 while test -n "$1" ; do
501 help|--help) help ; STATUS=$? ;;
502 version|--version) version ; STATUS=$? ;;
503 with_logs|--logs) enablelogging ; STATUS=$? ;;
504 prep) $f_prep ; STATUS=$? ;;
505 mkdirs) $f_mkdirs ; STATUS=$? ;;
506 conf) $f_conf ; STATUS=$? ;;
507 configure) $f_conf ; STATUS=$? ;;
508 reconf) $f_reconf ; STATUS=$? ;;
509 build) $f_build ; STATUS=$? ;;
510 make) $f_build ; STATUS=$? ;;
511 check) $f_check ; STATUS=$? ;;
512 test) $f_check ; STATUS=$? ;;
513 clean) $f_clean ; STATUS=$? ;;
514 install) $f_install ; STATUS=$? ;;
515 list) list ; STATUS=$? ;;
516 depend) depend ; STATUS=$? ;;
517 strip) strip ; STATUS=$? ;;
518 package) pkg ; STATUS=$? ;;
519 pkg) pkg ; STATUS=$? ;;
520 mkpatch) mkpatch ; STATUS=$? ;;
521 acceptpatch) acceptpatch ; STATUS=$? ;;
522 src-package) $f_spkg ; STATUS=$? ;;
523 spkg) $f_spkg ; STATUS=$? ;;
524 finish) finish ; STATUS=$? ;;
525 checksig) checksig ; STATUS=$? ;;
526 first) $f_mkdirs && $f_spkg && finish ; STATUS=$? ;;
527 almostall) checksig && $f_prep && $f_conf && $f_build && \
528 $f_install && strip && pkg && $f_spkg ; STATUS=$? ;;
529 all) checksig && $f_prep && $f_conf && $f_build && \
530 $f_install && strip && pkg && $f_spkg && finish ; \
532 *) echo "Error: bad arguments" ; exit 1 ;;
534 ( exit ${STATUS} ) || exit ${STATUS}