<commit_before>#!/bin/sh
#
# Helper script to make release packages:
#  - mCtrl-$VERSION-src.zip
#  - mCtrl-$VERSION-bin.zip
#
# All packages are put in current directory (and overwritten if exist already).


# We want to control what's going to stdout/err.
exec 3>&1
exec 1>/dev/null 2>&1

# Change dir to project root.
cd `dirname "$0"`/..

CWD=`pwd`
PRJ="$CWD"

# Sanity check we run this script from the right directory:
if [ ! -x $PRJ/scripts/mkrel.sh ]; then
    echo "There is some path mismatch." >&3
    exit 1
fi

# We will do all the real work in $TMP directory:
if [ x$TMP = x ]; then
    TMP=/tmp
fi
if [ ! -d $TMP ]; then
    echo "Directory '$TMP' does not exist." >&3
    exit 1
fi


##################
# Detect version #
##################

echo -n "Detecting mCtrl version... " >&3
VERSION_MAJOR=`grep VERSION_MAJOR src/version.h | head -1 | sed "s/\#def.*MAJOR\ *//"`
VERSION_MINOR=`grep VERSION_MINOR src/version.h | head -1 | sed "s/\#def.*MINOR\ *//"`
VERSION_RELEASE=`grep VERSION_RELEASE src/version.h | head -1 | sed "s/\#def.*RELEASE\ *//"`
VERSION=$VERSION_MAJOR.$VERSION_MINOR.$VERSION_RELEASE
if [ x$VERSION = x ]; then
    echo "Failed." >&3
    exit 1
fi
echo "$VERSION" >&3


#####################
# Detect a zip tool #
#####################

echo -n "Detecting zip archiver... " >&3
if which 7za; then
    MKZIP="7za a -r -mx9"
elif which 7z; then
    MKZIP="7z a -r -mx9"
elif which zip; then
    MKZIP="zip -r"
else
    echo "Not found." >&3
    exit 1
fi
echo "$MKZIP" >&3


##################
# Detect lib.exe #
##################

# 1. Try lib.exe in $PATH
# 2. Try default install place(s) for MSVC 10.0
# 3. Try default install place(s) for any MSVC version

echo -n "Detecting lib.exe... " >&3
if which lib.exe ; then
    LIBEXE="lib.exe"
elif [ -x "/c/Program Files/Microsoft Visual Studio 10.0/VC/bin/amd64/lib.exe" ]; then
    LIBEXE="/c/Program Files/Microsoft Visual Studio 10.0/VC/bin/amd64/lib.exe"
elif [ -x "/c/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/amd64/lib.exe" ]; then
    LIBEXE="/c/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/amd64/lib.exe"
else
    LIBEXE=`ls /c/Program\ Files*/Microsoft\ Visual\ Studio*/VC/bin/amd64/lib.exe | head -1`
fi
if [ "x$LIBEXE" = x ]; then
    echo "Not found: MSVC import libs won't be generated" >&3
else
    echo "$LIBEXE" >&3
fi


#########################
# Build 64-bit binaries #
#########################

rm -rf $TMP/mCtrl-$VERSION
git clone . $TMP/mCtrl-$VERSION

echo -n "Building 64-bit binaries... " >&3
(cd $TMP/mCtrl-$VERSION && scripts/build.sh --release --64 all examples > $CWD/build-x86_64.log 2>&1)
if [ $? -eq 0 ]; then
    HAVE_X86_64=yes
    echo "Done." >&3
else
    echo "Failed. See build-x86_64.log." >&3
fi

if [ x$HAVE_X86_64 != x ]; then
    echo -n "Create 64-bit MSVC import lib... " >&3
    if [ "x$LIBEXE" != x ]; then
        (cd $TMP/mCtrl-$VERSION && "$LIBEXE" /machine:x64 /def:obj/mCtrl.def /out:lib/mCtrl.lib >> $CWD/build-x86.log 2>&1)
        echo "Done." >&3
    else
        echo "Skipped: lib.exe not found." >&3
    fi

    mv $TMP/mCtrl-$VERSION/bin $TMP/mCtrl-$VERSION/bin64
    mv $TMP/mCtrl-$VERSION/lib $TMP/mCtrl-$VERSION/lib64
    mkdir $TMP/mCtrl-$VERSION/bin
    mkdir $TMP/mCtrl-$VERSION/lib
fi

(cd $TMP/mCtrl-$VERSION && make distclean)


#########################
# Build 32-bit binaries #
#########################

echo -n "Building 32-bit binaries... " >&3
(cd $TMP/mCtrl-$VERSION && scripts/build.sh --release --32 all examples > $CWD/build-x86.log 2>&1)
if [ $? -eq 0 ]; then
    HAVE_X86=yes
    echo "Done." >&3
else
    echo "Failed. See build-x86.log." >&3
fi

if [ x$HAVE_X86 != x ]; then
    echo -n "Create 32-bit MSVC import lib... " >&3
    if [ "x$LIBEXE" != x ]; then
        (cd $TMP/mCtrl-$VERSION && "$LIBEXE" /machine:x86 /def:obj/mCtrl.def /out:lib/mCtrl.lib >> $CWD/build-x86.log 2>&1)
        echo "Done." >&3
    else
        echo "Skipped: lib.exe not found." >&3
    fi
fi


##########################
# Generate documentation #
##########################

echo -n "Generate documentation... " >&3
if `which doxygen`; then
    (cd $TMP/mCtrl-$VERSION && ( cat Doxyfile ; echo "PROJECT_NUMBER=$VERSION" ) | doxygen - > $CWD/build-doc.log 2>&1)
    if [ $? -ne 0 ]; then
        echo "Failed: See build-doc.log."
        exit 1
    fi<commit_msg>[scripts/mkrel.sh] Fix path to mCtrl.def.<commit_after>#!/bin/sh
#
# Helper script to make release packages:
#  - mCtrl-$VERSION-src.zip
#  - mCtrl-$VERSION-bin.zip
#
# All packages are put in current directory (and overwritten if exist already).


# We want to control what's going to stdout/err.
exec 3>&1
exec 1>/dev/null 2>&1

# Change dir to project root.
cd `dirname "$0"`/..

CWD=`pwd`
PRJ="$CWD"

# Sanity check we run this script from the right directory:
if [ ! -x $PRJ/scripts/mkrel.sh ]; then
    echo "There is some path mismatch." >&3
    exit 1
fi

# We will do all the real work in $TMP directory:
if [ x$TMP = x ]; then
    TMP=/tmp
fi
if [ ! -d $TMP ]; then
    echo "Directory '$TMP' does not exist." >&3
    exit 1
fi


##################
# Detect version #
##################

echo -n "Detecting mCtrl version... " >&3
VERSION_MAJOR=`grep VERSION_MAJOR src/version.h | head -1 | sed "s/\#def.*MAJOR\ *//"`
VERSION_MINOR=`grep VERSION_MINOR src/version.h | head -1 | sed "s/\#def.*MINOR\ *//"`
VERSION_RELEASE=`grep VERSION_RELEASE src/version.h | head -1 | sed "s/\#def.*RELEASE\ *//"`
VERSION=$VERSION_MAJOR.$VERSION_MINOR.$VERSION_RELEASE
if [ x$VERSION = x ]; then
    echo "Failed." >&3
    exit 1
fi
echo "$VERSION" >&3


#####################
# Detect a zip tool #
#####################

echo -n "Detecting zip archiver... " >&3
if which 7za; then
    MKZIP="7za a -r -mx9"
elif which 7z; then
    MKZIP="7z a -r -mx9"
elif which zip; then
    MKZIP="zip -r"
else
    echo "Not found." >&3
    exit 1
fi
echo "$MKZIP" >&3


##################
# Detect lib.exe #
##################

