From 9dec6d0dc7d88956c926fed01a76e023e736f9c8 Mon Sep 17 00:00:00 2001 From: Colin Finck Date: Tue, 3 Nov 2009 22:51:09 +0000 Subject: [PATCH] - Rename the toolchain packages for RosBE-Windows to the more appropriate names "rosbe_1.4" and "rosbe_1.5". Packages for them can be downloaded from http://svn.reactos.org/RosBE-Sources. - Use "setuplibrary.sh" for the current "buildtoolchain.sh" script and share as much code as possible between this file and RosBE-Unix' "RosBE-Builder.sh". - Add a new parameter to this script for specifying the work/output directory. - Add the cpucount tool to speed up the build process. svn path=/trunk/tools/RosBE/; revision=1131 --- .../gcc_4.4.2/buildtoolchain.sh | 316 ------------------ .../buildtoolchain.sh | 6 +- .../rosbe_1.5/buildtoolchain.sh | 231 +++++++++++++ .../rosbe_1.5/scripts/setuplibrary.sh | 230 +++++++++++++ .../Buildtoolchain/rosbe_1.5/tools/cpucount.c | 100 ++++++ 5 files changed, 565 insertions(+), 318 deletions(-) delete mode 100644 RosBE-Windows/Buildtoolchain/gcc_4.4.2/buildtoolchain.sh rename RosBE-Windows/Buildtoolchain/{gcc_4.1.3 => rosbe_1.4}/buildtoolchain.sh (97%) create mode 100644 RosBE-Windows/Buildtoolchain/rosbe_1.5/buildtoolchain.sh create mode 100644 RosBE-Windows/Buildtoolchain/rosbe_1.5/scripts/setuplibrary.sh create mode 100644 RosBE-Windows/Buildtoolchain/rosbe_1.5/tools/cpucount.c diff --git a/RosBE-Windows/Buildtoolchain/gcc_4.4.2/buildtoolchain.sh b/RosBE-Windows/Buildtoolchain/gcc_4.4.2/buildtoolchain.sh deleted file mode 100644 index 851b41e..0000000 --- a/RosBE-Windows/Buildtoolchain/gcc_4.4.2/buildtoolchain.sh +++ /dev/null @@ -1,316 +0,0 @@ -#!/bin/bash -# -# ReactOS Build Environment for Windows - Script for building a binutils/GCC/mingw-runtime/w32api toolchain for Windows -# Partly based on RosBE-Unix' "RosBE-Builder.sh" -# Copyright 2009 Colin Finck -# -# Released under GNU GPL v2 or any later version. - -######################################################################################################################## -# This script was built for the following toolchain versions: -# - binutils 2.20.51-20091017 (snapshot) -# - gcc 4.4.2 -# patched with: -# * http://gcc.gnu.org/bugzilla/attachment.cgi?id=18882&action=view (committed in GCC r153606) -# - gmp 4.3.1 -# - mingw-runtime 3.16 -# - mpfr 2.4.2-rc1 -# - w32api 3.13 -# -# These tools were compiled under MSYS with "gcc version 3.4.5 (mingw-vista special r3)" -# -# These versions are used in RosBE-Windows 1.5 and RosBE-Unix 1.5. -# Get the toolchain packages from this RosBE-Unix version. -######################################################################################################################## - - -# -# Constants -# -WORKDIR="/c/buildtoolchain" - -HOST_CFLAGS="-pipe -fno-common -O3 -march=pentium3 -mfpmath=sse" -HOST_GCC_VERSION="gcc version 3.4.5 (mingw-vista special r3)" -INSTALLDIR="$WORKDIR/mingw" -NEEDED_TOOLS="bison flex gcc g++ grep make makeinfo" -SUPPORTDIR="$WORKDIR/support" -SYSHEADERDIR="/mingw/include" -TARGET="mingw32" -TARGET_CFLAGS="-pipe -gstabs+ -O3 -march=pentium -mtune=i686" - - -# -# Functions -# -boldmsg() -{ - echo -e $2 "\e[1m$1\e[0m" -} - -greenmsg() -{ - echo -e $2 "\e[32m$1\e[0m" -} - -redmsg() -{ - echo -e $2 "\e[31m$1\e[0m" -} - -check_run() -{ - if [ $? -ne 0 ]; then - redmsg "FAILED" - echo "Please take a look at the log file \"$WORKDIR/build.log\"" - echo "Aborted!" - exit 1 - else - greenmsg "OK" - rm "$WORKDIR/build.log" - fi -} - -mkdir_if_not_exists() -{ - if ! [ -d "$1" ]; then - mkdir -p "$1" - fi -} - -mkdir_empty() -{ - if [ -d "$1" ]; then - rm -rf "$1" - fi - - mkdir -p "$1" -} - -prepare_module() -{ - # Check if the module shall be built and extract it then - process_it=$1 - module=$2 - - if [ "$process_it" = "0" ]; then - return 1 - fi - - cd "$WORKDIR" - rm -rf "$module" - rm -rf "$module-build" - - echo -n "Extracting $module... " - tar -xjf "$source_path/$module.tar.bz2" >& build.log - check_run - - mkdir "$module-build" - cd "$module-build" - - return 0 -} - -do_command() -{ - echo -n "Running \"$*\"... " - $* >& "$WORKDIR/build.log" - check_run -} - -clean_module() -{ - echo "Cleaning up $1..." - cd "$WORKDIR" - rm -rf "$1-build" - rm -rf "$1" -} - - -# -# Entry point -# -echo "buildtoolchain - Build a binutils/GCC/mingw-runtime/w32api toolchain for Windows" -echo "Script for gcc_4.4.2 (see script header for details)" -echo "by Colin Finck " -echo - -if [ "`uname -o`" != "Msys" ]; then - echo "You can only run this script under a MSYS environment!" - exit 1 -fi - -# We don't want too less parameters -if [ "$1" == "" ]; then - echo "Syntax: ./buildtoolchain.sh [w32api] [mingw-runtime] [gmp] [mpfr] [binutils] [gcc]" - echo - echo " sources - Path to the directory containing RosBE-Unix toolchain packages (.tar.bz2 files)" - echo - echo "The rest of the arguments are optional. You specify them if you want to prevent a component" - echo "from being (re)built. Do this by passing 0 as the argument of the appropriate component." - echo "Pass 1 if you want them to be built." - echo "By default, all of these components are built, so you don't need to pass any of these parameters." - exit 1 -fi - -# Get the absolute path to the script directory -cd `dirname $0` -SCRIPTDIR="$PWD" - -# Find out whether the script directory contains spaces -case "$SCRIPTDIR" in -*" "*) - redmsg "The script directory \"$SCRIPTDIR\" contains spaces!" - redmsg "Therefore some build tools cannot be compiled properly." - echo - redmsg "Please move \"$SCRIPTDIR\" to a directory, which does not contain spaces." - - exit 1;; -esac - -# Check if all necessary tools exist -boldmsg "Checking for the needed tools..." - -toolmissing=false -for tool in $NEEDED_TOOLS; do - echo -n "Checking for $tool... " - - if which "$tool" >& /dev/null; then - greenmsg "OK" - else - redmsg "MISSING" - toolmissing=true - fi -done - -# Check for the correct GCC version -echo -n "Checking for the correct GCC version... " - -if gcc -v 2>&1 | grep "$HOST_GCC_VERSION" >& /dev/null; then - greenmsg "OK" -else - redmsg "MISSING" - toolmissing=true -fi - -if $toolmissing; then - echo "At least one needed tool is missing, aborted!" - exit 1 -fi - -echo - -# Get the absolute path to the source directory -cd "$1" -source_path="$PWD" - -# Create all necessary directories -mkdir_if_not_exists "$INSTALLDIR/$TARGET" -mkdir_empty "$SYSHEADERDIR" -mkdir_if_not_exists "$SUPPORTDIR" - -# Process each module -boldmsg "Building..." - - -if [ "$2" != "0" ]; then - echo -n "Extracting w32api... " - - cd "$INSTALLDIR/$TARGET" - tar -xjf "$source_path/w32api.tar.bz2" >& "$WORKDIR/build.log" - check_run -fi - -if prepare_module "$3" "mingw-runtime"; then - export CFLAGS="$TARGET_CFLAGS" - export C_INCLUDE_PATH="$INSTALLDIR/$TARGET/include" - - do_command ../mingw-runtime/configure --prefix="$INSTALLDIR/$TARGET" --host="$TARGET" --build="$TARGET" - do_command make - do_command make install - - # libmingwex.a of the MinGW Runtime 3.15 and later references to _get_output_format, which is exported by msvcr80.dll and later. - # For older Runtime DLLs (such as the msvcrt.dll we primarily use for ReactOS), MinGW adds a _get_output_format function returning 0 to libmsvcrt.a. - # As we use MinGW's libmingwex.a, but our own libmsvcrt.a, linking to MinGW's libmingwex.a will fail by default. Therefore we have to create an archive for the compiled - # _get_output_format stub, copy it to our "lib" directory and include it when linking to libmingwex.a. - ar r ofmt_stub.a ofmt_stub.o >& /dev/null - cp ofmt_stub.a "$INSTALLDIR/$TARGET/lib" - - clean_module mingw-runtime - - export CFLAGS="" - export C_INCLUDE_PATH="" -fi - -if prepare_module "$4" "gmp"; then - export CFLAGS="$HOST_CFLAGS" - - do_command ../gmp/configure ABI=32 --prefix="$SUPPORTDIR" --host="$TARGET" --build="$TARGET" --disable-shared - do_command make - do_command make check - do_command make install - clean_module gmp - - export CFLAGS="" -fi - -if prepare_module "$5" "mpfr"; then - export CFLAGS="$HOST_CFLAGS" - - do_command ../mpfr/configure --prefix="$SUPPORTDIR" --host="$TARGET" --build="$TARGET" --with-gmp="$SUPPORTDIR" --disable-shared - do_command make - do_command make check - do_command make install - clean_module mpfr - - export CFLAGS="" -fi - -if prepare_module "$6" "binutils"; then - export CFLAGS="$HOST_CFLAGS" - - do_command ../binutils/configure --prefix="$INSTALLDIR" --host="$TARGET" --build="$TARGET" --target="$TARGET" --disable-nls - do_command make - do_command make install - clean_module binutils - - export CFLAGS="" -fi - -if prepare_module "$7" "gcc"; then - export STAGE1_CFLAGS="$HOST_CFLAGS" - export BOOT_CFLAGS="$HOST_CFLAGS" - export CFLAGS_FOR_TARGET="$TARGET_CFLAGS" - export CXXFLAGS_FOR_TARGET="$TARGET_CFLAGS" - export C_INCLUDE_PATH="$INSTALLDIR/$TARGET/include" - export LIBRARY_PATH="$INSTALLDIR/$TARGET/lib" - - do_command ../gcc/configure --prefix="$INSTALLDIR" --host="$TARGET" --build="$TARGET" --target="$TARGET" --with-gmp="$SUPPORTDIR" --with-mpfr="$SUPPORTDIR" --enable-languages=c,c++ --enable-checking=release --enable-version-specific-runtime-libs --enable-threads=win32 --disable-win32-registry --disable-shared --disable-nls - do_command make profiledbootstrap - do_command make install - clean_module gcc - - export STAGE1_CFLAGS="" - export BOOT_CFLAGS="" - export CFLAGS_FOR_TARGET="" - export CXXFLAGS_FOR_TARGET="" - export C_INCLUDE_PATH="" - export LIBRARY_PATH="" -fi - - -# Final actions -echo -boldmsg "Final actions" -cd "$INSTALLDIR" - -echo "Removing unneeded files..." -rm -rf $TARGET/bin $TARGET/doc $TARGET/share include info man share -rm -f lib/* >& /dev/null -rm -f bin/c++.exe bin/gccbug bin/$TARGET-* - -echo "Removing debugging symbols..." -find -name "*.exe" -type f -exec strip -s {} ";" -find -name "*.a" -type f -exec strip -d {} ";" -find -name "*.o" -type f -exec strip -d {} ";" - -echo "Finished!" diff --git a/RosBE-Windows/Buildtoolchain/gcc_4.1.3/buildtoolchain.sh b/RosBE-Windows/Buildtoolchain/rosbe_1.4/buildtoolchain.sh similarity index 97% rename from RosBE-Windows/Buildtoolchain/gcc_4.1.3/buildtoolchain.sh rename to RosBE-Windows/Buildtoolchain/rosbe_1.4/buildtoolchain.sh index 7df44f7..b02c4eb 100644 --- a/RosBE-Windows/Buildtoolchain/gcc_4.1.3/buildtoolchain.sh +++ b/RosBE-Windows/Buildtoolchain/rosbe_1.4/buildtoolchain.sh @@ -7,6 +7,8 @@ # Released under GNU GPL v2 or any later version. ################################################################################## +# Package "rosbe_1.4" +# # This script was built for the following toolchain versions: # - binutils v2.19.51-20090127 (snapshot) # patched with: @@ -20,7 +22,7 @@ # - w32api 3.10 # # These versions are used in RosBE-Windows 1.4.2-1.4.5 and RosBE-Unix 1.4-1.4.2. -# Get the toolchain packages from one of these RosBE-Unix versions. +# Get the toolchain packages from http://svn.reactos.org/RosBE-Sources/rosbe_1.4 ################################################################################## # @@ -80,7 +82,7 @@ check_run() # Entry point # echo "buildtoolchain - Build a binutils/GCC/mingw-runtime/w32api toolchain for Windows" -echo "Script for gcc_4.1.3 (see script header for details)" +echo "Script for rosbe_1.4 (see script header for details)" echo "by Colin Finck " echo diff --git a/RosBE-Windows/Buildtoolchain/rosbe_1.5/buildtoolchain.sh b/RosBE-Windows/Buildtoolchain/rosbe_1.5/buildtoolchain.sh new file mode 100644 index 0000000..6254436 --- /dev/null +++ b/RosBE-Windows/Buildtoolchain/rosbe_1.5/buildtoolchain.sh @@ -0,0 +1,231 @@ +#!/bin/bash +# +# ReactOS Build Environment for Windows - Script for building a binutils/GCC/mingw-runtime/w32api toolchain for Windows +# Partly based on RosBE-Unix' "RosBE-Builder.sh" +# Copyright 2009 Colin Finck +# +# Released under GNU GPL v2 or any later version. + +######################################################################################################################## +# Package "rosbe_1.5" +# +# This script was built for the following toolchain versions: +# - binutils 2.20.51-20091017 (snapshot) +# - gcc 4.4.2 +# patched with: +# * http://gcc.gnu.org/bugzilla/attachment.cgi?id=18882&action=view (committed in GCC r153606) +# - gmp 4.3.1 +# - mingw-runtime 3.16 +# - mpfr 2.4.2-rc1 +# - w32api 3.13 +# +# These tools have to be compiled under MSYS with "gcc version 3.4.5 (mingw-vista special r3)" +# +# These versions are used in RosBE-Windows 1.5 and RosBE-Unix 1.5. +# Get the toolchain packages from http://svn.reactos.org/RosBE-Sources/rosbe_1.5 +######################################################################################################################## + + +# RosBE Setup Variables +rs_host_cflags="-pipe -fno-common -O3 -march=pentium3 -mfpmath=sse" +rs_needed_tools="bison flex gcc g++ grep makeinfo" # GNU Make has a special check +rs_target="mingw32" +rs_target_cflags="-pipe -gstabs+ -O3 -march=pentium -mtune=i686" + +# Get the absolute path to the script directory +cd `dirname $0` +rs_scriptdir="$PWD" + +# buildtoolchain Constants +HOST_GCC_VERSION="gcc version 3.4.5 (mingw-vista special r3)" +MODULES="w32api mingw_runtime gmp mpfr binutils gcc" +SYSHEADERDIR="/mingw/include" + +source "$rs_scriptdir/scripts/setuplibrary.sh" + + +echo "*******************************************************************************" +echo "* Buildtoolchain script for the ReactOS Build Environment for Windows *" +echo "* Package \"rosbe_1.5\" *" +echo "* by Colin Finck *" +echo "*******************************************************************************" + +echo +echo "This script builds a binutils/GCC/mingw-runtime/w32api toolchain for Windows." +echo + +if [ "`uname -o`" != "Msys" ]; then + echo "You can only run this script under a MSYS environment!" + exit 1 +fi + +# We don't want too less parameters +if [ "$2" == "" ]; then + echo -n "Syntax: ./buildtoolchain.sh " + + for module in $MODULES; do + echo -n " [$module]" + done + + echo + echo + echo " sources - Path to the directory containing RosBE-Unix toolchain packages (.tar.bz2 files)" + echo " workdir - Path to the directory used for building. Will contain the final executables and" + echo " temporary files." + echo + echo "The rest of the arguments are optional. You specify them if you want to prevent a component" + echo "from being (re)built. Do this by passing 0 as the argument of the appropriate component." + echo "Pass 1 if you want them to be built." + echo "By default, all of these components are built, so you don't need to pass any of these parameters." + exit 1 +fi + +rs_check_requirements + +# Check for the correct GCC version +echo -n "Checking for the correct GCC version... " + +if gcc -v 2>&1 | grep "$HOST_GCC_VERSION" >& /dev/null; then + rs_greenmsg "OK" +else + rs_redmsg "MISSING" + echo "Correct GCC version is missing, aborted!" + exit 1 +fi + +echo + +# Get the absolute path to the source directory +cd "$1" +rs_sourcedir="$PWD" +shift + +# As the work directory might not yet exist, we cannot "cd" here +rs_workdir="$1" +shift + +rs_prefixdir="$rs_workdir/mingw" +rs_supportprefixdir="$rs_workdir/support" + +# Set the rs_process_* variables based on the parameters +for module in $MODULES; do + if [ "$1" = "0" ]; then + eval "rs_process_$module=false" + else + eval "rs_process_$module=true" + fi + + shift +done + +rs_mkdir_empty "$SYSHEADERDIR" + + +##### BEGIN almost shared buildtoolchain/RosBE-Unix building part ############# +rs_boldmsg "Building..." + +rs_mkdir_if_not_exists "$rs_prefixdir/$rs_target" +rs_mkdir_if_not_exists "$rs_supportprefixdir" + +rs_extract_module "w32api" "$rs_prefixdir/$rs_target" + +rs_do_command gcc -s -o "$rs_supportprefixdir/cpucount.exe" "$rs_scriptdir/tools/cpucount.c" +rs_cpucount=`$rs_supportprefixdir/cpucount.exe -x1` + +if rs_prepare_module "mingw_runtime"; then + export CFLAGS="$rs_target_cflags" + export C_INCLUDE_PATH="$rs_prefixdir/$rs_target/include" + + rs_do_command ../mingw_runtime/configure --prefix="$rs_prefixdir/$rs_target" --host="$rs_target" --build="$rs_target" + rs_do_command $rs_makecmd -j $rs_cpucount + rs_do_command $rs_makecmd install + + # libmingwex.a of the MinGW Runtime 3.15 and later references to _get_output_format, which is exported by msvcr80.dll and later. + # For older Runtime DLLs (such as the msvcrt.dll we primarily use for ReactOS), MinGW adds a _get_output_format function returning 0 to libmsvcrt.a. + # As we use MinGW's libmingwex.a, but our own libmsvcrt.a, linking to MinGW's libmingwex.a will fail by default. Therefore we have to create an archive for the compiled + # _get_output_format stub, copy it to our "lib" directory and include it when linking to libmingwex.a. + ar r ofmt_stub.a ofmt_stub.o >& /dev/null + cp ofmt_stub.a "$rs_prefixdir/$rs_target/lib" + + rs_clean_module "mingw_runtime" + + # The "mingw_runtime_dev" package needed for RosBE-Unix is manually created from the result of this build. + + export CFLAGS="" + export C_INCLUDE_PATH="" +fi + +if rs_prepare_module "gmp"; then + export CFLAGS="$rs_host_cflags" + + rs_do_command ../gmp/configure ABI=32 --prefix="$rs_supportprefixdir" --host="$rs_target" --build="$rs_target" --disable-shared + rs_do_command $rs_makecmd -j $rs_cpucount + rs_do_command $rs_makecmd check + rs_do_command $rs_makecmd install + rs_clean_module "gmp" + + export CFLAGS="" +fi + +if rs_prepare_module "mpfr"; then + export CFLAGS="$rs_host_cflags" + + rs_do_command ../mpfr/configure --prefix="$rs_supportprefixdir" --host="$rs_target" --build="$rs_target" --with-gmp="$rs_supportprefixdir" --disable-shared + rs_do_command $rs_makecmd -j $rs_cpucount + rs_do_command $rs_makecmd check + rs_do_command $rs_makecmd install + rs_clean_module "mpfr" + + export CFLAGS="" +fi + +if rs_prepare_module "binutils"; then + export CFLAGS="$rs_host_cflags" + + rs_do_command ../binutils/configure --prefix="$rs_prefixdir" --host="$rs_target" --build="$rs_target" --target="$rs_target" --disable-nls + rs_do_command $rs_makecmd -j $rs_cpucount + rs_do_command $rs_makecmd install + rs_clean_module "binutils" + + export CFLAGS="" +fi + +if rs_prepare_module "gcc"; then + export STAGE1_CFLAGS="$rs_host_cflags" + export BOOT_CFLAGS="$rs_host_cflags" + export CFLAGS_FOR_TARGET="$rs_target_cflags" + export CXXFLAGS_FOR_TARGET="$rs_target_cflags" + export C_INCLUDE_PATH="$rs_prefixdir/$rs_target/include" + export LIBRARY_PATH="$rs_prefixdir/$rs_target/lib" + + rs_do_command ../gcc/configure --prefix="$rs_prefixdir" --host="$rs_target" --build="$rs_target" --target="$rs_target" --with-gmp="$rs_supportprefixdir" --with-mpfr="$rs_supportprefixdir" --enable-languages=c,c++ --enable-checking=release --enable-version-specific-runtime-libs --enable-threads=win32 --disable-win32-registry --disable-shared --disable-nls + rs_do_command $rs_makecmd profiledbootstrap + rs_do_command $rs_makecmd install + rs_clean_module "gcc" + + export STAGE1_CFLAGS="" + export BOOT_CFLAGS="" + export CFLAGS_FOR_TARGET="" + export CXXFLAGS_FOR_TARGET="" + export C_INCLUDE_PATH="" + export LIBRARY_PATH="" +fi + +# Final actions +echo +rs_boldmsg "Final actions" +cd "$rs_prefixdir" + +echo "Removing unneeded files..." +rm -rf $rs_target/bin $rs_target/doc $rs_target/share include info man share +rm -f lib/* >& /dev/null +rm -f bin/c++.exe bin/gccbug bin/$rs_target-* + +echo "Removing debugging symbols..." +find -executable -type f -exec strip -s {} ";" >& /dev/null +find -name "*.a" -type f -exec strip -d {} ";" +find -name "*.o" -type f -exec strip -d {} ";" +##### END almost shared buildtoolchain/RosBE-Unix building part ############### + + +echo "Finished!" diff --git a/RosBE-Windows/Buildtoolchain/rosbe_1.5/scripts/setuplibrary.sh b/RosBE-Windows/Buildtoolchain/rosbe_1.5/scripts/setuplibrary.sh new file mode 100644 index 0000000..c12a4fe --- /dev/null +++ b/RosBE-Windows/Buildtoolchain/rosbe_1.5/scripts/setuplibrary.sh @@ -0,0 +1,230 @@ +############################################################################### +# Shared setup functions for RosBE-Windows' buildtoolchain and RosBE-Unix +# Copyright 2009 Colin Finck +# +# Released under GNU GPL v2 or any later version. +############################################################################### +# Conventions: +# - Prepend all functions of this library with "rs_" (RosBE Setup) +# - Also prepend all variables used here and variables which are shared +# between buildtoolchain and RosBE-Unix and are used in conjunction with +# these functions in the calling script with "rs_" +############################################################################### + + +# Print a message in a bold font +# Parameter 1: The message +# Parameter 2: Optional additional parameters for "echo" +rs_boldmsg() +{ + echo -e $2 "\e[1m$1\e[0m" +} + +# Check for several requirements, which need to be met in order to run the installation script properly +rs_check_requirements() +{ + # Test if the script directory is writable + if [ ! -w "$rs_scriptdir" ]; then + rs_redmsg "The script directory \"$rs_scriptdir\" is not writable, aborted!" + exit 1 + fi + + # Test if the script directory contains spaces + case "$rs_scriptdir" in + *" "*) + rs_redmsg "The script directory \"$rs_scriptdir\" contains spaces!" + rs_redmsg "Therefore some build tools cannot be compiled properly." + echo + rs_redmsg "Please move \"$rs_scriptdir\" to a directory, which does not contain spaces." + + exit 1;; + esac + + # Check if all necessary tools exist + rs_boldmsg "Checking for the needed tools..." + + local toolmissing=false + for tool in $rs_needed_tools; do + echo -n "Checking for $tool... " + + if which "$tool" >& /dev/null; then + rs_greenmsg "OK" + else + rs_redmsg "MISSING" + toolmissing=true + fi + done + + # Special check for GNU Make + # For example FreeBSD's "make" is not GNU Make, so we have to define a variable + echo -n "Checking for GNU Make... " + + local app + local checkapps="make gmake" + rs_makecmd="" + + for app in $checkapps; do + if $app -v 2>&1 | grep "GNU Make" >& /dev/null; then + rs_makecmd="$app" + rs_greenmsg "OK" + fi + done + + if [ "$rs_makecmd" = "" ]; then + rs_redmsg "MISSING" + toolmissing=true + fi + + + if $toolmissing; then + echo "At least one needed tool is missing, aborted!" + exit 1 + fi + + echo +} + +# Check whether the previous command finished with errorlevel 0 +# If it did so, print a green "OK" and delete the debug logfile for the command. +# If that wasn't the case, print a red "FAILED" and give information about the debug logfile. +rs_check_run() +{ + if [ $? -ne 0 ]; then + rs_redmsg "FAILED" + echo "Please take a look at the log file \"$rs_workdir/build.log\"" + echo "If you did not do something wrong, please save the log file and contact the ReactOS Team." + + echo "Aborted!" + exit 1 + else + rs_greenmsg "OK" + rm "$rs_workdir/build.log" + fi +} + +# Cleans a module prepared with rs_prepare_module. +# Parameter 1: The module name +rs_clean_module() +{ + echo "Cleaning up $1..." + cd "$rs_workdir" + rm -rf "$1-build" + rm -rf "$1" +} + +# Executes a building command and checks whether it succeeded. +# Terminates the building process in case of failure. +# Parameters: The command to execute including parameters +rs_do_command() +{ + echo -n "Running \"$*\"... " + $* >& "$rs_workdir/build.log" + rs_check_run +} + +# Checks whether the given module needs to be processed and if so, extracts it. +# Returns 0 if it needs to be processed, otherwise 1. +# Parameter 1: The module name +# Parameter 2: The directory to extract the module to +rs_extract_module() +{ + local module=$1 + local target_dir=$2 + + if ! `eval echo \\$rs_process_$module`; then + return 1 + fi + + cd "$target_dir" + + echo -n "Extracting $module... " + tar -xjf "$rs_sourcedir/$module.tar.bz2" >& "$rs_workdir/build.log" + rs_check_run + + return 0 +} + +# Print a message in green color +# Parameter 1: The message +# Parameter 2: Optional additional parameters for "echo" +rs_greenmsg() +{ + echo -e $2 "\e[32m$1\e[0m" +} + +# Creates the given directory if it does not exist and cleans it if it does. +# Parameter 1: The directory +rs_mkdir_empty() +{ + if [ -d "$1" ]; then + rm -rf "$1" + fi + + mkdir -p "$1" +} + +# Creates a directory if it does not exist. +# Parameter 1: The directory +rs_mkdir_if_not_exists() +{ + if ! [ -d "$1" ]; then + mkdir -p "$1" + fi +} + +# Checks whether the given module needs to be processed and if so, extracts it into a dedicated build directory +# Returns 0 if it needs to be built, otherwise 1. +# Parameter 1: The module name +rs_prepare_module() +{ + local module=$1 + + rm -rf "$rs_workdir/$module" + + if ! rs_extract_module "$module" "$rs_workdir"; then + return 1 + fi + + rm -rf "$module-build" + mkdir "$module-build" + cd "$module-build" + + return 0 +} + +# Print a message in red color +# Parameter 1: The message +# Parameter 2: Optional additional parameters for "echo" +rs_redmsg() +{ + echo -e $2 "\e[31m$1\e[0m" +} + +# Allow a choice between several options +# If a valid choice was done, the result is stored in $choice +# Parameter 1 - The default value +# Parameter 2 - All possible values +rs_showchoice() +{ + local default_value="$1" + local valid_choices="$2" + + local breakloop=false + choice="" + + while ! $breakloop; do + read -p "Your choice [$default_value]: " choice + + if [ "$choice" = "" ]; then + choice="$default_value" + break + fi + + for valid_choice in $valid_choices; do + if [ "$choice" = "$valid_choice" ]; then + breakloop=true + break + fi + done + done +} diff --git a/RosBE-Windows/Buildtoolchain/rosbe_1.5/tools/cpucount.c b/RosBE-Windows/Buildtoolchain/rosbe_1.5/tools/cpucount.c new file mode 100644 index 0000000..df8b363 --- /dev/null +++ b/RosBE-Windows/Buildtoolchain/rosbe_1.5/tools/cpucount.c @@ -0,0 +1,100 @@ +/* + * PROJECT: ReactOS Build Environment Tools + * LICENSE: GNU General Public License v2. (see LICENSE.txt) + * FILE: Tools/cpucount.c + * PURPOSE: CPU Core Counter + * COPYRIGHT: Copyright 2007 Christoph von Wittich + * Copyright 2007 Colin Finck + * Copyright 2007 Peter Ward + * + */ + +#if defined(WIN32) +# include +#elif defined(__APPLE__) +# include +#else +# include +#endif + +#include +#include + +int main(int argc, char *argv[]) +{ + int cpuCount = 0; + +#if defined(WIN32) + if(argc > 3) +#else + if(argc > 2) +#endif + { + fprintf(stderr, "%s: Error too many parameters specified.\n", argv[0]); + return -1; + } + +#if defined(WIN32) + if (argc != 1 && !strncmp(argv[argc - 1], "-a", 2)) + { + DWORD_PTR ProcessAffinityMask, SystemAffinityMask; + + if (GetProcessAffinityMask(GetCurrentProcess(), &ProcessAffinityMask, &SystemAffinityMask)) + { + while (ProcessAffinityMask != 0) + { + if (ProcessAffinityMask & 0x1) + cpuCount++; + + ProcessAffinityMask >>= 1; + } + } + + argc--; /* don't look at this argument again */ + } + else + { + SYSTEM_INFO SystemInformation; + + GetSystemInfo(&SystemInformation); + cpuCount = SystemInformation.dwNumberOfProcessors; + } +#elif defined(__APPLE__) + size_t countSize = sizeof(cpuCount); + + sysctlbyname("hw.logicalcpu", &cpuCount, &countSize, NULL, 0); +#else + cpuCount = sysconf(_SC_NPROCESSORS_ONLN); +#endif + + if (argc != 1) + { + if(!strncmp(argv[1], "-x1", 3)) + { + cpuCount++; + } + else if(!strncmp(argv[1], "-x2", 3)) + { + cpuCount += cpuCount; + } + else + { +#if defined(WIN32) + printf("Usage: %s [-x1|-x2] [-a]\n", argv[0]); +#else + printf("Usage: %s [-x1|-x2]\n", argv[0]); +#endif + printf("Running cpucount without options returns the number of\n"); + printf("processors in the system.\n"); + printf("-x1 - Number of processors in the system, plus 1.\n"); + printf("-x2 - Number of processors in the system, doubled.\n"); +#if defined(WIN32) + printf("-a - Use the affinity mask to determine number of processors\n"); +#endif + return 0; + } + } + + printf("%u\n", cpuCount); + return 0; +}