Files
gnucash/libgnucash/core-utils/gnc-filepath-utils.h
John Ralls 66817bb997 Rework directory determination in CMake builds.
Sets paths for finding componenents depending on the state of ENABLE_BINRELOC,
GNC_UNINSTALLED, GNC_BUILDDIR and whether any install paths have been set
outside of CMAKE_INSTALL_PREFIX.

GNUInstallDirs changes the name of CMAKE_INSTALL_LIBDIR depending on the
operating system and distro. When CMAKE_INSTALL_PREFIX is /usr,
/usr/local, or any subdirectory of /opt it also changes
CMAKE_INSTALL_FULL_SYSCONFDIR to /etc. An earlier commit by Aaron Laws
mirrors the name of CMAKE_INSTALL_LIBDIR to the build library directory.

It's possible for builders to set any of the install directories
anywhere they please.

Setting any directory outside of CMAKE_INSTALL_PREFIX breaks Binreloc so
the toplevel CMakeLists.txt now detects that and disables Binreloc.

If Binreloc is enabled then all path queries use it to find paths. This
works in the build directory because the gnucash executable and all of
the test programs are in build_directory/bin and LIBDIR, DATADIR, and
SYSCONFDIR can be found in the same root path.

If Binreloc is disabled then in order to build or run programs from the
build directory one must set GNC_UNINSTALLED and set GNC_BUILDDIR to the
absolute path of the build directory. When those are set GNC_BUILDDIR
replaces CMAKE_INSTALL_PREFIX in all paths that are subdirectories of
CMAKE_INSTALL_PREFIX; paths that are not in CMAKE_INSTALL_PREFIX are
appended whole to GNC_BUILDDIR. This process is constent between CMake
and gnc_path_get_foo. GnuCash is unlikely to run from a DESTDIR without
Binreloc.
2017-12-05 17:25:52 -08:00

171 lines
7.2 KiB
C

/********************************************************************\
* gnc-filepath-utils.h -- file path resolution utilities *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
\********************************************************************/
/**
* @file gnc-filepath-utils.h
* @brief File path resolution utility functions
* @author Copyright (c) 1998-2004 Linas Vepstas <linas@linas.org>
* @author Copyright (c) 2000 Dave Peticolas
*/
#ifndef GNC_FILEPATH_UTILS_H
#define GNC_FILEPATH_UTILS_H
/** The gnc_resolve_file_path() routine is a utility that will accept
* a fragmentary filename as input, and resolve it into a fully
* qualified path in the file system, i.e. a path that begins with
* a leading slash. First, the current working directory is
* searched for the file. Next, the directory $HOME/.gnucash/data,
* and finally, a list of other (configurable) paths. If the file
* is not found, then the path $HOME/.gnucash/data is used. If
* $HOME is not defined, then the current working directory is
* used.
*/
gchar *gnc_resolve_file_path (const gchar *filefrag);
/** Given a prefix and a path return the relative portion of the path.
* @param prefix The prefix that might be the first part of the path
* @param path The path from which the prefix might be removed
* @return a char* that must be g_freed containing the path without
* the prefix if path begins with prefix, otherwise a copy of path.
*/
gchar *gnc_file_path_relative_part (const gchar *prefix, const gchar *path);
/** @brief Find an absolute path to a localized version of a given
* relative path to a html or html related file.
* If no localized version exists, an absolute path to the file
* is searched for. If that file doesn't exist either, returns NULL.
*
* @warning file_name should be a simple path fragment. It shouldn't
* contain xml:// or http:// or <whatever>:// other protocol specifiers.
*
* If passed a string which g_path_is_absolute declares an absolute
* path, return the argument.
*
* Otherwise, assume that file_name is a well-formed relative path and
* try to find a file with its path relative to
* \li a localized subdirectory in the html directory
* of the user's configuration directory
* (e.g. $HOME/.gnucash/html/de_DE, $HOME/.gnucash/html/en,...)
* \li a localized subdirectory in the gnucash documentation directory
* (e.g. /usr/share/doc/gnucash/C,...)
* \li the html directory of the user's configuration directory
* (e.g. $HOME/.gnucash/html)
* \li the gnucash documentation directory
* (e.g. /usr/share/doc/gnucash/)
*
* The paths are searched for in that order. If a matching file is
* found, return the absolute path to it.
* If one isn't found, return NULL.
*
* @param file_name The file path to resolve
*
* @return An absolute file path or NULL if no file is found.
*/
gchar *gnc_path_find_localized_html_file (const gchar *file_name);
/** @brief Initializes the gnucash user data directory.
* This function should be called very early at startup (before any
* other of the user data directory related function gets called).
*
* @param create If true the function will attempt to create the
* gnucash user data directory its subdirectories and parent directories
* if they don't exist yet. Note it won't attempt to create a home directory
* if that is missing. In that case the system's default temporary
* directory will be used instead. If false it will not attempt to create
* any directories at all unless they are in the temporary directory. This
* is a fallback measure to allow the calling application to more or less
* function even if gnc_filepath_init was never called.
*
* @note If the necessary directories did get created this
* function will also try to copy files from $HOME/.gnucash
* to there if that old location exists.
*
* @return whether files got copied from the old location.
*/
gboolean gnc_filepath_init(gboolean create);
const gchar *gnc_userdata_dir (void);
gchar *gnc_build_userdata_path (const gchar *filename);
gchar *gnc_build_book_path (const gchar *filename);
gchar *gnc_build_translog_path (const gchar *filename);
gchar *gnc_build_data_path (const gchar *filename);
gchar *gnc_build_report_path (const gchar *filename);
gchar *gnc_build_stdreports_path (const gchar *filename);
/** Given a pixmap/pixbuf file name, find the file in the pixmap
* directory associated with this application. This routine will
* display an error message if it can't find the file.
*
* @param name The name of the file to be found.
*
* @return the full path name of the file, or NULL of the file can't
* be found.
*
* @note It is the caller's responsibility to free the returned string.
*/
gchar *gnc_filepath_locate_pixmap (const gchar *name);
/** Given a file name, find the file in the directories associated
* with this application. This routine will display an error message
* if it can't find the file.
*
* @param name The name of the file to be found.
*
* @return the full path name of the file, or NULL of the file can't
* be found.
*
* @note It is the caller's responsibility to free the returned string.
*/
gchar *gnc_filepath_locate_data_file (const gchar *name);
/** Given a ui file name, find the file in the ui directory associated
* with this application. This routine will display an error message
* if it can't find the file.
*
* @param name The name of the file to be found.
*
* @return the full path name of the file, or NULL of the file can't
* be found.
*
* @note It is the caller's responsibility to free the returned string.
*/
gchar *gnc_filepath_locate_ui_file (const gchar *name);
/** Given a documentation file name, find the file in the doc directory
* associated with this application. This routine will display an error
* message if it can't find the file.
*
* @param name The name of the file to be found.
*
* @return the full path name of the file, or NULL of the file can't
* be found.
*
* @note It is the caller's responsibility to free the returned string.
*/
gchar *gnc_filepath_locate_doc_file (const gchar *name);
#endif /* GNC_FILEPATH_UTILS_H */