Commit 517d274e authored by Alexandre Julliard's avatar Alexandre Julliard

makefiles: Add support for building from source files from a parent directory.

parent eaef76f0
......@@ -11,7 +11,7 @@
# First some useful definitions
INCLUDES = -I$(srcdir) -I. -I$(top_srcdir)/include -I$(top_builddir)/include $(EXTRAINCL)
INCLUDES = -I$(srcdir) $(PARENTSRC:%=-I@srcdir@/%) -I. -I$(top_srcdir)/include -I$(top_builddir)/include $(EXTRAINCL)
DEFS = -D__WINESRC__ $(EXTRADEFS)
ALLCFLAGS = $(INCLUDES) $(DEFS) $(DLLFLAGS) $(EXTRACFLAGS) $(CPPFLAGS) $(CFLAGS) $(MODCFLAGS)
IDLFLAGS = $(INCLUDES) $(DEFS) $(EXTRAIDLFLAGS)
......@@ -88,7 +88,7 @@ DEPEND_SRCS = $(C_SRCS) $(OBJC_SRCS) $(RC_SRCS) $(MC_SRCS) \
$(BISON_SRCS) $(LEX_SRCS) $(EXTRA_OBJS)
depend: dummy
$(MAKEDEP) $(MAKEDEPFLAGS) -C$(srcdir) -S$(top_srcdir) -T$(top_builddir) $(EXTRAINCL) $(DEPEND_SRCS)
$(MAKEDEP) $(MAKEDEPFLAGS) -C$(srcdir) -S$(top_srcdir) -T$(top_builddir) $(PARENTSRC:%=-P%) $(EXTRAINCL) $(DEPEND_SRCS)
.PHONY: depend
......
......@@ -322,7 +322,7 @@ sub parse_makefile($)
$make{"=rules"} = $makerules{$var} || $var;
next;
}
if (/^\s*(MODULE|IMPORTLIB|TESTDLL|MANPAGE)\s*=\s*(.*)/)
if (/^\s*(MODULE|IMPORTLIB|TESTDLL|MANPAGE|PARENTSRC)\s*=\s*(.*)/)
{
my $var = $1;
$make{$var} = $2;
......@@ -386,6 +386,38 @@ sub get_makedep_flags($)
return %flags;
}
sub get_parent_makefile($)
{
my $file = shift;
my %make = %{$makefiles{$file}};
my $reldir = $make{"PARENTSRC"} || "";
return "" unless $reldir;
(my $path = $file) =~ s/\/Makefile$/\//;
while ($reldir =~ /^\.\.\//)
{
$reldir =~ s/^\.\.\///;
$path =~ s/[^\/]+\/$//;
}
return "$path$reldir/Makefile";
}
# preserve shared source files that are listed in the existing makefile
sub preserve_shared_source_files($$$)
{
my ($make, $parent, $var) = @_;
my %srcs;
return unless defined ${$parent}{"=$var"};
foreach my $file (@{${$parent}{"=$var"}}) { $srcs{$file} = 1; }
foreach my $file (@{${$make}{"=$var"}}) { $srcs{$file} = 0; }
foreach my $file (@{${$make}{$var}})
{
next unless defined $srcs{$file} && $srcs{$file} == 1;
push @{${$make}{"=$var"}}, $file;
}
}
# assign source files to their respective makefile
sub assign_sources_to_makefiles(@)
{
......@@ -474,6 +506,17 @@ sub assign_sources_to_makefiles(@)
unshift @{${$make}{"=SRCDIR_INCLUDES"}}, "\$(XTEMPLATE_SRCS)";
unshift @{${$make}{"=SRCDIR_INCLUDES"}}, "\$(PUBLIC_IDL_H_SRCS)";
unshift @{${$make}{"=SRCDIR_INCLUDES"}}, "\$(IDL_TLB_SRCS)";
# preserve shared source files from the parent makefile
foreach my $file (@makefiles)
{
my %make = %{$makefiles{$file}};
my $parent = get_parent_makefile( $file );
next unless $parent;
preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "C_SRCS" );
preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "LEX_SRCS" );
preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "BISON_SRCS" );
}
}
################################################################
......
......@@ -107,6 +107,7 @@ struct strarray
static const char *src_dir;
static const char *top_src_dir;
static const char *top_obj_dir;
static const char *parent_dir;
static const char *OutputFileName = "Makefile";
static const char *Separator = "### Dependencies";
static const char *input_file_name;
......@@ -121,6 +122,7 @@ static const char Usage[] =
" -Cdir Search for source files in directory 'dir'\n"
" -Sdir Set the top source directory\n"
" -Tdir Set the top object directory\n"
" -Pdir Set the parent source directory\n"
" -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";
......@@ -536,6 +538,16 @@ static FILE *open_src_file( struct incl_file *pFile )
pFile->filename = strmake( "%s/%s", src_dir, pFile->name );
file = fopen( pFile->filename, "r" );
}
/* 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 );
if ((file = fopen( pFile->filename, "r" ))) return file;
file = fopen( pFile->filename, "r" );
}
if (!file) fatal_perror( "open %s", pFile->name );
return file;
}
......@@ -601,6 +613,17 @@ static FILE *open_include_file( struct incl_file *pFile )
free( filename );
}
/* 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 );
if ((file = fopen( filename, "r" ))) goto found;
free( filename );
}
/* check for corresponding idl file in global includes */
if (strendswith( pFile->name, ".h" ))
......@@ -1410,6 +1433,9 @@ static void parse_option( const char *opt )
case 'T':
top_obj_dir = opt + 2;
break;
case 'P':
parent_dir = opt + 2;
break;
case 'f':
if (opt[2]) OutputFileName = opt + 2;
break;
......
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