Version 1.8.0.0
[socat.git] / socat_buildscript_for_android.sh
blob464af43fc8de1a4e6732b2d0dfe1a8d8c6f5d1ff
1 #!/bin/sh
3 # Customize these parameters according to your environment
4 ANDROID_NDK="${HOME}/bin/android-ndk-r6b"
6 # Check for parameters
7 if [ ! -d "${ANDROID_NDK}" ]; then
8 echo "Android NDK not found in ${ANDROID_NDK}, please edit $0 to fix it."
9 exit 1
12 if [ ! -e "${ANDROID_NDK}/build/tools/make-standalone-toolchain.sh" ]; then
13 echo "Your Android NDK is not compatible (make-standalone-toolchain.sh not found)."
14 echo "Android NDK r6b is known to work."
15 exit 1
18 # Extract the Android toolchain from NDK
19 ANDROID_PLATFORM="android-3"
20 ROOT="`pwd`"
21 OUT="${ROOT}/out"
22 ${ANDROID_NDK}/build/tools/make-standalone-toolchain.sh \
23 --ndk-dir="${ANDROID_NDK}" \
24 --platform="${ANDROID_PLATFORM}" \
25 --install-dir="${OUT}/toolchain" \
26 || exit 1
27 # Remove resolv.h because it is quite unusable as is
28 rm ${OUT}/toolchain/sysroot/usr/include/resolv.h
30 # Create configure script
31 cd ${ROOT}
32 autoconf || exit 1
34 # Create config.h and Makefile
35 cd ${OUT}
36 ${ROOT}/configure \
37 --host \
38 --disable-openssl \
39 --disable-unix \
40 CC="${OUT}/toolchain/bin/arm-linux-androideabi-gcc" \
41 || exit 1
43 # Replace misconfigured values in config.h and enable PTY functions
44 mv config.h config.old
45 cat config.old \
46 | sed 's/CRDLY_SHIFT.*/CRDLY_SHIFT 9/' \
47 | sed 's/TABDLY_SHIFT.*/TABDLY_SHIFT 11/' \
48 | sed 's/CSIZE_SHIFT.*/CSIZE_SHIFT 4/' \
49 | sed 's/\/\* #undef HAVE_OPENPTY \*\//#define HAVE_OPENPTY 1/' \
50 | sed 's/\/\* #undef HAVE_GRANTPT \*\//#define HAVE_GRANTPT 1/' \
51 > config.h
53 # Enable openpty() in Makefile
54 mv Makefile Makefile.old
55 cat Makefile.old | sed 's/error.c/error.c openpty.c/' > Makefile
57 # Provide openpty.c
58 cat >openpty.c <<EOF
59 /* Copyright (C) 1998, 1999, 2004 Free Software Foundation, Inc.
60 This file is part of the GNU C Library.
61 Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
63 The GNU C Library is free software; you can redistribute it and/or
64 modify it under the terms of the GNU Lesser General Public
65 License as published by the Free Software Foundation; either
66 version 2.1 of the License, or (at your option) any later version.
68 The GNU C Library is distributed in the hope that it will be useful,
69 but WITHOUT ANY WARRANTY; without even the implied warranty of
70 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
71 Lesser General Public License for more details.
73 You should have received a copy of the GNU Lesser General Public
74 License along with the GNU C Library; if not, write to the Free
75 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
76 02111-1307 USA. */
78 #include <errno.h>
79 #include <fcntl.h>
80 #include <limits.h>
81 #include <stdlib.h>
82 #include <string.h>
83 #include <termios.h>
84 #include <unistd.h>
85 #include <sys/types.h>
86 #include <sys/ioctl.h>
88 #define _PATH_DEVPTMX "/dev/ptmx"
90 int openpty (int *amaster, int *aslave, char *name, struct termios *termp,
91 struct winsize *winp)
93 char buf[PATH_MAX];
94 int master, slave;
96 master = open(_PATH_DEVPTMX, O_RDWR);
97 if (master == -1)
98 return -1;
100 if (grantpt(master))
101 goto fail;
103 if (unlockpt(master))
104 goto fail;
106 if (ptsname_r(master, buf, sizeof buf))
107 goto fail;
109 slave = open(buf, O_RDWR | O_NOCTTY);
110 if (slave == -1)
111 goto fail;
113 /* XXX Should we ignore errors here? */
114 if (termp)
115 tcsetattr(slave, TCSAFLUSH, termp);
116 if (winp)
117 ioctl(slave, TIOCSWINSZ, winp);
119 *amaster = master;
120 *aslave = slave;
121 if (name != NULL)
122 strcpy(name, buf);
124 return 0;
126 fail:
127 close(master);
128 return -1;
132 # Compile
133 make socat || exit 1
135 # Done
136 echo "Build finished, socat has been generated successfuly in out/socat"