diff options
author | ambrop7 <ambrop7@1a93d707-3861-5ebc-ad3b-9740d49b5140> | 2013-12-19 21:23:16 +0400 |
---|---|---|
committer | ambrop7 <ambrop7@1a93d707-3861-5ebc-ad3b-9740d49b5140> | 2013-12-19 21:23:16 +0400 |
commit | 0292d08f7438d10914edfd55f4707366330e6dd6 (patch) | |
tree | 03b87607fbe698238efdf021ffc84bbb878fcbf6 /compile-udpgw.sh | |
parent | 4c5e1d6ad426ddd5b0f278a65c78b3e436e1aad3 (diff) |
Add compile-udpgw.sh.
Diffstat (limited to 'compile-udpgw.sh')
-rwxr-xr-x | compile-udpgw.sh | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/compile-udpgw.sh b/compile-udpgw.sh new file mode 100755 index 0000000..5f132f9 --- /dev/null +++ b/compile-udpgw.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# +# Compiles udpgw for Linux. +# Intended as a convenience if you don't want to deal with CMake. + +# Input environment vars: +# SRCDIR - BadVPN source code +# CC - compiler +# CFLAGS - compiler compile flags +# LDFLAGS - compiler link flags +# ENDIAN - "little" or "big" +# KERNEL - "2.6" or "2.4", default "2.6" +# +# Puts object files and the executable in the working directory. +# + +if [[ -z $SRCDIR ]] || [[ ! -e $SRCDIR/CMakeLists.txt ]]; then + echo "SRCDIR is wrong" + exit 1 +fi + +if ! "${CC}" --version &>/dev/null; then + echo "CC is wrong" + exit 1 +fi + +if [[ $ENDIAN != "little" ]] && [[ $ENDIAN != "big" ]]; then + echo "ENDIAN is wrong" + exit 1 +fi + +if [[ -z $KERNEL ]]; then + KERNEL="2.6" +elif [[ $KERNEL != "2.6" ]] && [[ $KERNEL != "2.4" ]]; then + echo "KERNEL is wrong" + exit 1 +fi + +CFLAGS="${CFLAGS} -std=gnu99" +INCLUDES=( "-I${SRCDIR}" ) +DEFS=( -DBADVPN_THREAD_SAFE=0 -DBADVPN_LINUX -DBADVPN_BREACTOR_BADVPN -D_GNU_SOURCE ) + +[[ $KERNEL = "2.4" ]] && DEFS=( "${DEFS[@]}" -DBADVPN_USE_SELFPIPE -DBADVPN_USE_POLL ) || DEFS=( "${DEFS[@]}" -DBADVPN_USE_SIGNALFD -DBADVPN_USE_EPOLL ) + +[[ $ENDIAN = "little" ]] && DEFS=( "${DEFS[@]}" -DBADVPN_LITTLE_ENDIAN ) || DEFS=( "${DEFS[@]}" -DBADVPN_BIG_ENDIAN ) + +SOURCES=" +base/BLog_syslog.c +system/BReactor_badvpn.c +system/BSignal.c +system/BConnection_unix.c +system/BDatagram_unix.c +system/BTime.c +system/BUnixSignal.c +system/BNetwork.c +flow/StreamRecvInterface.c +flow/PacketRecvInterface.c +flow/PacketPassInterface.c +flow/StreamPassInterface.c +flow/SinglePacketBuffer.c +flow/BufferWriter.c +flow/PacketBuffer.c +flow/PacketStreamSender.c +flow/PacketProtoFlow.c +flow/PacketPassFairQueue.c +flow/PacketProtoEncoder.c +flow/PacketProtoDecoder.c +base/DebugObject.c +base/BLog.c +base/BPending.c +udpgw/udpgw.c +" + +set -e +set -x + +OBJS=() +for f in $SOURCES; do + obj=$(basename "${f}").o + "${CC}" -c ${CFLAGS} "${INCLUDES[@]}" "${DEFS[@]}" "${SRCDIR}/${f}" -o "${obj}" + OBJS=( "${OBJS[@]}" "${obj}" ) +done + +"${CC}" ${LDFLAGS} "${OBJS[@]}" -o udpgw -lrt |