You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.5 KiB

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