1#!/bin/sh
2
3echo "  checking PNG headers and libraries"
4allok=yes
5use_local=no
6
7## In the future we should be able to use
8## local=`${R_HOME}/bin/R CMD config LOCAL_SOFT`
9## but up to at least R 3.0.1 that doesn't work
10if [ -z "$MAKE" ]; then
11    MAKE=`${R_HOME}/bin/R CMD config MAKE`
12    if [ -z "$MAKE" ]; then
13	MAKE=make
14    fi
15fi
16makefiles="-f ${R_HOME}/etc${R_ARCH}/Makeconf -f ${R_SHARE_DIR}/make/config.mk"
17local=`${MAKE} -s ${makefiles} print R_HOME=${R_HOME} VAR=LOCAL_SOFT`
18
19if [ -e $local/lib ]; then
20    if ls $local/lib/libpng.* 2>/dev/null; then
21	echo "  found libpng in LOCAL_SOFT: $local/lib"
22	use_local=yes
23    elif ls $local/lib${R_ARCH}/libpng.* 2>/dev/null; then
24	echo "  found libpng in LOCAL_SOFT: $local/lib${R_ARCH}"
25	use_local=yes
26    else
27	echo "  LOCAL_SOFT does not contain libpng, fall back to external png"
28    fi
29else
30    echo "  LOCAL_SOFT does not exist, fall back to external png"
31fi
32
33if [ ${use_local} = no ]; then
34    if [ ! -e src/win32/libz.a ]; then
35	if [ ! -e src/libpng-current-win.tar.gz ]; then
36	    echo "  cannot find current PNG files"
37	    echo "  attempting to download them"
38	    echo 'download.file("http://www.rforge.net/png/files/libpng-current-win.tar.gz","src/libpng-current-win.tar.gz",mode="wb",quiet=TRUE)'|${R_HOME}/bin/R --vanilla --slave
39	fi
40	if [ ! -e src/libpng-current-win.tar.gz ]; then
41	    allok=no
42	else
43	    echo "  unpacking current PNG"
44	    tar fxz src/libpng-current-win.tar.gz -C src
45            if [ ! -e src/win32/libz.a ]; then
46		allok=no
47	    fi
48	fi
49    fi
50
51    if [ ! -e src/win32/libz.a ]; then
52	allok=no
53    fi
54fi
55
56if [ ${allok} != yes ]; then
57    echo ""
58    echo " *** ERROR: unable to find PNG files"
59    echo ""
60    echo " They must be either in src/win32, in a tar-ball"
61    echo " src/libpng-current-win.tar.gz or"
62    echo " available via the LOCAL_SOFT R make setting."
63    echo ""
64    echo " You can get the latest binary tar ball from"
65    echo " http://www.rforge.net/png/files/"
66    echo ""
67    exit 1
68fi
69
70echo "  seems ok, ready to go"
71
72exit 0
73