Start sharing some tools between RosBE-Windows and RosBE-Unix, beginning with "cpucount"

- Create a portable version (Windows, Mac OS X, other Unices) of "cpucount" based on the RosBE-Unix version along with a universal Makefile and a Readme file
- Remove the other versions of "cpucount"
- Remove the LFLAGS option from the RosBE-Windows Tools Makefile, it was never used.
  Instead add a STRIP option and use it for every target.
- Set WINVER in the RosBE-Windows Tools Makefile to 0x500 to ensure that no one uses API's, which are not compatible with Windows 2000 and XP

svn path=/trunk/tools/RosBE/; revision=545
This commit is contained in:
Colin Finck 2007-11-21 13:49:44 +00:00
parent 112c3d09ce
commit 789cb6e5df
5 changed files with 78 additions and 71 deletions

View File

@ -1,55 +0,0 @@
/* Program for printing the CPU count.
The output value will be used for the -j option of gcc.
Developed by Colin Finck <mail@colinfinck.de>
Released under GNU GPL v2 or any later version.
*/
#include <stdio.h>
#include <unistd.h>
#ifdef __APPLE__
#include <sys/sysctl.h>
#endif
int main(int argc, char *argv[])
{
int cpuCount = 0;
if(argc > 2)
{
fprintf(stderr, "%s: Error too many parameters specified.\n", argv[0]);
return -1;
}
#ifdef __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
{
printf("Usage: %s [OPTIONS]\n", argv[0]);
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");
return 0;
}
}
printf("%u\n", cpuCount);
return 0;
}

View File

@ -4,37 +4,43 @@
CC := gcc
CFLAGS := ${HOST_CFLAGS} -Wall -O2 -o
LFLAGS := -s
WINVER := 0x502
STRIP := strip
SUFFIX := .exe
WINVER := 0x500
all: buildtime chknewer chkslash cpucount echoh flash getdate scut tee
all: buildtime chknewer chkslash echoh flash getdate scut tee
buildtime: buildtime.c
${CC} ${CFLAGS} buildtime buildtime.c
${CC} ${CFLAGS} buildtime$(SUFFIX) buildtime.c
$(STRIP) buildtime$(SUFFIX)
chknewer: chknewer.c
${CC} ${CFLAGS} chknewer chknewer.c
$(STRIP) chknewer$(SUFFIX)
chkslash: chkslash.c
${CC} ${CFLAGS} chkslash chkslash.c
cpucount: cpucount.c
${CC} ${CFLAGS} cpucount cpucount.c
$(STRIP) chkslash$(SUFFIX)
echoh: echoh.c
${CC} ${CFLAGS} echoh echoh.c
$(STRIP) echoh$(SUFFIX)
flash: flash.c
${CC} -DWINVER=${WINVER} -D_WIN32_WINNT=${WINVER} ${CFLAGS} flash flash.c
$(STRIP) flash$(SUFFIX)
getdate: getdate.c
${CC} ${CFLAGS} getdate getdate.c
$(STRIP) getdate$(SUFFIX)
scut: scut.c
${CC} ${CFLAGS} scut scut.c
$(STRIP) scut$(SUFFIX)
tee: tee.c
${CC} ${CFLAGS} tee tee.c
$(STRIP) tee$(SUFFIX)
clean:
del /f buildtime.exe chknewer.exe chkslash.exe cpucount.exe echoh.exe flash.exe getdate.exe scut.exe tee.exe
del /f buildtime.exe chknewer.exe chkslash.exe echoh.exe flash.exe getdate.exe scut.exe tee.exe

9
Tools/SVN-Readme.txt Normal file
View File

@ -0,0 +1,9 @@
This directory contains tools shared between RosBE-Windows and RosBE-Unix.
For RosBE-Windows
------------------
The built tools need to be copied to RosBE-Windows\Root\Tools
For RosBE-Unix
---------------
The source files of the tools need to be copied to RosBE-Unix/tools

View File

@ -1,37 +1,57 @@
/*
* PROJECT: RosBE - ReactOS Build Environment for Windows.
* PROJECT: ReactOS Build Environment Tools
* LICENSE: GPL - See LICENSE.txt in the top level directory.
* FILE: Tools/cpucount.c
* PURPOSE: CPU Core Counter
* COPYRIGHT: Copyright 2007 Christoph von Wittich <Christoph_vW@reactos.org>
* Copyright 2007 Colin Finck <mail@colinfinck.de>
* Copyright 2007 Peter Ward <dralnix@gmail.com>
*
*/
#include <windows.h>
#if defined(WIN32)
# include <windows.h>
#elif defined(__APPLE__)
# include <sys/sysctl.h>
#else
# include <unistd.h>
#endif
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[])
int main(int argc, char *argv[])
{
SYSTEM_INFO SystemInformation;
int cpuCount = 0;
if (argc > 2)
if(argc > 2)
{
fprintf(stderr, "%s: Error too many parameters specified.\n", argv[0]);
return -1;
}
#if defined(WIN32)
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))
{
SystemInformation.dwNumberOfProcessors++;
cpuCount++;
}
else if(!strncmp(argv[1], "-x2", 3))
{
SystemInformation.dwNumberOfProcessors += SystemInformation.dwNumberOfProcessors;
cpuCount += cpuCount;
}
else
{
@ -44,6 +64,6 @@ int main(int argc, char* argv[])
}
}
printf("%u\n", SystemInformation.dwNumberOfProcessors);
printf("%u\n", cpuCount);
return 0;
}

27
Tools/makefile Normal file
View File

@ -0,0 +1,27 @@
# makefile - Simple makefile to build the various RosBE tools.
.PHONY: all clean
CC := gcc
CFLAGS := ${HOST_CFLAGS} -Wall -O2 -o
STRIP := strip
ifeq ($(word 1,$(shell gcc -dumpmachine)),mingw32)
# Windows host
RM := del /f
SUFFIX := .exe
else
# Unix host
RM := rm -f
SUFFIX :=
endif
all: cpucount
cpucount: cpucount.c
${CC} ${CFLAGS} cpucount$(SUFFIX) cpucount.c
$(STRIP) cpucount$(SUFFIX)
clean:
$(RM) cpucount$(SUFFIX)