-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·250 lines (204 loc) · 6.81 KB
/
configure
File metadata and controls
executable file
·250 lines (204 loc) · 6.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/bin/sh
# Configure script for unigd
# Based on anticonf pattern by Jeroen Ooms
#
# The script will try 'pkg-config' to find required cflags and ldflags.
# Make sure this executable is in PATH when installing the package.
# Alternatively, you can set INCLUDE_DIR and LIB_DIR manually:
# R CMD INSTALL --configure-vars='INCLUDE_DIR=/.../include LIB_DIR=/.../lib'
# Cleanup on exit
cleanup() {
rm -f tmp_libtiff_test tmp_libtiff_test-* configure.log autobrew
}
trap cleanup EXIT
# ------------------- Helpers -------------------
has_pkg_config() {
command -v pkg-config >/dev/null 2>&1
}
pkg_config_cflags() {
pkg-config --cflags "$@" 2>/dev/null
}
pkg_config_libs() {
pkg-config --libs "$@" 2>/dev/null
}
# Print a consistent section header
log_section() {
echo ""
echo "--- $1"
}
# Print a key=value pair for debugging
log_var() {
echo " $1=$2"
}
# Print an optional dependency warning with install hints
warn_optional() {
_name="$1"
_feature="$2"
_define="$3"
_deb="$4"
_rpm="$5"
_brew="$6"
echo ""
echo "
------------------------------------------------------------------------
NOTE: ${_name} was not found.
unigd will still work, but ${_feature} will not be available.
To enable ${_feature}, install ${_name}:
Debian/Ubuntu: sudo apt-get install ${_deb}
Fedora/RHEL: sudo dnf install ${_rpm}
macOS Homebrew: brew install ${_brew}
If ${_name} is installed but not detected, ensure pkg-config is in your
PATH and PKG_CONFIG_PATH includes the relevant .pc file, or set paths
manually:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
------------------------------------------------------------------------
"
if [ -f configure.log ] && [ -s configure.log ]; then
echo "Compiler output:"
cat configure.log
echo ""
fi
}
# ------------------- Cairo + Freetype -------------------
log_section "Checking for cairo and freetype2"
PKG_CFLAGS=""
PKG_LIBS="-lcairo -lfreetype"
PKG_TEST_FILE="src/sysdep_tests/sysdep_cairo.c"
# Use pkg-config if available
if has_pkg_config; then
PKGCONFIG_CFLAGS="$(pkg_config_cflags cairo freetype2)"
PKGCONFIG_LIBS="$(pkg_config_libs cairo freetype2)"
fi
# On CRAN build machines do not use pkgconfig cairo (which depends on XQuartz)
if [ -d "/Builds/CRAN-QA-Simon" ] || [ -d "/Volumes/Builds" ]; then
unset PKGCONFIG_CFLAGS
unset PKGCONFIG_LIBS
fi
# Determine flags: manual override > pkg-config > Homebrew fallback > autobrew
if [ "$INCLUDE_DIR" ] || [ "$LIB_DIR" ]; then
echo " Using manually specified INCLUDE_DIR / LIB_DIR"
PKG_CFLAGS="-I$INCLUDE_DIR $PKG_CFLAGS"
PKG_LIBS="-L$LIB_DIR $PKG_LIBS"
elif [ "$PKGCONFIG_CFLAGS" ] || [ "$PKGCONFIG_LIBS" ]; then
echo " Found via pkg-config"
PKG_CFLAGS="${PKGCONFIG_CFLAGS}"
PKG_LIBS="${PKGCONFIG_LIBS}"
elif [ "$(uname)" = "Darwin" ]; then
if command -v brew >/dev/null 2>&1; then
BREWDIR="$(brew --prefix)"
export PKG_CONFIG_PATH="${BREWDIR}/opt/cairo/lib/pkgconfig:${BREWDIR}/opt/freetype/lib/pkgconfig:${BREWDIR}/lib/pkgconfig:${PKG_CONFIG_PATH}"
if has_pkg_config; then
PKG_CFLAGS="$(pkg_config_cflags cairo freetype2)"
PKG_LIBS="$(pkg_config_libs cairo freetype2)"
fi
if [ -z "$PKG_CFLAGS" ] && [ -z "$PKG_LIBS" ]; then
echo " Using Homebrew fallback paths"
PKG_CFLAGS="-I${BREWDIR}/include/cairo -I${BREWDIR}/include/fontconfig -I${BREWDIR}/include/freetype2"
PKG_LIBS="-L${BREWDIR}/lib ${PKG_LIBS}"
else
echo " Found via Homebrew pkg-config"
fi
else
curl -sfL "https://autobrew.github.io/scripts/cairo" > autobrew
if [ -f autobrew ]; then
echo " Using autobrew"
. ./autobrew
fi
fi
fi
# Find C compiler
CC="$(${R_HOME}/bin/R CMD config CC)"
CFLAGS="$(${R_HOME}/bin/R CMD config CFLAGS)"
CPPFLAGS="$(${R_HOME}/bin/R CMD config CPPFLAGS)"
log_var "PKG_CFLAGS" "$PKG_CFLAGS"
log_var "PKG_LIBS" "$PKG_LIBS"
# Test cairo configuration
${CC} ${CPPFLAGS} ${PKG_CFLAGS} ${CFLAGS} -E ${PKG_TEST_FILE} >/dev/null 2>configure.log
if [ $? -ne 0 ]; then
warn_optional "cairo" \
"some plot file formats (e.g. PNG via cairo)" \
"UNIGD_NO_CAIRO" \
"libcairo2-dev" \
"cairo-devel" \
"cairo"
PKG_CFLAGS="-DUNIGD_NO_CAIRO"
PKG_LIBS=""
else
echo " OK"
fi
# ------------------- libtiff -------------------
log_section "Checking for libtiff"
PKG_LIBTIFF_CFLAGS=""
PKG_LIBTIFF_LIBS="-ltiff -ljpeg"
PKG_LIBTIFF_TEST_FILE="src/sysdep_tests/sysdep_libtiff.cpp"
if has_pkg_config; then
LIBTIFF_PC_CFLAGS="$(pkg-config --cflags --silence-errors libtiff-4 2>/dev/null)"
LIBTIFF_PC_LIBS="$(pkg_config_libs libtiff-4)"
if [ -n "$LIBTIFF_PC_LIBS" ]; then
echo " Found via pkg-config"
PKG_LIBTIFF_CFLAGS="${LIBTIFF_PC_CFLAGS}"
PKG_LIBTIFF_LIBS="${LIBTIFF_PC_LIBS} -ltiffxx"
fi
fi
# Find C++ compiler
CXX="$(${R_HOME}/bin/R CMD config CXX)"
CXXFLAGS="$(${R_HOME}/bin/R CMD config CXXFLAGS)"
log_var "PKG_LIBTIFF_CFLAGS" "$PKG_LIBTIFF_CFLAGS"
log_var "PKG_LIBTIFF_LIBS" "$PKG_LIBTIFF_LIBS"
# Test libtiff configuration
${CXX} ${CPPFLAGS} ${PKG_LIBTIFF_CFLAGS} ${CXXFLAGS} ${PKG_LIBTIFF_TEST_FILE} ${PKG_LIBTIFF_LIBS} -o tmp_libtiff_test >/dev/null 2>configure.log
if [ $? -ne 0 ]; then
warn_optional "libtiff-4" \
"TIFF output" \
"UNIGD_NO_TIFF" \
"libtiff-dev" \
"libtiff-devel" \
"libtiff"
PKG_LIBTIFF_CFLAGS="-DUNIGD_NO_TIFF"
PKG_LIBTIFF_LIBS=""
else
echo " OK"
fi
# ------------------- libpng -------------------
log_section "Checking for libpng"
PKG_LIBPNG_CFLAGS=""
PKG_LIBPNG_LIBS="-lpng"
if has_pkg_config; then
LIBPNG_PC_CFLAGS="$(pkg_config_cflags libpng)"
LIBPNG_PC_LIBS="$(pkg_config_libs libpng)"
if [ -n "$LIBPNG_PC_LIBS" ]; then
echo " Found via pkg-config"
PKG_LIBPNG_CFLAGS="${LIBPNG_PC_CFLAGS}"
PKG_LIBPNG_LIBS="${LIBPNG_PC_LIBS}"
fi
fi
log_var "PKG_LIBPNG_CFLAGS" "$PKG_LIBPNG_CFLAGS"
log_var "PKG_LIBPNG_LIBS" "$PKG_LIBPNG_LIBS"
echo " OK (using fallback -lpng if not found via pkg-config)"
# ------------------- zlib -------------------
log_section "Checking for zlib"
PKG_ZLIB_CFLAGS=""
PKG_ZLIB_LIBS="-lz"
if has_pkg_config; then
ZLIB_PC_CFLAGS="$(pkg_config_cflags zlib)"
ZLIB_PC_LIBS="$(pkg_config_libs zlib)"
if [ -n "$ZLIB_PC_LIBS" ]; then
echo " Found via pkg-config"
PKG_ZLIB_CFLAGS="${ZLIB_PC_CFLAGS}"
PKG_ZLIB_LIBS="${ZLIB_PC_LIBS}"
fi
fi
log_var "PKG_ZLIB_CFLAGS" "$PKG_ZLIB_CFLAGS"
log_var "PKG_ZLIB_LIBS" "$PKG_ZLIB_LIBS"
echo " OK (using fallback -lz if not found via pkg-config)"
# ------------------- Write Makevars -------------------
ALL_CFLAGS="${PKG_CFLAGS} ${PKG_LIBTIFF_CFLAGS} ${PKG_LIBPNG_CFLAGS} ${PKG_ZLIB_CFLAGS}"
ALL_LIBS="${PKG_LIBS} ${PKG_LIBTIFF_LIBS} ${PKG_LIBPNG_LIBS} ${PKG_ZLIB_LIBS}"
log_section "Configuration summary"
log_var "PKG_CPPFLAGS" "$ALL_CFLAGS"
log_var "PKG_LIBS" "$ALL_LIBS"
echo ""
sed -e "s|@cflags@|${ALL_CFLAGS}|" \
-e "s|@libs@|${ALL_LIBS}|" \
src/Makevars.in > src/Makevars
exit 0