1: #!/bin/sh
2: #
3: # Copyright (c) 2010-2013 Todd C. Miller <Todd.Miller@courtesan.com>
4: #
5: # Permission to use, copy, modify, and distribute this software for any
6: # purpose with or without fee is hereby granted, provided that the above
7: # copyright notice and this permission notice appear in all copies.
8: #
9: # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10: # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11: # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12: # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13: # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14: # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15: # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16: #
17: # Build a binary package using polypkg
18: # Usage: mkpkg [--debug] [--flavor flavor] [--platform platform] [--osversion ver]
19: #
20:
21: # Make sure IFS is set to space, tab, newline in that order.
22: space=' '
23: tab=' '
24: nl='
25: '
26: IFS=" $nl"
27:
28: # Parse arguments
29: usage="usage: mkpkg [--debug] [--flavor flavor] [--platform platform] [--osversion ver]"
30: debug=0
31: flavor=vanilla
32: crossbuild=false
33: while test $# -gt 0; do
34: case "$1" in
35: --debug)
36: set -x
37: debug=1
38: PPFLAGS="--debug${PPFLAGS+$space}${PPFLAGS}"
39: ;;
40: --flavor=?*)
41: flavor=`echo "$1" | sed -n 's/^--flavor=\(.*\)/\1/p'`
42: PPVARS="${PPVARS}${PPVARS+$space}flavor=$flavor"
43: ;;
44: --flavor)
45: if [ $# -lt 2 ]; then
46: echo "$usage" 1>&2
47: exit 1
48: fi
49: flavor="$2"
50: PPVARS="${PPVARS}${PPVARS+$space}flavor=$flavor"
51: shift
52: ;;
53: --platform=?*)
54: arg=`echo "$1" | sed -n 's/^--platform=\(.*\)/\1/p'`
55: PPFLAGS="${PPFLAGS}${PPFLAGS+$space}--platform $arg"
56: ;;
57: --platform)
58: if [ $# -lt 2 ]; then
59: echo "$usage" 1>&2
60: exit 1
61: fi
62: PPFLAGS="${PPFLAGS}${PPFLAGS+$space}--platform $2"
63: shift
64: ;;
65: --osversion=?*)
66: arg=`echo "$1" | sed -n 's/^--osversion=\(.*\)/\1/p'`
67: osversion="$arg"
68: ;;
69: --osversion)
70: if [ $# -lt 2 ]; then
71: echo "$usage" 1>&2
72: exit 1
73: fi
74: osversion="$2"
75: shift
76: ;;
77: --build|--host)
78: crossbuild=true
79: configure_opts="${configure_opts}${configure_opts+$tab}$1"
80: ;;
81: *)
82: # Pass unknown options to configure
83: configure_opts="${configure_opts}${configure_opts+$tab}$1"
84: ;;
85: esac
86: shift
87: done
88:
89: top_srcdir=`dirname $0`
90:
91: : ${osversion="`$top_srcdir/pp --probe`"}
92: test -n "$osversion" || exit 1
93: osrelease=`echo "$osversion" | sed -e 's/^[^0-9]*//' -e 's/-.*$//'`
94:
95: # Choose compiler options by osversion if not cross-compiling.
96: if [ "$crossbuild" = "false" ]; then
97: case "$osversion" in
98: hpux*)
99: # Use the HP ANSI C compiler on HP-UX if possible
100: if [ -z "$CC" -a -x /opt/ansic/bin/cc ]; then
101: CC=/opt/ansic/bin/cc; export CC
102: if [ -z "$CFLAGS" ]; then
103: CFLAGS=-O; export CFLAGS
104: fi
105: fi
106: ;;
107: sol[0-9]*)
108: # Use the Sun Studio C compiler on Solaris if possible
109: if [ -z "$CC" -a -x /usr/bin/cc ]; then
110: CC=/usr/bin/cc; export CC
111: if [ -z "$CFLAGS" ]; then
112: CFLAGS=-O; export CFLAGS
113: fi
114: fi
115: ;;
116: esac
117: fi
118:
119: # Choose configure options by osversion.
120: # We use the same configure options as vendor packages when possible.
121: case "$osversion" in
122: centos*|rhel*)
123: if [ $osrelease -ge 40 ]; then
124: # RHEL 4 and up support SELinux
125: configure_opts="${configure_opts}${configure_opts+$tab}--with-selinux"
126: fi
127: if [ $osrelease -ge 50 ]; then
128: # RHEL 5 and up has audit support and uses a separate PAM
129: # config file for "sudo -i".
130: configure_opts="${configure_opts}${configure_opts+$tab}--with-linux-audit"
131: configure_opts="${configure_opts}${configure_opts+$tab}--with-pam-login"
132: PPVARS="${PPVARS}${PPVARS+$space}linux_audit=1.4.0"
133: fi
134: if [ $osrelease -ge 60 ]; then
135: # RHEL 6 and above builds sudo with SSSD support
136: configure_opts="${configure_opts}${configure_opts+$tab}--with-sssd"
137: fi
138: # Note, must indent with tabs, not spaces due to IFS trickery
139: configure_opts="--prefix=/usr
140: --with-logging=syslog
141: --with-logfac=authpriv
142: --with-pam
143: --enable-zlib=system
144: --with-editor=/bin/vi
145: --with-env-editor
146: --with-ignore-dot
147: --with-tty-tickets
148: --with-ldap
149: --with-passprompt=[sudo] password for %p:
150: --with-sendmail=/usr/sbin/sendmail
151: $configure_opts"
152: ;;
153: sles*)
154: if [ $osrelease -ge 10 ]; then
155: # SLES 11 and higher has SELinux
156: if [ $osrelease -ge 11 ]; then
157: configure_opts="${configure_opts}${configure_opts+$tab}--with-selinux"
158: fi
159: fi
160: # SuSE doesn't have /usr/libexec
161: libexec=lib
162: case "$osversion" in
163: *64*) gcc -v 2>&1 | grep "with-cpu=[^ ]*32" >/dev/null || libexec=lib64
164: ;;
165: esac
166: # Note, must indent with tabs, not spaces due to IFS trickery
167: # XXX - SuSE uses secure path but only for env_reset
168: configure_opts="--prefix=/usr
169: --libexecdir=/usr/$libexec
170: --with-logging=syslog
171: --with-logfac=auth
172: --with-all-insults
173: --with-ignore-dot
174: --with-tty-tickets
175: --enable-shell-sets-home
176: --with-sudoers-mode=0440
177: --with-pam
178: --enable-zlib=system
179: --with-ldap
180: --with-env-editor
181: --with-passprompt=%p\'s password:
182: --with-sendmail=/usr/sbin/sendmail
183: $configure_opts"
184:
185: make_opts='docdir=$(datarootdir)/doc/packages/$(PACKAGE_TARNAME)'
186: ;;
187: deb*|ubu*)
188: # Man pages should be compressed in .deb files
189: export MANCOMPRESS='gzip -9'
190: export MANCOMPRESSEXT='.gz'
191: # If Ubuntu, add --enable-admin-flag
192: case "$osversion" in
193: ubu*)
194: configure_opts="${configure_opts}${configure_opts+$tab}--enable-admin-flag${tab}--without-lecture"
195: ;;
196: esac
197: # Note, must indent with tabs, not spaces due to IFS trickery
198: if test "$flavor" = "ldap"; then
199: configure_opts="${configure_opts}${configure_opts+$tab}--with-ldap
200: --with-ldap-conf-file=/etc/sudo-ldap.conf"
201: fi
202: configure_opts="${configure_opts}${configure_opts+$tab}--with-selinux"
203: configure_opts="--prefix=/usr
204: --with-all-insults
205: --with-pam
206: --enable-zlib=system
207: --with-fqdn
208: --with-logging=syslog
209: --with-logfac=authpriv
210: --with-env-editor
211: --with-editor=/usr/bin/editor
212: --with-timeout=15
213: --with-password-timeout=0
214: --with-passprompt=[sudo] password for %p:
215: --disable-root-mailer
216: --with-sendmail=/usr/sbin/sendmail
217: --mandir=/usr/share/man
218: --libexecdir=/usr/lib
219: --with-secure-path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
220: $configure_opts"
221: ;;
222: macos*)
223: case "$osversion" in
224: *i386|*x86_64)
225: # Build intel-only universal binaries
226: ARCH_FLAGS="-arch i386 -arch x86_64"
227: ;;
228: esac
229: if test "${osversion}" != "`$top_srcdir/pp --probe`"; then
230: sdkvers=`echo "${osversion}" | sed 's/^macos\([0-9][0-9]\)\([0-9]*\)-.*$/\1.\2/'`
231: # Newer Xcode puts /Developer under the app Contents dir.
232: SDK_DIR="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs"
233: if test -d "${SDK_DIR}/MacOSX${sdkvers}.sdk"; then
234: SDK_DIR="${SDK_DIR}/MacOSX${sdkvers}.sdk"
235: elif test -d "/Developer/SDKs/MacOSX${sdkvers}.sdk"; then
236: SDK_DIR="/Developer/SDKs/MacOSX${sdkvers}.sdk"
237: fi
238: SDK_FLAGS="-isysroot ${SDK_DIR} -mmacosx-version-min=${sdkvers}"
239: fi
240: export CFLAGS="-O2 -g $ARCH_FLAGS $SDK_FLAGS"
241: export LDFLAGS="$ARCH_FLAGS $SDK_FLAGS"
242: # Note, must indent with tabs, not spaces due to IFS trickery
243: configure_opts="--with-pam
244: --with-bsm-audit
245: --without-tty-tickets
246: --enable-zlib=system
247: --with-ldap
248: --with-insults=disabled
249: --with-logging=syslog
250: --with-logfac=authpriv
251: --with-editor=/usr/bin/vim
252: --with-env-editor
253: $configure_opts"
254: ;;
255: aix*)
256: # Use -gxcoff with gcc instead of -g for dbx-style debugging symbols.
257: if test -z "$CC" && gcc -v >/dev/null 2>&1; then
258: CFLAGS=-gxcoff; export CFLAGS
259: fi
260: # Note, must indent with tabs, not spaces due to IFS trickery
261: # Note: we include our own zlib instead of relying on the
262: # AIX freeware version being installed.
263: configure_opts="
264: --prefix=/opt/freeware
265: --mandir=/opt/freeware/man
266: --with-insults=disabled
267: --with-logging=syslog
268: --with-logfac=auth
269: --with-editor=/usr/bin/vi
270: --with-env-editor
271: --enable-zlib=builtin
272: --disable-nls
273: --with-sendmail=/usr/sbin/sendmail
274: $configure_opts"
275: PPVARS="${PPVARS}${PPVARS+$space}aix_freeware=true"
276: ;;
277: *)
278: # For Solaris, add project support and use let configure choose zlib.
279: # For all others, use the builtin zlib and disable NLS support.
280: case "$osversion" in
281: sol*)
282: configure_opts="${configure_opts}${configure_opts+$tab}--with-project"
283:
284: if [ $osrelease -ge 11 ]; then
285: configure_opts="${configure_opts}${configure_opts+$tab}--with-bsm-audit"
286: fi
287: ;;
288: *)
289: configure_opts="${configure_opts}${configure_opts+$tab}--enable-zlib=builtin${tab}--disable-nls"
290: ;;
291: esac
292: if test "$flavor" = "ldap"; then
293: configure_opts="${configure_opts}${configure_opts+$tab}--with-ldap"
294: fi
295: # Note, must indent with tabs, not spaces due to IFS trickery
296: configure_opts="
297: --with-insults=disabled
298: --with-logging=syslog
299: --with-logfac=auth
300: --with-editor=/usr/bin/vim:/usr/bin/vi:/bin/vi
301: --with-env-editor
302: $configure_opts"
303: ;;
304: esac
305:
306: # Remove spaces from IFS when setting $@ so that passprompt may include them
307: OIFS="$IFS"
308: IFS=" $nl"
309: set -- $configure_opts $extra_opts
310: IFS="$OIFS"
311: if [ -r Makefile ]; then
312: make $make_opts distclean
313: fi
314: $top_srcdir/configure "$@" || exit 1
315: make $make_opts && make $make_opts PPFLAGS="$PPFLAGS" PPVARS="$PPVARS" package
316: test $debug -eq 0 && rm -rf destdir
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>