1#!/bin/sh
2
3echo "  checking JPEG 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/libjpeg.* 2>/dev/null; then
21	echo "  found libjpeg in LOCAL_SOFT: $local/lib"
22	use_local=yes
23    elif ls $local/lib${R_ARCH}/libjpeg.* 2>/dev/null; then
24	echo "  found libjpeg in LOCAL_SOFT: $local/lib${R_ARCH}"
25	use_local=yes
26    else
27	echo "  LOCAL_SOFT does not contain libjpeg, fall back to external jpeg"
28    fi
29else
30    echo "  LOCAL_SOFT does not exist, fall back to external jpeg"
31fi
32
33if [ ${use_local} = yes ]; then
34    mv src/Makevars.win src/Makevars-in.win
35    mv src/Makevars-ls.win src/Makevars.win
36else
37    if [ ! -e src/win32/libjpeg.a ]; then
38	if [ ! -e src/libjpeg-current-win.tar.gz ]; then
39	    echo "  cannot find current JPEG files"
40	    echo "  attempting to download them"
41	    echo 'download.file("http://www.rforge.net/jpeg/files/libjpeg-current-win.tar.gz","src/libjpeg-current-win.tar.gz",mode="wb",quiet=TRUE)'|${R_HOME}/bin/R --vanilla --slave
42	fi
43	if [ ! -e src/libjpeg-current-win.tar.gz ]; then
44	    allok=no
45	else
46	    echo "  unpacking current JPEG"
47	    tar fxz src/libjpeg-current-win.tar.gz -C src
48            if [ ! -e src/win32/libjpeg.a ]; then
49		allok=no
50	    fi
51	fi
52    fi
53
54    if [ ! -e src/win32/libjpeg.a ]; then
55	allok=no
56    fi
57fi
58
59if [ ${allok} != yes ]; then
60    echo ""
61    echo " *** ERROR: unable to find JPEG files"
62    echo ""
63    echo " They must be either in src/win32, in a tar-ball"
64    echo " src/libjpeg-current-win.tar.gz or"
65    echo " available via the LOCAL_SOFT R make setting."
66    echo ""
67    echo " You can get the latest binary tar ball from"
68    echo " http://www.rforge.net/jpeg/files/"
69    echo ""
70    exit 1
71fi
72
73echo "  seems ok, ready to go"
74
75exit 0
76