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 # Change from generic-build-script: ${BASEPKG}.tar.bz2 is an output of
75 # this script, so don't trip over it on a rerun.
76 # elif [ -e ${BASEPKG}.tar.bz2 ] ; then
78 # export src_orig_pkg_name=${BASEPKG}.tar.bz2
79 elif [ -e ${BASEPKG}.tar.gz ] ; then
81 export src_orig_pkg_name=${BASEPKG}.tar.gz
82 elif [ -e ${BASEPKG}.tgz ] ; then
84 export src_orig_pkg_name=${BASEPKG}.tgz
85 elif [ -e ${BASEPKG}.tar ] ; then
87 export src_orig_pkg_name=${BASEPKG}.tar
89 # Change from generic-build-script: build the tarball if it doesn't exist.
90 (cd "${topdir}" && make dist)
91 if [ -e "${topdir}/${BASEPKG}.tar.gz" ] ; then
93 export src_orig_pkg_name=${BASEPKG}.tar.gz
95 echo "Cannot find PKG:${PKG} VER:${VER} REL:${REL}. Rename $0 to"
96 echo "something more appropriate, and try again."
101 export src_orig_pkg=${topdir}/${src_orig_pkg_name}
103 # determine correct names for generated files
104 export src_pkg_name=${FULLPKG}-src.tar.bz2
105 export src_patch_name=${FULLPKG}.patch
106 export bin_pkg_name=${FULLPKG}.tar.bz2
107 export log_pkg_name=${FULLPKG}-BUILDLOGS.tar.bz2
109 export configurelogname=${FULLPKG}-CONFIGURE.LOG
110 export makelogname=${FULLPKG}-MAKE.LOG
111 export checklogname=${FULLPKG}-CHECK.LOG
112 export installlogname=${FULLPKG}-INSTALL.LOG
114 # Change from generic-build-script: put src_pkg and bin_pkg in current
116 export src_pkg=${pwd}/${src_pkg_name}
117 export src_patch="${topdir}"/${src_patch_name}
118 export bin_pkg=${pwd}/${bin_pkg_name}
119 export srcdir="${topdir}"/${BASEPKG}
120 export objdir=${srcdir}/.build
121 export instdir=${srcdir}/.inst
122 export srcinstdir=${srcdir}/.sinst
123 export buildlogdir=${srcdir}/.buildlogs
124 export configurelogfile=${srcinstdir}/${configurelogname}
125 export makelogfile=${srcinstdir}/${makelogname}
126 export checklogfile=${srcinstdir}/${checklogname}
127 export installlogfile=${srcinstdir}/${installlogname}
132 if [ -z "$MY_CFLAGS" ]; then
135 if [ -z "$MY_LDFLAGS" ]; then
139 # Change from generic-build-script: removed ChangeLog because the nmh
140 # Makefile installs it.
141 export install_docs="\
167 export install_docs="`for i in ${install_docs}; do echo $i; done | sort -u`"
168 export test_rule=check
169 if [ -z "$SIG" ]; then
170 export SIG=0 # set to 1 to turn on signing by default
172 # Sort in POSIX order.
180 This is the cygwin packaging script for ${FULLPKG}.
181 Usage: $0 [<option>...] <action>...
183 help, --help Print this message
184 version, --version Print the version message
185 with_logs, --logs Create logs of remaining steps
187 prep Unpack and patch into ${srcdir}
188 mkdirs Make hidden directories needed during build
189 conf, configure Configure the package (./configure)
190 reconf Rerun configure
191 build, make Build the package (make)
192 check, test Run the testsuite (make ${test_rule})
193 clean Remove built files (make clean)
194 install Install package to staging area (make install)
195 list List package contents
196 depend List package dependencies
197 strip Strip package executables
198 pkg, package Prepare the binary package ${bin_pkg_name}
199 mkpatch Prepare the patch file ${src_patch_name}
200 acceptpatch Copy patch file ${src_patch_name} to ${topdir}
201 spkg, src-package Prepare the source package ${src_pkg_name}
202 finish Remove source directory ${srcdir}
203 checksig Validate GPG signatures (requires gpg)
204 first Full run for spkg (mkdirs, spkg, finish)
205 almostall Full run for bin pkg, except for finish
206 all Full run for bin pkg
210 # Provide version of generic-build-script modified to make this script.
212 vers=`echo '$Revision: 1.47 $' | sed -e 's/Revision: //' -e 's/ *\\$//g'`
213 echo "$0 based on generic-build-script $vers"
216 # Unpacks the original package source archive into ./${BASEPKG}/.
217 # Change this if the original package was not tarred
218 # or if it doesn't unpack to a correct directory.
220 tar xv${opt_decomp}f "$1"
223 # Make the hidden directories used by this script.
226 rm -fr ${objdir} ${instdir} ${srcinstdir} && \
227 mkdir -p ${objdir} && \
228 mkdir -p ${instdir} && \
229 mkdir -p ${srcinstdir} )
234 rm -fr ${buildlogdir} && \
235 mkdir -p ${buildlogdir} )
238 # Unpack the original tarball, and get everything set up for this script.
239 # Change from generic-build-script: cd to ${srcdir} instead of ${topdir}.
240 # Change from generic-build-script: use -p1 instead of -p0 patch option.
243 unpack ${src_orig_pkg} && \
245 if [ -f ${src_patch} ] ; then \
246 patch -Z -p1 < ${src_patch} ;\
253 if [ -f ${topdir}/${log_pkg_name} ] ; then \
254 # Change from generic-build-script: do the following in subshell
255 # so that cd isn't permanent.
256 (cd ${buildlogdir} && \
257 tar xvjf "${topdir}"/${log_pkg_name})
261 # Configure the package.
264 CFLAGS="${MY_CFLAGS}" LDFLAGS="${MY_LDFLAGS}" \
265 ${srcdir}/configure \
266 --srcdir=${srcdir} --prefix="${prefix}" \
267 --exec-prefix='${prefix}' --sysconfdir="${sysconfdir}" \
268 --libdir='${prefix}/lib' --includedir='${prefix}/include' \
269 --mandir='${prefix}/share/man' --infodir='${prefix}/share/info' \
270 --libexecdir='${sbindir}' --localstatedir="${localstatedir}" \
271 --datadir='${prefix}/share' )
274 conf "$@" 2>&1 | tee ${configurelogfile}
275 return ${PIPESTATUS[0]}
278 # Rerun configure to pick up changes in the environment.
281 rm -fr ${objdir} && \
282 mkdir -p ${objdir} && \
286 reconf "$@" 2>&1 | tee ${configurelogfile}
287 return ${PIPESTATUS[0]}
293 make CFLAGS="${MY_CFLAGS}" )
296 build "$@" 2>&1 | tee ${makelogfile}
297 return ${PIPESTATUS[0]}
300 # Run the package testsuite.
303 make -k ${test_rule} )
306 check "$@" 2>&1 | tee ${checklogfile}
307 return ${PIPESTATUS[0]}
310 # Remove files created by configure and make.
316 # Install the package, with DESTDIR set to '.inst'.
317 # Change from generic-build-script: added ":;" after "find ... | gzip"
318 # because it returns non-zero status.
321 rm -fr ${instdir}/* && \
322 make install DESTDIR=${instdir} && \
323 for f in ${prefix}/share/info/dir ${prefix}/info/dir ; do \
324 if [ -f ${instdir}${f} ] ; then \
325 rm -f ${instdir}${f} ; \
328 for d in ${prefix}/share/doc/${SHORTPKG} ${prefix}/share/doc/Cygwin ; do \
329 if [ ! -d ${instdir}${d} ] ; then \
330 mkdir -p ${instdir}${d} ;\
333 if [ -d ${instdir}${prefix}/share/info ] ; then \
334 find ${instdir}${prefix}/share/info -name "*.info" | xargs -r gzip -q ; \
336 if [ -d ${instdir}${prefix}/share/man ] ; then \
337 find ${instdir}${prefix}/share/man -name "*.1" -o -name "*.3" -o \
338 -name "*.3x" -o -name "*.3pm" -o -name "*.5" -o -name "*.6" -o \
339 -name "*.7" -o -name "*.8" | xargs -r gzip -q ; :; \
342 for fp in ${install_docs} ; do \
344 */) templist="$templist `find ${srcdir}/$fp -type f`" ;;
345 *) for f in ${srcdir}/$fp ; do \
346 if [ -f $f ] ; then \
347 templist="$templist $f"; \
352 if [ ! "x$templist" = "x" ]; then \
353 /usr/bin/install -m 644 $templist \
354 ${instdir}${prefix}/share/doc/${SHORTPKG} ; \
356 if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}.README ]; then \
357 /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/${PKG}.README \
358 ${instdir}${prefix}/share/doc/Cygwin/${SHORTPKG}.README ; \
359 elif [ -f ${srcdir}/CYGWIN-PATCHES/README ] ; then \
360 /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/README \
361 ${instdir}${prefix}/share/doc/Cygwin/${SHORTPKG}.README ; \
363 if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}.sh ] ; then \
364 if [ ! -d ${instdir}${sysconfdir}/postinstall ]; then \
365 mkdir -p ${instdir}${sysconfdir}/postinstall ; \
367 /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/${PKG}.sh \
368 ${instdir}${sysconfdir}/postinstall/${PKG}.sh ; \
369 elif [ -f ${srcdir}/CYGWIN-PATCHES/postinstall.sh ] ; then \
370 if [ ! -d ${instdir}${sysconfdir}/postinstall ]; then \
371 mkdir -p ${instdir}${sysconfdir}/postinstall ; \
373 /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/postinstall.sh \
374 ${instdir}${sysconfdir}/postinstall/${PKG}.sh ; \
376 if [ -f ${srcdir}/CYGWIN-PATCHES/preremove.sh ] ; then \
377 if [ ! -d ${instdir}${sysconfdir}/preremove ]; then \
378 mkdir -p ${instdir}${sysconfdir}/preremove ; \
380 /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/preremove.sh \
381 ${instdir}${sysconfdir}/preremove/${PKG}.sh ; \
383 if [ -f ${srcdir}/CYGWIN-PATCHES/manifest.lst ] ; then
384 if [ ! -d ${instdir}${sysconfdir}/preremove ]; then
385 mkdir -p ${instdir}${sysconfdir}/preremove ;
387 /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/manifest.lst \
388 ${instdir}${sysconfdir}/preremove/${PKG}-manifest.lst ;
392 install "$@" 2>&1 | tee ${installlogfile}
393 return ${PIPESTATUS[0]}
396 # Strip all binaries.
399 find . -name "*.dll" -or -name "*.exe" | xargs -r strip 2>&1 ; \
403 # List all non-hidden files that belong to the package.
406 find . -name "*" ! -type d | sed 's%^\.% %' | sort ; \
410 # List the static .dll dependencies of the package. This does not pick up
411 # dynamic dependencies (whether or not libtool was used), nor does it pick
412 # up program dependencies, such as system() depending on /bin/sh.
415 find ${instdir} -name "*.exe" -o -name "*.dll" | xargs -r cygcheck | \
416 sed -ne '/^ [^ ]/ s,\\,/,gp' | sort -bu | \
417 xargs -r -n1 cygpath -u | xargs -r cygcheck -f | sed 's%^% %' | sort -u ; \
421 # Build the binary package tarball.
424 tar cvjf ${bin_pkg} * )
427 # Compare the original tarball against cygwin modifications.
430 find . -name "autom4te.cache" | xargs -r rm -rf ; \
431 unpack ${src_orig_pkg} && \
432 mv ${BASEPKG} ../${BASEPKG}-orig && \
434 diff -urN -x '.build' -x '.inst' -x '.sinst' -x '.buildlogs' \
435 ${BASEPKG}-orig ${BASEPKG} > \
436 ${srcinstdir}/${src_patch_name} ; \
437 rm -rf ${BASEPKG}-orig )
440 # Note: maintainer-only functionality
442 cp --backup=numbered ${srcinstdir}/${src_patch_name} ${topdir}
445 # Build the source tarball.
446 # Change from generic-build-script: added VERSION file.
449 if [ "${SIG}" -eq 1 ] ; then \
450 name=${srcinstdir}/${src_patch_name} text="PATCH" sigfile ; \
452 cp ${src_orig_pkg} ${srcinstdir}/${src_orig_pkg_name} && \
453 if [ -e ${src_orig_pkg}.sig ] ; then \
454 cp ${src_orig_pkg}.sig ${srcinstdir}/ ; \
456 cp $0 ${srcinstdir}/`basename $0` && \
457 name=$0 text="SCRIPT" sigfile && \
458 if [ "${SIG}" -eq 1 ] ; then \
459 cp $0.sig ${srcinstdir}/ ; \
461 cp "${version}" "${srcinstdir}" && \
462 cd ${srcinstdir} && \
463 tar cvjf ${src_pkg} * )
467 (cd ${srcinstdir} && \
468 if [ -e ${configurelogname} -o -e ${makelogname} -o \
469 -e ${checklogname} -o -e ${installlogname} ]; then
470 tar --ignore-failed-read -cvjf ${log_pkg_name} \
471 ${configurelogname} ${makelogname} ${checklogname} ${installlogname} && \
473 ${configurelogname} ${makelogname} ${checklogname} ${installlogname} ; \
475 tar uvjf ${src_pkg} * )
478 # Clean up everything.
483 # Generate GPG signatures.
485 if [ \( "${SIG}" -eq 1 \) -a \( -e $name \) -a \( \( ! -e $name.sig \) -o \( $name -nt $name.sig \) \) ]; then \
486 if [ -x /usr/bin/gpg ]; then \
487 echo "$text signature need to be updated"; \
489 /usr/bin/gpg --detach-sign $name; \
491 echo "You need the gnupg package installed in order to make signatures."; \
496 # Validate GPG signatures.
498 if [ -x /usr/bin/gpg ]; then \
499 if [ -e ${src_orig_pkg}.sig ]; then \
500 echo "ORIGINAL PACKAGE signature follows:"; \
501 /usr/bin/gpg --verify ${src_orig_pkg}.sig ${src_orig_pkg}; \
503 echo "ORIGINAL PACKAGE signature missing."; \
505 if [ -e $0.sig ]; then \
506 echo "SCRIPT signature follows:"; \
507 /usr/bin/gpg --verify $0.sig $0; \
509 echo "SCRIPT signature missing."; \
511 if [ -e ${src_patch}.sig ]; then \
512 echo "PATCH signature follows:"; \
513 /usr/bin/gpg --verify ${src_patch}.sig ${src_patch}; \
515 echo "PATCH signature missing."; \
518 echo "You need the gnupg package installed in order to check signatures." ; \
532 f_mkdirs=mkdirs_log && \
535 f_reconf=reconf_log && \
536 f_build=build_log && \
537 f_check=check_log && \
538 f_install=install_log && \
542 while test -n "$1" ; do
544 help|--help) help ; STATUS=$? ;;
545 version|--version) version ; STATUS=$? ;;
546 with_logs|--logs) enablelogging ; STATUS=$? ;;
547 prep) $f_prep ; STATUS=$? ;;
548 mkdirs) $f_mkdirs ; STATUS=$? ;;
549 conf) $f_conf ; STATUS=$? ;;
550 configure) $f_conf ; STATUS=$? ;;
551 reconf) $f_reconf ; STATUS=$? ;;
552 build) $f_build ; STATUS=$? ;;
553 make) $f_build ; STATUS=$? ;;
554 check) $f_check ; STATUS=$? ;;
555 test) $f_check ; STATUS=$? ;;
556 clean) $f_clean ; STATUS=$? ;;
557 install) $f_install ; STATUS=$? ;;
558 list) list ; STATUS=$? ;;
559 depend) depend ; STATUS=$? ;;
560 strip) strip ; STATUS=$? ;;
561 package) pkg ; STATUS=$? ;;
562 pkg) pkg ; STATUS=$? ;;
563 mkpatch) mkpatch ; STATUS=$? ;;
564 acceptpatch) acceptpatch ; STATUS=$? ;;
565 src-package) $f_spkg ; STATUS=$? ;;
566 spkg) $f_spkg ; STATUS=$? ;;
567 finish) finish ; STATUS=$? ;;
568 checksig) checksig ; STATUS=$? ;;
569 first) $f_mkdirs && $f_spkg && finish ; STATUS=$? ;;
570 almostall) checksig && $f_prep && $f_conf && $f_build && \
571 $f_install && strip && pkg && $f_spkg ; STATUS=$? ;;
572 all) checksig && $f_prep && $f_conf && $f_build && \
573 $f_install && strip && pkg && $f_spkg && finish ; \
575 *) echo "Error: bad arguments" ; exit 1 ;;
577 ( exit ${STATUS} ) || exit ${STATUS}