compile-tun2socks.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/usr/bin/env bash
  2. #
  3. # Compiles tun2socks for Linux.
  4. # Intended as a convenience if you don't want to deal with CMake.
  5. # Input environment vars:
  6. # SRCDIR - BadVPN source code
  7. # OUTDIR - tun2socks binary output file directory
  8. # CC - compiler
  9. # CFLAGS - compiler compile flags
  10. # LDFLAGS - compiler link flags
  11. # ENDIAN - "little" or "big"
  12. # KERNEL - "2.6" or "2.4", default "2.6"
  13. #
  14. # Puts object files and the executable in the working directory.
  15. #
  16. if [[ -z $SRCDIR ]] || [[ ! -e $SRCDIR/CMakeLists.txt ]]; then
  17. echo "SRCDIR is wrong"
  18. exit 1
  19. fi
  20. if [[ ! -z $OUTDIR ]] && [[ ! -d $OUTDIR ]]; then
  21. echo "OUTDIR is wrong"
  22. exit 1
  23. fi
  24. if ! "${CC}" --version &>/dev/null; then
  25. echo "CC is wrong"
  26. exit 1
  27. fi
  28. if [[ $ENDIAN != "little" ]] && [[ $ENDIAN != "big" ]]; then
  29. echo "ENDIAN is wrong"
  30. exit 1
  31. fi
  32. if [[ -z $KERNEL ]]; then
  33. KERNEL="2.6"
  34. elif [[ $KERNEL != "2.6" ]] && [[ $KERNEL != "2.4" ]]; then
  35. echo "KERNEL is wrong"
  36. exit 1
  37. fi
  38. CFLAGS="${CFLAGS} -std=gnu99"
  39. INCLUDES=( "-I${SRCDIR}" "-I${SRCDIR}/lwip/src/include/ipv4" "-I${SRCDIR}/lwip/src/include/ipv6" "-I${SRCDIR}/lwip/src/include" "-I${SRCDIR}/lwip/custom" )
  40. DEFS=( -DBADVPN_THREAD_SAFE=0 -DBADVPN_LINUX -DBADVPN_BREACTOR_BADVPN -D_GNU_SOURCE )
  41. [[ $KERNEL = "2.4" ]] && DEFS=( "${DEFS[@]}" -DBADVPN_USE_SELFPIPE -DBADVPN_USE_POLL ) || DEFS=( "${DEFS[@]}" -DBADVPN_USE_SIGNALFD -DBADVPN_USE_EPOLL )
  42. [[ $ENDIAN = "little" ]] && DEFS=( "${DEFS[@]}" -DBADVPN_LITTLE_ENDIAN ) || DEFS=( "${DEFS[@]}" -DBADVPN_BIG_ENDIAN )
  43. [[ -z $OUTDIR ]] && OUTDIR="."
  44. SOURCES="
  45. base/BLog_syslog.c
  46. system/BReactor_badvpn.c
  47. system/BSignal.c
  48. system/BConnection_unix.c
  49. system/BConnection_common.c
  50. system/BTime.c
  51. system/BUnixSignal.c
  52. system/BNetwork.c
  53. system/BDatagram_common.c
  54. system/BDatagram_unix.c
  55. flow/StreamRecvInterface.c
  56. flow/PacketRecvInterface.c
  57. flow/PacketPassInterface.c
  58. flow/StreamPassInterface.c
  59. flow/SinglePacketBuffer.c
  60. flow/BufferWriter.c
  61. flow/PacketBuffer.c
  62. flow/PacketStreamSender.c
  63. flow/PacketPassConnector.c
  64. flow/PacketProtoFlow.c
  65. flow/PacketPassFairQueue.c
  66. flow/PacketProtoEncoder.c
  67. flow/PacketProtoDecoder.c
  68. socksclient/BSocksClient.c
  69. tuntap/BTap.c
  70. lwip/src/core/udp.c
  71. lwip/src/core/memp.c
  72. lwip/src/core/init.c
  73. lwip/src/core/pbuf.c
  74. lwip/src/core/tcp.c
  75. lwip/src/core/tcp_out.c
  76. lwip/src/core/sys.c
  77. lwip/src/core/netif.c
  78. lwip/src/core/def.c
  79. lwip/src/core/mem.c
  80. lwip/src/core/tcp_in.c
  81. lwip/src/core/stats.c
  82. lwip/src/core/ip.c
  83. lwip/src/core/timeouts.c
  84. lwip/src/core/inet_chksum.c
  85. lwip/src/core/ipv4/icmp.c
  86. lwip/src/core/ipv4/ip4.c
  87. lwip/src/core/ipv4/ip4_addr.c
  88. lwip/src/core/ipv4/ip4_frag.c
  89. lwip/src/core/ipv6/ip6.c
  90. lwip/src/core/ipv6/nd6.c
  91. lwip/src/core/ipv6/icmp6.c
  92. lwip/src/core/ipv6/ip6_addr.c
  93. lwip/src/core/ipv6/ip6_frag.c
  94. lwip/custom/sys.c
  95. tun2socks/tun2socks.c
  96. base/DebugObject.c
  97. base/BLog.c
  98. base/BPending.c
  99. flowextra/PacketPassInactivityMonitor.c
  100. tun2socks/SocksUdpGwClient.c
  101. udpgw_client/UdpGwClient.c
  102. socks_udp_client/SocksUdpClient.c
  103. "
  104. set -e
  105. set -x
  106. OBJS=()
  107. for f in $SOURCES; do
  108. obj=${f//\//_}.o
  109. "${CC}" -c ${CFLAGS} "${INCLUDES[@]}" "${DEFS[@]}" "${SRCDIR}/${f}" -o "${obj}"
  110. OBJS=( "${OBJS[@]}" "${obj}" )
  111. done
  112. "${CC}" ${LDFLAGS} "${OBJS[@]}" -o $OUTDIR/tun2socks -lrt -lpthread