From e93dd142d6eccf5738b503058a4c82e10c188804 Mon Sep 17 00:00:00 2001 From: dockes Date: Thu, 19 Jan 2006 17:11:46 +0000 Subject: [PATCH] slight config cleanup --- src/{Makefile => Makefile.in} | 25 +++++++--- src/common/rclconfig.cpp | 89 ++++++++++++++++++++++------------- src/common/rclconfig.h | 28 +++++++---- src/configure | 3 ++ src/configure.ac | 1 + src/internfile/internfile.cpp | 4 +- src/internfile/mh_exec.cpp | 4 +- src/mk/localdefs.in | 7 ++- src/qtgui/main.cpp | 11 ++--- src/qtgui/recoll.pro | 2 +- src/recollinstall.in | 13 ++++- 11 files changed, 122 insertions(+), 65 deletions(-) rename src/{Makefile => Makefile.in} (59%) diff --git a/src/Makefile b/src/Makefile.in similarity index 59% rename from src/Makefile rename to src/Makefile.in index 82e821c3..e8080609 100644 --- a/src/Makefile +++ b/src/Makefile.in @@ -1,14 +1,21 @@ -# @(#$Id: Makefile,v 1.26 2006-01-19 12:01:42 dockes Exp $ (C) 2005 J.F.Dockes +# @(#$Id: Makefile.in,v 1.1 2006-01-19 17:11:45 dockes Exp $ (C) 2005 J.F.Dockes + +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +datadir = @datadir@ +mandir = @mandir@ all: mk/sysconf common/rclversion.h cd lib; ${MAKE} cd bincimapmime; ${MAKE} cd index; ${MAKE} recollindex cd qtgui; PATH=${PATH}:${QTDIR}/bin; export PATH; qmake recoll.pro; \ - cat ../mk/sysconf Makefile | ${MAKE} -f - depth=.. + cat ../mk/sysconf Makefile | ${MAKE} -f - depth=.. mk/sysconf: - ./configure + @echo "You need to run configure first" ; exit 1 common/rclversion.h: VERSION echo 'static const char *rclversion = "'`cat VERSION`'";' \ @@ -22,7 +29,8 @@ static: cd qtgui; PATH=${PATH}:${QTDIR}/bin; export PATH; qmake recoll.pro; \ rm -f recoll; cat ../mk/sysconf Makefile | \ - ${MAKE} -f - BSTATIC=-Wl,-Bstatic BDYNAMIC=-Wl,-Bdynamic depth=.. + ${MAKE} -f - \ + BSTATIC=-Wl,-Bstatic BDYNAMIC=-Wl,-Bdynamic depth=.. clean: cd common; ${MAKE} clean @@ -39,9 +47,14 @@ distclean: clean rm -f mk/sysconf mk/localdefs sampleconf/recoll.conf \ recollinstall \ doc/user/*.html* doc/user/*.txt doc/user/HTML.manifest - +# recollinstall can be executed by the user and will compute 'normal' +# values for bindir etc., relative to the prefix argument. When executed +# here, we pass a bunch of variables in the environment, the values will +# override the computed defaults. install: all - bindir=${bindir} datadir=${datadir} ./recollinstall ${prefix} + DESTDIR=${DESTDIR} bindir=${bindir} datadir=${datadir} \ + mandir=${mandir} \ + ./recollinstall ${prefix} .PHONY: all static clean distclean install diff --git a/src/common/rclconfig.cpp b/src/common/rclconfig.cpp index 690f5ab0..50d59ab7 100644 --- a/src/common/rclconfig.cpp +++ b/src/common/rclconfig.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.18 2006-01-10 12:58:39 dockes Exp $ (C) 2004 J.F.Dockes"; +static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.19 2006-01-19 17:11:46 dockes Exp $ (C) 2004 J.F.Dockes"; #endif #include #include @@ -23,13 +23,11 @@ using namespace std; static const char *configfiles[] = {"recoll.conf", "mimemap", "mimeconf"}; static int ncffiles = sizeof(configfiles) / sizeof(char *); -static bool createConfig(string &reason) +static bool createConfig(const string &datadir, string &reason) { - const char *cprefix = getenv("RECOLL_PREFIX"); - if (cprefix == 0) - cprefix = RECOLL_PREFIX; - string prefix = path_cat(cprefix, "share/recoll/examples"); - + // Samples directory + string exdir = path_cat(datadir, "examples"); + // User's string recolldir = path_tildexpand("~/.recoll"); if (mkdir(recolldir.c_str(), 0755) < 0) { reason += string("mkdir(") + recolldir + ") failed: " + @@ -37,7 +35,7 @@ static bool createConfig(string &reason) return false; } for (int i = 0; i < ncffiles; i++) { - string src = path_cat((const string&)prefix, string(configfiles[i])); + string src = path_cat((const string&)exdir, string(configfiles[i])); string dst = path_cat((const string&)recolldir, string(configfiles[i])); if (!copyfile(src.c_str(), dst.c_str(), reason)) { LOGERR(("Copyfile failed: %s\n", reason.c_str())); @@ -49,8 +47,8 @@ static bool createConfig(string &reason) RclConfig::RclConfig() - : m_ok(false), conf(0), mimemap(0), mimeconf(0), stopsuffixes(0) - + : m_ok(false), m_conf(0), mimemap(0), mimeconf(0), mimemap_local(0), + stopsuffixes(0) { static int loginit = 0; if (!loginit) { @@ -59,35 +57,45 @@ RclConfig::RclConfig() loginit = 1; } + // Compute our data dir name, typically /usr/local/share/recoll + const char *cdatadir = getenv("RECOLL_DATADIR"); + if (cdatadir == 0) { + // If not in environment, use the compiled-in constant. + m_datadir = RECOLL_DATADIR; + } else { + m_datadir = cdatadir; + } + const char *cp = getenv("RECOLL_CONFDIR"); if (cp) { - confdir = cp; + m_confdir = cp; } else { - confdir = path_home(); - confdir += ".recoll/"; + m_confdir = path_home(); + m_confdir += ".recoll/"; } - string cfilename = path_cat(confdir, "recoll.conf"); + string cfilename = path_cat(m_confdir, "recoll.conf"); - if (access(confdir.c_str(), 0) != 0 || access(cfilename.c_str(), 0) != 0) { - if (!createConfig(reason)) + if (access(m_confdir.c_str(), 0) != 0 || + access(cfilename.c_str(), 0) != 0) { + if (!createConfig(m_datadir, reason)) return; } // Open readonly here so as not to casually create a config file - conf = new ConfTree(cfilename.c_str(), true); - if (conf == 0 || - (conf->getStatus() != ConfSimple::STATUS_RO && - conf->getStatus() != ConfSimple::STATUS_RW)) { + m_conf = new ConfTree(cfilename.c_str(), true); + if (m_conf == 0 || + (m_conf->getStatus() != ConfSimple::STATUS_RO && + m_conf->getStatus() != ConfSimple::STATUS_RW)) { reason = string("No main configuration file: ") + cfilename + " does not exist or cannot be parsed"; return; } string mimemapfile; - if (!conf->get("mimemapfile", mimemapfile, "")) { + if (!m_conf->get("mimemapfile", mimemapfile, "")) { mimemapfile = "mimemap"; } - string mpath = path_cat(confdir, mimemapfile); + string mpath = path_cat(m_confdir, mimemapfile); mimemap = new ConfTree(mpath.c_str(), true); if (mimemap == 0 || (mimemap->getStatus() != ConfSimple::STATUS_RO && @@ -99,10 +107,10 @@ RclConfig::RclConfig() // mimemap->list(); string mimeconffile; - if (!conf->get("mimeconffile", mimeconffile, "")) { + if (!m_conf->get("mimeconffile", mimeconffile, "")) { mimeconffile = "mimeconf"; } - mpath = path_cat(confdir, mimeconffile); + mpath = path_cat(m_confdir, mimeconffile); mimeconf = new ConfTree(mpath.c_str(), true); if (mimeconf == 0 || (mimeconf->getStatus() != ConfSimple::STATUS_RO && @@ -210,10 +218,9 @@ string RclConfig::getMimeIconName(const string &mtype) return hs; } -// Look up an executable filter. -// We look in RECOLL_FILTERSDIR, filtersdir param, then -// let the system use the PATH -string find_filter(RclConfig *conf, const string &icmd) +// Look up an executable filter. We look in $RECOLL_FILTERSDIR, +// filtersdir in config file, then let the system use the PATH +string RclConfig::findFilter(const string &icmd) { // If the path is absolute, this is it if (icmd[0] == '/') @@ -222,19 +229,33 @@ string find_filter(RclConfig *conf, const string &icmd) string cmd; const char *cp; + // Filters dir from environment ? if ((cp = getenv("RECOLL_FILTERSDIR"))) { cmd = path_cat(cp, icmd); if (access(cmd.c_str(), X_OK) == 0) return cmd; - } else if (conf->getConfParam(string("filtersdir"), cmd)) { + } + // Filters dir as configuration parameter? + if (getConfParam(string("filtersdir"), cmd)) { cmd = path_cat(cmd, icmd); if (access(cmd.c_str(), X_OK) == 0) return cmd; - } else { - cmd = path_cat(conf->getConfDir(), icmd); - if (access(cmd.c_str(), X_OK) == 0) - return cmd; - } + } + + // Filters dir as datadir subdir. Actually the standard case, but + // this is normally the same value found in config file (previous step) + cmd = path_cat(m_datadir, "filters"); + cmd = path_cat(cmd, icmd); + if (access(cmd.c_str(), X_OK) == 0) + return cmd; + + // Last resort for historical reasons: check in personal config + // directory + cmd = path_cat(getConfDir(), icmd); + if (access(cmd.c_str(), X_OK) == 0) + return cmd; + + // Let the shell try to find it... return icmd; } diff --git a/src/common/rclconfig.h b/src/common/rclconfig.h index 424cb5e2..1f5634b8 100644 --- a/src/common/rclconfig.h +++ b/src/common/rclconfig.h @@ -1,6 +1,6 @@ #ifndef _RCLCONFIG_H_INCLUDED_ #define _RCLCONFIG_H_INCLUDED_ -/* @(#$Id: rclconfig.h,v 1.11 2006-01-10 11:07:21 dockes Exp $ (C) 2004 J.F.Dockes */ +/* @(#$Id: rclconfig.h,v 1.12 2006-01-19 17:11:46 dockes Exp $ (C) 2004 J.F.Dockes */ #include @@ -11,19 +11,25 @@ class RclConfig { public: RclConfig(); - ~RclConfig() {delete conf;delete mimemap;delete mimeconf;} + ~RclConfig() { + delete m_conf; + delete mimemap; + delete mimeconf; + delete mimemap_local; + delete stopsuffixes; + } bool ok() {return m_ok;} const string &getReason() {return reason;} - string getConfDir() {return confdir;} + string getConfDir() {return m_confdir;} //ConfTree *getConfig() {return m_ok ? conf : 0;} /// Get generic configuration parameter according to current keydir bool getConfParam(const string &name, string &value) { - if (conf == 0) + if (m_conf == 0) return false; - return conf->get(name, value, keydir); + return m_conf->get(name, value, keydir); } /* @@ -36,9 +42,9 @@ class RclConfig { void setKeyDir(const string &dir) { keydir = dir; - conf->get("defaultcharset", defcharset, keydir); + m_conf->get("defaultcharset", defcharset, keydir); string str; - conf->get("guesscharset", str, keydir); + m_conf->get("guesscharset", str, keydir); guesscharset = stringToBool(str); } @@ -65,11 +71,14 @@ class RclConfig { bool getGuessCharset() {return guesscharset;} std::list getAllMimeTypes(); + std::string findFilter(const std::string& cmd); + private: int m_ok; string reason; // Explanation for bad state - string confdir; // Directory where the files are stored - ConfTree *conf; // Parsed main configuration + string m_confdir; // Directory where the files are stored + string m_datadir; // Example: /usr/local/share/recoll + ConfTree *m_conf; // Parsed main configuration string keydir; // Current directory used for parameter fetches. ConfTree *mimemap; // These are independant of current keydir. @@ -82,6 +91,5 @@ class RclConfig { bool guesscharset; // They are fetched initially or on setKeydir() }; -std::string find_filter(RclConfig *conf, const string& cmd); #endif /* _RCLCONFIG_H_INCLUDED_ */ diff --git a/src/configure b/src/configure index 3124960b..ae905754 100755 --- a/src/configure +++ b/src/configure @@ -2296,6 +2296,8 @@ ac_config_files="$ac_config_files recollinstall" ac_config_files="$ac_config_files sampleconf/recoll.conf" +ac_config_files="$ac_config_files Makefile" + for d in bincimapmime index lib query do @@ -2802,6 +2804,7 @@ do "mk/localdefs" ) CONFIG_FILES="$CONFIG_FILES mk/localdefs" ;; "recollinstall" ) CONFIG_FILES="$CONFIG_FILES recollinstall" ;; "sampleconf/recoll.conf" ) CONFIG_FILES="$CONFIG_FILES sampleconf/recoll.conf" ;; + "Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;; *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 echo "$as_me: error: invalid argument: $ac_config_target" >&2;} { (exit 1); exit 1; }; };; diff --git a/src/configure.ac b/src/configure.ac index 524fd61a..939c228b 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -116,6 +116,7 @@ AC_SUBST(INCICONV) AC_CONFIG_FILES(mk/localdefs) AC_CONFIG_FILES(recollinstall) AC_CONFIG_FILES(sampleconf/recoll.conf) +AC_CONFIG_FILES(Makefile) for d in bincimapmime index lib query do diff --git a/src/internfile/internfile.cpp b/src/internfile/internfile.cpp index 30844287..486b634a 100644 --- a/src/internfile/internfile.cpp +++ b/src/internfile/internfile.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: internfile.cpp,v 1.13 2005-12-08 08:44:14 dockes Exp $ (C) 2004 J.F.Dockes"; +static char rcsid[] = "@(#$Id: internfile.cpp,v 1.14 2006-01-19 17:11:46 dockes Exp $ (C) 2004 J.F.Dockes"; #endif #ifndef TEST_INTERNFILE @@ -33,7 +33,7 @@ static bool uncompressfile(RclConfig *conf, const string& ifn, LOGERR(("uncompressfile: can't clear temp dir %s\n", tdir.c_str())); return false; } - string cmd = find_filter(conf, cmdv.front()); + string cmd = conf->findFilter(cmdv.front()); // Substitute file name and temp dir in command elements list::const_iterator it = cmdv.begin(); diff --git a/src/internfile/mh_exec.cpp b/src/internfile/mh_exec.cpp index 844e2f40..8089a813 100644 --- a/src/internfile/mh_exec.cpp +++ b/src/internfile/mh_exec.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: mh_exec.cpp,v 1.3 2005-11-24 07:16:15 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: mh_exec.cpp,v 1.4 2006-01-19 17:11:46 dockes Exp $ (C) 2005 J.F.Dockes"; #endif #include "execmd.h" @@ -24,7 +24,7 @@ MimeHandlerExec::mkDoc(RclConfig *conf, const string &fn, return MimeHandler::MHError; } // Command name - string cmd = find_filter(conf, params.front()); + string cmd = conf->findFilter(params.front()); // Build parameter list: delete cmd name and add the file name list::iterator it = params.begin(); diff --git a/src/mk/localdefs.in b/src/mk/localdefs.in index 7d5306ca..ec8133b9 100644 --- a/src/mk/localdefs.in +++ b/src/mk/localdefs.in @@ -4,9 +4,12 @@ XAPIANCXXFLAGS=@XAPIANCXXFLAGS@ LIBICONV=@LIBICONV@ INCICONV=@INCICONV@ -RECOLL_PREFIX=@prefix@ + +prefix = @prefix@ +datadir = @datadir@ +RECOLL_DATADIR = ${datadir}/recoll LOCALCXXFLAGS = $(INCICONV) $(XAPIANCXXFLAGS) \ - -DRECOLL_PREFIX=\"$(RECOLL_PREFIX)\" + -DRECOLL_DATADIR=\"$(RECOLL_DATADIR)\" CXXFLAGS = -g diff --git a/src/qtgui/main.cpp b/src/qtgui/main.cpp index 000e915e..576b4937 100644 --- a/src/qtgui/main.cpp +++ b/src/qtgui/main.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: main.cpp,v 1.28 2006-01-04 11:33:44 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: main.cpp,v 1.29 2006-01-19 17:11:46 dockes Exp $ (C) 2005 J.F.Dockes"; #endif #include @@ -30,7 +30,7 @@ using Rcl::AdvSearchData; #include "recollmain.h" -static const char *recollprefix = RECOLL_PREFIX; +static const char *recoll_datadir = RECOLL_DATADIR; RclConfig *rclconfig; Rcl::Db *rcldb; @@ -137,8 +137,7 @@ int main( int argc, char ** argv ) a.installTranslator( &qt ); // Translations for Recoll - recollsharedir = path_cat(recollprefix, "share/recoll"); - string translatdir = path_cat(recollsharedir, "translations"); + string translatdir = path_cat(recoll_datadir, "translations"); QTranslator translator( 0 ); // QTextCodec::locale() returns $LANG translator.load( QString("recoll_") + QTextCodec::locale(), @@ -175,7 +174,7 @@ int main( int argc, char ** argv ) rclconfig->getConfParam("iconsdir", iconsdir); if (iconsdir.empty()) { - iconsdir = path_cat(recollsharedir, "images"); + iconsdir = path_cat(recoll_datadir, "images"); } else { iconsdir = path_tildexpand(iconsdir); } @@ -232,7 +231,7 @@ bool startHelpBrowser(const string &iurl) { string url; if (iurl.empty()) { - url = path_cat(recollsharedir, "doc"); + url = path_cat(recoll_datadir, "doc"); url = path_cat(url, "usermanual.html"); url = string("file://") + url; } else diff --git a/src/qtgui/recoll.pro b/src/qtgui/recoll.pro index 224359d6..d9bfaaf9 100644 --- a/src/qtgui/recoll.pro +++ b/src/qtgui/recoll.pro @@ -33,7 +33,7 @@ unix { UI_DIR = .ui MOC_DIR = .moc OBJECTS_DIR = .obj - DEFINES += RECOLL_PREFIX=\"$(RECOLL_PREFIX)\" + DEFINES += RECOLL_DATADIR=\"$(RECOLL_DATADIR)\" LIBS += ../lib/librcl.a ../bincimapmime/libmime.a \ $(BSTATIC) $(LIBXAPIAN) $(LIBICONV) $(BDYNAMIC) \ -lz diff --git a/src/recollinstall.in b/src/recollinstall.in index ce09d945..d9d2f807 100755 --- a/src/recollinstall.in +++ b/src/recollinstall.in @@ -19,7 +19,7 @@ else usage fi -echo "Installing to $PREFIX" + test -n "$bindir" || bindir=${PREFIX}/bin test -n "$datadir" || datadir=${PREFIX}/share if test -z "$mandir" ; then @@ -30,7 +30,16 @@ if test -z "$mandir" ; then fi fi -INSTALL=${INSTALL:="install -c"} +if test -n "$DESTDIR" ; then + PREFIX=$DESTDIR/$PREFIX + bindir=$DESTDIR/$bindir + datadir=$DESTDIR/$datadir + mandir=$DESTDIR/$mandir +fi + +echo "Installing to $PREFIX" + +INSTALL=${INSTALL:="install -c -v"} STRIP=${STRIP:=strip} test -x qtgui/recoll || fatal "qtgui/recoll does not exist." \