+ return -1;
+}
+
+/* For F a filename, return the name of language directory where F is located,
+ if any, NULL otherwise. */
+
+static const char *
+get_file_langdir (const char *f)
+{
+ /* Get the relative path to F from $(srcdir) and find the language by
+ comparing the prefix with language directory names. If F is not even
+ srcdir relative, no point in looking further. */
+
+ int lang_index;
+ const char * srcdir_relative_path = get_file_srcdir_relative_path (f);
+
+ if (!srcdir_relative_path)
+ return NULL;
+
+ lang_index = get_prefix_langdir_index (srcdir_relative_path);
+
+ return (lang_index >= 0) ? lang_dir_names [lang_index] : NULL;
+}
+
+/* The gt- output file name for F. */
+
+static const char *
+get_file_gtfilename (const char *f)
+{
+ /* Cook up an initial version of the gt- file name from the file real
+ basename and the language name, if any. */
+
+ const char *basename = get_file_realbasename (f);
+ const char *langdir = get_file_langdir (f);
+
+ char * result =
+ (langdir ? xasprintf ("gt-%s-%s", langdir, basename)
+ : xasprintf ("gt-%s", basename));
+
+ /* Then replace all non alphanumerics characters by '-' and change the
+ extenstion to ".h". We expect the input filename extension was at least
+ one character long. */
+
+ char *s = result;
+
+ for (; *s != '.'; s++)
+ if (! ISALNUM (*s) && *s != '-')
+ *s = '-';
+
+ memcpy (s, ".h", sizeof (".h"));
+
+ return result;