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