00001 /* Part of the culibs project, <http://www.eideticdew.org/culibs/>. 00002 * Copyright (C) 2009--2010 Petter Urkedal <paurkedal@eideticdew.org> 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 3 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #ifndef CU_INSTALLDIRS_H 00019 #define CU_INSTALLDIRS_H 00020 00021 #include <cu/fwd.h> 00022 #include <atomic_ops.h> 00023 00024 CU_BEGIN_DECLARATIONS 00025 /** \defgroup cu_installdirs_h cu/installdirs.h: Installation Directories 00026 ** @{ \ingroup cu_util_mod 00027 ** 00028 ** This provides a way for an application or library to manage its 00029 ** installation directories. Prefix substitutions are handled by allowing 00030 ** each directory to refer to any of the others as its prefix. 00031 ** 00032 ** A C source file which defines \ref cu_installdirs_t with preliminary 00033 ** initialisation for a package is generated by invoking the Autoconf macro 00034 ** \code 00035 ** CUAC_CONFIG_INSTALLDIRS(foo_installdirs.c, foo_installdirs) 00036 ** \endcode 00037 ** Then \c foo_installdirs can be used as 00038 ** \code 00039 ** #include <cu/installdirs.h> 00040 ** 00041 ** extern struct cu_installdirs foo_installdirs; 00042 ** 00043 ** void foo_init(void) 00044 ** { 00045 ** // ... 00046 ** cu_installdirs_finish(&foo_installdirs); 00047 ** // ... 00048 ** } 00049 ** 00050 ** char const *foo_get_installdir(cu_installdir_key_t key) 00051 ** { 00052 ** return foo_installdirs[key].dir; 00053 ** } 00054 ** \endcode 00055 **/ 00056 00057 /** A reference to one of the installation directories in \ref 00058 ** cu_installdirs_t. In the following, typical values for a prefix of \c /usr 00059 ** are shown in paretheses. */ 00060 typedef enum { 00061 /* Note! These must match cuac_config_installdirs.m4. */ 00062 CU_INSTALLDIR_PREFIX, /**< The \c ${prefix} (\c /usr) */ 00063 CU_INSTALLDIR_EXEC_PREFIX, /**< The \c ${exec_prefix} (\c /usr) */ 00064 00065 CU_INSTALLDIR_BINDIR, /**< The \c ${bindir} (\c /usr/bin) */ 00066 CU_INSTALLDIR_SBINDIR, /**< The \c ${sbindir} (\c /usr/sbin) */ 00067 CU_INSTALLDIR_LIBEXECDIR, /**< The \c ${libexecdir} (\c /usr/libexec) */ 00068 CU_INSTALLDIR_SYSCONFDIR, /**< The \c ${sysconfdir} (\c /etc) */ 00069 CU_INSTALLDIR_SHAREDSTATEDIR,/**< The \c ${sharedstatedir} (\c /var/com) */ 00070 CU_INSTALLDIR_LOCALSTATEDIR,/**< The \c ${localstatedir} (\c /var/lib) */ 00071 CU_INSTALLDIR_LIBDIR, /**< The \c ${libdir} (\c /usr/lib) */ 00072 CU_INSTALLDIR_INCLUDEDIR, /**< The \c ${includedir} (\c /usr/include) */ 00073 CU_INSTALLDIR_DATAROOTDIR, /**< The \c ${datarootdir} (\c /usr/share) */ 00074 CU_INSTALLDIR_DATADIR, /**< The \c ${datadir} (\c /usr/share) */ 00075 CU_INSTALLDIR_INFODIR, /**< The \c ${infodir} (\c /usr/share/info) */ 00076 CU_INSTALLDIR_LOCALEDIR,/**< The \c ${localedir} (\c /usr/share/locale) */ 00077 CU_INSTALLDIR_MANDIR, /**< The \c ${mandir} (\c /usr/share/man) */ 00078 CU_INSTALLDIR_DOCDIR, /**< The \c ${docdir} (\c /usr/share/doc/foo-1.0)*/ 00079 CU_INSTALLDIR_HTMLDIR, 00080 CU_INSTALLDIR_DVIDIR, 00081 CU_INSTALLDIR_PDFDIR, 00082 CU_INSTALLDIR_PSDIR, 00083 00084 CU_INSTALLDIR_NONE 00085 } cu_installdir_key_t; 00086 00087 typedef struct cu_installdir *cu_installdir_t; 00088 struct cu_installdir 00089 { 00090 char const *name; 00091 cu_installdir_key_t key; 00092 00093 cu_installdir_key_t prefix_key; 00094 char const *suffix; 00095 char const *dir; 00096 }; 00097 00098 struct cu_installdirs 00099 { 00100 AO_t done_init; 00101 struct cu_installdir dirs[CU_INSTALLDIR_NONE + 1]; 00102 }; 00103 00104 /** An array describing the installation directories of a package. */ 00105 typedef struct cu_installdirs *cu_installdirs_t; 00106 00107 /** Set the installation directory indicated by \a key to \a dir. The 00108 ** directory may be a prefix for other directories, in which case \ref 00109 ** cu_installdirs_finish will substitute it. This function must be called 00110 ** before \ref cu_installdirs_finish. */ 00111 void cu_installdirs_set(cu_installdirs_t installdirs, cu_installdir_key_t key, 00112 char const *dir); 00113 00114 /** If found, sets the configuration directory named \a name in lowercase to \a 00115 ** dir and returns true, else returns false. This function must be called 00116 ** before \ref cu_installdirs_finish. */ 00117 cu_bool_t cu_installdirs_set_byname(cu_installdirs_t installdirs, char const *name, 00118 char const *dir); 00119 00120 /** Set \a installdirs according to environment variables named \a var_prefix 00121 ** followed by the common installation directory names. If \a var_prefix 00122 ** starts with an uppercase, the directory names are uppercased as well. E.g. 00123 ** calling <tt>cu_installdirs_set_byenv(&mydirs, "MYAPP_")</tt> will pick up 00124 ** \c $MYAPP_PREFIX, \c $MYAPP_EXEC_PREFIX, \c $MYAPP_SYSCONFDIR, etc. This 00125 ** function must be called before \ref cu_installdirs_finish. */ 00126 void cu_installdirs_set_byenv(cu_installdirs_t installdirs, char const *var_prefix); 00127 00128 /** Return the directory identified by \a key from \a installdirs. */ 00129 CU_SINLINE char const * 00130 cu_installdirs_get(cu_installdirs_t installdirs, cu_installdir_key_t key) 00131 { return installdirs->dirs[key].dir; } 00132 00133 /** Completes the \c dir fields of the application's installation directory 00134 ** mapping, assuming the first two components have been initialised. This 00135 ** function is typically called during program initialisation. */ 00136 void cu_installdirs_finish(cu_installdirs_t installdirs); 00137 00138 void cu_installdirs_reset(cu_installdirs_t installdirs); 00139 00140 /** Prints out \a installdirs. */ 00141 void cu_installdirs_dump(cu_installdirs_t installdirs); 00142 00143 /** The culibs installation directory \a key. */ 00144 char const *cuconf_get_installdir(cu_installdir_key_t key); 00145 00146 /** @} */ 00147 CU_END_DECLARATIONS 00148 00149 #endif