Commit a072dbc1 authored by Alexandre Julliard's avatar Alexandre Julliard

makedep: Use string arrays for include paths and object extensions.

parent 3bc839f1
...@@ -81,22 +81,6 @@ static const struct ...@@ -81,22 +81,6 @@ static const struct
static struct list sources = LIST_INIT(sources); static struct list sources = LIST_INIT(sources);
static struct list includes = LIST_INIT(includes); static struct list includes = LIST_INIT(includes);
struct object_extension
{
struct list entry;
const char *extension;
};
static struct list object_extensions = LIST_INIT(object_extensions);
struct incl_path
{
struct list entry;
const char *name;
};
static struct list paths = LIST_INIT(paths);
struct strarray struct strarray
{ {
unsigned int count; /* strings in use */ unsigned int count; /* strings in use */
...@@ -104,6 +88,9 @@ struct strarray ...@@ -104,6 +88,9 @@ struct strarray
const char **str; const char **str;
}; };
static struct strarray paths;
static struct strarray object_extensions;
static const char *src_dir; static const char *src_dir;
static const char *top_src_dir; static const char *top_src_dir;
static const char *top_obj_dir; static const char *top_obj_dir;
...@@ -291,6 +278,19 @@ static void strarray_add( struct strarray *array, const char *str ) ...@@ -291,6 +278,19 @@ static void strarray_add( struct strarray *array, const char *str )
/******************************************************************* /*******************************************************************
* strarray_insert
*/
static void strarray_insert( struct strarray *array, unsigned int pos, const char *str )
{
unsigned int i;
strarray_add( array, NULL );
for (i = array->count - 1; i > pos; i--) array->str[i] = array->str[i - 1];
array->str[pos] = str;
}
/*******************************************************************
* output_filename * output_filename
*/ */
static void output_filename( const char *name, int *column ) static void output_filename( const char *name, int *column )
...@@ -418,30 +418,6 @@ static char *get_line( FILE *file ) ...@@ -418,30 +418,6 @@ static char *get_line( FILE *file )
} }
/******************************************************************* /*******************************************************************
* add_object_extension
*
* Add an extension for object files.
*/
static void add_object_extension( const char *ext )
{
struct object_extension *object_extension = xmalloc( sizeof(*object_extension) );
list_add_tail( &object_extensions, &object_extension->entry );
object_extension->extension = ext;
}
/*******************************************************************
* add_include_path
*
* Add a directory to the include path.
*/
static void add_include_path( const char *name )
{
struct incl_path *path = xmalloc( sizeof(*path) );
list_add_tail( &paths, &path->entry );
path->name = name;
}
/*******************************************************************
* find_src_file * find_src_file
*/ */
static struct incl_file *find_src_file( const char *name ) static struct incl_file *find_src_file( const char *name )
...@@ -560,7 +536,7 @@ static FILE *open_include_file( struct incl_file *pFile ) ...@@ -560,7 +536,7 @@ static FILE *open_include_file( struct incl_file *pFile )
{ {
FILE *file = NULL; FILE *file = NULL;
char *filename, *p; char *filename, *p;
struct incl_path *path; unsigned int i;
errno = ENOENT; errno = ENOENT;
...@@ -666,24 +642,17 @@ static FILE *open_include_file( struct incl_file *pFile ) ...@@ -666,24 +642,17 @@ static FILE *open_include_file( struct incl_file *pFile )
free( filename ); free( filename );
} }
/* now try in global includes */
if (top_obj_dir)
{
filename = strmake( "%s/include/%s", top_obj_dir, pFile->name );
if ((file = fopen( filename, "r" ))) goto found;
free( filename );
}
if (top_src_dir)
{
filename = strmake( "%s/include/%s", top_src_dir, pFile->name );
if ((file = fopen( filename, "r" ))) goto found;
free( filename );
}
/* now search in include paths */ /* now search in include paths */
LIST_FOR_EACH_ENTRY( path, &paths, struct incl_path, entry ) for (i = 0; i < paths.count; i++)
{ {
filename = strmake( "%s/%s", path->name, pFile->name ); if (paths.str[i][0] == '/')
{
/* ignore absolute paths that don't point into the source dir */
if (!top_src_dir) continue;
if (strncmp( paths.str[i], top_src_dir, strlen(top_src_dir) )) continue;
if (paths.str[i][strlen(top_src_dir)] != '/') continue;
}
filename = strmake( "%s/%s", paths.str[i], pFile->name );
if ((file = fopen( filename, "r" ))) goto found; if ((file = fopen( filename, "r" ))) goto found;
free( filename ); free( filename );
} }
...@@ -1300,12 +1269,11 @@ static void output_sources(void) ...@@ -1300,12 +1269,11 @@ static void output_sources(void)
} }
else else
{ {
struct object_extension *obj_ext; for (i = 0; i < object_extensions.count; i++)
LIST_FOR_EACH_ENTRY( obj_ext, &object_extensions, struct object_extension, entry )
{ {
strarray_add( &clean_files, strmake( "%s.%s", obj, obj_ext->extension )); strarray_add( &clean_files, strmake( "%s.%s", obj, object_extensions.str[i] ));
output( "%s.%s: %s\n", obj, obj_ext->extension, source->filename ); output( "%s.%s: %s\n", obj, object_extensions.str[i], source->filename );
if (strstr( obj_ext->extension, "cross" )) if (strstr( object_extensions.str[i], "cross" ))
output( "\t$(CROSSCC) -c $(ALLCROSSCFLAGS) -o $@ %s\n", source->filename ); output( "\t$(CROSSCC) -c $(ALLCROSSCFLAGS) -o $@ %s\n", source->filename );
else else
output( "\t$(CC) -c $(ALLCFLAGS) -o $@ %s\n", source->filename ); output( "\t$(CC) -c $(ALLCFLAGS) -o $@ %s\n", source->filename );
...@@ -1321,8 +1289,8 @@ static void output_sources(void) ...@@ -1321,8 +1289,8 @@ static void output_sources(void)
output( "%s.ok:\n", obj ); output( "%s.ok:\n", obj );
output( "\t$(RUNTEST) $(RUNTESTFLAGS) %s && touch $@\n", obj ); output( "\t$(RUNTEST) $(RUNTESTFLAGS) %s && touch $@\n", obj );
} }
LIST_FOR_EACH_ENTRY( obj_ext, &object_extensions, struct object_extension, entry ) for (i = 0; i < object_extensions.count; i++)
column += output( "%s.%s ", obj, obj_ext->extension ); column += output( "%s.%s ", obj, object_extensions.str[i] );
if (source->flags & FLAG_C_IMPLIB) column += output( "%s.cross.o", obj ); if (source->flags & FLAG_C_IMPLIB) column += output( "%s.cross.o", obj );
column += output( ":" ); column += output( ":" );
} }
...@@ -1498,7 +1466,7 @@ static void parse_option( const char *opt ) ...@@ -1498,7 +1466,7 @@ static void parse_option( const char *opt )
switch(opt[1]) switch(opt[1])
{ {
case 'I': case 'I':
if (opt[2]) add_include_path( opt + 2 ); if (opt[2]) strarray_add( &paths, xstrdup( opt + 2 ));
break; break;
case 'C': case 'C':
src_dir = opt + 2; src_dir = opt + 2;
...@@ -1523,7 +1491,7 @@ static void parse_option( const char *opt ) ...@@ -1523,7 +1491,7 @@ static void parse_option( const char *opt )
else Separator = NULL; else Separator = NULL;
break; break;
case 'x': case 'x':
if (opt[2]) add_object_extension( opt + 2 ); if (opt[2]) strarray_add( &object_extensions, xstrdup( opt + 2 ));
break; break;
default: default:
fprintf( stderr, "Unknown option '%s'\n%s", opt, Usage ); fprintf( stderr, "Unknown option '%s'\n%s", opt, Usage );
...@@ -1538,7 +1506,6 @@ static void parse_option( const char *opt ) ...@@ -1538,7 +1506,6 @@ static void parse_option( const char *opt )
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {
struct incl_file *pFile; struct incl_file *pFile;
struct incl_path *path, *next;
int i, j; int i, j;
i = 1; i = 1;
...@@ -1571,22 +1538,11 @@ int main( int argc, char *argv[] ) ...@@ -1571,22 +1538,11 @@ int main( int argc, char *argv[] )
if (src_dir && !strcmp( src_dir, "." )) src_dir = NULL; if (src_dir && !strcmp( src_dir, "." )) src_dir = NULL;
if (top_src_dir && top_obj_dir && !strcmp( top_src_dir, top_obj_dir )) top_src_dir = NULL; if (top_src_dir && top_obj_dir && !strcmp( top_src_dir, top_obj_dir )) top_src_dir = NULL;
/* set the default extension list for object files */ if (top_src_dir) strarray_insert( &paths, 0, strmake( "%s/include", top_src_dir ));
if (list_empty( &object_extensions )) if (top_obj_dir) strarray_insert( &paths, 0, strmake( "%s/include", top_obj_dir ));
add_object_extension( "o" );
/* get rid of absolute paths that don't point into the source dir */ /* set the default extension list for object files */
LIST_FOR_EACH_ENTRY_SAFE( path, next, &paths, struct incl_path, entry ) if (!object_extensions.count) strarray_add( &object_extensions, "o" );
{
if (path->name[0] != '/') continue;
if (top_src_dir)
{
if (!strncmp( path->name, top_src_dir, strlen(top_src_dir) ) &&
path->name[strlen(top_src_dir)] == '/') continue;
}
list_remove( &path->entry );
free( path );
}
for (i = 1; i < argc; i++) add_src_file( argv[i] ); for (i = 1; i < argc; i++) add_src_file( argv[i] );
add_generated_sources(); add_generated_sources();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment