Skip to content

Commit

Permalink
For ossrs#2532: Windows: Support CYGWIN64 for SRS (ossrs#3255)
Browse files Browse the repository at this point in the history
1. Support cygwin by '--cygwin64=on'
2. Detect cygwin automatically.
3. Disalbe sanitizer, srt and srtp with openssl.
4. Disable multiple threads, use single threads.
5. Support utest for cygwin64.
6. Query features for windows by API.
7. Disable stat APIs for cygwin.
8. Use ST select event driver.

Co-authored-by: wenjie.zhao <[email protected]>
  • Loading branch information
2 people authored and johzzy committed Apr 18, 2023
1 parent 5d0730b commit b06f71d
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 310 deletions.
5 changes: 5 additions & 0 deletions trunk/auto/auto_headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ if [[ $SRS_CROSS_BUILD == YES ]]; then
else
srs_undefine_macro "SRS_CROSSBUILD" $SRS_AUTO_HEADERS_H
fi
if [[ $SRS_CYGWIN64 == YES ]]; then
srs_define_macro "SRS_CYGWIN64" $SRS_AUTO_HEADERS_H
else
srs_undefine_macro "SRS_CYGWIN64" $SRS_AUTO_HEADERS_H
fi
if [[ $SRS_OSX == YES ]]; then
srs_define_macro "SRS_OSX" $SRS_AUTO_HEADERS_H
else
Expand Down
305 changes: 19 additions & 286 deletions trunk/auto/depends.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,286 +14,7 @@
#####################################################################################
# Check OS and CPU architectures.
#####################################################################################
function require_sudoer() {
sudo echo "" >/dev/null 2>&1

ret=$?; if [[ 0 -ne $ret ]]; then
echo "\"$1\" require sudoer failed. ret=$ret";
exit $ret;
fi
}

#####################################################################################
# for Ubuntu, auto install tools by apt-get
#####################################################################################
function Ubuntu_prepare() {
if [[ $OS_IS_UBUNTU != YES ]]; then return 0; fi
echo "Installing tools for Ubuntu."

gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Installing gcc."
require_sudoer "sudo apt-get install -y --force-yes gcc"
sudo apt-get install -y --force-yes gcc; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "The gcc is installed."
fi

g++ --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Installing g++."
require_sudoer "sudo apt-get install -y --force-yes g++"
sudo apt-get install -y --force-yes g++; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "The g++ is installed."
fi

make --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Installing make."
require_sudoer "sudo apt-get install -y --force-yes make"
sudo apt-get install -y --force-yes make; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "The make is installed."
fi

patch --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Installing patch."
require_sudoer "sudo apt-get install -y --force-yes patch"
sudo apt-get install -y --force-yes patch; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "The patch is installed."
fi

unzip --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Installing unzip."
require_sudoer "sudo apt-get install -y --force-yes unzip"
sudo apt-get install -y --force-yes unzip; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "The unzip is installed."
fi

if [[ $SRS_VALGRIND == YES ]]; then
valgrind --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Installing valgrind."
require_sudoer "sudo apt-get install -y --force-yes valgrind"
sudo apt-get install -y --force-yes valgrind; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "The valgrind is installed."
fi
fi

if [[ $SRS_VALGRIND == YES ]]; then
if [[ ! -f /usr/include/valgrind/valgrind.h ]]; then
echo "Installing valgrind-dev."
require_sudoer "sudo apt-get install -y --force-yes valgrind-dbg"
sudo apt-get install -y --force-yes valgrind-dev; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "The valgrind-dev is installed."
fi
fi

if [[ $SRS_SRT == YES ]]; then
echo "SRT enable, install depend tools"
tclsh <<< "exit" >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Installing tcl."
require_sudoer "sudo apt-get install -y --force-yes tcl"
sudo apt-get install -y --force-yes tcl; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "The tcl is installed."
fi

cmake --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Installing cmake."
require_sudoer "sudo apt-get install -y --force-yes cmake"
sudo apt-get install -y --force-yes cmake; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "The cmake is installed."
fi
fi

pkg-config --version >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Installing pkg-config."
require_sudoer "sudo apt-get install -y --force-yes pkg-config"
sudo apt-get install -y --force-yes pkg-config; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "The pkg-config is installed."
fi

echo "Tools for Ubuntu are installed."
return 0
}
# donot prepare tools, for srs-librtmp depends only gcc and g++.
Ubuntu_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "Install tools for ubuntu failed, ret=$ret"; exit $ret; fi

#####################################################################################
# for Centos, auto install tools by yum
#####################################################################################
function Centos_prepare() {
if [[ $OS_IS_CENTOS != YES ]]; then return 0; fi
echo "Installing tools for Centos."

gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Installing gcc."
require_sudoer "sudo yum install -y gcc"
sudo yum install -y gcc; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "The gcc is installed."
fi

g++ --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Installing gcc-c++."
require_sudoer "sudo yum install -y gcc-c++"
sudo yum install -y gcc-c++; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "The gcc-c++ is installed."
fi

make --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Installing make."
require_sudoer "sudo yum install -y make"
sudo yum install -y make; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "The make is installed."
fi

patch --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Installing patch."
require_sudoer "sudo yum install -y patch"
sudo yum install -y patch; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "The patch is installed."
fi

unzip --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Installing unzip."
require_sudoer "sudo yum install -y unzip"
sudo yum install -y unzip; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "The unzip is installed."
fi

if [[ $SRS_VALGRIND == YES ]]; then
valgrind --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Installing valgrind."
require_sudoer "sudo yum install -y valgrind"
sudo yum install -y valgrind; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "The valgrind is installed."
fi
fi

if [[ $SRS_VALGRIND == YES ]]; then
if [[ ! -f /usr/include/valgrind/valgrind.h ]]; then
echo "Installing valgrind-devel."
require_sudoer "sudo yum install -y valgrind-devel"
sudo yum install -y valgrind-devel; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "The valgrind-devel is installed."
fi
fi

if [[ $SRS_SRT == YES ]]; then
echo "SRT enable, install depend tools"
tclsh <<< "exit" >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Installing tcl."
require_sudoer "sudo yum install -y tcl"
sudo yum install -y tcl; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "The tcl is installed."
fi

cmake --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Installing cmake."
require_sudoer "sudo yum install -y cmake"
sudo yum install -y cmake; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "The cmake is installed."
fi
fi

pkg-config --version --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Please install pkg-config"; exit -1;
fi

echo "Tools for Centos are installed."
return 0
}
# donot prepare tools, for srs-librtmp depends only gcc and g++.
Centos_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "Install tools for CentOS failed, ret=$ret"; exit $ret; fi

#####################################################################################
# For OSX, auto install tools by brew
#####################################################################################
function OSX_prepare() {
if [[ $OS_IS_OSX != YES ]]; then
if [[ $SRS_OSX == YES ]]; then echo "OSX check failed, actual is `uname -s`"; exit 1; fi
return 0
fi

# cross build for arm, install the cross build tool chain.
if [[ $SRS_CROSS_BUILD == YES ]]; then
echo "The embeded(arm/mips) is invalid for OSX"
return 1
fi

# Requires the osx when darwin detected
if [[ $OS_IS_OSX == YES && $SRS_OSX != YES ]]; then
echo "OSX detected, please use: ./configure --osx"
exit 1
fi

echo "OSX detected, install tools if needed"

brew --version >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Please install brew at https://brew.sh/"
exit $ret
fi

gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "install gcc"
echo "brew install gcc"
brew install gcc; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "install gcc success"
fi

g++ --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "install gcc-c++"
echo "brew install gcc-c++"
brew install gcc-c++; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "install gcc-c++ success"
fi

make --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "install make"
echo "brew install make"
brew install make; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "install make success"
fi

patch --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "install patch"
echo "brew install patch"
brew install patch; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "install patch success"
fi

unzip --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "install unzip"
echo "brew install unzip"
brew install unzip; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "install unzip success"
fi

pkg-config --version >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Please install pkg-config"; exit -1;
fi

if [[ $SRS_SRT == YES ]]; then
echo "SRT enable, install depend tools"
tclsh <<< "exit" >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Installing tcl."
echo "brew install tcl."
brew install tcl; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "install tcl success"
fi

cmake --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
echo "Installing cmake."
echo "brew install cmake."
brew install cmake; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
echo "install cmake success"
fi
fi

echo "OSX install tools success"
return 0
}
# donot prepare tools, for srs-librtmp depends only gcc and g++.
OSX_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "OSX prepare failed, ret=$ret"; exit $ret; fi

#####################################################################################
# Check OS and CPU architectures.
#####################################################################################
if [[ $OS_IS_UBUNTU != YES && $OS_IS_CENTOS != YES && $OS_IS_OSX != YES && $SRS_CROSS_BUILD != YES ]]; then
if [[ $OS_IS_UBUNTU != YES && $OS_IS_CENTOS != YES && $OS_IS_OSX != YES && $SRS_CROSS_BUILD != YES && $SRS_CYGWIN64 != YES ]]; then
echo "Your OS `uname -s` is not supported."
exit 1
fi
Expand Down Expand Up @@ -385,6 +106,10 @@ fi
if [[ $SRS_OSX == YES ]]; then
_ST_MAKE=darwin-debug && _ST_OBJ="DARWIN_`uname -r`_DBG"
fi
# for windows/cygwin
if [[ $SRS_CYGWIN64 = YES ]]; then
_ST_MAKE=cygwin64-debug && _ST_OBJ="CYGWIN64_`uname -s`_DBG"
fi
# For Ubuntu, the epoll detection might be fail.
if [[ $OS_IS_UBUNTU == YES ]]; then
_ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DMD_HAVE_EPOLL"
Expand Down Expand Up @@ -660,8 +385,16 @@ if [[ $SRS_RTC == YES ]] && [[ $SRS_SSL_3_0 == NO ]]; then
rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srtp2 \
${SRS_OBJS}/srtp2 &&
cp -rf ${SRS_WORKDIR}/3rdparty/libsrtp-2-fit ${SRS_OBJS}/${SRS_PLATFORM}/ &&
patch -p0 ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/crypto/math/datatypes.c ${SRS_WORKDIR}/3rdparty/patches/srtp/gcc10-01.patch &&
patch -p0 ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/config.guess ${SRS_WORKDIR}/3rdparty/patches/srtp/config.guess-02.patch &&
# For cygwin64, the patch is not available, so use sed instead.
if [[ $SRS_CYGWIN64 == YES ]]; then
sed -i 's/char bit_string/static char bit_string/g' ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/crypto/math/datatypes.c
else
patch -p0 ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/crypto/math/datatypes.c ${SRS_WORKDIR}/3rdparty/patches/srtp/gcc10-01.patch
fi &&
# Patch the cpu arch guessing for RISCV.
if [[ $OS_IS_RISCV == YES ]]; then
patch -p0 ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/config.guess ${SRS_WORKDIR}/3rdparty/patches/srtp/config.guess-02.patch
fi &&
(
cd ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit &&
$SRTP_CONFIGURE ${SRTP_OPTIONS} --prefix=${SRS_DEPENDS_LIBS}/${SRS_PLATFORM}/3rdpatry/srtp2
Expand Down Expand Up @@ -878,16 +611,16 @@ if [[ $SRS_SRT == YES ]]; then
else
LIBSRT_OPTIONS="$LIBSRT_OPTIONS --enable-shared=0"
fi
# For windows build, over cygwin
if [[ $SRS_CYGWIN64 == YES ]]; then
LIBSRT_OPTIONS="$LIBSRT_OPTIONS --cygwin-use-posix"
fi
# For cross-build.
if [[ $SRS_CROSS_BUILD == YES ]]; then
TOOL_GCC_REALPATH=$(realpath $(which $SRS_TOOL_CC))
SRT_COMPILER_PREFIX=$(echo $TOOL_GCC_REALPATH |sed 's/-gcc.*$/-/')
LIBSRT_OPTIONS="$LIBSRT_OPTIONS --with-compiler-prefix=$SRT_COMPILER_PREFIX"
fi
# For windows build, over cygwin
if [[ $SRS_CYGWIN64 == YES ]]; then
LIBSRT_OPTIONS="$LIBSRT_OPTIONS --cygwin-use-posix"
fi

if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srt/lib/libsrt.a ]]; then
rm -rf ${SRS_OBJS}/srt && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srt ${SRS_OBJS}/ &&
Expand Down
Loading

0 comments on commit b06f71d

Please sign in to comment.