1996-10-23 09:59:13 -07:00
|
|
|
/*
|
|
|
|
* Generate include file dependencies
|
|
|
|
*
|
2013-12-24 03:37:52 -07:00
|
|
|
* Copyright 1996, 2013 Alexandre Julliard
|
2002-03-09 16:29:33 -07:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 05:49:52 -07:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1996-10-23 09:59:13 -07:00
|
|
|
*/
|
|
|
|
|
2002-04-26 12:05:15 -07:00
|
|
|
#include "config.h"
|
2003-03-20 14:08:28 -07:00
|
|
|
#define NO_LIBWINE_PORT
|
2002-04-26 12:05:15 -07:00
|
|
|
#include "wine/port.h"
|
|
|
|
|
2006-08-01 03:16:29 -07:00
|
|
|
#include <assert.h>
|
1996-10-23 09:59:13 -07:00
|
|
|
#include <ctype.h>
|
2006-08-01 03:13:57 -07:00
|
|
|
#include <errno.h>
|
1996-10-23 09:59:13 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2004-04-06 21:00:16 -07:00
|
|
|
#include <stdarg.h>
|
1996-10-23 09:59:13 -07:00
|
|
|
#include <string.h>
|
2002-08-17 11:28:43 -07:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2006-08-01 03:13:57 -07:00
|
|
|
#include "wine/list.h"
|
1996-10-23 09:59:13 -07:00
|
|
|
|
|
|
|
/* Max first-level includes per file */
|
2002-02-15 12:57:27 -07:00
|
|
|
#define MAX_INCLUDES 200
|
1996-10-23 09:59:13 -07:00
|
|
|
|
2013-10-14 01:51:37 -07:00
|
|
|
struct incl_file
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
2006-08-01 03:13:57 -07:00
|
|
|
struct list entry;
|
1996-10-23 09:59:13 -07:00
|
|
|
char *name;
|
|
|
|
char *filename;
|
2006-09-10 13:04:42 -07:00
|
|
|
char *sourcename; /* source file name for generated headers */
|
2013-10-14 01:51:37 -07:00
|
|
|
struct incl_file *included_by; /* file that included this one */
|
2000-11-05 22:32:59 -07:00
|
|
|
int included_line; /* line where this file was included */
|
2013-11-04 09:39:30 -07:00
|
|
|
unsigned int flags; /* flags (see below) */
|
2013-10-14 01:51:37 -07:00
|
|
|
struct incl_file *owner;
|
|
|
|
struct incl_file *files[MAX_INCLUDES];
|
|
|
|
};
|
1996-10-23 09:59:13 -07:00
|
|
|
|
2013-12-24 12:01:53 -07:00
|
|
|
#define FLAG_SYSTEM 0x0001 /* is it a system include (#include <name>) */
|
|
|
|
#define FLAG_IDL_PROXY 0x0002 /* generates a proxy (_p.c) file */
|
|
|
|
#define FLAG_IDL_CLIENT 0x0004 /* generates a client (_c.c) file */
|
|
|
|
#define FLAG_IDL_SERVER 0x0008 /* generates a server (_s.c) file */
|
|
|
|
#define FLAG_IDL_IDENT 0x0010 /* generates an ident (_i.c) file */
|
|
|
|
#define FLAG_IDL_REGISTER 0x0020 /* generates a registration (_r.res) file */
|
|
|
|
#define FLAG_IDL_TYPELIB 0x0040 /* generates a typelib (.tlb) file */
|
|
|
|
#define FLAG_IDL_REGTYPELIB 0x0080 /* generates a registered typelib (_t.res) file */
|
|
|
|
#define FLAG_IDL_HEADER 0x0100 /* generates a header (.h) file */
|
|
|
|
#define FLAG_RC_PO 0x0200 /* rc file contains translations */
|
|
|
|
#define FLAG_C_IMPLIB 0x0400 /* file is part of an import library */
|
2013-11-04 09:39:30 -07:00
|
|
|
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
unsigned int flag;
|
|
|
|
const char *ext;
|
|
|
|
} idl_outputs[] =
|
|
|
|
{
|
2013-12-24 13:12:08 -07:00
|
|
|
{ FLAG_IDL_TYPELIB, ".tlb" },
|
|
|
|
{ FLAG_IDL_REGTYPELIB, "_t.res" },
|
|
|
|
{ FLAG_IDL_CLIENT, "_c.c" },
|
|
|
|
{ FLAG_IDL_IDENT, "_i.c" },
|
|
|
|
{ FLAG_IDL_PROXY, "_p.c" },
|
|
|
|
{ FLAG_IDL_SERVER, "_s.c" },
|
|
|
|
{ FLAG_IDL_REGISTER, "_r.res" },
|
|
|
|
{ FLAG_IDL_HEADER, ".h" }
|
2013-11-04 09:39:30 -07:00
|
|
|
};
|
|
|
|
|
2006-08-01 03:13:57 -07:00
|
|
|
static struct list sources = LIST_INIT(sources);
|
|
|
|
static struct list includes = LIST_INIT(includes);
|
1996-10-23 09:59:13 -07:00
|
|
|
|
2013-11-09 10:57:00 -07:00
|
|
|
struct strarray
|
|
|
|
{
|
|
|
|
unsigned int count; /* strings in use */
|
|
|
|
unsigned int size; /* total allocated size */
|
|
|
|
const char **str;
|
|
|
|
};
|
|
|
|
|
2013-12-24 03:37:52 -07:00
|
|
|
static const struct strarray empty_strarray;
|
|
|
|
|
2013-11-30 04:50:30 -07:00
|
|
|
static struct strarray include_args;
|
2013-11-19 03:36:25 -07:00
|
|
|
static struct strarray object_extensions;
|
2013-12-26 11:25:57 -07:00
|
|
|
static struct strarray make_vars;
|
2013-12-26 11:26:29 -07:00
|
|
|
static struct strarray cmdline_vars;
|
2013-12-17 09:10:28 -07:00
|
|
|
|
|
|
|
static const char *base_dir = ".";
|
2006-08-01 03:27:22 -07:00
|
|
|
static const char *src_dir;
|
|
|
|
static const char *top_src_dir;
|
|
|
|
static const char *top_obj_dir;
|
2013-11-12 03:03:09 -07:00
|
|
|
static const char *parent_dir;
|
2013-12-17 09:10:28 -07:00
|
|
|
static const char *makefile_name = "Makefile";
|
1996-10-23 09:59:13 -07:00
|
|
|
static const char *Separator = "### Dependencies";
|
2013-10-14 02:11:07 -07:00
|
|
|
static const char *input_file_name;
|
2013-12-17 09:10:28 -07:00
|
|
|
static int parse_makefile_mode;
|
2013-11-08 13:11:59 -07:00
|
|
|
static int relative_dir_mode;
|
2006-08-01 03:16:29 -07:00
|
|
|
static int input_line;
|
2013-10-14 02:11:07 -07:00
|
|
|
static FILE *output_file;
|
1996-10-23 09:59:13 -07:00
|
|
|
|
|
|
|
static const char Usage[] =
|
2013-10-14 02:11:07 -07:00
|
|
|
"Usage: makedep [options] [files]\n"
|
1996-10-23 09:59:13 -07:00
|
|
|
"Options:\n"
|
2013-11-08 13:11:59 -07:00
|
|
|
" -Idir Search for include files in directory 'dir'\n"
|
|
|
|
" -Cdir Search for source files in directory 'dir'\n"
|
|
|
|
" -Sdir Set the top source directory\n"
|
|
|
|
" -Tdir Set the top object directory\n"
|
2013-11-12 03:03:09 -07:00
|
|
|
" -Pdir Set the parent source directory\n"
|
2013-12-17 09:10:28 -07:00
|
|
|
" -M dirs Parse the makefiles from the specified directories\n"
|
2013-11-08 13:11:59 -07:00
|
|
|
" -R from to Compute the relative path between two directories\n"
|
|
|
|
" -fxxx Store output in file 'xxx' (default: Makefile)\n"
|
|
|
|
" -sxxx Use 'xxx' as separator (default: \"### Dependencies\")\n";
|
1996-10-23 09:59:13 -07:00
|
|
|
|
|
|
|
|
2013-10-14 02:11:07 -07:00
|
|
|
#ifndef __GNUC__
|
|
|
|
#define __attribute__(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void fatal_error( const char *msg, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
|
|
|
|
static void fatal_perror( const char *msg, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
|
|
|
|
static int output( const char *format, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
|
2013-10-14 15:14:51 -07:00
|
|
|
static char *strmake( const char* fmt, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
|
2013-10-14 02:11:07 -07:00
|
|
|
|
2004-04-06 21:00:16 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* fatal_error
|
|
|
|
*/
|
|
|
|
static void fatal_error( const char *msg, ... )
|
|
|
|
{
|
|
|
|
va_list valist;
|
|
|
|
va_start( valist, msg );
|
2013-10-14 02:11:07 -07:00
|
|
|
if (input_file_name)
|
|
|
|
{
|
|
|
|
fprintf( stderr, "%s:", input_file_name );
|
|
|
|
if (input_line) fprintf( stderr, "%d:", input_line );
|
|
|
|
fprintf( stderr, " error: " );
|
|
|
|
}
|
|
|
|
else fprintf( stderr, "makedep: error: " );
|
2004-04-06 21:00:16 -07:00
|
|
|
vfprintf( stderr, msg, valist );
|
|
|
|
va_end( valist );
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-14 02:11:07 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* fatal_perror
|
|
|
|
*/
|
|
|
|
static void fatal_perror( const char *msg, ... )
|
|
|
|
{
|
|
|
|
va_list valist;
|
|
|
|
va_start( valist, msg );
|
|
|
|
if (input_file_name)
|
|
|
|
{
|
|
|
|
fprintf( stderr, "%s:", input_file_name );
|
|
|
|
if (input_line) fprintf( stderr, "%d:", input_line );
|
2013-11-04 09:39:30 -07:00
|
|
|
fprintf( stderr, " error: " );
|
2013-10-14 02:11:07 -07:00
|
|
|
}
|
2013-11-04 09:39:30 -07:00
|
|
|
else fprintf( stderr, "makedep: error: " );
|
|
|
|
vfprintf( stderr, msg, valist );
|
2013-10-14 02:11:07 -07:00
|
|
|
perror( " " );
|
|
|
|
va_end( valist );
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-10-23 09:59:13 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* xmalloc
|
|
|
|
*/
|
2006-08-01 03:16:29 -07:00
|
|
|
static void *xmalloc( size_t size )
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
|
|
|
void *res;
|
|
|
|
if (!(res = malloc (size ? size : 1)))
|
2013-10-14 02:11:07 -07:00
|
|
|
fatal_error( "Virtual memory exhausted.\n" );
|
1996-10-23 09:59:13 -07:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-01 03:16:29 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* xrealloc
|
|
|
|
*/
|
2006-09-10 13:04:42 -07:00
|
|
|
static void *xrealloc (void *ptr, size_t size)
|
2006-08-01 03:16:29 -07:00
|
|
|
{
|
|
|
|
void *res;
|
|
|
|
assert( size );
|
|
|
|
if (!(res = realloc( ptr, size )))
|
2013-10-14 02:11:07 -07:00
|
|
|
fatal_error( "Virtual memory exhausted.\n" );
|
2006-08-01 03:16:29 -07:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
1996-10-23 09:59:13 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* xstrdup
|
|
|
|
*/
|
|
|
|
static char *xstrdup( const char *str )
|
|
|
|
{
|
|
|
|
char *res = strdup( str );
|
2013-10-14 02:11:07 -07:00
|
|
|
if (!res) fatal_error( "Virtual memory exhausted.\n" );
|
1996-10-23 09:59:13 -07:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-01 03:37:18 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* strmake
|
|
|
|
*/
|
2006-09-10 13:04:42 -07:00
|
|
|
static char *strmake( const char* fmt, ... )
|
2006-08-01 03:37:18 -07:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-10 13:04:42 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* strendswith
|
|
|
|
*/
|
|
|
|
static int strendswith( const char* str, const char* end )
|
|
|
|
{
|
|
|
|
int l = strlen(str);
|
|
|
|
int m = strlen(end);
|
|
|
|
|
|
|
|
return l >= m && strcmp(str + l - m, end) == 0;
|
|
|
|
}
|
|
|
|
|
2013-10-14 02:11:07 -07:00
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* output
|
|
|
|
*/
|
|
|
|
static int output( const char *format, ... )
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
va_list valist;
|
|
|
|
|
|
|
|
va_start( valist, format );
|
|
|
|
ret = vfprintf( output_file, format, valist );
|
|
|
|
va_end( valist );
|
|
|
|
if (ret < 0) fatal_perror( "output" );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-09 10:57:00 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* strarray_add
|
|
|
|
*/
|
|
|
|
static void strarray_add( struct strarray *array, const char *str )
|
|
|
|
{
|
|
|
|
if (array->count == array->size)
|
|
|
|
{
|
|
|
|
if (array->size) array->size *= 2;
|
|
|
|
else array->size = 16;
|
|
|
|
array->str = xrealloc( array->str, sizeof(array->str[0]) * array->size );
|
|
|
|
}
|
|
|
|
array->str[array->count++] = str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-24 03:37:52 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* strarray_addall
|
|
|
|
*/
|
|
|
|
static void strarray_addall( struct strarray *array, const struct strarray *added )
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < added->count; i++) strarray_add( array, added->str[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-19 03:36:25 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-12 13:10:55 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* strarray_add_uniq
|
|
|
|
*/
|
|
|
|
static void strarray_add_uniq( struct strarray *array, const char *str )
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < array->count; i++) if (!strcmp( array->str[i], str )) return;
|
|
|
|
strarray_add( array, str );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-14 02:11:07 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* output_filename
|
|
|
|
*/
|
|
|
|
static void output_filename( const char *name, int *column )
|
|
|
|
{
|
|
|
|
if (*column + strlen(name) + 1 > 100)
|
|
|
|
{
|
2013-12-24 03:37:52 -07:00
|
|
|
output( " \\\n " );
|
|
|
|
*column = 2;
|
2013-10-14 02:11:07 -07:00
|
|
|
}
|
2013-12-24 03:37:52 -07:00
|
|
|
else if (*column) *column += output( " " );
|
|
|
|
*column += output( "%s", name );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* output_filenames
|
|
|
|
*/
|
|
|
|
static void output_filenames( struct strarray *array, int *column )
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < array->count; i++) output_filename( array->str[i], column );
|
2013-10-14 02:11:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-10 17:38:56 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* get_extension
|
|
|
|
*/
|
|
|
|
static char *get_extension( char *filename )
|
|
|
|
{
|
|
|
|
char *ext = strrchr( filename, '.' );
|
|
|
|
if (ext && strchr( ext, '/' )) ext = NULL;
|
|
|
|
return ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-15 11:29:09 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* replace_extension
|
|
|
|
*/
|
2013-12-24 03:27:35 -07:00
|
|
|
static char *replace_extension( const char *name, const char *old_ext, const char *new_ext )
|
2013-10-15 11:29:09 -07:00
|
|
|
{
|
2013-12-24 03:27:35 -07:00
|
|
|
char *ret;
|
|
|
|
int name_len = strlen( name );
|
|
|
|
int ext_len = strlen( old_ext );
|
|
|
|
|
|
|
|
if (name_len >= ext_len && !strcmp( name + name_len - ext_len, old_ext )) name_len -= ext_len;
|
|
|
|
ret = xmalloc( name_len + strlen( new_ext ) + 1 );
|
|
|
|
memcpy( ret, name, name_len );
|
|
|
|
strcpy( ret + name_len, new_ext );
|
2013-10-15 11:29:09 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-24 03:37:52 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* strarray_replace_extension
|
|
|
|
*/
|
|
|
|
static struct strarray strarray_replace_extension( const struct strarray *array,
|
|
|
|
const char *old_ext, const char *new_ext )
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
struct strarray ret;
|
|
|
|
|
|
|
|
ret.count = ret.size = array->count;
|
|
|
|
ret.str = xmalloc( sizeof(ret.str[0]) * ret.size );
|
|
|
|
for (i = 0; i < array->count; i++) ret.str[i] = replace_extension( array->str[i], old_ext, new_ext );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-17 09:10:28 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* replace_substr
|
|
|
|
*/
|
|
|
|
static char *replace_substr( const char *str, const char *start, unsigned int len, const char *replace )
|
|
|
|
{
|
|
|
|
unsigned int pos = start - str;
|
|
|
|
char *ret = xmalloc( pos + strlen(replace) + strlen(start + len) + 1 );
|
|
|
|
memcpy( ret, str, pos );
|
|
|
|
strcpy( ret + pos, replace );
|
|
|
|
strcat( ret + pos, start + len );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-08 13:11:59 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* get_relative_path
|
|
|
|
*
|
|
|
|
* Determine where the destination path is located relative to the 'from' path.
|
|
|
|
*/
|
|
|
|
static char *get_relative_path( const char *from, const char *dest )
|
|
|
|
{
|
|
|
|
const char *start;
|
|
|
|
char *ret, *p;
|
|
|
|
unsigned int dotdots = 0;
|
|
|
|
|
|
|
|
/* a path of "." is equivalent to an empty path */
|
|
|
|
if (!strcmp( from, "." )) from = "";
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
while (*from == '/') from++;
|
|
|
|
while (*dest == '/') dest++;
|
|
|
|
start = dest; /* save start of next path element */
|
|
|
|
if (!*from) break;
|
|
|
|
|
|
|
|
while (*from && *from != '/' && *from == *dest) { from++; dest++; }
|
|
|
|
if ((!*from || *from == '/') && (!*dest || *dest == '/')) continue;
|
|
|
|
|
|
|
|
/* count remaining elements in 'from' */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
dotdots++;
|
|
|
|
while (*from && *from != '/') from++;
|
|
|
|
while (*from == '/') from++;
|
|
|
|
}
|
|
|
|
while (*from);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!start[0] && !dotdots) return NULL; /* empty path */
|
|
|
|
|
|
|
|
ret = xmalloc( 3 * dotdots + strlen( start ) + 1 );
|
|
|
|
for (p = ret; dotdots; dotdots--, p += 3) memcpy( p, "../", 3 );
|
|
|
|
|
|
|
|
if (start[0]) strcpy( p, start );
|
|
|
|
else p[-1] = 0; /* remove trailing slash */
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-17 09:10:28 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* init_paths
|
|
|
|
*/
|
|
|
|
static void init_paths(void)
|
|
|
|
{
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
if (top_src_dir) strarray_insert( &include_args, 0, strmake( "-I%s/include", top_src_dir ));
|
|
|
|
else if (top_obj_dir) strarray_insert( &include_args, 0, strmake( "-I%s/include", top_obj_dir ));
|
|
|
|
|
|
|
|
/* set the default extension list for object files */
|
|
|
|
if (!object_extensions.count) strarray_add( &object_extensions, "o" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-01 03:16:29 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* get_line
|
|
|
|
*/
|
|
|
|
static char *get_line( FILE *file )
|
|
|
|
{
|
|
|
|
static char *buffer;
|
|
|
|
static unsigned int size;
|
|
|
|
|
|
|
|
if (!size)
|
|
|
|
{
|
|
|
|
size = 1024;
|
|
|
|
buffer = xmalloc( size );
|
|
|
|
}
|
|
|
|
if (!fgets( buffer, size, file )) return NULL;
|
|
|
|
input_line++;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
char *p = buffer + strlen(buffer);
|
|
|
|
/* if line is larger than buffer, resize buffer */
|
|
|
|
while (p == buffer + size - 1 && p[-1] != '\n')
|
|
|
|
{
|
|
|
|
buffer = xrealloc( buffer, size * 2 );
|
2010-04-02 10:06:31 -07:00
|
|
|
if (!fgets( buffer + size - 1, size + 1, file )) break;
|
2006-08-01 03:16:29 -07:00
|
|
|
p = buffer + strlen(buffer);
|
|
|
|
size *= 2;
|
|
|
|
}
|
|
|
|
if (p > buffer && p[-1] == '\n')
|
|
|
|
{
|
|
|
|
*(--p) = 0;
|
|
|
|
if (p > buffer && p[-1] == '\r') *(--p) = 0;
|
|
|
|
if (p > buffer && p[-1] == '\\')
|
|
|
|
{
|
|
|
|
*(--p) = 0;
|
|
|
|
/* line ends in backslash, read continuation line */
|
2010-04-02 10:06:31 -07:00
|
|
|
if (!fgets( p, size - (p - buffer), file )) return buffer;
|
2006-08-01 03:16:29 -07:00
|
|
|
input_line++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-16 08:19:07 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* find_src_file
|
|
|
|
*/
|
2013-10-14 01:51:37 -07:00
|
|
|
static struct incl_file *find_src_file( const char *name )
|
2006-10-16 08:19:07 -07:00
|
|
|
{
|
2013-10-14 01:51:37 -07:00
|
|
|
struct incl_file *file;
|
2006-10-16 08:19:07 -07:00
|
|
|
|
2013-10-14 01:51:37 -07:00
|
|
|
LIST_FOR_EACH_ENTRY( file, &sources, struct incl_file, entry )
|
2006-10-16 08:19:07 -07:00
|
|
|
if (!strcmp( name, file->name )) return file;
|
|
|
|
return NULL;
|
|
|
|
}
|
1996-10-23 09:59:13 -07:00
|
|
|
|
2010-03-16 05:27:51 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* find_include_file
|
|
|
|
*/
|
2013-10-14 01:51:37 -07:00
|
|
|
static struct incl_file *find_include_file( const char *name )
|
2010-03-16 05:27:51 -07:00
|
|
|
{
|
2013-10-14 01:51:37 -07:00
|
|
|
struct incl_file *file;
|
2010-03-16 05:27:51 -07:00
|
|
|
|
2013-10-14 01:51:37 -07:00
|
|
|
LIST_FOR_EACH_ENTRY( file, &includes, struct incl_file, entry )
|
2010-03-16 05:27:51 -07:00
|
|
|
if (!strcmp( name, file->name )) return file;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1996-10-23 09:59:13 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* add_include
|
|
|
|
*
|
|
|
|
* Add an include file if it doesn't already exists.
|
|
|
|
*/
|
2013-10-14 02:11:07 -07:00
|
|
|
static struct incl_file *add_include( struct incl_file *pFile, const char *name, int system )
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
2013-10-14 01:51:37 -07:00
|
|
|
struct incl_file *include;
|
2004-04-06 21:00:16 -07:00
|
|
|
char *ext;
|
1996-10-23 09:59:13 -07:00
|
|
|
int pos;
|
|
|
|
|
|
|
|
for (pos = 0; pos < MAX_INCLUDES; pos++) if (!pFile->files[pos]) break;
|
|
|
|
if (pos >= MAX_INCLUDES)
|
2013-10-14 02:11:07 -07:00
|
|
|
fatal_error( "too many included files, please fix MAX_INCLUDES\n" );
|
2004-04-06 21:00:16 -07:00
|
|
|
|
|
|
|
/* enforce some rules for the Wine tree */
|
|
|
|
|
|
|
|
if (!memcmp( name, "../", 3 ))
|
2013-10-14 02:11:07 -07:00
|
|
|
fatal_error( "#include directive with relative path not allowed\n" );
|
2004-04-06 21:00:16 -07:00
|
|
|
|
|
|
|
if (!strcmp( name, "config.h" ))
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
2004-04-06 21:00:16 -07:00
|
|
|
if ((ext = strrchr( pFile->filename, '.' )) && !strcmp( ext, ".h" ))
|
2013-10-14 02:11:07 -07:00
|
|
|
fatal_error( "config.h must not be included by a header file\n" );
|
2004-04-06 21:00:16 -07:00
|
|
|
if (pos)
|
2013-10-14 02:11:07 -07:00
|
|
|
fatal_error( "config.h must be included before anything else\n" );
|
2004-04-06 21:00:16 -07:00
|
|
|
}
|
|
|
|
else if (!strcmp( name, "wine/port.h" ))
|
|
|
|
{
|
|
|
|
if ((ext = strrchr( pFile->filename, '.' )) && !strcmp( ext, ".h" ))
|
2013-10-14 02:11:07 -07:00
|
|
|
fatal_error( "wine/port.h must not be included by a header file\n" );
|
|
|
|
if (!pos) fatal_error( "config.h must be included before wine/port.h\n" );
|
2004-04-06 21:00:16 -07:00
|
|
|
if (pos > 1)
|
2013-10-14 02:11:07 -07:00
|
|
|
fatal_error( "wine/port.h must be included before everything except config.h\n" );
|
2004-04-06 21:00:16 -07:00
|
|
|
if (strcmp( pFile->files[0]->name, "config.h" ))
|
2013-10-14 02:11:07 -07:00
|
|
|
fatal_error( "config.h must be included before wine/port.h\n" );
|
1996-10-23 09:59:13 -07:00
|
|
|
}
|
|
|
|
|
2013-10-14 01:51:37 -07:00
|
|
|
LIST_FOR_EACH_ENTRY( include, &includes, struct incl_file, entry )
|
2006-08-01 03:13:57 -07:00
|
|
|
if (!strcmp( name, include->name )) goto found;
|
|
|
|
|
2013-10-14 01:51:37 -07:00
|
|
|
include = xmalloc( sizeof(*include) );
|
|
|
|
memset( include, 0, sizeof(*include) );
|
2006-08-01 03:13:57 -07:00
|
|
|
include->name = xstrdup(name);
|
|
|
|
include->included_by = pFile;
|
2013-10-14 02:11:07 -07:00
|
|
|
include->included_line = input_line;
|
2013-11-04 09:39:30 -07:00
|
|
|
if (system) include->flags |= FLAG_SYSTEM;
|
2006-08-01 03:13:57 -07:00
|
|
|
list_add_tail( &includes, &include->entry );
|
|
|
|
found:
|
|
|
|
pFile->files[pos] = include;
|
|
|
|
return include;
|
1996-10-23 09:59:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-17 09:10:28 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* open_file
|
|
|
|
*/
|
|
|
|
static FILE *open_file( const char *path )
|
|
|
|
{
|
|
|
|
FILE *ret;
|
|
|
|
|
|
|
|
if (path[0] != '/' && strcmp( base_dir, "." ))
|
|
|
|
{
|
|
|
|
char *full_path = strmake( "%s/%s", base_dir, path );
|
|
|
|
ret = fopen( full_path, "r" );
|
|
|
|
free( full_path );
|
|
|
|
}
|
|
|
|
else ret = fopen( path, "r" );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
1996-10-23 09:59:13 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* open_src_file
|
|
|
|
*/
|
2013-10-14 01:51:37 -07:00
|
|
|
static FILE *open_src_file( struct incl_file *pFile )
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
|
2002-12-10 18:30:14 -07:00
|
|
|
/* first try name as is */
|
2013-12-17 09:10:28 -07:00
|
|
|
if ((file = open_file( pFile->name )))
|
2002-12-10 18:30:14 -07:00
|
|
|
{
|
|
|
|
pFile->filename = xstrdup( pFile->name );
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
/* now try in source dir */
|
2006-08-01 03:27:22 -07:00
|
|
|
if (src_dir)
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
2006-08-01 03:37:18 -07:00
|
|
|
pFile->filename = strmake( "%s/%s", src_dir, pFile->name );
|
2013-12-17 09:10:28 -07:00
|
|
|
file = open_file( pFile->filename );
|
1996-10-23 09:59:13 -07:00
|
|
|
}
|
2013-11-12 03:03:09 -07:00
|
|
|
/* now try parent dir */
|
|
|
|
if (!file && parent_dir)
|
|
|
|
{
|
|
|
|
if (src_dir)
|
|
|
|
pFile->filename = strmake( "%s/%s/%s", src_dir, parent_dir, pFile->name );
|
|
|
|
else
|
|
|
|
pFile->filename = strmake( "%s/%s", parent_dir, pFile->name );
|
2013-12-17 09:10:28 -07:00
|
|
|
file = open_file( pFile->filename );
|
2013-11-12 03:03:09 -07:00
|
|
|
}
|
2013-10-14 02:11:07 -07:00
|
|
|
if (!file) fatal_perror( "open %s", pFile->name );
|
1996-10-23 09:59:13 -07:00
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* open_include_file
|
|
|
|
*/
|
2013-10-14 01:51:37 -07:00
|
|
|
static FILE *open_include_file( struct incl_file *pFile )
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
|
|
|
FILE *file = NULL;
|
2006-08-01 03:37:18 -07:00
|
|
|
char *filename, *p;
|
2013-12-02 15:28:58 -07:00
|
|
|
unsigned int i, len;
|
1996-10-23 09:59:13 -07:00
|
|
|
|
2006-08-01 03:13:57 -07:00
|
|
|
errno = ENOENT;
|
|
|
|
|
2006-09-10 13:04:42 -07:00
|
|
|
/* check for generated bison header */
|
|
|
|
|
|
|
|
if (strendswith( pFile->name, ".tab.h" ))
|
|
|
|
{
|
2013-12-24 03:27:35 -07:00
|
|
|
filename = replace_extension( pFile->name, ".tab.h", ".y" );
|
2013-10-15 11:29:09 -07:00
|
|
|
if (src_dir) filename = strmake( "%s/%s", src_dir, filename );
|
2006-09-10 13:04:42 -07:00
|
|
|
|
2013-12-17 09:10:28 -07:00
|
|
|
if ((file = open_file( filename )))
|
2006-09-10 13:04:42 -07:00
|
|
|
{
|
|
|
|
pFile->sourcename = filename;
|
|
|
|
pFile->filename = xstrdup( pFile->name );
|
|
|
|
/* don't bother to parse it */
|
|
|
|
fclose( file );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
free( filename );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for corresponding idl file in source dir */
|
|
|
|
|
|
|
|
if (strendswith( pFile->name, ".h" ))
|
|
|
|
{
|
2013-12-24 03:27:35 -07:00
|
|
|
filename = replace_extension( pFile->name, ".h", ".idl" );
|
2013-10-15 11:29:09 -07:00
|
|
|
if (src_dir) filename = strmake( "%s/%s", src_dir, filename );
|
2006-09-10 13:04:42 -07:00
|
|
|
|
2013-12-17 09:10:28 -07:00
|
|
|
if ((file = open_file( filename )))
|
2006-09-10 13:04:42 -07:00
|
|
|
{
|
|
|
|
pFile->sourcename = filename;
|
|
|
|
pFile->filename = xstrdup( pFile->name );
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
free( filename );
|
|
|
|
}
|
|
|
|
|
2006-08-01 03:37:18 -07:00
|
|
|
/* now try in source dir */
|
|
|
|
if (src_dir)
|
|
|
|
filename = strmake( "%s/%s", src_dir, pFile->name );
|
2013-11-30 04:50:30 -07:00
|
|
|
else
|
|
|
|
filename = xstrdup( pFile->name );
|
2013-12-17 09:10:28 -07:00
|
|
|
if ((file = open_file( filename ))) goto found;
|
2013-11-30 04:50:30 -07:00
|
|
|
free( filename );
|
2006-08-01 03:37:18 -07:00
|
|
|
|
2013-11-12 03:03:09 -07:00
|
|
|
/* now try in parent source dir */
|
|
|
|
if (parent_dir)
|
|
|
|
{
|
|
|
|
if (src_dir)
|
|
|
|
filename = strmake( "%s/%s/%s", src_dir, parent_dir, pFile->name );
|
|
|
|
else
|
|
|
|
filename = strmake( "%s/%s", parent_dir, pFile->name );
|
2013-12-17 09:10:28 -07:00
|
|
|
if ((file = open_file( filename ))) goto found;
|
2013-11-12 03:03:09 -07:00
|
|
|
free( filename );
|
|
|
|
}
|
|
|
|
|
2006-09-10 13:04:42 -07:00
|
|
|
/* check for corresponding idl file in global includes */
|
|
|
|
|
|
|
|
if (strendswith( pFile->name, ".h" ))
|
|
|
|
{
|
2013-12-24 03:27:35 -07:00
|
|
|
filename = replace_extension( pFile->name, ".h", ".idl" );
|
2006-09-10 13:04:42 -07:00
|
|
|
if (top_src_dir)
|
2013-10-15 11:29:09 -07:00
|
|
|
filename = strmake( "%s/include/%s", top_src_dir, filename );
|
2006-09-10 13:04:42 -07:00
|
|
|
else if (top_obj_dir)
|
2013-10-15 11:29:09 -07:00
|
|
|
filename = strmake( "%s/include/%s", top_obj_dir, filename );
|
2006-09-10 13:04:42 -07:00
|
|
|
else
|
|
|
|
filename = NULL;
|
|
|
|
|
2013-12-17 09:10:28 -07:00
|
|
|
if (filename && (file = open_file( filename )))
|
2006-09-10 13:04:42 -07:00
|
|
|
{
|
|
|
|
pFile->sourcename = filename;
|
|
|
|
pFile->filename = strmake( "%s/include/%s", top_obj_dir, pFile->name );
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
free( filename );
|
|
|
|
}
|
|
|
|
|
2013-11-30 04:50:30 -07:00
|
|
|
/* check for corresponding .in file in global includes (for config.h.in) */
|
|
|
|
|
|
|
|
if (strendswith( pFile->name, ".h" ))
|
|
|
|
{
|
2013-12-24 03:27:35 -07:00
|
|
|
filename = replace_extension( pFile->name, ".h", ".h.in" );
|
2013-11-30 04:50:30 -07:00
|
|
|
if (top_src_dir)
|
|
|
|
filename = strmake( "%s/include/%s", top_src_dir, filename );
|
|
|
|
else if (top_obj_dir)
|
|
|
|
filename = strmake( "%s/include/%s", top_obj_dir, filename );
|
|
|
|
else
|
|
|
|
filename = NULL;
|
|
|
|
|
2013-12-17 09:10:28 -07:00
|
|
|
if (filename && (file = open_file( filename )))
|
2013-11-30 04:50:30 -07:00
|
|
|
{
|
|
|
|
pFile->sourcename = filename;
|
|
|
|
pFile->filename = strmake( "%s/include/%s", top_obj_dir, pFile->name );
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
free( filename );
|
|
|
|
}
|
|
|
|
|
2011-05-05 06:02:25 -07:00
|
|
|
/* check for corresponding .x file in global includes */
|
|
|
|
|
|
|
|
if (strendswith( pFile->name, "tmpl.h" ))
|
|
|
|
{
|
2013-12-24 03:27:35 -07:00
|
|
|
filename = replace_extension( pFile->name, ".h", ".x" );
|
2011-05-05 06:02:25 -07:00
|
|
|
if (top_src_dir)
|
2013-10-15 11:29:09 -07:00
|
|
|
filename = strmake( "%s/include/%s", top_src_dir, filename );
|
2011-05-05 06:02:25 -07:00
|
|
|
else if (top_obj_dir)
|
2013-10-15 11:29:09 -07:00
|
|
|
filename = strmake( "%s/include/%s", top_obj_dir, filename );
|
2011-05-05 06:02:25 -07:00
|
|
|
else
|
|
|
|
filename = NULL;
|
|
|
|
|
2013-12-17 09:10:28 -07:00
|
|
|
if (filename && (file = open_file( filename )))
|
2011-05-05 06:02:25 -07:00
|
|
|
{
|
|
|
|
pFile->sourcename = filename;
|
|
|
|
pFile->filename = strmake( "%s/include/%s", top_obj_dir, pFile->name );
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
free( filename );
|
|
|
|
}
|
|
|
|
|
2006-08-01 03:37:18 -07:00
|
|
|
/* now search in include paths */
|
2013-11-30 04:50:30 -07:00
|
|
|
for (i = 0; i < include_args.count; i++)
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
2013-11-30 04:50:30 -07:00
|
|
|
const char *dir = include_args.str[i] + 2; /* skip -I */
|
|
|
|
if (*dir == '/')
|
2013-11-19 03:36:25 -07:00
|
|
|
{
|
|
|
|
/* ignore absolute paths that don't point into the source dir */
|
|
|
|
if (!top_src_dir) continue;
|
2013-12-02 15:28:58 -07:00
|
|
|
len = strlen( top_src_dir );
|
|
|
|
if (strncmp( dir, top_src_dir, len )) continue;
|
|
|
|
if (dir[len] && dir[len] != '/') continue;
|
2013-11-19 03:36:25 -07:00
|
|
|
}
|
2013-11-30 04:50:30 -07:00
|
|
|
filename = strmake( "%s/%s", dir, pFile->name );
|
2013-12-17 09:10:28 -07:00
|
|
|
if ((file = open_file( filename ))) goto found;
|
1996-10-23 09:59:13 -07:00
|
|
|
free( filename );
|
|
|
|
}
|
2013-11-04 09:39:30 -07:00
|
|
|
if (pFile->flags & FLAG_SYSTEM) return NULL; /* ignore system files we cannot find */
|
2002-02-15 12:57:27 -07:00
|
|
|
|
2000-12-13 14:27:26 -07:00
|
|
|
/* try in src file directory */
|
2006-08-01 03:37:18 -07:00
|
|
|
if ((p = strrchr(pFile->included_by->filename, '/')))
|
2000-12-13 14:27:26 -07:00
|
|
|
{
|
2006-08-01 03:37:18 -07:00
|
|
|
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 );
|
2013-12-17 09:10:28 -07:00
|
|
|
if ((file = open_file( filename ))) goto found;
|
2006-08-01 03:37:18 -07:00
|
|
|
free( filename );
|
2000-12-13 14:27:26 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 03:55:16 -07:00
|
|
|
fprintf( stderr, "%s:%d: error: ", pFile->included_by->filename, pFile->included_line );
|
2006-08-01 03:37:18 -07:00
|
|
|
perror( pFile->name );
|
2011-09-28 03:55:16 -07:00
|
|
|
pFile = pFile->included_by;
|
|
|
|
while (pFile && pFile->included_by)
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
2006-09-10 13:04:42 -07:00
|
|
|
const char *parent = pFile->included_by->sourcename;
|
|
|
|
if (!parent) parent = pFile->included_by->name;
|
2011-09-28 03:55:16 -07:00
|
|
|
fprintf( stderr, "%s:%d: note: %s was first included here\n",
|
|
|
|
parent, pFile->included_line, pFile->name );
|
2006-08-01 03:37:18 -07:00
|
|
|
pFile = pFile->included_by;
|
1996-10-23 09:59:13 -07:00
|
|
|
}
|
2006-08-01 03:37:18 -07:00
|
|
|
exit(1);
|
|
|
|
|
|
|
|
found:
|
|
|
|
pFile->filename = filename;
|
1996-10-23 09:59:13 -07:00
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-05 04:48:16 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* parse_include_directive
|
|
|
|
*/
|
|
|
|
static void parse_include_directive( struct incl_file *source, char *str )
|
|
|
|
{
|
|
|
|
char quote, *include, *p = str;
|
|
|
|
|
|
|
|
while (*p && isspace(*p)) p++;
|
|
|
|
if (*p != '\"' && *p != '<' ) return;
|
|
|
|
quote = *p++;
|
|
|
|
if (quote == '<') quote = '>';
|
|
|
|
include = p;
|
|
|
|
while (*p && (*p != quote)) p++;
|
|
|
|
if (!*p) fatal_error( "malformed include directive '%s'\n", str );
|
|
|
|
*p = 0;
|
|
|
|
add_include( source, include, (quote == '>') );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* parse_pragma_directive
|
|
|
|
*/
|
|
|
|
static void parse_pragma_directive( struct incl_file *source, char *str )
|
|
|
|
{
|
|
|
|
char *flag, *p = str;
|
|
|
|
|
|
|
|
if (!isspace( *p )) return;
|
|
|
|
while (*p && isspace(*p)) p++;
|
|
|
|
p = strtok( p, " \t" );
|
|
|
|
if (strcmp( p, "makedep" )) return;
|
|
|
|
|
|
|
|
while ((flag = strtok( NULL, " \t" )))
|
|
|
|
{
|
|
|
|
if (!strcmp( flag, "depend" ))
|
|
|
|
{
|
|
|
|
while ((p = strtok( NULL, " \t" ))) add_include( source, p, 0 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (strendswith( source->name, ".idl" ))
|
|
|
|
{
|
|
|
|
if (!strcmp( flag, "header" )) source->flags |= FLAG_IDL_HEADER;
|
|
|
|
else if (!strcmp( flag, "proxy" )) source->flags |= FLAG_IDL_PROXY;
|
|
|
|
else if (!strcmp( flag, "client" )) source->flags |= FLAG_IDL_CLIENT;
|
|
|
|
else if (!strcmp( flag, "server" )) source->flags |= FLAG_IDL_SERVER;
|
|
|
|
else if (!strcmp( flag, "ident" )) source->flags |= FLAG_IDL_IDENT;
|
|
|
|
else if (!strcmp( flag, "typelib" )) source->flags |= FLAG_IDL_TYPELIB;
|
|
|
|
else if (!strcmp( flag, "register" )) source->flags |= FLAG_IDL_REGISTER;
|
2013-12-24 12:01:53 -07:00
|
|
|
else if (!strcmp( flag, "regtypelib" )) source->flags |= FLAG_IDL_REGTYPELIB;
|
2013-11-05 04:48:16 -07:00
|
|
|
}
|
|
|
|
else if (strendswith( source->name, ".rc" ))
|
|
|
|
{
|
|
|
|
if (!strcmp( flag, "po" )) source->flags |= FLAG_RC_PO;
|
|
|
|
}
|
2013-11-11 03:23:38 -07:00
|
|
|
else if (!strcmp( flag, "implib" )) source->flags |= FLAG_C_IMPLIB;
|
2013-11-05 04:48:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* parse_cpp_directive
|
|
|
|
*/
|
|
|
|
static void parse_cpp_directive( struct incl_file *source, char *str )
|
|
|
|
{
|
|
|
|
while (*str && isspace(*str)) str++;
|
|
|
|
if (*str++ != '#') return;
|
|
|
|
while (*str && isspace(*str)) str++;
|
|
|
|
|
|
|
|
if (!strncmp( str, "include", 7 ))
|
|
|
|
parse_include_directive( source, str + 7 );
|
|
|
|
else if (!strncmp( str, "import", 6 ) && strendswith( source->name, ".m" ))
|
|
|
|
parse_include_directive( source, str + 6 );
|
|
|
|
else if (!strncmp( str, "pragma", 6 ))
|
|
|
|
parse_pragma_directive( source, str + 6 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-10-23 09:59:13 -07:00
|
|
|
/*******************************************************************
|
2003-04-10 17:38:56 -07:00
|
|
|
* parse_idl_file
|
2006-09-10 13:04:42 -07:00
|
|
|
*
|
|
|
|
* If for_h_file is non-zero, it means we are not interested in the idl file
|
|
|
|
* itself, but only in the contents of the .h file that will be generated from it.
|
1996-10-23 09:59:13 -07:00
|
|
|
*/
|
2013-10-14 01:51:37 -07:00
|
|
|
static void parse_idl_file( struct incl_file *pFile, FILE *file, int for_h_file )
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
2006-08-01 03:16:29 -07:00
|
|
|
char *buffer, *include;
|
2000-11-05 22:32:59 -07:00
|
|
|
|
2013-10-14 02:11:07 -07:00
|
|
|
input_line = 0;
|
2006-09-10 13:04:42 -07:00
|
|
|
if (for_h_file)
|
|
|
|
{
|
|
|
|
/* generated .h file always includes these */
|
2013-10-14 02:11:07 -07:00
|
|
|
add_include( pFile, "rpc.h", 1 );
|
|
|
|
add_include( pFile, "rpcndr.h", 1 );
|
2006-09-10 13:04:42 -07:00
|
|
|
}
|
|
|
|
|
2006-08-01 03:16:29 -07:00
|
|
|
while ((buffer = get_line( file )))
|
2000-11-05 22:32:59 -07:00
|
|
|
{
|
2003-06-20 14:31:13 -07:00
|
|
|
char quote;
|
2003-04-10 17:38:56 -07:00
|
|
|
char *p = buffer;
|
|
|
|
while (*p && isspace(*p)) p++;
|
2003-06-20 14:31:13 -07:00
|
|
|
|
|
|
|
if (!strncmp( p, "import", 6 ))
|
|
|
|
{
|
|
|
|
p += 6;
|
|
|
|
while (*p && isspace(*p)) p++;
|
2006-09-10 13:04:42 -07:00
|
|
|
if (*p != '"') continue;
|
|
|
|
include = ++p;
|
|
|
|
while (*p && (*p != '"')) p++;
|
2013-10-14 02:11:07 -07:00
|
|
|
if (!*p) fatal_error( "malformed import directive\n" );
|
2006-09-10 13:04:42 -07:00
|
|
|
*p = 0;
|
|
|
|
if (for_h_file && strendswith( include, ".idl" )) strcpy( p - 4, ".h" );
|
2013-10-14 02:11:07 -07:00
|
|
|
add_include( pFile, include, 0 );
|
2006-09-10 13:04:42 -07:00
|
|
|
continue;
|
2003-06-20 14:31:13 -07:00
|
|
|
}
|
2006-09-10 13:04:42 -07:00
|
|
|
|
|
|
|
if (for_h_file) /* only check for #include inside cpp_quote */
|
2003-06-20 14:31:13 -07:00
|
|
|
{
|
2006-09-10 13:04:42 -07:00
|
|
|
if (strncmp( p, "cpp_quote", 9 )) continue;
|
|
|
|
p += 9;
|
|
|
|
while (*p && isspace(*p)) p++;
|
|
|
|
if (*p++ != '(') continue;
|
|
|
|
while (*p && isspace(*p)) p++;
|
|
|
|
if (*p++ != '"') continue;
|
2003-06-20 14:31:13 -07:00
|
|
|
if (*p++ != '#') continue;
|
|
|
|
while (*p && isspace(*p)) p++;
|
|
|
|
if (strncmp( p, "include", 7 )) continue;
|
|
|
|
p += 7;
|
|
|
|
while (*p && isspace(*p)) p++;
|
2006-09-10 13:04:42 -07:00
|
|
|
if (*p == '\\' && p[1] == '"')
|
|
|
|
{
|
|
|
|
p += 2;
|
|
|
|
quote = '"';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (*p++ != '<' ) continue;
|
|
|
|
quote = '>';
|
|
|
|
}
|
|
|
|
include = p;
|
|
|
|
while (*p && (*p != quote)) p++;
|
|
|
|
if (!*p || (quote == '"' && p[-1] != '\\'))
|
2013-10-14 02:11:07 -07:00
|
|
|
fatal_error( "malformed #include directive inside cpp_quote\n" );
|
2006-09-10 13:04:42 -07:00
|
|
|
if (quote == '"') p--; /* remove backslash */
|
|
|
|
*p = 0;
|
2013-10-14 02:11:07 -07:00
|
|
|
add_include( pFile, include, (quote == '>') );
|
2006-09-10 13:04:42 -07:00
|
|
|
continue;
|
2003-06-20 14:31:13 -07:00
|
|
|
}
|
|
|
|
|
2013-11-05 04:48:16 -07:00
|
|
|
parse_cpp_directive( pFile, p );
|
2000-11-05 22:32:59 -07:00
|
|
|
}
|
2003-04-10 17:38:56 -07:00
|
|
|
}
|
2000-11-05 22:32:59 -07:00
|
|
|
|
2003-04-10 17:38:56 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* parse_c_file
|
|
|
|
*/
|
2013-10-14 01:51:37 -07:00
|
|
|
static void parse_c_file( struct incl_file *pFile, FILE *file )
|
2003-04-10 17:38:56 -07:00
|
|
|
{
|
2013-11-05 04:48:16 -07:00
|
|
|
char *buffer;
|
1996-10-23 09:59:13 -07:00
|
|
|
|
2006-08-01 03:16:29 -07:00
|
|
|
input_line = 0;
|
|
|
|
while ((buffer = get_line( file )))
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
2013-11-05 04:48:16 -07:00
|
|
|
parse_cpp_directive( pFile, buffer );
|
1996-10-23 09:59:13 -07:00
|
|
|
}
|
2003-04-10 17:38:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-26 07:02:03 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* parse_rc_file
|
|
|
|
*/
|
2013-10-14 01:51:37 -07:00
|
|
|
static void parse_rc_file( struct incl_file *pFile, FILE *file )
|
2006-12-26 07:02:03 -07:00
|
|
|
{
|
|
|
|
char *buffer, *include;
|
|
|
|
|
|
|
|
input_line = 0;
|
|
|
|
while ((buffer = get_line( file )))
|
|
|
|
{
|
|
|
|
char quote;
|
|
|
|
char *p = buffer;
|
|
|
|
while (*p && isspace(*p)) p++;
|
|
|
|
|
|
|
|
if (p[0] == '/' && p[1] == '*') /* check for magic makedep comment */
|
|
|
|
{
|
|
|
|
p += 2;
|
|
|
|
while (*p && isspace(*p)) p++;
|
|
|
|
if (strncmp( p, "@makedep:", 9 )) continue;
|
|
|
|
p += 9;
|
|
|
|
while (*p && isspace(*p)) p++;
|
|
|
|
quote = '"';
|
|
|
|
if (*p == quote)
|
|
|
|
{
|
|
|
|
include = ++p;
|
|
|
|
while (*p && *p != quote) p++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
include = p;
|
|
|
|
while (*p && !isspace(*p) && *p != '*') p++;
|
|
|
|
}
|
|
|
|
if (!*p)
|
2013-10-14 02:11:07 -07:00
|
|
|
fatal_error( "malformed makedep comment\n" );
|
2006-12-26 07:02:03 -07:00
|
|
|
*p = 0;
|
2013-11-05 04:48:16 -07:00
|
|
|
add_include( pFile, include, (quote == '>') );
|
|
|
|
continue;
|
2006-12-26 07:02:03 -07:00
|
|
|
}
|
2013-11-05 04:48:16 -07:00
|
|
|
|
|
|
|
parse_cpp_directive( pFile, buffer );
|
2006-12-26 07:02:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-18 03:34:03 -07:00
|
|
|
/*******************************************************************
|
2013-12-12 12:04:53 -07:00
|
|
|
* parse_in_file
|
2013-11-18 03:34:03 -07:00
|
|
|
*/
|
2013-12-12 12:04:53 -07:00
|
|
|
static void parse_in_file( struct incl_file *source, FILE *file )
|
2013-11-18 03:34:03 -07:00
|
|
|
{
|
|
|
|
char *p, *buffer;
|
|
|
|
|
|
|
|
/* make sure it gets rebuilt when the version changes */
|
|
|
|
add_include( source, "config.h", 1 );
|
|
|
|
|
2013-12-12 12:04:53 -07:00
|
|
|
if (!strendswith( source->filename, ".man.in" )) return; /* not a man page */
|
|
|
|
|
2013-11-18 03:34:03 -07:00
|
|
|
input_line = 0;
|
|
|
|
while ((buffer = get_line( file )))
|
|
|
|
{
|
|
|
|
if (strncmp( buffer, ".TH", 3 )) continue;
|
|
|
|
if (!(p = strtok( buffer, " \t" ))) continue; /* .TH */
|
|
|
|
if (!(p = strtok( NULL, " \t" ))) continue; /* program name */
|
|
|
|
if (!(p = strtok( NULL, " \t" ))) continue; /* man section */
|
|
|
|
source->sourcename = xstrdup( p ); /* abuse source name to store section */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-16 08:19:07 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* parse_generated_idl
|
|
|
|
*/
|
2013-10-14 01:51:37 -07:00
|
|
|
static void parse_generated_idl( struct incl_file *source )
|
2006-10-16 08:19:07 -07:00
|
|
|
{
|
|
|
|
source->filename = xstrdup( source->name );
|
|
|
|
|
|
|
|
if (strendswith( source->name, "_c.c" ))
|
|
|
|
{
|
2013-12-24 03:27:35 -07:00
|
|
|
add_include( source, replace_extension( source->name, "_c.c", ".h" ), 0 );
|
2006-10-16 08:19:07 -07:00
|
|
|
}
|
|
|
|
else if (strendswith( source->name, "_i.c" ))
|
|
|
|
{
|
2013-10-14 02:11:07 -07:00
|
|
|
add_include( source, "rpc.h", 1 );
|
|
|
|
add_include( source, "rpcndr.h", 1 );
|
|
|
|
add_include( source, "guiddef.h", 1 );
|
2006-10-16 08:19:07 -07:00
|
|
|
}
|
|
|
|
else if (strendswith( source->name, "_p.c" ))
|
|
|
|
{
|
2013-10-14 02:11:07 -07:00
|
|
|
add_include( source, "objbase.h", 1 );
|
|
|
|
add_include( source, "rpcproxy.h", 1 );
|
|
|
|
add_include( source, "wine/exception.h", 1 );
|
2013-12-24 03:27:35 -07:00
|
|
|
add_include( source, replace_extension( source->name, "_p.c", ".h" ), 0 );
|
2006-10-16 08:19:07 -07:00
|
|
|
}
|
|
|
|
else if (strendswith( source->name, "_s.c" ))
|
|
|
|
{
|
2013-10-14 02:11:07 -07:00
|
|
|
add_include( source, "wine/exception.h", 1 );
|
2013-12-24 03:27:35 -07:00
|
|
|
add_include( source, replace_extension( source->name, "_s.c", ".h" ), 0 );
|
2006-10-16 08:19:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-15 03:39:42 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* is_generated_idl
|
|
|
|
*/
|
|
|
|
static int is_generated_idl( struct incl_file *source )
|
|
|
|
{
|
|
|
|
return (strendswith( source->name, "_c.c" ) ||
|
|
|
|
strendswith( source->name, "_i.c" ) ||
|
|
|
|
strendswith( source->name, "_p.c" ) ||
|
|
|
|
strendswith( source->name, "_s.c" ));
|
|
|
|
}
|
|
|
|
|
2003-04-10 17:38:56 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* parse_file
|
|
|
|
*/
|
2013-10-14 03:12:26 -07:00
|
|
|
static void parse_file( struct incl_file *source, int src )
|
2003-04-10 17:38:56 -07:00
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
|
2011-05-05 06:02:25 -07:00
|
|
|
/* don't try to open certain types of files */
|
2013-12-11 13:18:53 -07:00
|
|
|
if (strendswith( source->name, ".tlb" ))
|
2008-04-24 14:43:04 -07:00
|
|
|
{
|
2013-10-14 03:12:26 -07:00
|
|
|
source->filename = xstrdup( source->name );
|
2006-10-16 08:19:07 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-14 03:12:26 -07:00
|
|
|
file = src ? open_src_file( source ) : open_include_file( source );
|
2003-04-10 17:38:56 -07:00
|
|
|
if (!file) return;
|
2013-10-14 03:12:26 -07:00
|
|
|
input_file_name = source->filename;
|
|
|
|
|
|
|
|
if (source->sourcename && strendswith( source->sourcename, ".idl" ))
|
|
|
|
parse_idl_file( source, file, 1 );
|
|
|
|
else if (strendswith( source->filename, ".idl" ))
|
|
|
|
parse_idl_file( source, file, 0 );
|
|
|
|
else if (strendswith( source->filename, ".c" ) ||
|
|
|
|
strendswith( source->filename, ".m" ) ||
|
|
|
|
strendswith( source->filename, ".h" ) ||
|
|
|
|
strendswith( source->filename, ".l" ) ||
|
|
|
|
strendswith( source->filename, ".y" ))
|
|
|
|
parse_c_file( source, file );
|
|
|
|
else if (strendswith( source->filename, ".rc" ))
|
|
|
|
parse_rc_file( source, file );
|
2013-12-12 12:04:53 -07:00
|
|
|
else if (strendswith( source->filename, ".in" ))
|
|
|
|
parse_in_file( source, file );
|
1996-11-02 07:24:07 -07:00
|
|
|
fclose(file);
|
2013-10-14 02:11:07 -07:00
|
|
|
input_file_name = NULL;
|
1996-10-23 09:59:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-10 06:26:25 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* add_src_file
|
|
|
|
*
|
|
|
|
* Add a source file to the list.
|
|
|
|
*/
|
2013-10-14 01:51:37 -07:00
|
|
|
static struct incl_file *add_src_file( const char *name )
|
2007-12-10 06:26:25 -07:00
|
|
|
{
|
2013-10-14 01:51:37 -07:00
|
|
|
struct incl_file *file;
|
2007-12-10 06:26:25 -07:00
|
|
|
|
2013-11-04 09:39:30 -07:00
|
|
|
if ((file = find_src_file( name ))) return file; /* we already have it */
|
2007-12-10 06:26:25 -07:00
|
|
|
file = xmalloc( sizeof(*file) );
|
|
|
|
memset( file, 0, sizeof(*file) );
|
|
|
|
file->name = xstrdup(name);
|
|
|
|
list_add_tail( &sources, &file->entry );
|
2013-10-15 04:15:06 -07:00
|
|
|
|
|
|
|
/* special cases for generated files */
|
|
|
|
|
|
|
|
if (is_generated_idl( file ))
|
|
|
|
{
|
|
|
|
parse_generated_idl( file );
|
2013-11-04 09:39:30 -07:00
|
|
|
return file;
|
2013-10-15 04:15:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp( file->name, "dlldata.o" ))
|
|
|
|
{
|
|
|
|
file->filename = xstrdup( "dlldata.c" );
|
|
|
|
add_include( file, "objbase.h", 1 );
|
|
|
|
add_include( file, "rpcproxy.h", 1 );
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp( file->name, "testlist.o" ))
|
|
|
|
{
|
|
|
|
file->filename = xstrdup( "testlist.c" );
|
|
|
|
add_include( file, "wine/test.h", 1 );
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strendswith( file->name, ".o" ))
|
|
|
|
{
|
|
|
|
/* default to .c for unknown extra object files */
|
2013-12-24 03:27:35 -07:00
|
|
|
file->filename = replace_extension( file->name, ".o", ".c" );
|
2013-10-15 04:15:06 -07:00
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strendswith( file->name, ".tlb" ) ||
|
2013-11-05 04:48:16 -07:00
|
|
|
strendswith( file->name, ".res" ) ||
|
2013-12-11 13:18:53 -07:00
|
|
|
strendswith( file->name, ".pot" ))
|
2013-10-15 04:15:06 -07:00
|
|
|
{
|
|
|
|
file->filename = xstrdup( file->name );
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2007-12-10 06:26:25 -07:00
|
|
|
parse_file( file, 1 );
|
|
|
|
return file;
|
2013-11-04 09:39:30 -07:00
|
|
|
}
|
2013-10-15 04:15:06 -07:00
|
|
|
|
2013-11-04 09:39:30 -07:00
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* add_generated_sources
|
|
|
|
*/
|
|
|
|
static void add_generated_sources(void)
|
|
|
|
{
|
2013-11-05 04:48:16 -07:00
|
|
|
unsigned int i;
|
2013-11-04 09:39:30 -07:00
|
|
|
struct incl_file *source, *next;
|
|
|
|
|
2013-11-05 04:48:16 -07:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE( source, next, &sources, struct incl_file, entry )
|
|
|
|
{
|
|
|
|
if (!source->flags) continue;
|
|
|
|
for (i = 0; i < sizeof(idl_outputs) / sizeof(idl_outputs[0]); i++)
|
|
|
|
{
|
|
|
|
if (!(source->flags & idl_outputs[i].flag)) continue;
|
|
|
|
if (!strendswith( idl_outputs[i].ext, ".c" )) continue;
|
2013-12-24 03:27:35 -07:00
|
|
|
add_src_file( replace_extension( source->name, ".idl", idl_outputs[i].ext ));
|
2013-11-05 04:48:16 -07:00
|
|
|
}
|
|
|
|
if (source->flags & FLAG_IDL_PROXY) add_src_file( "dlldata.o" );
|
|
|
|
}
|
2007-12-10 06:26:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-17 09:10:28 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* get_make_variable
|
|
|
|
*/
|
|
|
|
static char *get_make_variable( const char *name )
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2013-12-26 11:26:29 -07:00
|
|
|
for (i = 0; i < cmdline_vars.count; i += 2)
|
|
|
|
if (!strcmp( cmdline_vars.str[i], name ))
|
|
|
|
return xstrdup( cmdline_vars.str[i + 1] );
|
|
|
|
|
2013-12-26 11:25:57 -07:00
|
|
|
for (i = 0; i < make_vars.count; i += 2)
|
|
|
|
if (!strcmp( make_vars.str[i], name ))
|
|
|
|
return xstrdup( make_vars.str[i + 1] );
|
2013-12-17 09:10:28 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* get_expanded_make_variable
|
|
|
|
*/
|
|
|
|
static char *get_expanded_make_variable( const char *name )
|
|
|
|
{
|
|
|
|
char *p, *end, *var, *expand, *tmp;
|
|
|
|
|
|
|
|
expand = get_make_variable( name );
|
|
|
|
if (!expand) return NULL;
|
|
|
|
|
|
|
|
p = expand;
|
|
|
|
while ((p = strchr( p, '$' )))
|
|
|
|
{
|
|
|
|
if (p[1] == '(')
|
|
|
|
{
|
|
|
|
if (!(end = strchr( p + 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand );
|
|
|
|
*end++ = 0;
|
|
|
|
if (strchr( p + 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p + 2 );
|
|
|
|
var = get_make_variable( p + 2 );
|
|
|
|
tmp = replace_substr( expand, p, end - p, var ? var : "" );
|
|
|
|
free( var );
|
|
|
|
}
|
|
|
|
else if (p[1] == '$')
|
|
|
|
{
|
|
|
|
tmp = replace_substr( expand, p, 2, "$" );
|
|
|
|
}
|
|
|
|
else fatal_error( "syntax error in '%s'\n", expand );
|
|
|
|
|
|
|
|
/* switch to the new string */
|
|
|
|
p = tmp + (p - expand);
|
|
|
|
free( expand );
|
|
|
|
expand = tmp;
|
|
|
|
}
|
2013-12-26 11:25:57 -07:00
|
|
|
|
|
|
|
/* consider empty variables undefined */
|
|
|
|
p = expand;
|
|
|
|
while (*p && isspace(*p)) p++;
|
|
|
|
if (*p) return expand;
|
|
|
|
free( expand );
|
|
|
|
return NULL;
|
2013-12-17 09:10:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* get_expanded_make_var_array
|
|
|
|
*/
|
|
|
|
static struct strarray get_expanded_make_var_array( const char *name )
|
|
|
|
{
|
2013-12-24 03:37:52 -07:00
|
|
|
struct strarray ret = empty_strarray;
|
2013-12-17 09:10:28 -07:00
|
|
|
char *value, *token;
|
|
|
|
|
|
|
|
if ((value = get_expanded_make_variable( name )))
|
|
|
|
for (token = strtok( value, " \t" ); token; token = strtok( NULL, " \t" ))
|
|
|
|
strarray_add( &ret, token );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-26 11:25:57 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* set_make_variable
|
|
|
|
*/
|
|
|
|
static int set_make_variable( struct strarray *array, const char *assignment )
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
char *p, *name;
|
|
|
|
|
|
|
|
p = name = xstrdup( assignment );
|
|
|
|
while (isalnum(*p) || *p == '_') p++;
|
|
|
|
if (name == p) return 0; /* not a variable */
|
|
|
|
if (isspace(*p))
|
|
|
|
{
|
|
|
|
*p++ = 0;
|
|
|
|
while (isspace(*p)) p++;
|
|
|
|
}
|
|
|
|
if (*p != '=') return 0; /* not an assignment */
|
|
|
|
*p++ = 0;
|
|
|
|
while (isspace(*p)) p++;
|
|
|
|
|
|
|
|
/* redefining a variable replaces the previous value */
|
|
|
|
for (i = 0; i < array->count; i += 2)
|
|
|
|
{
|
|
|
|
if (strcmp( array->str[i], name )) continue;
|
|
|
|
array->str[i + 1] = p;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
strarray_add( array, name );
|
|
|
|
strarray_add( array, p );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-17 09:10:28 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* parse_makefile
|
|
|
|
*/
|
|
|
|
static void parse_makefile(void)
|
|
|
|
{
|
|
|
|
char *buffer;
|
|
|
|
FILE *file;
|
|
|
|
|
|
|
|
input_file_name = strmake( "%s/%s", base_dir, makefile_name );
|
|
|
|
if (!(file = fopen( input_file_name, "r" )))
|
|
|
|
{
|
|
|
|
fatal_perror( "open" );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
input_line = 0;
|
|
|
|
while ((buffer = get_line( file )))
|
|
|
|
{
|
|
|
|
if (Separator && !strncmp( buffer, Separator, strlen(Separator) )) break;
|
2013-12-26 11:25:57 -07:00
|
|
|
if (*buffer == '\t') continue; /* command */
|
|
|
|
while (isspace( *buffer )) buffer++;
|
|
|
|
if (*buffer == '#') continue; /* comment */
|
|
|
|
set_make_variable( &make_vars, buffer );
|
2013-12-17 09:10:28 -07:00
|
|
|
}
|
|
|
|
fclose( file );
|
|
|
|
input_file_name = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-10-23 09:59:13 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* output_include
|
|
|
|
*/
|
2013-10-14 02:11:07 -07:00
|
|
|
static void output_include( struct incl_file *pFile, struct incl_file *owner, int *column )
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (pFile->owner == owner) return;
|
2002-02-15 12:57:27 -07:00
|
|
|
if (!pFile->filename) return;
|
1996-10-23 09:59:13 -07:00
|
|
|
pFile->owner = owner;
|
2013-10-14 02:11:07 -07:00
|
|
|
output_filename( pFile->filename, column );
|
1996-10-23 09:59:13 -07:00
|
|
|
for (i = 0; i < MAX_INCLUDES; i++)
|
2013-10-14 02:11:07 -07:00
|
|
|
if (pFile->files[i]) output_include( pFile->files[i], owner, column );
|
1996-10-23 09:59:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-09-28 10:43:24 -07:00
|
|
|
/*******************************************************************
|
2013-10-14 02:11:07 -07:00
|
|
|
* output_sources
|
1997-09-28 10:43:24 -07:00
|
|
|
*/
|
2013-12-13 12:37:26 -07:00
|
|
|
static struct strarray output_sources(void)
|
1997-09-28 10:43:24 -07:00
|
|
|
{
|
2013-10-14 02:11:07 -07:00
|
|
|
struct incl_file *source;
|
2013-12-24 03:37:52 -07:00
|
|
|
int i, column;
|
2013-11-16 03:57:14 -07:00
|
|
|
int is_test = find_src_file( "testlist.o" ) != NULL;
|
2013-12-24 03:37:52 -07:00
|
|
|
struct strarray clean_files = empty_strarray;
|
|
|
|
struct strarray po_files = empty_strarray;
|
|
|
|
struct strarray mc_files = empty_strarray;
|
|
|
|
struct strarray test_files = empty_strarray;
|
2013-12-27 06:26:37 -07:00
|
|
|
struct strarray dlldata_files = empty_strarray;
|
2013-12-26 13:51:38 -07:00
|
|
|
struct strarray includes = empty_strarray;
|
2013-12-24 03:37:52 -07:00
|
|
|
struct strarray subdirs = empty_strarray;
|
2013-11-09 10:57:00 -07:00
|
|
|
|
2013-12-26 13:51:38 -07:00
|
|
|
strarray_add( &includes, "-I." );
|
|
|
|
if (src_dir) strarray_add( &includes, strmake( "-I%s", src_dir ));
|
2013-11-19 05:03:55 -07:00
|
|
|
if (parent_dir)
|
|
|
|
{
|
2013-12-26 13:51:38 -07:00
|
|
|
if (src_dir) strarray_add( &includes, strmake( "-I%s/%s", src_dir, parent_dir ));
|
|
|
|
else strarray_add( &includes, strmake( "-I%s", parent_dir ));
|
2013-11-19 05:03:55 -07:00
|
|
|
}
|
2013-12-26 13:51:38 -07:00
|
|
|
if (top_src_dir && top_obj_dir) strarray_add( &includes, strmake( "-I%s/include", top_obj_dir ));
|
|
|
|
strarray_addall( &includes, &include_args );
|
2013-11-19 05:03:55 -07:00
|
|
|
|
2013-10-14 02:11:07 -07:00
|
|
|
LIST_FOR_EACH_ENTRY( source, &sources, struct incl_file, entry )
|
1997-09-28 10:43:24 -07:00
|
|
|
{
|
2013-12-12 13:10:55 -07:00
|
|
|
char *sourcedep;
|
2013-10-14 02:11:07 -07:00
|
|
|
char *obj = xstrdup( source->name );
|
|
|
|
char *ext = get_extension( obj );
|
|
|
|
|
|
|
|
if (!ext) fatal_error( "unsupported file type %s\n", source->name );
|
2000-10-23 14:39:39 -07:00
|
|
|
*ext++ = 0;
|
2013-10-14 02:11:07 -07:00
|
|
|
column = 0;
|
|
|
|
|
2013-12-12 13:10:55 -07:00
|
|
|
if (src_dir && strchr( obj, '/' ))
|
|
|
|
{
|
|
|
|
char *dir = xstrdup( obj );
|
|
|
|
*strrchr( dir, '/' ) = 0;
|
|
|
|
strarray_add_uniq( &subdirs, dir );
|
|
|
|
sourcedep = strmake( "%s %s", dir, source->filename );
|
|
|
|
}
|
|
|
|
else sourcedep = xstrdup( source->filename );
|
|
|
|
|
2000-10-23 14:39:39 -07:00
|
|
|
if (!strcmp( ext, "y" )) /* yacc file */
|
1997-09-28 10:43:24 -07:00
|
|
|
{
|
2010-03-16 05:27:51 -07:00
|
|
|
/* add source file dependency for parallel makes */
|
|
|
|
char *header = strmake( "%s.tab.h", obj );
|
2013-11-09 10:57:00 -07:00
|
|
|
|
2013-10-14 10:52:52 -07:00
|
|
|
if (find_include_file( header ))
|
|
|
|
{
|
2013-12-12 13:10:55 -07:00
|
|
|
output( "%s.tab.h: %s\n", obj, sourcedep );
|
2013-10-14 10:52:52 -07:00
|
|
|
output( "\t$(BISON) $(BISONFLAGS) -p %s_ -o %s.tab.c -d %s\n",
|
|
|
|
obj, obj, source->filename );
|
|
|
|
output( "%s.tab.c: %s %s\n", obj, source->filename, header );
|
2013-11-09 10:57:00 -07:00
|
|
|
strarray_add( &clean_files, strmake( "%s.tab.h", obj ));
|
2013-10-14 10:52:52 -07:00
|
|
|
}
|
2013-12-12 13:10:55 -07:00
|
|
|
else output( "%s.tab.c: %s\n", obj, sourcedep );
|
2013-10-14 10:52:52 -07:00
|
|
|
|
|
|
|
output( "\t$(BISON) $(BISONFLAGS) -p %s_ -o $@ %s\n", obj, source->filename );
|
2013-10-28 03:16:11 -07:00
|
|
|
output( "%s.tab.o: %s.tab.c\n", obj, obj );
|
2013-11-19 05:03:55 -07:00
|
|
|
output( "\t$(CC) -c $(includes) $(ALLCFLAGS) -o $@ %s.tab.c\n", obj );
|
2013-11-09 10:57:00 -07:00
|
|
|
strarray_add( &clean_files, strmake( "%s.tab.c", obj ));
|
|
|
|
strarray_add( &clean_files, strmake( "%s.tab.o", obj ));
|
2013-10-28 03:16:11 -07:00
|
|
|
column += output( "%s.tab.o:", obj );
|
2013-10-14 10:52:52 -07:00
|
|
|
free( header );
|
1997-09-28 10:43:24 -07:00
|
|
|
}
|
2013-12-11 13:18:53 -07:00
|
|
|
else if (!strcmp( ext, "x" )) /* template file */
|
|
|
|
{
|
2013-12-12 13:10:55 -07:00
|
|
|
output( "%s.h: $(MAKEXFTMPL) %s\n", obj, sourcedep );
|
2013-12-11 13:18:53 -07:00
|
|
|
output( "\t$(MAKEXFTMPL) -H -o $@ %s\n", source->filename );
|
|
|
|
strarray_add( &clean_files, strmake( "%s.h", obj ));
|
|
|
|
continue;
|
|
|
|
}
|
2000-10-23 14:39:39 -07:00
|
|
|
else if (!strcmp( ext, "l" )) /* lex file */
|
1997-09-28 10:43:24 -07:00
|
|
|
{
|
2013-12-12 13:10:55 -07:00
|
|
|
output( "%s.yy.c: %s\n", obj, sourcedep );
|
2013-10-14 10:49:29 -07:00
|
|
|
output( "\t$(FLEX) $(LEXFLAGS) -o$@ %s\n", source->filename );
|
2013-10-28 03:16:11 -07:00
|
|
|
output( "%s.yy.o: %s.yy.c\n", obj, obj );
|
2013-11-19 05:03:55 -07:00
|
|
|
output( "\t$(CC) -c $(includes) $(ALLCFLAGS) -o $@ %s.yy.c\n", obj );
|
2013-11-09 10:57:00 -07:00
|
|
|
strarray_add( &clean_files, strmake( "%s.yy.c", obj ));
|
|
|
|
strarray_add( &clean_files, strmake( "%s.yy.o", obj ));
|
2013-10-28 03:16:11 -07:00
|
|
|
column += output( "%s.yy.o:", obj );
|
1997-09-28 10:43:24 -07:00
|
|
|
}
|
2000-10-23 14:39:39 -07:00
|
|
|
else if (!strcmp( ext, "rc" )) /* resource file */
|
1997-09-28 10:43:24 -07:00
|
|
|
{
|
2013-11-04 09:39:30 -07:00
|
|
|
if (source->flags & FLAG_RC_PO)
|
2013-10-14 15:14:51 -07:00
|
|
|
{
|
2013-12-12 13:10:55 -07:00
|
|
|
output( "%s.res: $(WRC) $(ALL_MO_FILES) %s\n", obj, sourcedep );
|
2013-12-26 13:51:38 -07:00
|
|
|
column = output( "\t$(WRC) -o $@ %s", source->filename );
|
|
|
|
output_filenames( &includes, &column );
|
|
|
|
output_filename( "$(RCFLAGS)", &column );
|
|
|
|
output( "\n" );
|
|
|
|
column = output( "%s.res rsrc.pot:", obj );
|
2013-12-24 03:37:52 -07:00
|
|
|
strarray_add( &po_files, source->filename );
|
2013-10-14 15:14:51 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-12 13:10:55 -07:00
|
|
|
output( "%s.res: $(WRC) %s\n", obj, sourcedep );
|
2013-12-26 13:51:38 -07:00
|
|
|
column = output( "\t$(WRC) -o $@ %s", source->filename );
|
|
|
|
output_filenames( &includes, &column );
|
|
|
|
output_filename( "$(RCFLAGS)", &column );
|
|
|
|
output( "\n" );
|
|
|
|
column = output( "%s.res:", obj );
|
2013-10-14 15:14:51 -07:00
|
|
|
}
|
2013-11-09 10:57:00 -07:00
|
|
|
strarray_add( &clean_files, strmake( "%s.res", obj ));
|
2000-10-23 14:39:39 -07:00
|
|
|
}
|
2000-11-05 22:32:59 -07:00
|
|
|
else if (!strcmp( ext, "mc" )) /* message file */
|
2000-10-23 14:39:39 -07:00
|
|
|
{
|
2013-12-12 13:10:55 -07:00
|
|
|
output( "%s.res: $(WMC) $(ALL_MO_FILES) %s\n", obj, sourcedep );
|
2013-10-14 11:18:18 -07:00
|
|
|
output( "\t$(WMC) -U -O res $(PORCFLAGS) -o $@ %s\n", source->filename );
|
2013-11-09 10:57:00 -07:00
|
|
|
strarray_add( &clean_files, strmake( "%s.res", obj ));
|
2013-12-24 03:37:52 -07:00
|
|
|
strarray_add( &mc_files, source->filename );
|
2013-10-14 11:18:18 -07:00
|
|
|
column += output( "msg.pot %s.res:", obj );
|
1997-09-28 10:43:24 -07:00
|
|
|
}
|
2003-04-10 17:38:56 -07:00
|
|
|
else if (!strcmp( ext, "idl" )) /* IDL file */
|
|
|
|
{
|
2013-12-24 03:37:52 -07:00
|
|
|
struct strarray targets = empty_strarray;
|
|
|
|
unsigned int i;
|
|
|
|
char *dest;
|
2006-10-16 08:19:07 -07:00
|
|
|
|
2013-11-04 09:39:30 -07:00
|
|
|
if (!source->flags || find_include_file( strmake( "%s.h", obj )))
|
|
|
|
source->flags |= FLAG_IDL_HEADER;
|
2006-10-16 08:19:07 -07:00
|
|
|
|
2013-11-04 09:39:30 -07:00
|
|
|
for (i = 0; i < sizeof(idl_outputs) / sizeof(idl_outputs[0]); i++)
|
2008-04-24 13:13:57 -07:00
|
|
|
{
|
2013-11-04 09:39:30 -07:00
|
|
|
if (!(source->flags & idl_outputs[i].flag)) continue;
|
2013-12-24 03:37:52 -07:00
|
|
|
dest = strmake( "%s%s", obj, idl_outputs[i].ext );
|
|
|
|
strarray_add( &clean_files, dest );
|
|
|
|
strarray_add( &targets, dest );
|
2013-10-15 03:30:54 -07:00
|
|
|
}
|
2013-12-27 06:26:37 -07:00
|
|
|
if (source->flags & FLAG_IDL_PROXY) strarray_add( &dlldata_files, source->name );
|
2013-12-24 03:37:52 -07:00
|
|
|
column = 0;
|
|
|
|
output_filenames( &targets, &column );
|
2013-12-24 13:12:08 -07:00
|
|
|
output( ": $(WIDL)\n" );
|
2013-12-26 13:51:38 -07:00
|
|
|
column = output( "\t$(WIDL) -o $@ %s", source->filename );
|
|
|
|
output_filenames( &includes, &column );
|
|
|
|
output_filename( "$(TARGETFLAGS)", &column );
|
|
|
|
output_filename( "$(IDLFLAGS)", &column );
|
|
|
|
output( "\n" );
|
2013-12-24 13:12:08 -07:00
|
|
|
column = 0;
|
|
|
|
output_filenames( &targets, &column );
|
2013-12-24 03:37:52 -07:00
|
|
|
column += output( ": %s", sourcedep );
|
2003-04-10 17:38:56 -07:00
|
|
|
}
|
2013-12-12 12:04:53 -07:00
|
|
|
else if (!strcmp( ext, "in" )) /* .in file or man page */
|
2013-11-18 03:34:03 -07:00
|
|
|
{
|
|
|
|
if (strendswith( obj, ".man" ) && source->sourcename)
|
|
|
|
{
|
2013-12-24 03:27:35 -07:00
|
|
|
char *dir, *dest = replace_extension( obj, ".man", "" );
|
2013-11-18 03:34:03 -07:00
|
|
|
char *lang = strchr( dest, '.' );
|
|
|
|
if (lang)
|
|
|
|
{
|
|
|
|
*lang++ = 0;
|
|
|
|
dir = strmake( "$(DESTDIR)$(mandir)/%s/man%s", lang, source->sourcename );
|
|
|
|
}
|
|
|
|
else dir = strmake( "$(DESTDIR)$(mandir)/man%s", source->sourcename );
|
2013-12-26 05:24:26 -07:00
|
|
|
output( "install-man-pages:: %s\n", obj );
|
2013-11-18 03:34:03 -07:00
|
|
|
output( "\t$(INSTALL_DATA) %s %s/%s.%s\n",
|
|
|
|
obj, dir, dest, source->sourcename );
|
|
|
|
output( "uninstall::\n" );
|
|
|
|
output( "\t$(RM) %s/%s.%s\n",
|
|
|
|
dir, dest, source->sourcename );
|
|
|
|
free( dest );
|
2013-12-26 05:24:26 -07:00
|
|
|
free( dir );
|
2013-11-18 03:34:03 -07:00
|
|
|
}
|
|
|
|
strarray_add( &clean_files, xstrdup(obj) );
|
2013-12-12 13:10:55 -07:00
|
|
|
output( "%s: %s\n", obj, sourcedep );
|
2013-11-18 03:34:03 -07:00
|
|
|
output( "\t$(SED_CMD) %s >$@ || ($(RM) $@ && false)\n", source->filename );
|
|
|
|
column += output( "%s:", obj );
|
|
|
|
}
|
2013-10-14 15:14:51 -07:00
|
|
|
else if (!strcmp( ext, "tlb" ) || !strcmp( ext, "res" ) || !strcmp( ext, "pot" ))
|
2008-04-24 13:13:57 -07:00
|
|
|
{
|
2013-12-13 12:37:26 -07:00
|
|
|
strarray_add( &clean_files, source->name );
|
2013-10-14 02:11:07 -07:00
|
|
|
continue; /* nothing to do for typelib files */
|
2008-04-24 13:13:57 -07:00
|
|
|
}
|
1997-09-28 10:43:24 -07:00
|
|
|
else
|
|
|
|
{
|
2013-11-19 03:36:25 -07:00
|
|
|
for (i = 0; i < object_extensions.count; i++)
|
2013-10-28 03:16:11 -07:00
|
|
|
{
|
2013-11-19 03:36:25 -07:00
|
|
|
strarray_add( &clean_files, strmake( "%s.%s", obj, object_extensions.str[i] ));
|
2013-12-12 13:10:55 -07:00
|
|
|
output( "%s.%s: %s\n", obj, object_extensions.str[i], sourcedep );
|
2013-11-19 03:36:25 -07:00
|
|
|
if (strstr( object_extensions.str[i], "cross" ))
|
2013-12-26 13:51:38 -07:00
|
|
|
{
|
|
|
|
column = output( "\t$(CROSSCC) -c -o $@ %s", source->filename );
|
|
|
|
output_filenames( &includes, &column );
|
|
|
|
output_filename( "$(ALLCROSSCFLAGS)", &column );
|
|
|
|
output( "\n" );
|
|
|
|
}
|
2013-10-28 03:16:11 -07:00
|
|
|
else
|
2013-12-26 13:51:38 -07:00
|
|
|
{
|
|
|
|
column = output( "\t$(CC) -c -o $@ %s", source->filename );
|
|
|
|
output_filenames( &includes, &column );
|
|
|
|
output_filename( "$(ALLCFLAGS)", &column );
|
|
|
|
output( "\n" );
|
|
|
|
}
|
2013-10-28 03:16:11 -07:00
|
|
|
}
|
2013-11-11 03:23:38 -07:00
|
|
|
if (source->flags & FLAG_C_IMPLIB)
|
|
|
|
{
|
|
|
|
strarray_add( &clean_files, strmake( "%s.cross.o", obj ));
|
2013-12-12 13:10:55 -07:00
|
|
|
output( "%s.cross.o: %s\n", obj, sourcedep );
|
2013-12-26 13:51:38 -07:00
|
|
|
column = output( "\t$(CROSSCC) -c -o $@ %s", source->filename );
|
|
|
|
output_filenames( &includes, &column );
|
|
|
|
output_filename( "$(ALLCROSSCFLAGS)", &column );
|
|
|
|
output( "\n" );
|
2013-11-11 03:23:38 -07:00
|
|
|
}
|
2013-11-16 03:57:14 -07:00
|
|
|
if (is_test && !strcmp( ext, "c" ) && !is_generated_idl( source ))
|
|
|
|
{
|
2013-12-24 03:37:52 -07:00
|
|
|
strarray_add( &test_files, source->name );
|
2013-11-16 03:57:14 -07:00
|
|
|
output( "%s.ok:\n", obj );
|
|
|
|
output( "\t$(RUNTEST) $(RUNTESTFLAGS) %s && touch $@\n", obj );
|
|
|
|
}
|
2013-12-26 13:51:38 -07:00
|
|
|
column = 0;
|
2013-11-19 03:36:25 -07:00
|
|
|
for (i = 0; i < object_extensions.count; i++)
|
|
|
|
column += output( "%s.%s ", obj, object_extensions.str[i] );
|
2013-11-11 03:23:38 -07:00
|
|
|
if (source->flags & FLAG_C_IMPLIB) column += output( "%s.cross.o", obj );
|
2013-10-28 03:16:11 -07:00
|
|
|
column += output( ":" );
|
1997-09-28 10:43:24 -07:00
|
|
|
}
|
2013-10-14 02:11:07 -07:00
|
|
|
free( obj );
|
2013-12-12 13:10:55 -07:00
|
|
|
free( sourcedep );
|
2013-10-14 02:11:07 -07:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_INCLUDES; i++)
|
|
|
|
if (source->files[i]) output_include( source->files[i], source, &column );
|
|
|
|
output( "\n" );
|
1997-09-28 10:43:24 -07:00
|
|
|
}
|
2013-10-14 11:18:18 -07:00
|
|
|
|
|
|
|
/* rules for files that depend on multiple sources */
|
|
|
|
|
2013-12-24 03:37:52 -07:00
|
|
|
if (po_files.count)
|
2013-10-14 15:14:51 -07:00
|
|
|
{
|
|
|
|
column = output( "rsrc.pot: $(WRC)" );
|
2013-12-24 03:37:52 -07:00
|
|
|
output_filenames( &po_files, &column );
|
2013-10-14 15:14:51 -07:00
|
|
|
output( "\n" );
|
2013-12-26 13:51:38 -07:00
|
|
|
column = output( "\t$(WRC) -O pot -o $@" );
|
|
|
|
output_filenames( &includes, &column );
|
|
|
|
output_filename( "$(RCFLAGS)", &column );
|
2013-12-24 03:37:52 -07:00
|
|
|
output_filenames( &po_files, &column );
|
2013-10-14 15:14:51 -07:00
|
|
|
output( "\n" );
|
2013-11-09 10:57:00 -07:00
|
|
|
strarray_add( &clean_files, "rsrc.pot" );
|
2013-10-14 15:14:51 -07:00
|
|
|
}
|
|
|
|
|
2013-12-24 03:37:52 -07:00
|
|
|
if (mc_files.count)
|
2013-10-14 11:18:18 -07:00
|
|
|
{
|
|
|
|
column = output( "msg.pot: $(WMC)" );
|
2013-12-24 03:37:52 -07:00
|
|
|
output_filenames( &mc_files, &column );
|
2013-10-14 11:18:18 -07:00
|
|
|
output( "\n" );
|
|
|
|
column = output( "\t$(WMC) -O pot -o $@" );
|
2013-12-24 03:37:52 -07:00
|
|
|
output_filenames( &mc_files, &column );
|
2013-10-14 11:18:18 -07:00
|
|
|
output( "\n" );
|
2013-11-09 10:57:00 -07:00
|
|
|
strarray_add( &clean_files, "msg.pot" );
|
2013-10-14 11:18:18 -07:00
|
|
|
}
|
2013-10-15 03:35:11 -07:00
|
|
|
|
2013-12-27 06:26:37 -07:00
|
|
|
if (dlldata_files.count)
|
2013-10-15 03:35:11 -07:00
|
|
|
{
|
2013-12-12 05:15:34 -07:00
|
|
|
output( "dlldata.c: $(WIDL) %s\n", src_dir ? strmake("%s/Makefile.in", src_dir ) : "Makefile.in" );
|
2013-11-19 05:03:55 -07:00
|
|
|
column = output( "\t$(WIDL) --dlldata-only -o $@" );
|
2013-12-27 06:26:37 -07:00
|
|
|
output_filenames( &dlldata_files, &column );
|
2013-10-15 03:35:11 -07:00
|
|
|
output( "\n" );
|
2013-11-09 10:57:00 -07:00
|
|
|
strarray_add( &clean_files, "dlldata.c" );
|
2013-10-15 03:35:11 -07:00
|
|
|
}
|
2013-10-15 03:39:42 -07:00
|
|
|
|
2013-11-16 03:57:14 -07:00
|
|
|
if (is_test)
|
2013-10-15 03:39:42 -07:00
|
|
|
{
|
2013-12-24 03:37:52 -07:00
|
|
|
struct strarray ok_files = strarray_replace_extension( &test_files, ".c", ".ok" );
|
2013-12-12 05:15:34 -07:00
|
|
|
output( "testlist.c: $(MAKECTESTS) %s\n", src_dir ? strmake("%s/Makefile.in", src_dir ) : "Makefile.in" );
|
2013-10-15 03:39:42 -07:00
|
|
|
column = output( "\t$(MAKECTESTS) -o $@" );
|
2013-12-24 03:37:52 -07:00
|
|
|
output_filenames( &test_files, &column );
|
2013-11-16 03:57:14 -07:00
|
|
|
output( "\n" );
|
|
|
|
column = output( "check test:" );
|
2013-12-24 03:37:52 -07:00
|
|
|
output_filenames( &ok_files, &column );
|
2013-11-16 03:57:14 -07:00
|
|
|
output( "\n" );
|
2013-12-13 12:37:26 -07:00
|
|
|
output( "testclean::\n" );
|
2013-11-16 03:57:14 -07:00
|
|
|
column = output( "\t$(RM)" );
|
2013-12-24 03:37:52 -07:00
|
|
|
output_filenames( &ok_files, &column );
|
2013-10-15 03:39:42 -07:00
|
|
|
output( "\n" );
|
2013-11-09 10:57:00 -07:00
|
|
|
strarray_add( &clean_files, "testlist.c" );
|
2013-12-24 03:37:52 -07:00
|
|
|
strarray_addall( &clean_files, &ok_files );
|
2013-11-09 10:57:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (clean_files.count)
|
|
|
|
{
|
|
|
|
output( "clean::\n" );
|
|
|
|
column = output( "\t$(RM)" );
|
2013-12-24 03:37:52 -07:00
|
|
|
output_filenames( &clean_files, &column );
|
2013-11-09 10:57:00 -07:00
|
|
|
output( "\n" );
|
2013-10-15 03:39:42 -07:00
|
|
|
}
|
2013-11-18 03:34:03 -07:00
|
|
|
|
|
|
|
if (subdirs.count)
|
|
|
|
{
|
2013-12-24 03:37:52 -07:00
|
|
|
column = 0;
|
|
|
|
output_filenames( &subdirs, &column );
|
2013-11-18 03:34:03 -07:00
|
|
|
output( ":\n" );
|
|
|
|
output( "\t$(MKDIR_P) -m 755 $@\n" );
|
|
|
|
}
|
2013-12-13 12:37:26 -07:00
|
|
|
return clean_files;
|
1997-09-28 10:43:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-12 06:43:15 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* create_temp_file
|
|
|
|
*/
|
2013-12-13 12:37:26 -07:00
|
|
|
static FILE *create_temp_file( const char *orig, char **tmp_name )
|
2009-01-12 06:43:15 -07:00
|
|
|
{
|
2013-12-13 12:37:26 -07:00
|
|
|
char *name = xmalloc( strlen(orig) + 13 );
|
2009-01-12 06:43:15 -07:00
|
|
|
unsigned int i, id = getpid();
|
|
|
|
int fd;
|
|
|
|
FILE *ret = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < 100; i++)
|
|
|
|
{
|
2013-12-13 12:37:26 -07:00
|
|
|
sprintf( name, "%s.tmp%08x", orig, id );
|
2009-02-22 12:39:52 -07:00
|
|
|
if ((fd = open( name, O_RDWR | O_CREAT | O_EXCL, 0666 )) != -1)
|
2009-01-12 06:43:15 -07:00
|
|
|
{
|
|
|
|
ret = fdopen( fd, "w" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (errno != EEXIST) break;
|
|
|
|
id += 7777;
|
|
|
|
}
|
2013-12-13 12:37:26 -07:00
|
|
|
if (!ret) fatal_error( "failed to create output file for '%s'\n", orig );
|
2009-01-12 06:43:15 -07:00
|
|
|
*tmp_name = name;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-13 12:37:26 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* rename_temp_file
|
|
|
|
*/
|
|
|
|
static void rename_temp_file( const char *tmp_name, const char *dest )
|
|
|
|
{
|
|
|
|
int ret = rename( tmp_name, dest );
|
|
|
|
if (ret == -1 && errno == EEXIST)
|
|
|
|
{
|
|
|
|
/* rename doesn't overwrite on windows */
|
|
|
|
unlink( dest );
|
|
|
|
ret = rename( tmp_name, dest );
|
|
|
|
}
|
|
|
|
if (ret == -1)
|
|
|
|
{
|
|
|
|
unlink( tmp_name );
|
|
|
|
fatal_error( "failed to rename output file to '%s'\n", dest );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* output_gitignore
|
|
|
|
*/
|
|
|
|
static void output_gitignore( const char *dest, const struct strarray *files )
|
|
|
|
{
|
|
|
|
char *tmp_name;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
output_file = create_temp_file( dest, &tmp_name );
|
|
|
|
|
|
|
|
output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
|
|
|
|
output( "/.gitignore\n" );
|
|
|
|
output( "/Makefile\n" );
|
|
|
|
for (i = 0; i < files->count; i++)
|
|
|
|
{
|
|
|
|
if (!strchr( files->str[i], '/' )) output( "/" );
|
|
|
|
output( "%s\n", files->str[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose( output_file );
|
|
|
|
output_file = NULL;
|
|
|
|
rename_temp_file( tmp_name, dest );
|
|
|
|
free( tmp_name );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-10-23 09:59:13 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* output_dependencies
|
|
|
|
*/
|
|
|
|
static void output_dependencies(void)
|
|
|
|
{
|
2009-01-12 06:43:15 -07:00
|
|
|
char *tmp_name = NULL;
|
2013-12-17 09:10:28 -07:00
|
|
|
char *path = strmake( "%s/%s", base_dir, makefile_name );
|
2013-12-24 03:37:52 -07:00
|
|
|
struct strarray targets = empty_strarray;
|
1996-10-23 09:59:13 -07:00
|
|
|
|
2013-12-17 09:10:28 -07:00
|
|
|
if (Separator && ((output_file = fopen( path, "r" ))))
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
2009-01-12 06:43:15 -07:00
|
|
|
char buffer[1024];
|
2013-12-17 09:10:28 -07:00
|
|
|
FILE *tmp_file = create_temp_file( path, &tmp_name );
|
2010-03-16 05:14:21 -07:00
|
|
|
int found = 0;
|
2009-01-12 06:43:15 -07:00
|
|
|
|
2013-10-14 02:11:07 -07:00
|
|
|
while (fgets( buffer, sizeof(buffer), output_file ) && !found)
|
2006-09-22 00:25:49 -07:00
|
|
|
{
|
2009-01-12 06:43:15 -07:00
|
|
|
if (fwrite( buffer, 1, strlen(buffer), tmp_file ) != strlen(buffer))
|
2013-10-14 02:11:07 -07:00
|
|
|
fatal_error( "failed to write to %s\n", tmp_name );
|
2010-03-16 05:14:21 -07:00
|
|
|
found = !strncmp( buffer, Separator, strlen(Separator) );
|
2006-09-22 00:25:49 -07:00
|
|
|
}
|
2013-10-14 02:11:07 -07:00
|
|
|
fclose( output_file );
|
|
|
|
output_file = tmp_file;
|
2013-11-30 04:50:30 -07:00
|
|
|
if (!found && !list_empty(&sources)) output( "\n%s\n", Separator );
|
1996-10-23 09:59:13 -07:00
|
|
|
}
|
2009-01-12 06:43:15 -07:00
|
|
|
else
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
2013-12-17 09:10:28 -07:00
|
|
|
if (!(output_file = fopen( path, Separator ? "a" : "w" )))
|
|
|
|
fatal_perror( "%s", path );
|
1996-10-23 09:59:13 -07:00
|
|
|
}
|
2013-10-14 02:11:07 -07:00
|
|
|
|
2013-12-13 12:37:26 -07:00
|
|
|
if (!list_empty( &sources )) targets = output_sources();
|
2013-10-14 02:11:07 -07:00
|
|
|
|
|
|
|
fclose( output_file );
|
|
|
|
output_file = NULL;
|
2009-01-12 06:43:15 -07:00
|
|
|
if (tmp_name)
|
|
|
|
{
|
2013-12-17 09:10:28 -07:00
|
|
|
rename_temp_file( tmp_name, path );
|
2009-01-12 06:43:15 -07:00
|
|
|
free( tmp_name );
|
|
|
|
}
|
2013-12-17 09:10:28 -07:00
|
|
|
free( path );
|
2013-12-13 12:37:26 -07:00
|
|
|
|
2013-12-17 09:10:28 -07:00
|
|
|
if (!src_dir) output_gitignore( strmake( "%s/.gitignore", base_dir ), &targets );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* update_makefile
|
|
|
|
*/
|
|
|
|
static void update_makefile( const char *path )
|
|
|
|
{
|
|
|
|
static const char *source_vars[] =
|
|
|
|
{
|
|
|
|
"C_SRCS",
|
|
|
|
"OBJC_SRCS",
|
|
|
|
"RC_SRCS",
|
|
|
|
"MC_SRCS",
|
|
|
|
"IDL_H_SRCS",
|
|
|
|
"IDL_C_SRCS",
|
|
|
|
"IDL_I_SRCS",
|
|
|
|
"IDL_P_SRCS",
|
|
|
|
"IDL_S_SRCS",
|
|
|
|
"IDL_R_SRCS",
|
|
|
|
"IDL_TLB_SRCS",
|
|
|
|
"BISON_SRCS",
|
|
|
|
"LEX_SRCS",
|
|
|
|
"XTEMPLATE_SRCS",
|
|
|
|
"IN_SRCS",
|
|
|
|
"EXTRA_OBJS",
|
|
|
|
"MANPAGES",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
const char **var;
|
|
|
|
unsigned int i;
|
|
|
|
struct strarray value;
|
|
|
|
struct incl_file *file;
|
|
|
|
|
|
|
|
base_dir = path;
|
|
|
|
parse_makefile();
|
|
|
|
|
|
|
|
src_dir = get_expanded_make_variable( "srcdir" );
|
|
|
|
top_src_dir = get_expanded_make_variable( "top_srcdir" );
|
|
|
|
top_obj_dir = get_expanded_make_variable( "top_builddir" );
|
|
|
|
parent_dir = get_expanded_make_variable( "PARENTSRC" );
|
|
|
|
|
2013-12-24 03:37:52 -07:00
|
|
|
object_extensions = empty_strarray;
|
2013-12-17 09:10:28 -07:00
|
|
|
value = get_expanded_make_var_array( "MAKEDEPFLAGS" );
|
|
|
|
for (i = 0; i < value.count; i++)
|
|
|
|
if (!strncmp( value.str[i], "-x", 2 ))
|
|
|
|
strarray_add( &object_extensions, value.str[i] + 2 );
|
|
|
|
|
2013-12-24 03:37:52 -07:00
|
|
|
include_args = empty_strarray;
|
2013-12-17 09:10:28 -07:00
|
|
|
value = get_expanded_make_var_array( "EXTRAINCL" );
|
|
|
|
for (i = 0; i < value.count; i++)
|
|
|
|
if (!strncmp( value.str[i], "-I", 2 ))
|
2013-12-26 13:51:38 -07:00
|
|
|
strarray_add_uniq( &include_args, value.str[i] );
|
2013-12-17 09:10:28 -07:00
|
|
|
|
|
|
|
init_paths();
|
|
|
|
|
|
|
|
list_init( &sources );
|
|
|
|
list_init( &includes );
|
|
|
|
|
|
|
|
for (var = source_vars; *var; var++)
|
|
|
|
{
|
|
|
|
value = get_expanded_make_var_array( *var );
|
|
|
|
for (i = 0; i < value.count; i++) add_src_file( value.str[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
add_generated_sources();
|
|
|
|
LIST_FOR_EACH_ENTRY( file, &includes, struct incl_file, entry ) parse_file( file, 0 );
|
|
|
|
output_dependencies();
|
1996-10-23 09:59:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-26 11:26:37 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* parse_makeflags
|
|
|
|
*/
|
|
|
|
static void parse_makeflags( const char *flags )
|
|
|
|
{
|
|
|
|
const char *p = flags;
|
|
|
|
char *var, *buffer = xmalloc( strlen(flags) + 1 );
|
|
|
|
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
while (isspace(*p)) p++;
|
|
|
|
var = buffer;
|
|
|
|
while (*p && !isspace(*p))
|
|
|
|
{
|
|
|
|
if (*p == '\\' && p[1]) p++;
|
|
|
|
*var++ = *p++;
|
|
|
|
}
|
|
|
|
*var = 0;
|
|
|
|
if (var > buffer) set_make_variable( &cmdline_vars, buffer );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-10-23 09:59:13 -07:00
|
|
|
/*******************************************************************
|
|
|
|
* parse_option
|
|
|
|
*/
|
2013-12-26 11:26:29 -07:00
|
|
|
static int parse_option( const char *opt )
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
2013-12-26 11:26:29 -07:00
|
|
|
if (opt[0] != '-')
|
|
|
|
{
|
|
|
|
if (strchr( opt, '=' )) return set_make_variable( &cmdline_vars, opt );
|
|
|
|
return 0;
|
|
|
|
}
|
1996-10-23 09:59:13 -07:00
|
|
|
switch(opt[1])
|
|
|
|
{
|
|
|
|
case 'I':
|
2013-12-26 13:51:38 -07:00
|
|
|
if (opt[2]) strarray_add_uniq( &include_args, opt );
|
1996-10-23 09:59:13 -07:00
|
|
|
break;
|
|
|
|
case 'C':
|
2006-08-01 03:27:22 -07:00
|
|
|
src_dir = opt + 2;
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
top_src_dir = opt + 2;
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
top_obj_dir = opt + 2;
|
1996-10-23 09:59:13 -07:00
|
|
|
break;
|
2013-11-12 03:03:09 -07:00
|
|
|
case 'P':
|
|
|
|
parent_dir = opt + 2;
|
|
|
|
break;
|
1996-10-23 09:59:13 -07:00
|
|
|
case 'f':
|
2013-12-17 09:10:28 -07:00
|
|
|
if (opt[2]) makefile_name = opt + 2;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
parse_makefile_mode = 1;
|
1996-10-23 09:59:13 -07:00
|
|
|
break;
|
2013-11-08 13:11:59 -07:00
|
|
|
case 'R':
|
|
|
|
relative_dir_mode = 1;
|
|
|
|
break;
|
1996-10-23 09:59:13 -07:00
|
|
|
case 's':
|
|
|
|
if (opt[2]) Separator = opt + 2;
|
|
|
|
else Separator = NULL;
|
|
|
|
break;
|
2009-06-30 01:25:05 -07:00
|
|
|
case 'x':
|
2013-11-19 03:36:25 -07:00
|
|
|
if (opt[2]) strarray_add( &object_extensions, xstrdup( opt + 2 ));
|
2009-06-30 01:25:05 -07:00
|
|
|
break;
|
1996-10-23 09:59:13 -07:00
|
|
|
default:
|
2013-10-14 02:11:07 -07:00
|
|
|
fprintf( stderr, "Unknown option '%s'\n%s", opt, Usage );
|
1996-10-23 09:59:13 -07:00
|
|
|
exit(1);
|
|
|
|
}
|
2013-12-26 11:26:29 -07:00
|
|
|
return 1;
|
1996-10-23 09:59:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* main
|
|
|
|
*/
|
|
|
|
int main( int argc, char *argv[] )
|
|
|
|
{
|
2013-12-26 11:26:37 -07:00
|
|
|
const char *makeflags = getenv( "MAKEFLAGS" );
|
2013-10-14 01:51:37 -07:00
|
|
|
struct incl_file *pFile;
|
2006-08-01 03:27:22 -07:00
|
|
|
int i, j;
|
1996-10-23 09:59:13 -07:00
|
|
|
|
2013-12-26 11:26:37 -07:00
|
|
|
if (makeflags) parse_makeflags( makeflags );
|
|
|
|
|
2006-08-01 03:27:22 -07:00
|
|
|
i = 1;
|
|
|
|
while (i < argc)
|
1996-10-23 09:59:13 -07:00
|
|
|
{
|
2013-12-26 11:26:29 -07:00
|
|
|
if (parse_option( argv[i] ))
|
2006-08-01 03:27:22 -07:00
|
|
|
{
|
|
|
|
for (j = i; j < argc; j++) argv[j] = argv[j+1];
|
|
|
|
argc--;
|
|
|
|
}
|
|
|
|
else i++;
|
|
|
|
}
|
|
|
|
|
2013-11-08 13:11:59 -07:00
|
|
|
if (relative_dir_mode)
|
|
|
|
{
|
|
|
|
char *relpath;
|
|
|
|
|
|
|
|
if (argc != 3)
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Option -r needs two directories\n%s", Usage );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
relpath = get_relative_path( argv[1], argv[2] );
|
|
|
|
printf( "%s\n", relpath ? relpath : "." );
|
|
|
|
exit( 0 );
|
|
|
|
}
|
|
|
|
|
2013-12-17 09:10:28 -07:00
|
|
|
if (parse_makefile_mode)
|
|
|
|
{
|
|
|
|
for (i = 1; i < argc; i++) update_makefile( argv[i] );
|
|
|
|
exit( 0 );
|
|
|
|
}
|
2006-08-01 03:27:22 -07:00
|
|
|
|
2013-12-17 09:10:28 -07:00
|
|
|
init_paths();
|
2013-10-14 03:12:26 -07:00
|
|
|
for (i = 1; i < argc; i++) add_src_file( argv[i] );
|
2013-11-04 09:39:30 -07:00
|
|
|
add_generated_sources();
|
2013-10-14 03:12:26 -07:00
|
|
|
|
2013-10-14 01:51:37 -07:00
|
|
|
LIST_FOR_EACH_ENTRY( pFile, &includes, struct incl_file, entry ) parse_file( pFile, 0 );
|
2006-09-22 00:25:49 -07:00
|
|
|
output_dependencies();
|
1996-10-23 09:59:13 -07:00
|
|
|
return 0;
|
|
|
|
}
|