From: Alexandros Frantzis alexandros.frantzis@collabora.com
Wayland protocol descriptions are distributed as source XML files that need to be transformed to C source and header files with a version of the wayland-scanner tool compatible with the used libwayland library.
This commit enhances the makedep build tool to support building such Wayland protocol XML files. Components can use the WAYLAND_PROTOCOL_SRCS build variable to add protocol XML files to their build.
Since protocol files likely reside outside of the source tree, they may be missing, in which case the Wayland driver will be disabled. To handle this scenario, update the makedep tool to not bail out when we have such missing external sources in disabled makefiles.
Signed-off-by: Alexandros Frantzis alexandros.frantzis@collabora.com --- tools/makedep.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 108 insertions(+), 4 deletions(-)
diff --git a/tools/makedep.c b/tools/makedep.c index 49a7514c9f0..28be80049d2 100644 --- a/tools/makedep.c +++ b/tools/makedep.c @@ -157,6 +157,7 @@ static const char *icotool; static const char *msgfmt; static const char *ln_s; static const char *sed_cmd; +static const char *wayland_scanner; /* per-architecture global variables */ static const char *arch_dirs[MAX_ARCHS]; static const char *arch_pe_dirs[MAX_ARCHS]; @@ -470,6 +471,15 @@ static char *replace_filename( const char *path, const char *name ) return ret; }
+/******************************************************************* + * get_filename + */ +static const char *get_filename( const char *name ) +{ + char *filename = strrchr( name, '/' ); + if (!filename) return name; + return filename + 1; +}
/******************************************************************* * replace_substr @@ -1197,9 +1207,9 @@ static const struct };
/******************************************************************* - * load_file + * load_file_maybe_missing */ -static struct file *load_file( const char *name ) +static struct file *load_file_maybe_missing( const char *name, int allow_missing ) { struct file *file; FILE *f; @@ -1208,10 +1218,13 @@ static struct file *load_file( const char *name ) LIST_FOR_EACH_ENTRY( file, &files[hash], struct file, entry ) if (!strcmp( name, file->name )) return file;
- if (!(f = fopen( name, "r" ))) return NULL; + if (!(f = fopen( name, "r" )) && !allow_missing) return NULL;
file = add_file( name ); list_add_tail( &files[hash], &file->entry ); + + if (!f) return file; + input_file_name = file->name; input_line = 0;
@@ -1229,6 +1242,15 @@ static struct file *load_file( const char *name ) }
+/******************************************************************* + * load_file + */ +static struct file *load_file( const char *name ) +{ + return load_file_maybe_missing(name, 0); +} + + /******************************************************************* * open_include_path_file * @@ -1383,12 +1405,52 @@ static struct file *open_global_generated_file( const struct makefile *make, str */ static struct file *open_src_file( const struct makefile *make, struct incl_file *pFile ) { - struct file *file = open_local_file( make, pFile->name, &pFile->filename ); + struct file *file; + + if (pFile->name[0] == '/') + { + /* Allow missing external source files if the makefile is disabled. */ + file = load_file_maybe_missing( pFile->name, make->disabled[0] ); + pFile->filename = xstrdup( pFile->name ); + } + else + { + file = open_local_file( make, pFile->name, &pFile->filename ); + }
if (!file) fatal_perror( "open %s", pFile->name ); return file; }
+/******************************************************************* + * open_wayland_protocol_file + */ +static struct file *open_wayland_protocol_file( const struct makefile *make, + struct incl_file *pFile ) +{ + char *proto_filename; + struct incl_file *incl_file; + struct file *ret_file = NULL; + + if (!strendswith( pFile->name, "-client-protocol.h" )) return NULL; + + proto_filename = replace_extension( pFile->name, "-client-protocol.h", ".xml" ); + + LIST_FOR_EACH_ENTRY( incl_file, &make->sources, struct incl_file, entry ) + { + if (strendswith( incl_file->name, proto_filename )) + { + pFile->sourcename = incl_file->filename; + pFile->filename = obj_dir_path( make, pFile->name ); + ret_file = incl_file->file; + break; + } + } + + free( proto_filename ); + + return ret_file; +}
/******************************************************************* * find_importlib_module @@ -1428,6 +1490,7 @@ static struct file *open_include_file( const struct makefile *make, struct incl_ if ((file = open_local_generated_file( make, pFile, ".cur", ".svg" ))) return file; if ((file = open_local_generated_file( make, pFile, ".ico", ".svg" ))) return file; } + if ((file = open_wayland_protocol_file( make, pFile ))) return file;
/* check for extra targets */ if (strarray_exists( &make->extra_targets, pFile->name )) @@ -1802,6 +1865,15 @@ static struct makefile *parse_makefile( const char *path ) return make; }
+/******************************************************************* + * is_wayland_protocol + */ +static int is_wayland_protocol( struct incl_file *source ) +{ + return strendswith( source->name, ".xml" ) && + (strstr( source->name, "stable/" ) || strstr( source->name, "unstable/" ) || + strstr( source->name, "staging/" )); +}
/******************************************************************* * add_generated_sources @@ -1915,6 +1987,22 @@ static void add_generated_sources( struct makefile *make ) strarray_addall_uniq( &make->extra_imports, get_expanded_file_local_var( make, obj, "IMPORTS" )); } + if (is_wayland_protocol( source )) + { + const char *filename = get_filename( source->name ); + char *code_filename = replace_extension ( filename , ".xml", "-protocol.c" ); + char *header_filename = replace_extension ( filename , ".xml", "-client-protocol.h" ); + + file = add_generated_source( make, code_filename, NULL, 0 ); + file->file->flags |= FLAG_C_UNIX; + file->use_msvcrt = 0; + file = add_generated_source( make, header_filename, NULL, 0 ); + file->file->flags |= FLAG_C_UNIX; + file->use_msvcrt = 0; + + free( code_filename ); + free( header_filename ); + } } if (make->testdll) { @@ -3101,6 +3189,18 @@ static void output_source_spec( struct makefile *make, struct incl_file *source, } }
+static void output_source_xml( struct makefile *make, struct incl_file *source, const char *obj ) +{ + const char *base; + + if (!is_wayland_protocol( source )) return; + + base = get_filename( obj ); + output( "%s-protocol.c: %s\n", obj_dir_path( make, base ), source->filename ); + output( "\t%s%s private-code $< $@\n", cmd_prefix( "WAYLAND_SCANNER" ), wayland_scanner ); + output( "%s-client-protocol.h: %s\n", obj_dir_path( make, base ), source->filename ); + output( "\t%s%s client-header $< $@\n", cmd_prefix( "WAYLAND_SCANNER" ), wayland_scanner); +}
/******************************************************************* * output_source_one_arch @@ -3240,6 +3340,7 @@ static const struct { "in", output_source_in }, { "x", output_source_x }, { "spec", output_source_spec }, + { "xml", output_source_xml }, { NULL, output_source_default } };
@@ -4054,6 +4155,7 @@ static void output_silent_rules(void) "MSG", "SED", "TEST", + "WAYLAND_SCANNER", "WIDL", "WMC", "WRC" @@ -4153,6 +4255,7 @@ static void load_sources( struct makefile *make ) "IN_SRCS", "PO_SRCS", "MANPAGES", + "WAYLAND_PROTOCOL_SRCS", NULL }; const char **var; @@ -4383,6 +4486,7 @@ int main( int argc, char *argv[] ) msgfmt = get_expanded_make_variable( top_makefile, "MSGFMT" ); sed_cmd = get_expanded_make_variable( top_makefile, "SED_CMD" ); ln_s = get_expanded_make_variable( top_makefile, "LN_S" ); + wayland_scanner = get_expanded_make_variable( top_makefile, "WAYLAND_SCANNER" );
if (root_src_dir && !strcmp( root_src_dir, "." )) root_src_dir = NULL; if (tools_dir && !strcmp( tools_dir, "." )) tools_dir = NULL;