Skip to content

Instantly share code, notes, and snippets.

@GBuella
Created February 14, 2017 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GBuella/ddcadefd5abac7f54334e03d1b510d39 to your computer and use it in GitHub Desktop.
Save GBuella/ddcadefd5abac7f54334e03d1b510d39 to your computer and use it in GitHub Desktop.
openttd config.lib iconv patch
diff --git a/config.lib b/config.lib
index 3d10aaa..b2ef695 100644
--- config.lib
+++ config.lib
@@ -2866,26 +2866,33 @@ detect_iconv() {
return 0
fi
- # Try to find iconv.h, seems to only thing to detect iconv with
-
- if [ "$with_iconv" = "1" ] || [ "$with_iconv" = "" ] || [ "$with_iconv" = "2" ]; then
- iconv=`ls -1 /usr/include 2>/dev/null | grep "iconv.h"`
- if [ -z "$iconv" ]; then
- iconv=`ls -1 /usr/local/include 2>/dev/null | grep "iconv.h"`
- fi
- else
- # Make sure it exists
- iconv=`ls $with_iconv/include/iconv.h 2>/dev/null`
+ cat > tmp.iconv.cpp << EOF
+#include <iconv.h>
+int main() {
+ return &iconv == &iconv;
+}
+EOF
+ local iconv_CFLAGS="$CFLAGS"
+ if [ "$with_iconv" != "" ] && [ "$with_iconv" != "1" ] && \
+ [ "$with_iconv" != "2" ] ; then
+ iconv_CFLAGS="$CFLAGS -I$with_iconv/include"
fi
+ execute="$cxx_host $OSX_SYSROOT $iconv_CFLAGS -c tmp.iconv.cpp -o tmp.iconv -DTESTING 2>&1"
+ eval $execute > /dev/null
+ ret=$?
+ log 2 "executing $execute"
+ log 2 " exit code $ret"
+ if [ "$ret" = "0" ]; then iconv_h_found="yes"; else iconv_h_found="no"; fi
+ log 1 "checking iconv.h... $iconv_h_found"
- if [ -z "$iconv" ]; then
- log 1 "checking iconv... not found"
+
+ if [ "$iconv_h_found" = "no" ]; then
if [ "$with_iconv" = "2" ]; then
- log 1 "configure: error: iconv couldn't be found"
+ log 1 "configure: error: iconv.h couldn't be found"
exit 1
elif [ "$with_iconv" != "1" ]; then
- log 1 "configure: error: iconv couldn't be found"
+ log 1 "configure: error: iconv.h couldn't be found"
log 1 "configure: error: you supplied '$with_iconv', but I couldn't detect iconv in it"
exit 1
@@ -2898,16 +2905,11 @@ detect_iconv() {
with_iconv="2"
fi
- log 2 "found iconv in $iconv"
-
- log 1 "checking iconv... found"
-
# There are different implementations of iconv. The older ones,
# e.g. SUSv2, pass a const pointer, whereas the newer ones, e.g.
# IEEE 1003.1 (2004), pass a non-const pointer.
cat > tmp.iconv.cpp << EOF
-#include "src/stdafx.h"
#include <iconv.h>
int main() {
static char buf[1024];
@@ -2919,7 +2921,7 @@ int main() {
return iconv(convd, &inbuf, &inlen, &outbuf, &outlen);
}
EOF
- execute="$cxx_host $OSX_SYSROOT $CFLAGS -c tmp.iconv.cpp -o tmp.iconv -DTESTING 2>&1"
+ execute="$cxx_host $OSX_SYSROOT $iconv_CFLAGS -c tmp.iconv.cpp -o tmp.iconv -DTESTING 2>&1"
eval $execute > /dev/null
ret=$?
log 2 "executing $execute"
@@ -2927,8 +2929,8 @@ EOF
if [ "$ret" = "0" ]; then have_non_const_iconv="no"; else have_non_const_iconv="yes"; fi
log 1 "checking if iconv has non-const inbuf... $have_non_const_iconv"
- cat > tmp.iconv.cpp << EOF
-#include "src/stdafx.h"
+ if [ "$have_non_const_iconv" = "yes" ] ; then
+ cat > tmp.iconv.cpp << EOF
#include <iconv.h>
int main() {
static char buf[1024];
@@ -2940,7 +2942,9 @@ int main() {
return iconv(convd, &inbuf, &inlen, &outbuf, &outlen);
}
EOF
- execute="$cxx_host $OSX_SYSROOT $OSX_LD_SYSROOT $CFLAGS tmp.iconv.cpp -o tmp.iconv -DTESTING 2>&1"
+ fi
+
+ execute="$cxx_host $OSX_SYSROOT $OSX_LD_SYSROOT $iconv_CFLAGS tmp.iconv.cpp -o tmp.iconv -DTESTING 2>&1"
eval $execute > /dev/null
ret=$?
log 2 "executing $execute"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment