Script: Discover version from code.

pull/3349/head
winlin 2 years ago
parent 8a0ac8e3a1
commit 87a2ef100a

@ -320,7 +320,7 @@ echo ""
# Use srs-cache from base image. See https://github.com/ossrs/dev-docker/blob/ubuntu20-cache/Dockerfile
# Note that the cache for cygwin is not under /usr/local, but copy to objs instead.
if [[ -d /usr/local/srs-cache/srs/trunk/objs && $(pwd) != "/usr/local/srs-cache/srs/trunk" ]]; then
SOURCE_DIR=$(ls -d /usr/local/srs-cache/srs/trunk/objs/Platform-* 2>/dev/null|head -n 1)
SOURCE_DIR=$(ls -d /usr/local/srs-cache/srs/trunk/objs/Platform-SRS${SRS_MAJOR}-* 2>/dev/null|head -n 1)
if [[ -d $SOURCE_DIR ]]; then
TARGET_DIR=${SRS_OBJS}/${SRS_PLATFORM} &&
echo "Build from cache, source=$SOURCE_DIR, target=$TARGET_DIR" &&

@ -5,12 +5,29 @@ OS_KERNEL_NAME=$(uname -s)
OS_KERNRL_RELEASE=$(uname -r|awk -F '-' '{print $1}')
OS_PREFIX="Platform"
# Detect gcc, which is required.
gcc --version >/dev/null 2>/dev/null || (ret=$?; echo "Please install gcc"; exit $ret)
# Discover SRS version from header file.
mkdir -p ${SRS_OBJS} &&
echo '#include <stdio.h>' > ${SRS_OBJS}/test_version.c &&
echo '#include <srs_core_version.hpp>' >> ${SRS_OBJS}/test_version.c &&
echo 'int main(int argc, char** argv) {' >> ${SRS_OBJS}/test_version.c &&
echo ' printf("%d.%d.%d\n", VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION);' >> ${SRS_OBJS}/test_version.c &&
echo ' return 0;' >> ${SRS_OBJS}/test_version.c &&
echo '}' >> ${SRS_OBJS}/test_version.c &&
gcc -g -O0 ${SRS_OBJS}/test_version.c -I${SRS_WORKDIR}/src/core -o ${SRS_OBJS}/test_version 1>/dev/null 2>&1 &&
SRS_VERSION=$(./${SRS_OBJS}/test_version 2>/dev/null) &&
SRS_MAJOR=$(echo $SRS_VERSION |awk -F . '{print $1}');
ret=$?; rm -rf ${SRS_OBJS}/test_version*; if [[ $ret -ne 0 ]]; then echo "Detect SRS version failed"; exit $ret; fi
echo "Discover SRS version=${SRS_VERSION}, major=${SRS_MAJOR}"
if [[ $OSTYPE == cygwin ]]; then
OS_KERNRL_RELEASE=$(uname -r|awk -F '(' '{print $1}')
fi
# Build platform cache.
SRS_PLATFORM="${SRS_BUILD_TAG}${OS_PREFIX}-${OS_KERNEL_NAME}-${OS_KERNRL_RELEASE}"
SRS_PLATFORM="${SRS_BUILD_TAG}${OS_PREFIX}-SRS${SRS_MAJOR}-${OS_KERNEL_NAME}-${OS_KERNRL_RELEASE}"
# Build platform cache with gcc version.
if [[ $OS_KERNEL_NAME == Darwin ]]; then
GCC_VERSION="Clang$(gcc --version 2>/dev/null|grep clang|awk '{print $4}')"
@ -21,7 +38,7 @@ else
SRS_PLATFORM="${SRS_PLATFORM}-${GCC_VERSION}"
fi
# Use isolate cache for different SRS version.
SRS_PLATFORM="${SRS_PLATFORM}-SRS5-$(uname -m)"
SRS_PLATFORM="${SRS_PLATFORM}-$(uname -m)"
if [[ $SRS_CROSS_BUILD == YES ]]; then
SRS_TOOL_CC_NAME=$(basename $SRS_TOOL_CC)

2
trunk/configure vendored

@ -236,7 +236,7 @@ fi
MODULE_ID="CORE"
MODULE_DEPENDS=()
ModuleLibIncs=(${SRS_OBJS})
MODULE_FILES=("srs_core" "srs_core_version5" "srs_core_autofree" "srs_core_performance"
MODULE_FILES=("srs_core" "srs_core_version" "srs_core_version5" "srs_core_autofree" "srs_core_performance"
"srs_core_time" "srs_core_platform")
CORE_INCS="src/core"; MODULE_DIR=${CORE_INCS} . $SRS_WORKDIR/auto/modules.sh
CORE_OBJS="${MODULE_OBJS[@]}"

@ -8,7 +8,7 @@
#define SRS_CORE_HPP
// The version config.
#include <srs_core_version5.hpp>
#include <srs_core_version.hpp>
// The macros generated by configure script.
#include <srs_auto_headers.hpp>

@ -0,0 +1,8 @@
//
// Copyright (c) 2013-2022 The SRS Authors
//
// SPDX-License-Identifier: MIT or MulanPSL-2.0
//
#include <srs_core_version.hpp>

@ -0,0 +1,12 @@
//
// Copyright (c) 2013-2022 The SRS Authors
//
// SPDX-License-Identifier: MIT or MulanPSL-2.0
//
#ifndef SRS_CORE_VERSION_HPP
#define SRS_CORE_VERSION_HPP
#include <srs_core_version5.hpp>
#endif
Loading…
Cancel
Save