Commit 8c4a6814 authored by mark's avatar mark
Browse files

ENH: respect '-silent' option for cmake builds

- minor cleanup of wmake sources
parent 92065e2b
......@@ -28,8 +28,7 @@ $(OBJECTS_DIR)/%.dep : %
$(call QUIET_MESSAGE,wmkdep,$(<F))
$(call VERBOSE_MESSAGE,Making dependency list for source file,$(<F))
@$(WM_SCRIPTS)/makeTargetDir $@
@$(WMAKE_BIN)/wmkdep -I$(*D) $(LIB_HEADER_DIRS) $< | \
sed -e 's,^$(WM_PROJECT_DIR)/,$$(WM_PROJECT_DIR)/,' \
-e 's,^$(WM_THIRD_PARTY_DIR)/,$$(WM_THIRD_PARTY_DIR)/,' > $@
@$(WMAKE_BIN)/wmkdep -o$@ -I$(*D) $(LIB_HEADER_DIRS) \
-eWM_PROJECT_DIR -eWM_THIRD_PARTY_DIR $<
#------------------------------------------------------------------------------
......@@ -72,6 +72,19 @@ sameDependency()
}
# CMake with output suppressed according to WM_QUIET
_cmake()
{
echo "cmake..."
if [ -n "$WM_QUIET" ]
then
cmake -DCMAKE_RULE_MESSAGES=OFF $@ >/dev/null
else
cmake $@
fi
}
# CMake into objectsDir with external dependency
# - use sentinel file(s) to handle paraview/vtk version changes
cmakeVersioned()
......@@ -89,7 +102,7 @@ cmakeVersioned()
mkdir -p $objectsDir && \
(
cd $objectsDir && cmake $sourceDir && make \
cd $objectsDir && _cmake $sourceDir && make \
&& echo "$depend" > ${sentinel:-/dev/null}
)
}
......
......@@ -31,6 +31,7 @@
# Usage : makeFiles
#
#------------------------------------------------------------------------------
dirToString=$WM_DIR/platforms/$WM_ARCH$WM_COMPILER/dirToString
if [ -r Make/files ]
then
......@@ -38,10 +39,15 @@ then
exit 1
fi
dirToString=$WM_DIR/platforms/$WM_ARCH$WM_COMPILER/dirToString
[ -x "$dirToString" ] || {
echo "Error: no command $dirToString" 1>&2
exit 1
}
[ -d Make ] || mkdir Make
rm -f Make/files
#------------------------------------------------------------------------------
echo "Creating Make/files"
for dir in $(find . -mindepth 1 -type d -print)
do
......@@ -53,7 +59,7 @@ do
echo "$(echo $dir | $dirToString -strip) = ${dir#./}"
;;
esac
done >> Make/files
done > Make/files
[ -s Make/files ] && echo >> Make/files
for file in $(find . -name "*.[cCylLfF]" -type f -print)
......
......@@ -39,11 +39,12 @@ then
fi
[ -d Make ] || mkdir Make
rm -f Make/options
#------------------------------------------------------------------------------
echo "Creating Make/options"
echo 'EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude' >> Make/options
-I$(LIB_SRC)/finiteVolume/lnInclude' > Make/options
echo >> Make/options
echo 'EXE_LIBS = \
-lfiniteVolume' >> Make/options
......
......@@ -28,7 +28,7 @@
# Description
# Makes a directory hierarchy for the given target file
#
# Usage: makeTargetDir <directory>
# Usage: makeTargetDir <file>
#
#------------------------------------------------------------------------------
......
......@@ -78,5 +78,4 @@ $(WMAKE_BIN)/wmkdep: wmkdep.l
$E flex -o $@.c $(<F) && $(cc) $(cFLAGS) $@.c -o $@
@rm -f $@.c 2>/dev/null
#------------------------------------------------------------------------------
......@@ -25,8 +25,8 @@ Application
dirToString
Description
converts a directory path into a string with appropriate capitalisation
e.g. dir1/dir2 becomes dir1Dir2
Converts a directory path into a camelCase string.
e.g. dir1/dir2/dir3 becomes dir1Dir2Dir3
Usage
echo dirName | dirToString
......@@ -45,34 +45,34 @@ Usage
#include <string.h>
#include <ctype.h>
/* The executable name (for messages), without requiring access to argv[] */
#define EXENAME "dirToString"
int main(int argc, char* argv[])
{
int c;
int nextupper = 0;
if (argc > 1)
{
if (!strncmp(argv[1], "-h", 2)) /* -h, -help */
if (!strncmp(argv[1], "-h", 2))
{
fprintf
(
stderr,
"\nUsage: %s [-strip]\n\n",
"dirToString"
);
/* Option: -h, -help */
fprintf
fputs
(
stderr,
"\nUsage: " EXENAME
" [-strip]\n\n"
" -strip ignore leading [./] characters.\n\n"
"Transform dir1/dir2 to camel-case dir1Dir2\n\n"
"Converts a directory path into a camelCase string\n\n",
stderr
);
return 0;
}
if (!strcmp(argv[1], "-s") || !strcmp(argv[1], "-strip")) /* -s, -strip */
if (!strcmp(argv[1], "-s") || !strcmp(argv[1], "-strip"))
{
/* Option: -s, -strip */
while ((c=getchar()) != EOF && (c == '.' || c == '/'))
{
/* nop */
......@@ -88,23 +88,21 @@ int main(int argc, char* argv[])
}
while ((c=getchar()) != EOF)
int nextUpper = 0;
while ((c = getchar()) != EOF)
{
if (c == '/')
{
nextupper = 1;
nextUpper = 1;
}
else if (nextUpper)
{
putchar(toupper(c));
nextUpper = 0;
}
else
{
if (nextupper)
{
putchar(toupper(c));
nextupper = 0;
}
else
{
putchar(c);
}
putchar(c);
}
}
......
......@@ -26,18 +26,26 @@ Application
wmkdep
Description
A fast dependency list generator that emulates the behaviour and the
output of cpp -M. However, the output contains no duplicates and
is approx. 40% faster than cpp.
A fast dependency list generator that emulates the behaviour and output
of cpp -M. However, the output contains no duplicates and is thus
approx. 40% faster than cpp.
It also handles missing files somewhat more gracefully.
The algorithm uses flex to scan for includes and searches the files
found. Each file is entered into a hash table so that files are scanned
only once. This is why this program is faster than cpp.
The algorithm uses flex to scan for includes and searches the files found.
The files are only visited once (the names of the files visited are hashed),
which makes this faster than cpp.
Usage
wmkdep [ -Idir ... -Idir ] [ -iheader .. -iheader ] filename
wmkdep [-Idir..] [-iheader...] [-eENV...] [-ofile] filename
\*---------------------------------------------------------------------------*/
/* With cpp:
*
* cpp -x c++ -std=c++11 -nostdinc -nostdinc++
* -M -DWM_$(WM_PRECISION_OPTION) -DWM_LABEL_SIZE=$(WM_LABEL_SIZE) |
* sed -e 's,^$(WM_PROJECT_DIR)/,$$(WM_PROJECT_DIR)/,' \
* -e 's,^$(WM_THIRD_PARTY_DIR)/,$$(WM_THIRD_PARTY_DIR)/,'
*/
#define FILE_STACK_SIZE 300
#define HASH_TABLE_SIZE 500
......@@ -51,8 +59,7 @@ Usage
/* The executable name (for messages), without requiring access to argv[] */
#define EXENAME "wmkdep"
#undef yywrap /* sometimes a macro by default */
#define YY_NO_INPUT /* no input(), yyinput() required */
#undef yywrap /* sometimes a macro by default */
#pragma GCC diagnostic ignored "-Wunused-function"
void nextFile(const char* fileName);
......@@ -60,29 +67,31 @@ void nextFile(const char* fileName);
/*---------------------------------------------------------------------------*/
%}
%x CMNT CFNAME SCFNAME JFNAME FFNAME
%x CMNT CFNAME FFNAME
%%
"//".*\n ; /* remove c++ style one line comments */
"//".*\n ; /* Remove C++-style comment */
"/*" BEGIN(CMNT); /* start removing c style comment */
<CMNT>.|\n ;
<CMNT>"*/" BEGIN(INITIAL); /* end removing c style comment */
"/*" BEGIN(CMNT); /* Begin removing C-style comment */
<CMNT>.|\n ;
<CMNT>"*/" BEGIN(INITIAL); /* End removing C-style comment */
^[ \t]*#[ \t]*include[ \t]+\" BEGIN(CFNAME); /* c-file name */
<CFNAME>[^"\n ]* { BEGIN(INITIAL); nextFile(yytext); } /*"*/
^[ \t]*#[ \t]*include[ \t]+\" BEGIN(CFNAME); /* C-file name */
<CFNAME>[^"\n ]* { BEGIN(INITIAL); nextFile(yytext); } /* "-quoted */
" "include[ \t]+\' BEGIN(FFNAME); /* FORTRAN-file name */
<FFNAME>[^']* { BEGIN(INITIAL); nextFile(yytext); } /*'*/
" "include[ \t]+\' BEGIN(FFNAME); /* FORTRAN-file name */
<FFNAME>[^']* { BEGIN(INITIAL); nextFile(yytext); } /* '-quoted */
.|\t|\n ;
.|\t|\n ;
%%
/*---------------------------------------------------------------------------*/
/* char* entry in hash table */
/*
* A char* entry in hash table
*/
struct HashEntry
{
char* name;
......@@ -91,49 +100,173 @@ struct HashEntry
/*
* lookup name in hash table.
* Lookup name in hashTable.
* if found - return 1
* if not found - insert in table and return 0
* if not found - insert in hashTable and return 0
*/
int lookUp(struct HashEntry** hashTable, const char* p)
static int lookUp(struct HashEntry* hashTable[HASH_TABLE_SIZE], const char* str)
{
int ii = 0;
struct HashEntry* n;
struct HashEntry* nn;
/* hash */
const char* pp = p;
while (*pp) ii = ii<<1 ^ *pp++;
if (ii < 0) ii = -ii;
ii %= HASH_TABLE_SIZE;
/* search */
for (n=hashTable[ii]; n; n=n->next)
unsigned idx = 0; /* Hash index */
{
const char* pp = str;
while (*pp) idx = idx << 1 ^ *pp++;
idx %= HASH_TABLE_SIZE;
}
/* Search for entry */
struct HashEntry* entry;
for (entry = hashTable[idx]; entry; entry = entry->next)
{
if (strcmp(p, n->name) == 0)
if (!strcmp(str, entry->name))
{
/* entry found so return true */
return 1;
return 1; /* True: entry found */
}
}
/* insert */
nn = (struct HashEntry*)malloc(sizeof(struct HashEntry));
nn->name = strdup(p);
nn->next = hashTable[ii];
hashTable[ii] = nn;
/* Entry not found - insert a new entry */
entry = (struct HashEntry*)malloc(sizeof(struct HashEntry));
entry->name = strdup(str);
entry->next = hashTable[idx];
hashTable[idx] = entry;
/* entry not found, and therefore added. return false */
return 0;
return 0; /* False: entry did not previously exist */
}
/*
* Free allocated memory in hashTable.
*/
static void free_hashTable(struct HashEntry* hashTable[HASH_TABLE_SIZE])
{
int idx;
for (idx = 0; idx < HASH_TABLE_SIZE; ++idx)
{
struct HashEntry* entry = hashTable[idx];
hashTable[idx] = NULL;
while (entry)
{
struct HashEntry* next = entry->next;
free(entry->name);
free(entry);
entry = next;
}
}
}
/*
* Environment entry - as a linked-list
*/
struct KeyValue
{
char* name;
char* value;
size_t len;
struct KeyValue* next;
};
/* List of environ variables to substitute */
struct KeyValue* envTable = NULL;
/*
* Add envTable replacements:
*
* Eg,
* /openfoam/project/path/directory/xyz
* -> $(WM_PROJECT_DIR)/directory/xyz
*/
static void add_env(const char* key)
{
const char *val = getenv(key);
if (val && *val)
{
const size_t keyLen = strlen(key);
const size_t valLen = strlen(val);
/* "$(ENV)/" */
char *replace = (char*)malloc(keyLen + 5);
strcpy(replace, "$(");
strcat(replace, key);
strcat(replace, ")/");
/* "/env/value/" */
char *orig = (char*)malloc(valLen + 2);
strcpy(orig, val);
if (val[valLen-1] != '/')
{
strcat(orig, "/");
}
struct KeyValue* entry =
(struct KeyValue*)malloc(sizeof(struct KeyValue));
entry->name = replace;
entry->value = orig;
entry->len = strlen(orig);
entry->next = envTable;
envTable = entry;
}
}
/*
* Free allocated memory in envTable.
*/
static void free_envTable()
{
struct KeyValue* entry = envTable;
while (entry)
{
struct KeyValue* next = entry->next;
free(entry->name);
free(entry->value);
free(entry);
entry = next;
}
}
/*
* Print fileName to stdout,
* with envTable substitutions at the beginning of the path
*
* Eg,
* /openfoam/project/path/directory/xyz
* -> $(WM_PROJECT_DIR)/directory/xyz
*/
static void print_fileName(const char* fileName)
{
const size_t len = strlen(fileName);
const char *substr = fileName;
struct KeyValue* entry = envTable;
while (entry)
{
if (len > entry->len && !strncmp(fileName, entry->value, entry->len))
{
substr = (fileName + entry->len);
fputs(entry->name, stdout);
break;
}
entry = entry->next;
}
fputs(substr, stdout);
fputs(" \\\n", stdout);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int nDirectories = 0;
char** directories;
char** directories = NULL;
char* sourceFile = NULL;
char* depFile = NULL;
/* Set of files already visited */
struct HashEntry* visitedFiles[HASH_TABLE_SIZE];
......@@ -150,7 +283,6 @@ const char* bufferPaths[FILE_STACK_SIZE];
int main(int argc, char* argv[])
{
char *basePos, *dotPos;
int i;
if (argc < 2)
......@@ -158,148 +290,211 @@ int main(int argc, char* argv[])
fputs(EXENAME ": input file not supplied\n", stderr);
return 1;
}
else if (!strncmp(argv[1], "-h", 2)) /* -h, -help */
{
fputs
(
"\nUsage: " EXENAME
" [-Idir ... -Idir] [-iheader .. -iheader] filename\n\n"
" -Idir Directories to be searched for headers.\n"
" -iheader Headers to be ignored.\n\n"
"Dependency list generator, similar to 'cpp -M'\n\n",
stderr
);
return 0;
}
sourceFile = strdup(argv[argc-1]);
if ((basePos = strrchr(sourceFile, '/')) == NULL)
#if 0
for (i = 0; i < argc; ++i)
{
basePos = sourceFile;
}
else
{
++basePos;
}
if
(
(dotPos = strrchr(sourceFile, '.')) == NULL
|| (dotPos < basePos)
)
{
fprintf
(
stderr,
EXENAME ": cannot find extension in source file name '%s'\n",
sourceFile
);
return 1;
if (i) fputs(" ", stderr);
fputs(argv[i], stderr);
}
#endif
/* count number of -I directories */
/* Prechecks:
* - help
* - count number of -I directories
*/
nDirectories = 0;
for (i = 1; i < argc; ++i)
{
if (strncmp(argv[i], "-I", 2) == 0)
if (argv[i][0] != '-') continue;
switch (argv[i][1])
{
if (strlen(argv[i]) > 2)
{
case 'h': /* Option: -h, -help */
fputs
(
"\nUsage: " EXENAME
" [-Idir...] [-iheader...] [-eENV...]"
" [-ofile] filename\n\n"
" -Idir Directories to be searched for headers.\n"
" -iheader Headers to be ignored.\n"
" -eENV Environment variable path substitutions.\n"
" -ofile Write output to file.\n"
"\nDependency list generator, similar to 'cpp -M'\n\n",
stderr
);
return 0;
break;
case 'I': /* Option: -Idir */
++nDirectories;
}
break;
/* Could check other options, warn about unknown options... */
}
}
directories = (char**)malloc(sizeof(char*)*nDirectories);
sourceFile = strdup(argv[argc-1]);
/* build list of -I directories and add -i ignores */
/* Verify that it has an extension */
{
char *base = strrchr(sourceFile, '/');
if (!base)
{
base = sourceFile;
}
if (!strrchr(base, '.'))
{
fprintf
(
stderr,
EXENAME ": cannot find extension in source file name '%s'\n",
sourceFile
);
exit(1);
}
}
const char *outputFile = NULL;
/* Build list of -I directories and add -i ignores */
directories = (char**)malloc(sizeof(char*)*nDirectories);
nDirectories = 0;
for (i = 1; i < argc; ++i)
{
if (strncmp(argv[i], "-I", 2) == 0)
const size_t optLen = strlen(argv[i]);
if (!strncmp(argv[i], "-I", 2))
{
if (strlen(argv[i]) > 2)
/* Option: -Idir */
if (optLen > 2)
{
directories[nDirectories++] = strdup(argv[i] + 2);
}
}
else if (strncmp(argv[i], "-i", 2) == 0)
else if (!strncmp(argv[i], "-i", 2))
{
if (strlen(argv[i]) > 2)
/* Option: -iheader */
if (optLen > 2)
{
lookUp(visitedFiles, (argv[i] + 2));
}
}
else if (!strncmp(argv[i], "-e", 2))
{
/* Option: -eENV */
if (optLen > 2)
{
add_env(argv[i] + 2);
}
}
else if (!strncmp(argv[i], "-o", 2))
{
/* Option: -ofile */
if (optLen > 2)
{
outputFile = (argv[i] + 2);
}
}
}
/*
* initialise depFile to zero and use strncat rather than strncpy
* because there is a bug in the SGI strncat that if 0 preceeds the '.'
* it inserts a space