# 1. Try lib.exe in $PATH
# 2. Try default install place(s) for MSVC 10.0
# 3. Try default install place(s) for any MSVC version

echo -n "Detecting lib.exe... " >&3
if which lib.exe ; then
    LIBEXE="lib.exe"
elif [ -x "/c/Program Files/Microsoft Visual Studio 10.0/VC/bin/amd64/lib.exe" ]; then
    LIBEXE="/c/Program Files/Microsoft Visual Studio 10.0/VC/bin/amd64/lib.exe"
elif [ -x "/c/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/amd64/lib.exe" ]; then
    LIBEXE="/c/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/amd64/lib.exe"
else
    LIBEXE=`ls /c/Program\ Files*/Microsoft\ Visual\ Studio*/VC/bin/amd64/lib.exe | head -1`
fi
if [ "x$LIBEXE" = x ]; then
    echo "Not found: MSVC import libs won't be generated" >&3
else
    echo "$LIBEXE" >&3
fi


#########################
# Build 64-bit binaries #
#########################

rm -rf $TMP/mCtrl-$VERSION
git clone . $TMP/mCtrl-$VERSION

echo -n "Building 64-bit binaries... " >&3
(cd $TMP/mCtrl-$VERSION && scripts/build.sh --release --64 all examples > $CWD/build-x86_64.log 2>&1)
if [ $? -eq 0 ]; then
    HAVE_X86_64=yes
    echo "Done." >&3
else
    echo "Failed. See build-x86_64.log." >&3
fi

if [ x$HAVE_X86_64 != x ]; then
    echo -n "Create 64-bit MSVC import lib... " >&3
    if [ "x$LIBEXE" != x ]; then
        (cd $TMP/mCtrl-$VERSION && "$LIBEXE" /machine:x64 /def:src/mCtrl.def /out:lib/mCtrl.lib >> $CWD/build-x86_64.log 2>&1)
        echo "Done." >&3
    else
        echo "Skipped: lib.exe not found." >&3
    fi

    mv $TMP/mCtrl-$VERSION/bin $TMP/mCtrl-$VERSION/bin64
    mv $TMP/mCtrl-$VERSION/lib $TMP/mCtrl-$VERSION/lib64
    mkdir $TMP/mCtrl-$VERSION/bin
    mkdir $TMP/mCtrl-$VERSION/lib
fi

(cd $TMP/mCtrl-$VERSION && make distclean)


#########################
# Build 32-bit binaries #
#########################

echo -n "Building 32-bit binaries... " >&3
(cd $TMP/mCtrl-$VERSION && scripts/build.sh --release --32 all examples > $CWD/build-x86.log 2>&1)
if [ $? -eq 0 ]; then
    HAVE_X86=yes
    echo "Done." >&3
else
    echo "Failed. See build-x86.log." >&3
fi

if [ x$HAVE_X86 != x ]; then
    echo -n "Create 32-bit MSVC import lib... " >&3
    if [ "x$LIBEXE" != x ]; then
        (cd $TMP/mCtrl-$VERSION && "$LIBEXE" /machine:x86 /def:src/mCtrl.def /out:lib/mCtrl.lib >> $CWD/build-x86.log 2>&1)
        echo "Done." >&3
    else
        echo "Skipped: lib.exe not found." >&3
    fi
fi


##########################
# Generate documentation #
##########################

echo -n "Generate documentation... " >&3
if `which doxygen`; then
    (cd $TMP/mCtrl-$VERSION && ( cat Doxyfile ; echo "PROJECT_NUMBER=$VERSION" ) | doxygen - > $CWD/build-doc.log 2>&1)
    if [ $? -ne 0 ]; then
        echo "Failed: See build-doc.log."
        exit 1
    fi
{'fraction_non_alphanumeric': 0.21676797797912606, 'fraction_numerical': 0.03280192682647093, 'mean_word_length': 2.9871970736168265, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7439510', 'n_tokens_mistral': 3466, 'n_tokens_neox': 3259, 'n_words': 929}