Module: wine Branch: refs/heads/master Commit: ded32d5194eede2aa2f41c1554584c5e7dfdefe9 URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=ded32d5194eede2aa2f41c15...
Author: Alexandre Julliard julliard@winehq.org Date: Tue Aug 1 12:37:18 2006 +0200
makedep: Always search for includes in the standard directories, even without -I option.
---
Make.rules.in | 2 - tools/makedep.c | 115 ++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 81 insertions(+), 36 deletions(-)
diff --git a/Make.rules.in b/Make.rules.in index 6ba20df..57e6ba7 100644 --- a/Make.rules.in +++ b/Make.rules.in @@ -203,7 +203,7 @@ # Rules for dependencies cd `dirname $@` && $(MAKE) depend
depend: $(IDL_SRCS:.idl=.h) $(SUBDIRS:%=%/__depend__) - $(MAKEDEP) -C$(SRCDIR) -S$(TOPSRCDIR) -T$(TOPOBJDIR) $(INCLUDES) $(C_SRCS) $(C_SRCS16) $(RC_SRCS) $(RC_SRCS16) $(MC_SRCS) $(IDL_SRCS) $(EXTRA_SRCS) + $(MAKEDEP) -C$(SRCDIR) -S$(TOPSRCDIR) -T$(TOPOBJDIR) $(EXTRAINCL) $(C_SRCS) $(C_SRCS16) $(RC_SRCS) $(RC_SRCS16) $(MC_SRCS) $(IDL_SRCS) $(EXTRA_SRCS)
.PHONY: depend $(SUBDIRS:%=%/__depend__)
diff --git a/tools/makedep.c b/tools/makedep.c index dd12380..0b9fa67 100644 --- a/tools/makedep.c +++ b/tools/makedep.c @@ -128,6 +128,29 @@ static char *xstrdup( const char *str )
/******************************************************************* + * strmake + */ +char *strmake( const char* fmt, ... ) +{ + int n; + size_t size = 100; + va_list ap; + + for (;;) + { + char *p = xmalloc (size); + va_start(ap, fmt); + n = vsnprintf (p, size, fmt, ap); + va_end(ap); + if (n == -1) size *= 2; + else if ((size_t)n >= size) size = n + 1; + else return p; + free(p); + } +} + + +/******************************************************************* * get_extension */ static char *get_extension( char *filename ) @@ -305,10 +328,7 @@ static FILE *open_src_file( INCL_FILE *p /* now try in source dir */ if (src_dir) { - pFile->filename = xmalloc( strlen(src_dir) + strlen(pFile->name) + 2 ); - strcpy( pFile->filename, src_dir ); - strcat( pFile->filename, "/" ); - strcat( pFile->filename, pFile->name ); + pFile->filename = strmake( "%s/%s", src_dir, pFile->name ); file = fopen( pFile->filename, "r" ); } if (!file) @@ -326,52 +346,73 @@ static FILE *open_src_file( INCL_FILE *p static FILE *open_include_file( INCL_FILE *pFile ) { FILE *file = NULL; + char *filename, *p; INCL_PATH *path;
errno = ENOENT;
+ /* first try name as is */ + if ((file = fopen( pFile->name, "r" ))) + { + pFile->filename = xstrdup( pFile->name ); + return file; + } + + /* now try in source dir */ + if (src_dir) + { + filename = strmake( "%s/%s", src_dir, pFile->name ); + if ((file = fopen( filename, "r" ))) goto found; + 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 */ LIST_FOR_EACH_ENTRY( path, &paths, INCL_PATH, entry ) { - char *filename = xmalloc(strlen(path->name) + strlen(pFile->name) + 2); - strcpy( filename, path->name ); - strcat( filename, "/" ); - strcat( filename, pFile->name ); - if ((file = fopen( filename, "r" ))) - { - pFile->filename = filename; - break; - } + filename = strmake( "%s/%s", path->name, pFile->name ); + if ((file = fopen( filename, "r" ))) goto found; free( filename ); } - if (!file && pFile->system) return NULL; /* ignore system files we cannot find */ + if (pFile->system) return NULL; /* ignore system files we cannot find */
/* try in src file directory */ - if (!file) + if ((p = strrchr(pFile->included_by->filename, '/'))) { - char *p = strrchr(pFile->included_by->filename, '/'); - if (p) - { - int l = p - pFile->included_by->filename + 1; - char *filename = xmalloc(l + strlen(pFile->name) + 1); - memcpy( filename, pFile->included_by->filename, l ); - strcpy( filename + l, pFile->name ); - if ((file = fopen( filename, "r" ))) pFile->filename = filename; - else free( filename ); - } + int l = p - pFile->included_by->filename + 1; + filename = xmalloc(l + strlen(pFile->name) + 1); + memcpy( filename, pFile->included_by->filename, l ); + strcpy( filename + l, pFile->name ); + if ((file = fopen( filename, "r" ))) goto found; + free( filename ); }
- if (!file) + if (pFile->included_by->system) return NULL; /* ignore if included by a system file */ + + perror( pFile->name ); + while (pFile->included_by) { - if (pFile->included_by->system) return NULL; /* ignore if included by a system file */ - perror( pFile->name ); - while (pFile->included_by) - { - fprintf( stderr, " %s was first included from %s:%d\n", - pFile->name, pFile->included_by->name, pFile->included_line ); - pFile = pFile->included_by; - } - exit(1); + fprintf( stderr, " %s was first included from %s:%d\n", + pFile->name, pFile->included_by->name, pFile->included_line ); + pFile = pFile->included_by; } + exit(1); + +found: + pFile->filename = filename; return file; }
@@ -630,6 +671,10 @@ int main( int argc, char *argv[] ) else i++; }
+ /* ignore redundant source paths */ + 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; + /* get rid of absolute paths that don't point into the source dir */ LIST_FOR_EACH_ENTRY_SAFE( path, next, &paths, INCL_PATH, entry ) {