mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: respect '-silent' option for cmake builds
- minor cleanup of wmake sources
This commit is contained in:
@ -28,8 +28,7 @@ $(OBJECTS_DIR)/%.dep : %
|
|||||||
$(call QUIET_MESSAGE,wmkdep,$(<F))
|
$(call QUIET_MESSAGE,wmkdep,$(<F))
|
||||||
$(call VERBOSE_MESSAGE,Making dependency list for source file,$(<F))
|
$(call VERBOSE_MESSAGE,Making dependency list for source file,$(<F))
|
||||||
@$(WM_SCRIPTS)/makeTargetDir $@
|
@$(WM_SCRIPTS)/makeTargetDir $@
|
||||||
@$(WMAKE_BIN)/wmkdep -I$(*D) $(LIB_HEADER_DIRS) $< | \
|
@$(WMAKE_BIN)/wmkdep -o$@ -I$(*D) $(LIB_HEADER_DIRS) \
|
||||||
sed -e 's,^$(WM_PROJECT_DIR)/,$$(WM_PROJECT_DIR)/,' \
|
-eWM_PROJECT_DIR -eWM_THIRD_PARTY_DIR $<
|
||||||
-e 's,^$(WM_THIRD_PARTY_DIR)/,$$(WM_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
|
# CMake into objectsDir with external dependency
|
||||||
# - use sentinel file(s) to handle paraview/vtk version changes
|
# - use sentinel file(s) to handle paraview/vtk version changes
|
||||||
cmakeVersioned()
|
cmakeVersioned()
|
||||||
@ -89,7 +102,7 @@ cmakeVersioned()
|
|||||||
|
|
||||||
mkdir -p $objectsDir && \
|
mkdir -p $objectsDir && \
|
||||||
(
|
(
|
||||||
cd $objectsDir && cmake $sourceDir && make \
|
cd $objectsDir && _cmake $sourceDir && make \
|
||||||
&& echo "$depend" > ${sentinel:-/dev/null}
|
&& echo "$depend" > ${sentinel:-/dev/null}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,6 +31,7 @@
|
|||||||
# Usage : makeFiles
|
# Usage : makeFiles
|
||||||
#
|
#
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
dirToString=$WM_DIR/platforms/$WM_ARCH$WM_COMPILER/dirToString
|
||||||
|
|
||||||
if [ -r Make/files ]
|
if [ -r Make/files ]
|
||||||
then
|
then
|
||||||
@ -38,10 +39,15 @@ then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
[ -d Make ] || mkdir Make
|
||||||
rm -f Make/files
|
rm -f Make/files
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
echo "Creating Make/files"
|
||||||
|
|
||||||
for dir in $(find . -mindepth 1 -type d -print)
|
for dir in $(find . -mindepth 1 -type d -print)
|
||||||
do
|
do
|
||||||
@ -53,7 +59,7 @@ do
|
|||||||
echo "$(echo $dir | $dirToString -strip) = ${dir#./}"
|
echo "$(echo $dir | $dirToString -strip) = ${dir#./}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done >> Make/files
|
done > Make/files
|
||||||
[ -s Make/files ] && echo >> Make/files
|
[ -s Make/files ] && echo >> Make/files
|
||||||
|
|
||||||
for file in $(find . -name "*.[cCylLfF]" -type f -print)
|
for file in $(find . -name "*.[cCylLfF]" -type f -print)
|
||||||
|
|||||||
@ -39,11 +39,12 @@ then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
[ -d Make ] || mkdir Make
|
[ -d Make ] || mkdir Make
|
||||||
|
|
||||||
rm -f Make/options
|
rm -f Make/options
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
echo "Creating Make/options"
|
||||||
|
|
||||||
echo 'EXE_INC = \
|
echo 'EXE_INC = \
|
||||||
-I$(LIB_SRC)/finiteVolume/lnInclude' >> Make/options
|
-I$(LIB_SRC)/finiteVolume/lnInclude' > Make/options
|
||||||
echo >> Make/options
|
echo >> Make/options
|
||||||
echo 'EXE_LIBS = \
|
echo 'EXE_LIBS = \
|
||||||
-lfiniteVolume' >> Make/options
|
-lfiniteVolume' >> Make/options
|
||||||
|
|||||||
@ -28,7 +28,7 @@
|
|||||||
# Description
|
# Description
|
||||||
# Makes a directory hierarchy for the given target file
|
# 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 $@
|
$E flex -o $@.c $(<F) && $(cc) $(cFLAGS) $@.c -o $@
|
||||||
@rm -f $@.c 2>/dev/null
|
@rm -f $@.c 2>/dev/null
|
||||||
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|||||||
@ -25,8 +25,8 @@ Application
|
|||||||
dirToString
|
dirToString
|
||||||
|
|
||||||
Description
|
Description
|
||||||
converts a directory path into a string with appropriate capitalisation
|
Converts a directory path into a camelCase string.
|
||||||
e.g. dir1/dir2 becomes dir1Dir2
|
e.g. dir1/dir2/dir3 becomes dir1Dir2Dir3
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
echo dirName | dirToString
|
echo dirName | dirToString
|
||||||
@ -45,34 +45,34 @@ Usage
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
/* The executable name (for messages), without requiring access to argv[] */
|
||||||
|
#define EXENAME "dirToString"
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
int nextupper = 0;
|
|
||||||
|
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
{
|
{
|
||||||
if (!strncmp(argv[1], "-h", 2)) /* -h, -help */
|
if (!strncmp(argv[1], "-h", 2))
|
||||||
{
|
{
|
||||||
fprintf
|
/* Option: -h, -help */
|
||||||
(
|
|
||||||
stderr,
|
|
||||||
"\nUsage: %s [-strip]\n\n",
|
|
||||||
"dirToString"
|
|
||||||
);
|
|
||||||
|
|
||||||
fprintf
|
fputs
|
||||||
(
|
(
|
||||||
stderr,
|
"\nUsage: " EXENAME
|
||||||
|
" [-strip]\n\n"
|
||||||
" -strip ignore leading [./] characters.\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;
|
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 == '/'))
|
while ((c=getchar()) != EOF && (c == '.' || c == '/'))
|
||||||
{
|
{
|
||||||
/* nop */
|
/* nop */
|
||||||
@ -88,25 +88,23 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int nextUpper = 0;
|
||||||
while ((c = getchar()) != EOF)
|
while ((c = getchar()) != EOF)
|
||||||
{
|
{
|
||||||
if (c == '/')
|
if (c == '/')
|
||||||
{
|
{
|
||||||
nextupper = 1;
|
nextUpper = 1;
|
||||||
}
|
}
|
||||||
else
|
else if (nextUpper)
|
||||||
{
|
|
||||||
if (nextupper)
|
|
||||||
{
|
{
|
||||||
putchar(toupper(c));
|
putchar(toupper(c));
|
||||||
nextupper = 0;
|
nextUpper = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
putchar(c);
|
putchar(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,18 +26,26 @@ Application
|
|||||||
wmkdep
|
wmkdep
|
||||||
|
|
||||||
Description
|
Description
|
||||||
A fast dependency list generator that emulates the behaviour and the
|
A fast dependency list generator that emulates the behaviour and output
|
||||||
output of cpp -M. However, the output contains no duplicates and
|
of cpp -M. However, the output contains no duplicates and is thus
|
||||||
is approx. 40% faster than cpp.
|
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
|
The algorithm uses flex to scan for includes and searches the files found.
|
||||||
found. Each file is entered into a hash table so that files are scanned
|
The files are only visited once (the names of the files visited are hashed),
|
||||||
only once. This is why this program is faster than cpp.
|
which makes this faster than cpp.
|
||||||
|
|
||||||
Usage
|
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 FILE_STACK_SIZE 300
|
||||||
#define HASH_TABLE_SIZE 500
|
#define HASH_TABLE_SIZE 500
|
||||||
@ -52,7 +60,6 @@ Usage
|
|||||||
/* The executable name (for messages), without requiring access to argv[] */
|
/* The executable name (for messages), without requiring access to argv[] */
|
||||||
#define EXENAME "wmkdep"
|
#define EXENAME "wmkdep"
|
||||||
#undef yywrap /* sometimes a macro by default */
|
#undef yywrap /* sometimes a macro by default */
|
||||||
#define YY_NO_INPUT /* no input(), yyinput() required */
|
|
||||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||||
|
|
||||||
void nextFile(const char* fileName);
|
void nextFile(const char* fileName);
|
||||||
@ -60,20 +67,20 @@ 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 */
|
"/*" BEGIN(CMNT); /* Begin removing C-style comment */
|
||||||
<CMNT>.|\n ;
|
<CMNT>.|\n ;
|
||||||
<CMNT>"*/" BEGIN(INITIAL); /* end removing c style comment */
|
<CMNT>"*/" BEGIN(INITIAL); /* End removing C-style comment */
|
||||||
|
|
||||||
^[ \t]*#[ \t]*include[ \t]+\" BEGIN(CFNAME); /* c-file name */
|
^[ \t]*#[ \t]*include[ \t]+\" BEGIN(CFNAME); /* C-file name */
|
||||||
<CFNAME>[^"\n ]* { BEGIN(INITIAL); nextFile(yytext); } /*"*/
|
<CFNAME>[^"\n ]* { BEGIN(INITIAL); nextFile(yytext); } /* "-quoted */
|
||||||
|
|
||||||
" "include[ \t]+\' BEGIN(FFNAME); /* FORTRAN-file name */
|
" "include[ \t]+\' BEGIN(FFNAME); /* FORTRAN-file name */
|
||||||
<FFNAME>[^']* { BEGIN(INITIAL); nextFile(yytext); } /*'*/
|
<FFNAME>[^']* { BEGIN(INITIAL); nextFile(yytext); } /* '-quoted */
|
||||||
|
|
||||||
.|\t|\n ;
|
.|\t|\n ;
|
||||||
|
|
||||||
@ -82,7 +89,9 @@ void nextFile(const char* fileName);
|
|||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/* char* entry in hash table */
|
/*
|
||||||
|
* A char* entry in hash table
|
||||||
|
*/
|
||||||
struct HashEntry
|
struct HashEntry
|
||||||
{
|
{
|
||||||
char* name;
|
char* name;
|
||||||
@ -91,49 +100,173 @@ struct HashEntry
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* lookup name in hash table.
|
* Lookup name in hashTable.
|
||||||
* if found - return 1
|
* 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;
|
unsigned idx = 0; /* Hash index */
|
||||||
struct HashEntry* n;
|
{
|
||||||
struct HashEntry* nn;
|
const char* pp = str;
|
||||||
|
while (*pp) idx = idx << 1 ^ *pp++;
|
||||||
|
idx %= HASH_TABLE_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
/* hash */
|
/* Search for entry */
|
||||||
const char* pp = p;
|
struct HashEntry* entry;
|
||||||
while (*pp) ii = ii<<1 ^ *pp++;
|
for (entry = hashTable[idx]; entry; entry = entry->next)
|
||||||
if (ii < 0) ii = -ii;
|
|
||||||
ii %= HASH_TABLE_SIZE;
|
|
||||||
|
|
||||||
/* search */
|
|
||||||
for (n=hashTable[ii]; n; n=n->next)
|
|
||||||
{
|
{
|
||||||
if (strcmp(p, n->name) == 0)
|
if (!strcmp(str, entry->name))
|
||||||
{
|
{
|
||||||
/* entry found so return true */
|
return 1; /* True: entry found */
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* insert */
|
/* Entry not found - insert a new entry */
|
||||||
nn = (struct HashEntry*)malloc(sizeof(struct HashEntry));
|
entry = (struct HashEntry*)malloc(sizeof(struct HashEntry));
|
||||||
nn->name = strdup(p);
|
entry->name = strdup(str);
|
||||||
nn->next = hashTable[ii];
|
entry->next = hashTable[idx];
|
||||||
hashTable[ii] = nn;
|
hashTable[idx] = entry;
|
||||||
|
|
||||||
/* entry not found, and therefore added. return false */
|
return 0; /* False: entry did not previously exist */
|
||||||
return 0;
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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;
|
int nDirectories = 0;
|
||||||
char** directories;
|
char** directories = NULL;
|
||||||
char* sourceFile = NULL;
|
char* sourceFile = NULL;
|
||||||
char* depFile = NULL;
|
|
||||||
|
|
||||||
/* Set of files already visited */
|
/* Set of files already visited */
|
||||||
struct HashEntry* visitedFiles[HASH_TABLE_SIZE];
|
struct HashEntry* visitedFiles[HASH_TABLE_SIZE];
|
||||||
@ -150,7 +283,6 @@ const char* bufferPaths[FILE_STACK_SIZE];
|
|||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
char *basePos, *dotPos;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
@ -158,37 +290,60 @@ int main(int argc, char* argv[])
|
|||||||
fputs(EXENAME ": input file not supplied\n", stderr);
|
fputs(EXENAME ": input file not supplied\n", stderr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (!strncmp(argv[1], "-h", 2)) /* -h, -help */
|
|
||||||
|
#if 0
|
||||||
|
for (i = 0; i < argc; ++i)
|
||||||
{
|
{
|
||||||
|
if (i) fputs(" ", stderr);
|
||||||
|
fputs(argv[i], stderr);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Prechecks:
|
||||||
|
* - help
|
||||||
|
* - count number of -I directories
|
||||||
|
*/
|
||||||
|
nDirectories = 0;
|
||||||
|
for (i = 1; i < argc; ++i)
|
||||||
|
{
|
||||||
|
if (argv[i][0] != '-') continue;
|
||||||
|
|
||||||
|
switch (argv[i][1])
|
||||||
|
{
|
||||||
|
case 'h': /* Option: -h, -help */
|
||||||
fputs
|
fputs
|
||||||
(
|
(
|
||||||
"\nUsage: " EXENAME
|
"\nUsage: " EXENAME
|
||||||
" [-Idir ... -Idir] [-iheader .. -iheader] filename\n\n"
|
" [-Idir...] [-iheader...] [-eENV...]"
|
||||||
|
" [-ofile] filename\n\n"
|
||||||
" -Idir Directories to be searched for headers.\n"
|
" -Idir Directories to be searched for headers.\n"
|
||||||
" -iheader Headers to be ignored.\n\n"
|
" -iheader Headers to be ignored.\n"
|
||||||
"Dependency list generator, similar to 'cpp -M'\n\n",
|
" -eENV Environment variable path substitutions.\n"
|
||||||
|
" -ofile Write output to file.\n"
|
||||||
|
"\nDependency list generator, similar to 'cpp -M'\n\n",
|
||||||
stderr
|
stderr
|
||||||
);
|
);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'I': /* Option: -Idir */
|
||||||
|
++nDirectories;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Could check other options, warn about unknown options... */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceFile = strdup(argv[argc-1]);
|
sourceFile = strdup(argv[argc-1]);
|
||||||
|
|
||||||
if ((basePos = strrchr(sourceFile, '/')) == NULL)
|
/* Verify that it has an extension */
|
||||||
{
|
{
|
||||||
basePos = sourceFile;
|
char *base = strrchr(sourceFile, '/');
|
||||||
}
|
if (!base)
|
||||||
else
|
|
||||||
{
|
{
|
||||||
++basePos;
|
base = sourceFile;
|
||||||
}
|
}
|
||||||
|
if (!strrchr(base, '.'))
|
||||||
if
|
|
||||||
(
|
|
||||||
(dotPos = strrchr(sourceFile, '.')) == NULL
|
|
||||||
|| (dotPos < basePos)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
fprintf
|
fprintf
|
||||||
(
|
(
|
||||||
@ -196,110 +351,150 @@ int main(int argc, char* argv[])
|
|||||||
EXENAME ": cannot find extension in source file name '%s'\n",
|
EXENAME ": cannot find extension in source file name '%s'\n",
|
||||||
sourceFile
|
sourceFile
|
||||||
);
|
);
|
||||||
return 1;
|
exit(1);
|
||||||
}
|
|
||||||
|
|
||||||
/* count number of -I directories */
|
|
||||||
nDirectories = 0;
|
|
||||||
for (i = 1; i < argc; ++i)
|
|
||||||
{
|
|
||||||
if (strncmp(argv[i], "-I", 2) == 0)
|
|
||||||
{
|
|
||||||
if (strlen(argv[i]) > 2)
|
|
||||||
{
|
|
||||||
++nDirectories;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *outputFile = NULL;
|
||||||
|
|
||||||
|
/* Build list of -I directories and add -i ignores */
|
||||||
directories = (char**)malloc(sizeof(char*)*nDirectories);
|
directories = (char**)malloc(sizeof(char*)*nDirectories);
|
||||||
|
|
||||||
/* build list of -I directories and add -i ignores */
|
|
||||||
nDirectories = 0;
|
nDirectories = 0;
|
||||||
for (i = 1; i < argc; ++i)
|
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);
|
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));
|
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
|
|
||||||
*/
|
|
||||||
depFile = (char*)malloc(strlen(sourceFile) + 20);
|
|
||||||
depFile[0] = 0;
|
|
||||||
strcat(depFile, "$(OBJECTS_DIR)/");
|
|
||||||
strcat(depFile, sourceFile);
|
|
||||||
strcat(depFile, ".dep");
|
|
||||||
|
|
||||||
char *objectFile = strdup(basePos);
|
|
||||||
objectFile[(dotPos - basePos)/sizeof(char)] = 0;
|
|
||||||
|
|
||||||
/* printf("$(OBJECTS_DIR)/%s.o: %s\n", objectFile, depFile); */
|
|
||||||
printf("%s: \\\n", depFile);
|
|
||||||
free(objectFile);
|
|
||||||
|
|
||||||
/* Initialize buffer path for currentBuffer */
|
/* Initialize buffer path for currentBuffer */
|
||||||
|
currentBuffer = 0;
|
||||||
bufferPaths[currentBuffer] = NULL;
|
bufferPaths[currentBuffer] = NULL;
|
||||||
|
|
||||||
|
/* Start of output */
|
||||||
|
if (outputFile)
|
||||||
|
{
|
||||||
|
FILE *reopened = freopen(outputFile, "w", stdout);
|
||||||
|
if (!reopened)
|
||||||
|
{
|
||||||
|
fprintf
|
||||||
|
(
|
||||||
|
stderr,
|
||||||
|
EXENAME ": could not open file '%s' for output: %s\n",
|
||||||
|
outputFile, strerror(errno)
|
||||||
|
);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fputs("$(OBJECTS_DIR)/", stdout);
|
||||||
|
fputs(sourceFile, stdout);
|
||||||
|
fputs(".dep: \\\n", stdout);
|
||||||
|
|
||||||
nextFile(sourceFile);
|
nextFile(sourceFile);
|
||||||
yylex();
|
yylex();
|
||||||
|
|
||||||
puts("\n");
|
fputs("\n\n", stdout);
|
||||||
|
|
||||||
for (i = 0; i < nDirectories; ++i)
|
for (i = nDirectories-1; i >= 0; --i)
|
||||||
{
|
{
|
||||||
free(directories[i]);
|
free(directories[i]);
|
||||||
}
|
}
|
||||||
free(directories);
|
free(directories);
|
||||||
|
|
||||||
free(sourceFile);
|
free(sourceFile);
|
||||||
free(depFile);
|
|
||||||
|
free_hashTable(visitedFiles);
|
||||||
|
free_envTable();
|
||||||
|
|
||||||
|
fflush(stdout);
|
||||||
|
fflush(stderr);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add a directory name to the file name
|
* Open a file for reading and print its qualified name
|
||||||
*/
|
*/
|
||||||
char* addDirectoryName(const char* dirName, const char* fileName)
|
static FILE* fopen_file(const char* dirName, const char* fileName)
|
||||||
{
|
{
|
||||||
char* pathName = (char*)malloc(strlen(dirName) + strlen(fileName) + 2);
|
FILE *file;
|
||||||
strcpy(pathName, dirName);
|
|
||||||
|
|
||||||
if (dirName[strlen(dirName)-1] != '/')
|
if (dirName && *dirName)
|
||||||
{
|
{
|
||||||
strcat(pathName, "/");
|
const size_t dirLen = strlen(dirName);
|
||||||
|
char* fullName = (char*)malloc(dirLen + strlen(fileName) + 2);
|
||||||
|
|
||||||
|
strcpy(fullName, dirName);
|
||||||
|
if (dirName[dirLen-1] != '/')
|
||||||
|
{
|
||||||
|
strcat(fullName, "/");
|
||||||
|
}
|
||||||
|
strcat(fullName, fileName);
|
||||||
|
|
||||||
|
file = fopen(fullName, "r");
|
||||||
|
|
||||||
|
if (file)
|
||||||
|
{
|
||||||
|
print_fileName(fullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
strcat(pathName, fileName);
|
free(fullName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
file = fopen(fileName, "r");
|
||||||
|
|
||||||
return pathName;
|
if (file)
|
||||||
|
{
|
||||||
|
print_fileName(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* open a file and create buffer and put on stack
|
* Open a file and create buffer and put on stack
|
||||||
*/
|
*/
|
||||||
void nextFile(const char* fileName)
|
void nextFile(const char* fileName)
|
||||||
{
|
{
|
||||||
if (lookUp(visitedFiles, fileName))
|
if (lookUp(visitedFiles, fileName))
|
||||||
{
|
{
|
||||||
return; /* already existed (did not insert) */
|
return; /* Already existed (did not insert) */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentBuffer >= FILE_STACK_SIZE)
|
if (currentBuffer >= FILE_STACK_SIZE)
|
||||||
@ -311,6 +506,9 @@ void nextFile(const char* fileName)
|
|||||||
"while opening '%s' for file '%s'\n",
|
"while opening '%s' for file '%s'\n",
|
||||||
FILE_STACK_SIZE, fileName, sourceFile
|
FILE_STACK_SIZE, fileName, sourceFile
|
||||||
);
|
);
|
||||||
|
|
||||||
|
fflush(stdout);
|
||||||
|
fflush(stderr);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,47 +518,39 @@ void nextFile(const char* fileName)
|
|||||||
/* Check if the file has same path as the file in the current buffer */
|
/* Check if the file has same path as the file in the current buffer */
|
||||||
if (bufferPaths[currentBuffer] != NULL)
|
if (bufferPaths[currentBuffer] != NULL)
|
||||||
{
|
{
|
||||||
char* pathName = addDirectoryName(bufferPaths[currentBuffer], fileName);
|
newyyin = fopen_file(bufferPaths[currentBuffer], fileName);
|
||||||
|
if (newyyin)
|
||||||
if ((newyyin = fopen(pathName, "r")))
|
|
||||||
{
|
{
|
||||||
printf("%s \\\n", pathName);
|
|
||||||
|
|
||||||
buffers[currentBuffer++] = YY_CURRENT_BUFFER;
|
buffers[currentBuffer++] = YY_CURRENT_BUFFER;
|
||||||
bufferPaths[currentBuffer] = bufferPaths[currentBuffer-1];
|
bufferPaths[currentBuffer] = bufferPaths[currentBuffer-1];
|
||||||
|
|
||||||
yy_switch_to_buffer(yy_create_buffer(newyyin, YY_BUF_SIZE));
|
yy_switch_to_buffer(yy_create_buffer(newyyin, YY_BUF_SIZE));
|
||||||
|
|
||||||
free(pathName);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(pathName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(newyyin = fopen(fileName, "r")))
|
newyyin = fopen_file(NULL, fileName);
|
||||||
|
if (newyyin)
|
||||||
|
{
|
||||||
|
buffers[currentBuffer++] = YY_CURRENT_BUFFER;
|
||||||
|
bufferPaths[currentBuffer] = NULL;
|
||||||
|
|
||||||
|
yy_switch_to_buffer(yy_create_buffer(newyyin, YY_BUF_SIZE));
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
int d;
|
int d;
|
||||||
for (d=0; d<nDirectories; ++d)
|
for (d=0; d<nDirectories; ++d)
|
||||||
{
|
{
|
||||||
char* pathName = addDirectoryName(directories[d], fileName);
|
newyyin = fopen_file(directories[d], fileName);
|
||||||
|
if (newyyin)
|
||||||
if ((newyyin = fopen(pathName, "r")))
|
|
||||||
{
|
{
|
||||||
printf("%s \\\n", pathName);
|
|
||||||
|
|
||||||
buffers[currentBuffer++] = YY_CURRENT_BUFFER;
|
buffers[currentBuffer++] = YY_CURRENT_BUFFER;
|
||||||
bufferPaths[currentBuffer] = directories[d];
|
bufferPaths[currentBuffer] = directories[d];
|
||||||
|
|
||||||
yy_switch_to_buffer(yy_create_buffer(newyyin, YY_BUF_SIZE));
|
yy_switch_to_buffer(yy_create_buffer(newyyin, YY_BUF_SIZE));
|
||||||
|
|
||||||
free(pathName);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(pathName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf
|
fprintf
|
||||||
@ -378,34 +568,9 @@ void nextFile(const char* fileName)
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
|
|
||||||
/* only report the first occurance */
|
/* Only report the first occurrence */
|
||||||
lookUp(visitedFiles, fileName);
|
lookUp(visitedFiles, fileName);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("%s \\\n", fileName);
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
buffers[currentBuffer++] = YY_CURRENT_BUFFER;
|
|
||||||
bufferPaths[currentBuffer] = NULL;
|
|
||||||
|
|
||||||
yy_switch_to_buffer(yy_create_buffer(newyyin, YY_BUF_SIZE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Replace all '.' with '/'
|
|
||||||
*/
|
|
||||||
void dotToSlash(char* fileName)
|
|
||||||
{
|
|
||||||
const size_t len = strlen(fileName);
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
for (i=0; i<len; ++i)
|
|
||||||
{
|
|
||||||
if (fileName[i] == '.') fileName[i] = '/';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -415,9 +580,9 @@ void dotToSlash(char* fileName)
|
|||||||
int yywrap()
|
int yywrap()
|
||||||
{
|
{
|
||||||
/* Close the file for the buffer which has just reached EOF */
|
/* Close the file for the buffer which has just reached EOF */
|
||||||
/* This causes strange problems on some systems
|
/* This causes strange problems on several systems:
|
||||||
fclose(yyin);
|
fclose(yyin);
|
||||||
yyin = 0;
|
yyin = NULL;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Delete the buffer */
|
/* Delete the buffer */
|
||||||
@ -426,23 +591,25 @@ int yywrap()
|
|||||||
/* Set buffer counter to previous buffer */
|
/* Set buffer counter to previous buffer */
|
||||||
currentBuffer--;
|
currentBuffer--;
|
||||||
|
|
||||||
if (currentBuffer >= 0) /* if buffer counter refers to a valid file */
|
if (currentBuffer >= 0)
|
||||||
{
|
{
|
||||||
/* reset input buffer to the previous buffer on the stack */
|
/* Buffer counter refers to a valid file */
|
||||||
|
|
||||||
|
/* Reset input buffer to the previous buffer on the stack */
|
||||||
yy_switch_to_buffer(buffers[currentBuffer]);
|
yy_switch_to_buffer(buffers[currentBuffer]);
|
||||||
|
|
||||||
/* Return to the normal state for the previous buffer on the stack */
|
/* Return to the normal state for the previous buffer on the stack */
|
||||||
BEGIN(INITIAL);
|
BEGIN(INITIAL);
|
||||||
|
|
||||||
/* return 0 to inform lex to continue reading */
|
/* Return 0 to inform lex to continue reading */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else /* else there are no more buffers on the stack */
|
|
||||||
{
|
/* No more buffers on the stack:
|
||||||
/* return 1 to inform lex finish now that all buffers have been read */
|
* Return 1 to inform lex to finish now that all buffers have been read
|
||||||
|
*/
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|||||||
@ -105,7 +105,7 @@ if [ $# -ge 1 ]
|
|||||||
then
|
then
|
||||||
if [ -d "$1" ]
|
if [ -d "$1" ]
|
||||||
then
|
then
|
||||||
dir=$1
|
dir="${1%/}"
|
||||||
elif [ -f "$1" ]
|
elif [ -f "$1" ]
|
||||||
then
|
then
|
||||||
dir="${1%/*}"
|
dir="${1%/*}"
|
||||||
@ -115,10 +115,10 @@ then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Specified directory name:
|
# Specified directory name:
|
||||||
[ $# -ge 2 ] && dir=$2
|
[ $# -ge 2 ] && dir="${2%/}"
|
||||||
|
|
||||||
# Specified alternative name for the Make sub-directory:
|
# Specified alternative name for the Make sub-directory:
|
||||||
[ $# -ge 3 ] && MakeDir=$3
|
[ $# -ge 3 ] && MakeDir="${3%/}"
|
||||||
|
|
||||||
if [ -n "$dir" ]
|
if [ -n "$dir" ]
|
||||||
then
|
then
|
||||||
|
|||||||
15
wmake/wmake
15
wmake/wmake
@ -243,14 +243,15 @@ fi
|
|||||||
# The variables 'targetType' and 'MakeDir' are considered global
|
# The variables 'targetType' and 'MakeDir' are considered global
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
unset dir targetType
|
unset targetType
|
||||||
MakeDir=Make
|
MakeDir=Make
|
||||||
|
|
||||||
if [ $# -ge 1 ]
|
if [ $# -ge 1 ]
|
||||||
then
|
then
|
||||||
|
unset dir
|
||||||
if [ -d "$1" ]
|
if [ -d "$1" ]
|
||||||
then
|
then
|
||||||
dir="$1"
|
dir="${1%/}"
|
||||||
elif [ -f "$1" ]
|
elif [ -f "$1" ]
|
||||||
then
|
then
|
||||||
dir="${1%/*}"
|
dir="${1%/*}"
|
||||||
@ -260,10 +261,10 @@ then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Specified directory name:
|
# Specified directory name:
|
||||||
[ $# -ge 2 ] && dir=$2
|
[ $# -ge 2 ] && dir="${2%/}"
|
||||||
|
|
||||||
# Specified alternative name for the Make sub-directory:
|
# Specified alternative name for the Make sub-directory:
|
||||||
[ $# -ge 3 ] && MakeDir=$3
|
[ $# -ge 3 ] && MakeDir="${3%/}"
|
||||||
|
|
||||||
if [ -n "$dir" ]
|
if [ -n "$dir" ]
|
||||||
then
|
then
|
||||||
@ -271,10 +272,14 @@ then
|
|||||||
echo "$Script error: could not change to directory '$dir'" 1>&2
|
echo "$Script error: could not change to directory '$dir'" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
elif [ -f "$MakeDir/files" ]
|
||||||
|
then
|
||||||
|
dir="(${PWD##*/})" # Implicit directory information
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Print command
|
# Print command
|
||||||
echo "$Script $targetType${targetType:+ }${dir:-.}"
|
echo "$Script $targetType${targetType:+ }$dir"
|
||||||
|
unset dir
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -29,16 +29,17 @@
|
|||||||
# wmakeCheckPwd <dir>
|
# wmakeCheckPwd <dir>
|
||||||
#
|
#
|
||||||
# Description
|
# Description
|
||||||
# Check that the current working directory is the directory <dir>
|
# Check that the current working directory is the directory <dir>.
|
||||||
|
# Exit status 0 when the directories are identical
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
Script=${0##*/}
|
Script=${0##*/}
|
||||||
|
|
||||||
unset quietOpt
|
unset optQuiet
|
||||||
|
exec 1>&2 # No stdout, stderr only
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
[ "$quietOpt" = true ] && exit 1
|
[ "$optQuiet" = true ] && exit 1
|
||||||
exec 1>&2
|
|
||||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||||
cat<<USAGE
|
cat<<USAGE
|
||||||
|
|
||||||
@ -57,6 +58,17 @@ USAGE
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
error()
|
||||||
|
{
|
||||||
|
if [ "$optQuiet" != true ]
|
||||||
|
then
|
||||||
|
echo "$Script error: $1"
|
||||||
|
shift
|
||||||
|
while [ "$#" -ge 1 ]; do echo " $1"; shift; done
|
||||||
|
fi
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
# Parse arguments and options
|
# Parse arguments and options
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
@ -68,11 +80,11 @@ do
|
|||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
-q | -quiet)
|
-q | -quiet)
|
||||||
quietOpt=true
|
optQuiet=true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-*)
|
-*)
|
||||||
usage "unknown option: '$*'"
|
usage "Unknown option: '$1'"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
break
|
break
|
||||||
@ -80,35 +92,21 @@ do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
[ "$#" -eq 1 ] || usage "Incorrect number of arguments"
|
||||||
|
|
||||||
[ "$#" -eq 1 ] || usage
|
|
||||||
|
|
||||||
# Set dirName to <dir>
|
|
||||||
dirName="$1"
|
dirName="$1"
|
||||||
|
|
||||||
# Simple check against $PWD
|
# Simple lexical check against PWD
|
||||||
[ "$PWD" = "$dirName" ] && exit 0
|
[ "$PWD" = "$dirName" ] && exit 0
|
||||||
|
|
||||||
# Check existence of <dir>
|
# Check existence of <dir>
|
||||||
[ -d "$dirName" ] || {
|
[ -d "$dirName" ] || error "Directory does not exist '$dirName'"
|
||||||
[ "$quietOpt" = true ] || {
|
|
||||||
echo "$Script error: Directory does not exist $dirName"
|
|
||||||
}
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Use /bin/pwd to get the absolute path (could be linked)
|
# Compare absolute paths, without symlinks
|
||||||
thisDir=$(/bin/pwd)
|
[ "$(cd $dirName 2>/dev/null && pwd -P)" = "$(pwd -P)" ] || \
|
||||||
target=$(cd $dirName 2>/dev/null && /bin/pwd)
|
error "Current directory is not '$dirName'"
|
||||||
|
|
||||||
# Return 0 if this directory is <dir>
|
|
||||||
[ "$thisDir" = "$target" ] && exit 0
|
|
||||||
|
|
||||||
# This directory is not <dir>
|
exit 0 # clean exit
|
||||||
[ "$quietOpt" = true ] || {
|
|
||||||
echo "$Script error: Current directory is not $dirName"
|
|
||||||
}
|
|
||||||
|
|
||||||
exit 1
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|||||||
@ -59,23 +59,23 @@ do
|
|||||||
-h | -help) # Provide immediate help
|
-h | -help) # Provide immediate help
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
-*)
|
|
||||||
usage "unknown option: '$1'"
|
|
||||||
;;
|
|
||||||
*)
|
*)
|
||||||
break
|
# No options/arguments
|
||||||
|
usage "unexpected options/arguments: $*"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# No arguments
|
if [ -e Make ]
|
||||||
[ "$#" -eq 0 ] || usage "unexpected arguments: '$*'"
|
then
|
||||||
|
echo "$Script error: Make directory already exists" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
# Check environment variables
|
# Check environment variables
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
for check in WM_OPTIONS WM_LINK_LANGUAGE WM_DIR
|
for check in WM_DIR WM_ARCH WM_COMPILER
|
||||||
do
|
do
|
||||||
eval test "\$$check" || {
|
eval test "\$$check" || {
|
||||||
echo "$Script error: environment variable \$$check not set" 1>&2
|
echo "$Script error: environment variable \$$check not set" 1>&2
|
||||||
@ -83,24 +83,9 @@ do
|
|||||||
}
|
}
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -d Make ]
|
|
||||||
then
|
|
||||||
echo "$Script error: Make directory already exists" 1>&2
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
mkdir Make
|
mkdir Make
|
||||||
fi
|
[ -e Make/files ] || $WM_DIR/scripts/makeFiles
|
||||||
|
[ -e Make/options ] || $WM_DIR/scripts/makeOptions
|
||||||
[ -e Make/files ] || {
|
|
||||||
echo "$Script: Creating Make/files"
|
|
||||||
$WM_DIR/scripts/makeFiles
|
|
||||||
}
|
|
||||||
|
|
||||||
[ -e Make/options ] || {
|
|
||||||
echo "$Script: Creating Make/options"
|
|
||||||
$WM_DIR/scripts/makeOptions
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
exit 0 # clean exit
|
exit 0 # clean exit
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user