1#!/bin/bash
2#
3# This script configures, builds and packs the binary package for
4# the Cygwin net distribution version of OpenSSL
5#
6
7# Uncomment when debugging
8#set -x
9
10CONFIG_OPTIONS="--prefix=/usr shared zlib no-idea no-rc5"
11INSTALL_PREFIX=/tmp/install/INSTALL
12
13VERSION=
14SUBVERSION=$1
15
16function cleanup()
17{
18  rm -rf ${INSTALL_PREFIX}/etc
19  rm -rf ${INSTALL_PREFIX}/usr
20}
21
22function get_openssl_version()
23{
24  eval `grep '^VERSION=' Makefile`
25  if [ -z "${VERSION}" ]
26  then
27    echo "Error: Couldn't retrieve OpenSSL version from Makefile."
28    echo "       Check value of variable VERSION in Makefile."
29    exit 1
30  fi
31}
32
33function base_install()
34{
35  mkdir -p ${INSTALL_PREFIX}
36  cleanup
37  make install INSTALL_PREFIX="${INSTALL_PREFIX}"
38}
39
40function doc_install()
41{
42  DOC_DIR=${INSTALL_PREFIX}/usr/share/doc/openssl
43
44  mkdir -p ${DOC_DIR}
45  cp CHANGES CHANGES.SSLeay INSTALL LICENSE NEWS README ${DOC_DIR}
46
47  create_cygwin_readme
48}
49
50function certs_install()
51{
52  CERTS_DIR=${INSTALL_PREFIX}/usr/ssl/certs
53
54  mkdir -p ${CERTS_DIR}
55  cp -rp certs/* ${CERTS_DIR}
56}
57
58function create_cygwin_readme()
59{
60  README_DIR=${INSTALL_PREFIX}/usr/share/doc/Cygwin
61  README_FILE=${README_DIR}/openssl-${VERSION}.README
62
63  mkdir -p ${README_DIR}
64  cat > ${README_FILE} <<- EOF
65	The Cygwin version has been built using the following configure:
66
67	  ./config ${CONFIG_OPTIONS}
68
69	The IDEA and RC5 algorithms are disabled due to patent and/or
70	licensing issues.
71	EOF
72}
73
74function create_profile_files()
75{
76  PROFILE_DIR=${INSTALL_PREFIX}/etc/profile.d
77
78  mkdir -p $PROFILE_DIR
79  cat > ${PROFILE_DIR}/openssl.sh <<- "EOF"
80	export MANPATH="${MANPATH}:/usr/ssl/man"
81	EOF
82  cat > ${PROFILE_DIR}/openssl.csh <<- "EOF"
83	if ( $?MANPATH ) then
84	  setenv MANPATH "${MANPATH}:/usr/ssl/man"
85	else
86	  setenv MANPATH ":/usr/ssl/man"
87	endif
88	EOF
89}
90
91if [ -z "${SUBVERSION}" ]
92then
93  echo "Usage: $0 subversion"
94  exit 1
95fi
96
97if [ ! -f config ]
98then
99  echo "You must start this script in the OpenSSL toplevel source dir."
100  exit 1
101fi
102
103./config ${CONFIG_OPTIONS}
104
105get_openssl_version
106
107make depend || exit 1
108
109make || exit 1
110
111base_install
112
113doc_install
114
115certs_install
116
117create_cygwin_readme
118
119create_profile_files
120
121cd ${INSTALL_PREFIX}
122chmod u+w usr/lib/engines/*.so
123strip usr/bin/*.exe usr/bin/*.dll usr/lib/engines/*.so
124chmod u-w usr/lib/engines/*.so
125
126# Runtime package
127tar cjf libopenssl${VERSION//[!0-9]/}-${VERSION}-${SUBVERSION}.tar.bz2 \
128     usr/bin/cyg*dll
129# Base package
130find etc usr/bin/openssl.exe usr/bin/c_rehash usr/lib/engines usr/share/doc \
131     usr/ssl/certs usr/ssl/man/man[157] usr/ssl/misc usr/ssl/openssl.cnf \
132     usr/ssl/private \
133     -empty -o \! -type d |
134tar cjfT openssl-${VERSION}-${SUBVERSION}.tar.bz2 -
135# Development package
136find usr/include usr/lib/*.a usr/lib/pkgconfig usr/ssl/man/man3 \
137     -empty -o \! -type d |
138tar cjfT openssl-devel-${VERSION}-${SUBVERSION}.tar.bz2 -
139
140ls -l openssl-${VERSION}-${SUBVERSION}.tar.bz2
141ls -l openssl-devel-${VERSION}-${SUBVERSION}.tar.bz2
142ls -l libopenssl${VERSION//[!0-9]/}-${VERSION}-${SUBVERSION}.tar.bz2
143
144cleanup
145
146exit 0
147