Skip to content

Commit a013c30

Browse files
committed
zlib: use bash_utils
1 parent d15d828 commit a013c30

File tree

4 files changed

+157
-211
lines changed

4 files changed

+157
-211
lines changed

configuration.ccl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
PROVIDES zlib
44
{
5-
SCRIPT configure.sh
5+
SCRIPT src/detect.sh
66
LANG bash
7-
OPTIONS ZLIB_DIR ZLIB_INSTALL_DIR
7+
OPTIONS ZLIB_DIR ZLIB_INSTALL_DIR ZLIB_LIBS ZLIB_INCLUDE_DIRS ZLIB_LIB_DIRS
88
}
9+
10+
# Pass configuration options to build script
11+
REQUIRES zlib

configure.sh

Lines changed: 0 additions & 209 deletions
This file was deleted.

src/build.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#! /bin/bash
2+
3+
################################################################################
4+
# Build
5+
################################################################################
6+
7+
# Set up shell
8+
if [ "$(echo ${VERBOSE} | tr '[:upper:]' '[:lower:]')" = 'yes' ]; then
9+
set -x # Output commands
10+
fi
11+
set -e # Abort on errors
12+
13+
# Set locations
14+
THORN=ZLIB
15+
NAME=zlib-1.2.8
16+
SRCDIR="$(dirname $0)"
17+
BUILD_DIR=${SCRATCH_BUILD}/build/${THORN}
18+
if [ -z "${ZLIB_INSTALL_DIR}" ]; then
19+
INSTALL_DIR=${SCRATCH_BUILD}/external/${THORN}
20+
else
21+
echo "Installing zlib into ${ZLIB_INSTALL_DIR} "
22+
INSTALL_DIR=${ZLIB_INSTALL_DIR}
23+
fi
24+
DONE_FILE=${SCRATCH_BUILD}/done/${THORN}
25+
ZLIB_DIR=${INSTALL_DIR}
26+
27+
# Set up environment
28+
unset LIBS
29+
if echo '' ${ARFLAGS} | grep 64 > /dev/null 2>&1; then
30+
export OBJECT_MODE=64
31+
fi
32+
33+
# Disable parallel make. With parallel make, I sometimes
34+
# encounter a build error "ld: in libz.a, malformed archive
35+
# TOC entry for _zlibVersion, offset 824872 is beyond end of
36+
# file 237568 for architecture x86_64"
37+
unset MAKEFLAGS
38+
39+
echo "zlib: Preparing directory structure..."
40+
cd ${SCRATCH_BUILD}
41+
mkdir build external done 2> /dev/null || true
42+
rm -rf ${BUILD_DIR} ${INSTALL_DIR}
43+
mkdir ${BUILD_DIR} ${INSTALL_DIR}
44+
45+
echo "zlib: Unpacking archive..."
46+
pushd ${BUILD_DIR}
47+
${TAR?} xzf ${SRCDIR}/dist/${NAME}.tar.gz
48+
49+
echo "zlib: Configuring..."
50+
cd ${NAME}
51+
./configure --prefix=${ZLIB_DIR} --static
52+
53+
echo "zlib: Building..."
54+
${MAKE}
55+
56+
echo "zlib: Installing..."
57+
${MAKE} install prefix=${ZLIB_DIR}
58+
popd
59+
60+
echo "zlib: Cleaning up..."
61+
rm -rf ${BUILD_DIR}
62+
63+
date > ${DONE_FILE}
64+
echo "zlib: Done."

src/detect.sh

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#! /bin/bash
2+
3+
################################################################################
4+
# Prepare
5+
################################################################################
6+
7+
# Set up shell
8+
if [ "$(echo ${VERBOSE} | tr '[:upper:]' '[:lower:]')" = 'yes' ]; then
9+
set -x # Output commands
10+
fi
11+
set -e # Abort on errors
12+
13+
. $CCTK_HOME/lib/make/bash_utils.sh
14+
15+
# Take care of requests to build the library in any case
16+
ZLIB_DIR_INPUT=$ZLIB_DIR
17+
if [ "$(echo "${ZLIB_DIR}" | tr '[a-z]' '[A-Z]')" = 'BUILD' ]; then
18+
ZLIB_BUILD=yes
19+
ZLIB_DIR=
20+
else
21+
ZLIB_BUILD=
22+
fi
23+
24+
# Try to find the library if build isn't explicitly requested
25+
if [ -z "${ZLIB_BUILD}" ]; then
26+
find_lib ZLIB zlib 1 1.0 "z" "zlib.h" "$ZLIB_DIR"
27+
fi
28+
29+
THORN=zlib
30+
31+
################################################################################
32+
# Build
33+
################################################################################
34+
35+
if [ -n "${ZLIB_BUILD}" -o -z "${ZLIB_DIR}" ]; then
36+
echo "BEGIN MESSAGE"
37+
echo "Using bundled zlib..."
38+
echo "END MESSAGE"
39+
40+
check_tools "tar"
41+
42+
# Set locations
43+
BUILD_DIR=${SCRATCH_BUILD}/build/${THORN}
44+
if [ -z "${ZLIB_INSTALL_DIR}" ]; then
45+
INSTALL_DIR=${SCRATCH_BUILD}/external/${THORN}
46+
else
47+
echo "BEGIN MESSAGE"
48+
echo "Installing zlib into ${ZLIB_INSTALL_DIR}"
49+
echo "END MESSAGE"
50+
INSTALL_DIR=${ZLIB_INSTALL_DIR}
51+
fi
52+
ZLIB_BUILD=1
53+
ZLIB_DIR=${INSTALL_DIR}
54+
ZLIB_INC_DIRS=${ZLIB_DIR}/include
55+
ZLIB_LIB_DIRS=${ZLIB_DIR}/lib
56+
ZLIB_LIBS=z
57+
else
58+
ZLIB_BUILD=
59+
DONE_FILE=${SCRATCH_BUILD}/done/${THORN}
60+
if [ ! -e ${DONE_FILE} ]; then
61+
mkdir ${SCRATCH_BUILD}/done 2> /dev/null || true
62+
date > ${DONE_FILE}
63+
fi
64+
fi
65+
66+
################################################################################
67+
# Configure Cactus
68+
################################################################################
69+
70+
# Pass configuration options to build script
71+
echo "BEGIN MAKE_DEFINITION"
72+
echo "ZLIB_BUILD = ${ZLIB_BUILD}"
73+
echo "ZLIB_INSTALL_DIR = ${ZLIB_INSTALL_DIR}"
74+
echo "END MAKE_DEFINITION"
75+
76+
set_make_vars "ZLIB" "$ZLIB_LIBS" "$ZLIB_LIB_DIRS" "$ZLIB_INC_DIRS"
77+
78+
# Pass options to Cactus
79+
echo "BEGIN MAKE_DEFINITION"
80+
echo "ZLIB_DIR = ${ZLIB_DIR}"
81+
echo "ZLIB_INC_DIRS = ${ZLIB_INC_DIRS}"
82+
echo "ZLIB_LIB_DIRS = ${ZLIB_LIB_DIRS}"
83+
echo "ZLIB_LIBS = ${ZLIB_LIBS}"
84+
echo "END MAKE_DEFINITION"
85+
86+
echo 'INCLUDE_DIRECTORY $(ZLIB_INC_DIRS)'
87+
echo 'LIBRARY_DIRECTORY $(ZLIB_LIB_DIRS)'
88+
echo 'LIBRARY $(ZLIB_LIBS)'

0 commit comments

Comments
 (0)