2011-04-24 00:35:30 -07:00
|
|
|
#ifndef EINA_PREFIX_H_
|
|
|
|
#define EINA_PREFIX_H_
|
|
|
|
|
|
|
|
/**
|
2014-10-31 01:24:35 -07:00
|
|
|
* @defgroup Eina_Prefix_Group Prefix
|
|
|
|
* @ingroup Eina_Tools_Group
|
2011-04-24 00:35:30 -07:00
|
|
|
*
|
2014-10-31 01:24:35 -07:00
|
|
|
* @brief This group discusses the functions that provide the ability to determine the runtime
|
|
|
|
* location of a software package.
|
2011-04-24 00:35:30 -07:00
|
|
|
*
|
|
|
|
* @{
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2011-04-24 01:30:12 -07:00
|
|
|
* @since 1.1.0
|
2011-04-24 00:35:30 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef Eina_Prefix
|
2017-02-19 22:18:21 -08:00
|
|
|
* @brief An opaque type for prefix handle.
|
2014-10-31 01:24:35 -07:00
|
|
|
* @details This is a prefix object that is returned by eina_prefix_new() when trying
|
|
|
|
* to determine the runtime location of the software in question so that other
|
|
|
|
* data files such as images, sound files, other executable utilities,
|
|
|
|
* libraries, modules, and locale files can be found.
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2011-04-24 01:30:12 -07:00
|
|
|
* @since 1.1.0
|
2011-04-24 00:35:30 -07:00
|
|
|
*/
|
|
|
|
typedef struct _Eina_Prefix Eina_Prefix;
|
|
|
|
|
|
|
|
/**
|
2014-10-31 01:24:35 -07:00
|
|
|
* @brief Creates a new prefix handle given that some input information is provided.
|
|
|
|
*
|
|
|
|
* @param[in] argv0 If this is an executable this is argv[0] of the binary, otherwise @c NULL if it is used from a shared library
|
|
|
|
* @param[in] symbol A symbol (function for example) inside the binary or library to find the source location of, provide @c NULL if not used
|
|
|
|
* @param[in] envprefix The prefix to any environment variable that may override prefix detection and give the exact location of the software
|
|
|
|
* @param[in] sharedir The directory inside the standard share or data dir where the software stores data files
|
|
|
|
* @param[in] magicsharefile A magic file to check existence of and determine whether the prefix found is correct, and it must be located in the data
|
|
|
|
* dir under the share dir provided above, or @c NULL if the check is not to be done
|
|
|
|
* @param[in] pkg_bin The compile-time binary install dir
|
|
|
|
* @param[in] pkg_lib The compile-time library install dir
|
|
|
|
* @param[in] pkg_data The compile-time share/data install dir
|
|
|
|
* @param[in] pkg_locale The compile-time locale install dir
|
|
|
|
* @return The prefix handle, otherwise @c NULL on failure
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2011-04-24 00:35:30 -07:00
|
|
|
* Applications and libraries are most often not just single executables nor
|
2014-10-31 01:24:35 -07:00
|
|
|
* single shared library binaries, but also come with extra modules that they
|
2011-04-24 00:35:30 -07:00
|
|
|
* have to load, extra binary utilities they need to run, or have data files
|
2014-10-31 01:24:35 -07:00
|
|
|
* that they need to load. A very primitive application ASSUMES a fixed install
|
2011-04-24 00:35:30 -07:00
|
|
|
* location at compile-time, but this disallows the ability to re-locate
|
|
|
|
* the application (or library) somewhere else after compilation (if you run
|
2017-11-07 22:20:34 -08:00
|
|
|
* out of space on a given disk, partition, etc. for example), or necessitate
|
2011-05-30 09:08:20 -07:00
|
|
|
* the need for having to maintain environment variables for every piece of
|
|
|
|
* software to let it know its location, or have to use large sets of
|
2011-04-24 00:35:30 -07:00
|
|
|
* symlinks pointing from the compiled location to the new one.
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2011-04-24 00:35:30 -07:00
|
|
|
* Being re-locatable at runtime allows much easier distribution and
|
|
|
|
* installation into places like the users own home directory, instead of
|
|
|
|
* on a system partition, if the developer wishes for easier distribution
|
|
|
|
* of pre-compiled binaries.
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2011-04-24 00:35:30 -07:00
|
|
|
* The prefix system is designed to locate where the given software is
|
|
|
|
* installed (under a common prefix) at runtime and then report specific
|
|
|
|
* locations of this prefix and common directories inside this prefix like
|
2014-10-31 01:24:35 -07:00
|
|
|
* the binary, library, data, and locale directories.
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2011-04-24 00:35:30 -07:00
|
|
|
* To do this some information needs to be provided to eina_prefix_new(). If
|
2014-10-31 01:24:35 -07:00
|
|
|
* you have developed a binary executable, then provide argv[0] as the @a argv0
|
|
|
|
* argument. This plus the PATH environment variable helps the prefix system
|
2011-04-24 00:35:30 -07:00
|
|
|
* to determine its location. Call eina_prefix_new() early on before you
|
2014-10-31 01:24:35 -07:00
|
|
|
* change the working directory or anything about argv[0], so it gets accurate
|
|
|
|
* information. It uses the first argument, being the executable itself,
|
|
|
|
* to look in absolute directories, relative paths, and PATH to see if it
|
2011-04-24 00:35:30 -07:00
|
|
|
* finds the right executable to determine just where the actual binary is
|
2017-11-07 22:20:34 -08:00
|
|
|
* installed and being run from. If you develop a shared library, just pass
|
2014-10-31 01:24:35 -07:00
|
|
|
* @c NULL as @a argv0.
|
|
|
|
*
|
|
|
|
* @note It would prefer to use the @a symbol function to determine the location as
|
|
|
|
* that function is unique inside the application and try and trace
|
|
|
|
* back which file this function comes from (be it a binary or shared library)
|
|
|
|
* as this avoids more expensive searches via @a argv0. It uses this
|
|
|
|
* symbol if given in preference to @a argv0.
|
|
|
|
*
|
2017-11-07 22:20:34 -08:00
|
|
|
* @note The @a envprefix parameter provides a string prefix to prepend before
|
2014-10-31 01:24:35 -07:00
|
|
|
* environment variables to allow a fallback to specific environment variables
|
|
|
|
* to locate the software. For example, if "MYAPP" is provided as the prefix,
|
|
|
|
* then it uses "MYAPP_PREFIX" as a master environment variable to specify
|
|
|
|
* the exact install prefix for the software, or more specific environment
|
|
|
|
* variables like "MYAPP_BIN_DIR", "MYAPP_LIB_DIR", "MYAPP_DATA_DIR", and
|
|
|
|
* "MYAPP_LOCALE_DIR", which can be set by the user or scripts before
|
|
|
|
* launching. If not provided (NULL) environment variables are not
|
|
|
|
* used to override compiled-in defaults or auto detections.
|
|
|
|
*
|
|
|
|
* @note The @a sharedir string provides a subdirectory inside the system shared
|
|
|
|
* data dir for data files. For example, if the system dir is
|
|
|
|
* /usr/local/share then this dir name is appended, creating
|
|
|
|
* /usr/local/share/appname if this dir is the "appname" string. It is
|
|
|
|
* expected that the application or library installs data files in this directory.
|
|
|
|
*
|
|
|
|
* @note The @a magicsharefile is a filename or path of something inside the share
|
|
|
|
* or data dir to be used to test that the prefix detection worked. For
|
|
|
|
* example, your app installs a wallpaper image as
|
|
|
|
* /usr/local/share/appname/images/wallpaper.jpg and so to check that this
|
|
|
|
* worked, provide "images/wallpaper.jpg" as the @a magicsharefile string
|
2017-11-07 22:20:34 -08:00
|
|
|
* so detection can know if it worked or not.
|
2014-10-31 01:24:35 -07:00
|
|
|
*
|
|
|
|
* @note The @a pkg_bin, @a pkg_lib, @a pkg_data, and @a pkg_locale are compile-time
|
|
|
|
* strings (the kind standard autoconf/automake define) to be passed in
|
|
|
|
* so that there can be a fallback to compiled-in defaults as well as use them
|
|
|
|
* to determine actual names of directories like libdirs maybe changing to
|
|
|
|
* be lib32 or lib64 instead of lib, and so on.
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2011-04-24 00:35:30 -07:00
|
|
|
* Compile the following defining at compile time your prefixes like (example):
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2012-04-17 10:18:58 -07:00
|
|
|
* gcc appname.c -o appname
|
|
|
|
* -DPACKAGE_BIN_DIR=\\"/usr/local/bin\"
|
|
|
|
* -DPACKAGE_LIB_DIR=\\"/usr/local/lib\"
|
|
|
|
* -DPACKAGE_DATA_DIR=\\"/usr/local/share/appname\"
|
|
|
|
* -DLOCALE_DIR=\\"/usr/local/share/locale\"
|
|
|
|
* `pkg-config --cflags --libs eina`
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2014-10-31 01:24:35 -07:00
|
|
|
* (of course add appropriate compile flags to linking and note that
|
|
|
|
* locale dir is optional. If you don't need it, provide data dir as the
|
|
|
|
* locale dir. Also note that the magicsharefile is optional for testing and
|
|
|
|
* ensuring that the prefix check is correct. This file must be installed
|
2017-11-07 22:20:34 -08:00
|
|
|
* in the application data dir (e.g. /usr/local/share/appname) and be referred
|
2011-04-24 00:35:30 -07:00
|
|
|
* to using a unix-style relative path from that dir, eg directory/filename.png)
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2011-04-24 00:35:30 -07:00
|
|
|
* @code
|
2012-04-17 10:18:58 -07:00
|
|
|
* #include <Eina.h>
|
|
|
|
*
|
2011-04-24 00:35:30 -07:00
|
|
|
* static Eina_Prefix *pfx = NULL;
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2012-04-17 10:18:58 -07:00
|
|
|
* int main(int argc, char **argv)
|
2011-04-24 00:35:30 -07:00
|
|
|
* {
|
2012-04-17 10:18:58 -07:00
|
|
|
* eina_init();
|
|
|
|
*
|
2011-04-24 02:32:16 -07:00
|
|
|
* pfx = eina_prefix_new(argv[0], main, "APPNAME", "appname", NULL,
|
|
|
|
* PACKAGE_BIN_DIR, PACKAGE_LIB_DIR,
|
2011-05-30 09:08:20 -07:00
|
|
|
* PACKAGE_DATA_DIR, LOCALE_DIR);
|
2011-04-24 00:35:30 -07:00
|
|
|
* if (!pfx) printf("ERROR: Critical error in finding prefix\n");
|
|
|
|
* printf("install prefix is: %s\n", eina_prefix_get(pfx));
|
|
|
|
* printf("binaries are in: %s\n", eina_prefix_bin_get(pfx));
|
|
|
|
* printf("libraries are in: %s\n", eina_prefix_lib_get(pfx));
|
|
|
|
* printf("data files are in: %s\n", eina_prefix_data_get(pfx));
|
2011-04-24 02:32:16 -07:00
|
|
|
* eina_prefix_free(pfx);
|
2012-04-17 10:18:58 -07:00
|
|
|
*
|
|
|
|
* eina_shutdown();
|
2011-04-24 00:35:30 -07:00
|
|
|
* }
|
|
|
|
* @endcode
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2011-04-24 01:30:12 -07:00
|
|
|
* @since 1.1.0
|
2014-10-31 01:24:35 -07:00
|
|
|
*
|
|
|
|
* @see eina_prefix_free()
|
2011-04-24 00:35:30 -07:00
|
|
|
*/
|
2014-10-31 01:24:35 -07:00
|
|
|
EAPI Eina_Prefix *eina_prefix_new(const char *argv0, void *symbol, const char *envprefix,
|
|
|
|
const char *sharedir, const char *magicsharefile,
|
|
|
|
const char *pkg_bin, const char *pkg_lib,
|
|
|
|
const char *pkg_data, const char *pkg_locale) EINA_ARG_NONNULL(6, 7, 8, 9) EINA_WARN_UNUSED_RESULT;
|
2011-04-24 00:35:30 -07:00
|
|
|
|
2011-04-24 01:37:52 -07:00
|
|
|
/**
|
2014-10-31 01:24:35 -07:00
|
|
|
* @brief Frees the prefix object and all its contents.
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2014-10-31 01:24:35 -07:00
|
|
|
* @param[in] pfx The prefix object
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2014-10-31 01:24:35 -07:00
|
|
|
* @details This function frees the prefix object and all its allocated content. It is invalid
|
|
|
|
* to access the object after it is freed.
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2011-04-24 01:30:12 -07:00
|
|
|
* @since 1.1.0
|
2014-10-31 01:24:35 -07:00
|
|
|
*
|
|
|
|
* @see eina_prefix_new()
|
2011-04-24 00:35:30 -07:00
|
|
|
*/
|
2014-10-31 01:24:35 -07:00
|
|
|
EAPI void eina_prefix_free(Eina_Prefix *pfx) EINA_ARG_NONNULL(1);
|
2011-04-24 00:35:30 -07:00
|
|
|
|
|
|
|
/**
|
2014-10-31 01:24:35 -07:00
|
|
|
* @brief Gets the prefix base directory.
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2014-10-31 01:24:35 -07:00
|
|
|
* @param[in] pfx The prefix object
|
2012-04-04 20:52:51 -07:00
|
|
|
* @return The base prefix (eg "/usr/local", "/usr", "/opt/appname" or
|
2017-11-07 22:20:34 -08:00
|
|
|
* "/home/user/myapps/appname", etc.) that the software resides in at runtime
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2011-04-24 01:30:12 -07:00
|
|
|
* @since 1.1.0
|
2011-04-24 00:35:30 -07:00
|
|
|
*/
|
2014-10-31 01:24:35 -07:00
|
|
|
EAPI const char *eina_prefix_get(Eina_Prefix *pfx) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE;
|
2011-04-24 00:35:30 -07:00
|
|
|
|
|
|
|
/**
|
2014-10-31 01:24:35 -07:00
|
|
|
* @brief Gets the binary installation directory.
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2014-10-31 01:24:35 -07:00
|
|
|
* @param[in] pfx The prefix object
|
2012-04-04 20:52:51 -07:00
|
|
|
* @return The location of installed binaries (eg "/usr/local/bin",
|
2014-10-31 01:24:35 -07:00
|
|
|
* "/usr/bin", "/opt/appname/bin", "/home/user/myapps/appname/bin" etc.)
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2011-04-24 01:30:12 -07:00
|
|
|
* @since 1.1.0
|
2011-04-24 00:35:30 -07:00
|
|
|
*/
|
2014-10-31 01:24:35 -07:00
|
|
|
EAPI const char *eina_prefix_bin_get(Eina_Prefix *pfx) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE;
|
2011-04-24 00:35:30 -07:00
|
|
|
|
|
|
|
/**
|
2014-10-31 01:24:35 -07:00
|
|
|
* @brief Gets the library installation directory.
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2014-10-31 01:24:35 -07:00
|
|
|
* @param[in] pfx The prefix object
|
2012-04-04 20:52:51 -07:00
|
|
|
* @return The location of installed binaries (eg "/usr/local/lib",
|
2014-10-31 01:24:35 -07:00
|
|
|
* "/usr/lib32", "/opt/appname/lib64", "/home/user/myapps/appname/lib" etc.)
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2011-04-24 01:30:12 -07:00
|
|
|
* @since 1.1.0
|
2011-04-24 00:35:30 -07:00
|
|
|
*/
|
2014-10-31 01:24:35 -07:00
|
|
|
EAPI const char *eina_prefix_lib_get(Eina_Prefix *pfx) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE;
|
2011-04-24 00:35:30 -07:00
|
|
|
|
|
|
|
/**
|
2014-10-31 01:24:35 -07:00
|
|
|
* @brief Gets the data installation directory.
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2014-10-31 01:24:35 -07:00
|
|
|
* @param[in] pfx The prefix object
|
2012-04-04 20:52:51 -07:00
|
|
|
* @return The location of installed binaries (eg "/usr/local/share/appname",
|
2014-10-31 01:24:35 -07:00
|
|
|
* "/usr/share/appname", "/opt/appname/share/appname", "/home/user/myapps/appname/share/appname" etc.)
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2011-04-24 01:30:12 -07:00
|
|
|
* @since 1.1.0
|
2011-04-24 00:35:30 -07:00
|
|
|
*/
|
2014-10-31 01:24:35 -07:00
|
|
|
EAPI const char *eina_prefix_data_get(Eina_Prefix *pfx) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE;
|
2011-04-24 00:35:30 -07:00
|
|
|
|
|
|
|
/**
|
2014-10-31 01:24:35 -07:00
|
|
|
* @brief Gets the locale installation directory.
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2014-10-31 01:24:35 -07:00
|
|
|
* @param[in] pfx The prefix object
|
2012-04-04 20:52:51 -07:00
|
|
|
* @return The location of installed binaries (eg "/usr/local/share/locale",
|
2014-10-31 01:24:35 -07:00
|
|
|
* "/usr/share/locale", "/opt/appname/share/locale", "/home/user/myapps/appname/share/locale" etc.)
|
2011-04-24 01:37:52 -07:00
|
|
|
*
|
2011-04-24 01:30:12 -07:00
|
|
|
* @since 1.1.0
|
2011-04-24 00:35:30 -07:00
|
|
|
*/
|
2014-10-31 01:24:35 -07:00
|
|
|
EAPI const char *eina_prefix_locale_get(Eina_Prefix *pfx) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE;
|
2011-04-24 00:35:30 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
#endif
|