6 * @file: the name of a data file
7 * @caller: caller program (argv[0])
9 * Builds the proper path of a data file, without checking
10 * for @file existence. This wrapper is needed to allow
11 * running the program either when uninstalled and installed
12 * and to deal with different platform issues.
14 * A call is considered coming from an uninstalled program
15 * if @caller (containing the supposed absolute path of
16 * the program) contains the LT_OBJDIR constant (usually
17 * ".libs"), typically used to store an uninstalled binary.
19 * If the call comes from an uninstalled program, @file will
20 * be searched in the parent directory of @caller dirname.
22 * If the call comes from an installed program, the
23 * %ADG_DATADIR will be used instead. This constant is set
24 * by the makefile throught preprocessor flags and will be
25 * considered an absolute path on non-windows platforms,
26 * hence resolving to $(pkgdatadir), or a path relative to
27 * the @caller dirname on windows platforms.
29 * Returns: the full path to @file that must bel freed with
30 * g_free() or %NULL on errors
33 demo_find_data_file(const gchar
*file
, const gchar
*caller
)
35 static gchar
*data_root
= NULL
;
37 if (data_root
== NULL
) {
38 if (caller
== NULL
|| strstr(caller
, LT_OBJDIR
) == NULL
) {
39 /* Supposedly, this is a call to an installed program */
42 /* On windows, ADG_DATADIR is a path relative to the
43 * caller dirname. This is needed because the data
44 * files must be relocatable, so the installer is free
45 * to put the project tree under custom directories.
46 * Other files, such as headers and libraries, are
47 * yet properly managed by autotools.
49 gchar
*caller_dirname
= g_path_get_dirname(caller
);
50 data_root
= g_build_filename(caller_dirname
, ADG_DATADIR
, NULL
);
51 g_free(caller_dirname
);
53 #else /* ! G_OS_WIN32 */
55 /* On other operating systems, ADG_DATADIR is an
56 * absolute path, so no further processing is required.
58 data_root
= ADG_DATADIR
;
62 /* This is likely an uninstalled program call: set
63 * data_root to the parent directory of the caller dirname.
65 gchar
*caller_dirname
= g_path_get_dirname(caller
);
66 data_root
= g_build_filename(caller_dirname
, "..", NULL
);
67 g_free(caller_dirname
);
71 return g_build_filename(data_root
, file
, NULL
);