]> diplodocus.org Git - nmh/blob - SPECS/build-nmh-cygwin
Removed docs/pending-release-notes-tmp, which was added by mistake.
[nmh] / SPECS / build-nmh-cygwin
1 #!/bin/bash
2 #
3 # ==========================================================================
4 # Change from generic-build-script: added this comment block.
5 # Based on Cygwin generic package build script, customized for nmh.
6 #
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 # ==========================================================================
10 #
11 # Generic package build script
12 #
13 # $Id: generic-build-script,v 1.47 2006/02/01 14:01:14 igor Exp $
14 #
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.
20
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`
25 # find src directory.
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`
33 else
34 if [ "x$topdir2" != "x$scriptdir" ] ; then # CYGWIN-PATCHES
35 topdir=`cd ${scriptdir}/../..; pwd`
36 else
37 topdir=`cd ${scriptdir}; pwd`
38 fi
39 fi
40
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}
55
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
61 # opt_decomp of z.
62 # export opt_decomp=? # Make sure tar punts if unpack() is not redefined
63 export opt_decomp=z
64 elif [ -e ${BASEPKG}.tar.bz2 ] ; then
65 export opt_decomp=j
66 export src_orig_pkg_name=${BASEPKG}.tar.bz2
67 elif [ -e ${BASEPKG}.tar.gz ] ; then
68 export opt_decomp=z
69 export src_orig_pkg_name=${BASEPKG}.tar.gz
70 elif [ -e ${BASEPKG}.tgz ] ; then
71 export opt_decomp=z
72 export src_orig_pkg_name=${BASEPKG}.tgz
73 elif [ -e ${BASEPKG}.tar ] ; then
74 export opt_decomp=
75 export src_orig_pkg_name=${BASEPKG}.tar
76 else
77 echo "Cannot find PKG:${PKG} VER:${VER} REL:${REL}. Rename $0 to"
78 echo "something more appropriate, and try again."
79 exit 1
80 fi
81
82 export src_orig_pkg=${topdir}/${src_orig_pkg_name}
83
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
89
90 export configurelogname=${FULLPKG}-CONFIGURE.LOG
91 export makelogname=${FULLPKG}-MAKE.LOG
92 export checklogname=${FULLPKG}-CHECK.LOG
93 export installlogname=${FULLPKG}-INSTALL.LOG
94
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}
107
108 prefix=/usr
109 sysconfdir=/etc
110 localstatedir=/var
111 if [ -z "$MY_CFLAGS" ]; then
112 MY_CFLAGS="-O2"
113 fi
114 if [ -z "$MY_LDFLAGS" ]; then
115 MY_LDFLAGS=
116 fi
117
118 # Change from generic-build-script: removed ChangeLog because the nmh
119 # Makefile installs it.
120 export install_docs="\
121 ABOUT-NLS \
122 ANNOUNCE \
123 AUTHORS \
124 BUG-REPORTS \
125 CHANGES \
126 CONTRIBUTORS \
127 COPYING \
128 COPYRIGHT \
129 CREDITS \
130 CHANGELOG \
131 FAQ \
132 HOW-TO-CONTRIBUTE \
133 INSTALL \
134 KNOWNBUG \
135 LEGAL \
136 LICENSE \
137 NEWS \
138 NOTES \
139 PROGLIST \
140 README \
141 RELEASE_NOTES \
142 THANKS \
143 TODO \
144 USAGE \
145 "
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
150 fi
151 # Sort in POSIX order.
152 export LC_ALL=C
153
154 # helper functions
155
156 # Provide help.
157 help() {
158 cat <<EOF
159 This is the cygwin packaging script for ${FULLPKG}.
160 Usage: $0 [<option>...] <action>...
161 Options are:
162 help, --help Print this message
163 version, --version Print the version message
164 with_logs, --logs Create logs of remaining steps
165 Actions are:
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
186 EOF
187 }
188
189 # Provide version of generic-build-script modified to make this script.
190 version() {
191 vers=`echo '$Revision: 1.47 $' | sed -e 's/Revision: //' -e 's/ *\\$//g'`
192 echo "$0 based on generic-build-script $vers"
193 }
194
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.
198 unpack() {
199 tar xv${opt_decomp}f "$1"
200 }
201
202 # Make the hidden directories used by this script.
203 mkdirs() {
204 (cd ${topdir} && \
205 rm -fr ${objdir} ${instdir} ${srcinstdir} && \
206 mkdir -p ${objdir} && \
207 mkdir -p ${instdir} && \
208 mkdir -p ${srcinstdir} )
209 }
210 mkdirs_log() {
211 (cd ${topdir} && \
212 mkdirs "$@" && \
213 rm -fr ${buildlogdir} && \
214 mkdir -p ${buildlogdir} )
215 }
216
217 # Unpack the original tarball, and get everything set up for this script.
218 prep() {
219 (cd ${topdir} && \
220 unpack ${src_orig_pkg} && \
221 cd ${topdir} && \
222 if [ -f ${src_patch} ] ; then \
223 patch -Z -p0 < ${src_patch} ;\
224 fi && \
225 mkdirs )
226 }
227 prep_log() {
228 prep "$@" && \
229 mkdirs_log && \
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})
235 fi
236 }
237
238 # Configure the package.
239 conf() {
240 (cd ${objdir} && \
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' )
249 }
250 conf_log() {
251 conf "$@" 2>&1 | tee ${configurelogfile}
252 return ${PIPESTATUS[0]}
253 }
254
255 # Rerun configure to pick up changes in the environment.
256 reconf() {
257 (cd ${topdir} && \
258 rm -fr ${objdir} && \
259 mkdir -p ${objdir} && \
260 conf )
261 }
262 reconf_log() {
263 reconf "$@" 2>&1 | tee ${configurelogfile}
264 return ${PIPESTATUS[0]}
265 }
266
267 # Run make.
268 build() {
269 (cd ${objdir} && \
270 make CFLAGS="${MY_CFLAGS}" )
271 }
272 build_log() {
273 build "$@" 2>&1 | tee ${makelogfile}
274 return ${PIPESTATUS[0]}
275 }
276
277 # Run the package testsuite.
278 check() {
279 (cd ${objdir} && \
280 make -k ${test_rule} )
281 }
282 check_log() {
283 check "$@" 2>&1 | tee ${checklogfile}
284 return ${PIPESTATUS[0]}
285 }
286
287 # Remove files created by configure and make.
288 clean() {
289 (cd ${objdir} && \
290 make clean )
291 }
292
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.
296 install() {
297 (cd ${objdir} && \
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} ; \
303 fi ;\
304 done &&\
305 for d in ${prefix}/share/doc/${SHORTPKG} ${prefix}/share/doc/Cygwin ; do \
306 if [ ! -d ${instdir}${d} ] ; then \
307 mkdir -p ${instdir}${d} ;\
308 fi ;\
309 done &&\
310 if [ -d ${instdir}${prefix}/share/info ] ; then \
311 find ${instdir}${prefix}/share/info -name "*.info" | xargs -r gzip -q ; \
312 fi && \
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 ; :; \
317 fi && \
318 templist="" && \
319 for fp in ${install_docs} ; do \
320 case "$fp" in \
321 */) templist="$templist `find ${srcdir}/$fp -type f`" ;;
322 *) for f in ${srcdir}/$fp ; do \
323 if [ -f $f ] ; then \
324 templist="$templist $f"; \
325 fi ; \
326 done ;; \
327 esac ; \
328 done && \
329 if [ ! "x$templist" = "x" ]; then \
330 /usr/bin/install -m 644 $templist \
331 ${instdir}${prefix}/share/doc/${SHORTPKG} ; \
332 fi && \
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 ; \
339 fi && \
340 if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}.sh ] ; then \
341 if [ ! -d ${instdir}${sysconfdir}/postinstall ]; then \
342 mkdir -p ${instdir}${sysconfdir}/postinstall ; \
343 fi && \
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 ; \
349 fi && \
350 /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/postinstall.sh \
351 ${instdir}${sysconfdir}/postinstall/${PKG}.sh ; \
352 fi && \
353 if [ -f ${srcdir}/CYGWIN-PATCHES/preremove.sh ] ; then \
354 if [ ! -d ${instdir}${sysconfdir}/preremove ]; then \
355 mkdir -p ${instdir}${sysconfdir}/preremove ; \
356 fi && \
357 /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/preremove.sh \
358 ${instdir}${sysconfdir}/preremove/${PKG}.sh ; \
359 fi &&
360 if [ -f ${srcdir}/CYGWIN-PATCHES/manifest.lst ] ; then
361 if [ ! -d ${instdir}${sysconfdir}/preremove ]; then
362 mkdir -p ${instdir}${sysconfdir}/preremove ;
363 fi &&
364 /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/manifest.lst \
365 ${instdir}${sysconfdir}/preremove/${PKG}-manifest.lst ;
366 fi )
367 }
368 install_log() {
369 install "$@" 2>&1 | tee ${installlogfile}
370 return ${PIPESTATUS[0]}
371 }
372
373 # Strip all binaries.
374 strip() {
375 (cd ${instdir} && \
376 find . -name "*.dll" -or -name "*.exe" | xargs -r strip 2>&1 ; \
377 true )
378 }
379
380 # List all non-hidden files that belong to the package.
381 list() {
382 (cd ${instdir} && \
383 find . -name "*" ! -type d | sed 's%^\.% %' | sort ; \
384 true )
385 }
386
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.
390 depend() {
391 (cd ${instdir} && \
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 ; \
395 true )
396 }
397
398 # Build the binary package tarball.
399 pkg() {
400 (cd ${instdir} && \
401 tar cvjf ${bin_pkg} * )
402 }
403
404 # Compare the original tarball against cygwin modifications.
405 mkpatch() {
406 (cd ${srcdir} && \
407 find . -name "autom4te.cache" | xargs -r rm -rf ; \
408 unpack ${src_orig_pkg} && \
409 mv ${BASEPKG} ../${BASEPKG}-orig && \
410 cd ${topdir} && \
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 )
415 }
416
417 # Note: maintainer-only functionality
418 acceptpatch() {
419 cp --backup=numbered ${srcinstdir}/${src_patch_name} ${topdir}
420 }
421
422 # Build the source tarball.
423 spkg() {
424 (mkpatch && \
425 if [ "${SIG}" -eq 1 ] ; then \
426 name=${srcinstdir}/${src_patch_name} text="PATCH" sigfile ; \
427 fi && \
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}/ ; \
431 fi && \
432 cp $0 ${srcinstdir}/`basename $0` && \
433 name=$0 text="SCRIPT" sigfile && \
434 if [ "${SIG}" -eq 1 ] ; then \
435 cp $0.sig ${srcinstdir}/ ; \
436 fi && \
437 cd ${srcinstdir} && \
438 tar cvjf ${src_pkg} * )
439 }
440 spkg_log() {
441 spkg "$@" && \
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} && \
447 rm -f \
448 ${configurelogname} ${makelogname} ${checklogname} ${installlogname} ; \
449 fi && \
450 tar uvjf ${src_pkg} * )
451 }
452
453 # Clean up everything.
454 finish() {
455 rm -rf ${srcdir}
456 }
457
458 # Generate GPG signatures.
459 sigfile() {
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"; \
463 rm -f $name.sig; \
464 /usr/bin/gpg --detach-sign $name; \
465 else \
466 echo "You need the gnupg package installed in order to make signatures."; \
467 fi; \
468 fi
469 }
470
471 # Validate GPG signatures.
472 checksig() {
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}; \
477 else \
478 echo "ORIGINAL PACKAGE signature missing."; \
479 fi; \
480 if [ -e $0.sig ]; then \
481 echo "SCRIPT signature follows:"; \
482 /usr/bin/gpg --verify $0.sig $0; \
483 else \
484 echo "SCRIPT signature missing."; \
485 fi; \
486 if [ -e ${src_patch}.sig ]; then \
487 echo "PATCH signature follows:"; \
488 /usr/bin/gpg --verify ${src_patch}.sig ${src_patch}; \
489 else \
490 echo "PATCH signature missing."; \
491 fi; \
492 else
493 echo "You need the gnupg package installed in order to check signatures." ; \
494 fi
495 }
496
497 f_mkdirs=mkdirs
498 f_prep=prep
499 f_conf=conf
500 f_reconf=conf
501 f_build=build
502 f_check=check
503 f_install=install
504 f_spkg=spkg
505
506 enablelogging() {
507 f_mkdirs=mkdirs_log && \
508 f_prep=prep_log && \
509 f_conf=conf_log && \
510 f_reconf=reconf_log && \
511 f_build=build_log && \
512 f_check=check_log && \
513 f_install=install_log && \
514 f_spkg=spkg_log
515 }
516
517 while test -n "$1" ; do
518 case $1 in
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 ; \
549 STATUS=$? ;;
550 *) echo "Error: bad arguments" ; exit 1 ;;
551 esac
552 ( exit ${STATUS} ) || exit ${STATUS}
553 shift
554 done