summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-01-08 19:11:13 +0000
committerDavid Robillard <d@drobilla.net>2011-01-08 19:11:13 +0000
commit9a1cd7003886f89e2228d74d61130dc5d24c06a3 (patch)
tree133972adfb7802750f62d9db69639cd2c18459ba
parentc92301fc4cd5620fe8193e2e6648ea86c580784d (diff)
downloadpatchage-9a1cd7003886f89e2228d74d61130dc5d24c06a3.tar.gz
patchage-9a1cd7003886f89e2228d74d61130dc5d24c06a3.tar.bz2
patchage-9a1cd7003886f89e2228d74d61130dc5d24c06a3.zip
Support via waf for running from the build directory.
git-svn-id: http://svn.drobilla.net/lad/trunk/patchage@2799 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--src/GladeFile.hpp51
-rw-r--r--src/binary_location.h22
-rw-r--r--src/main.cpp7
-rw-r--r--wscript19
4 files changed, 63 insertions, 36 deletions
diff --git a/src/GladeFile.hpp b/src/GladeFile.hpp
index 2f6ad4b..da9ea3b 100644
--- a/src/GladeFile.hpp
+++ b/src/GladeFile.hpp
@@ -25,35 +25,50 @@
#include <libglademm/xml.h>
-#include "patchage-config.h"
+#include "raul/log.hpp"
-#ifdef BUNDLE
+#include "patchage-config.h"
+#ifdef PATCHAGE_BINLOC
#include "binary_location.h"
#endif
class GladeFile {
public:
+ inline static bool is_readable(const std::string& filename) {
+ std::ifstream fs(filename.c_str());
+ const bool fail = fs.fail();
+ fs.close();
+ return !fail;
+ }
+
static Glib::RefPtr<Gnome::Glade::Xml> open(const std::string& base_name) {
std::string glade_filename;
-#ifdef BUNDLE
- char* loc = binary_location();
- std::string bundle = loc;
- bundle = bundle.substr(0, bundle.find_last_of("/"));
- glade_filename = bundle + "/" + PATCHAGE_DATA_DIR + "/" + base_name + ".glade";
- free(loc);
-#else
- glade_filename = std::string(PATCHAGE_DATA_DIR) + "/" + base_name + ".glade";
+ char* loc = NULL;
+#ifdef PATCHAGE_BINLOC
+ loc = binary_location();
+ if (loc) {
+ std::string bundle = loc;
+ bundle = bundle.substr(0, bundle.find_last_of("/"));
+ glade_filename = bundle + "/" + base_name + ".glade";
+ free(loc);
+ if (is_readable(glade_filename)) {
+ Raul::info << "Loading glade file " << glade_filename << std::endl;
+ return Gnome::Glade::Xml::create(glade_filename);
+ }
+ }
#endif
- std::ifstream fs(glade_filename.c_str());
- if (fs.fail()) {
- std::ostringstream ss;
- ss << "Unable to find " << base_name << ".glade in " << PATCHAGE_DATA_DIR << std::endl;
- throw std::runtime_error(ss.str());
+ glade_filename = std::string(PATCHAGE_DATA_DIR) + "/" + base_name + ".glade";
+ if (is_readable(glade_filename)) {
+ Raul::info << "Loading glade file " << glade_filename << std::endl;
+ return Gnome::Glade::Xml::create(glade_filename);
}
- fs.close();
-
- return Gnome::Glade::Xml::create(glade_filename);
+ std::stringstream ss;
+ ss << "Unable to find " << base_name << ".glade in " << loc
+ << " or " << PATCHAGE_DATA_DIR << std::endl;
+ throw std::runtime_error(ss.str());
+ return Glib::RefPtr<Gnome::Glade::Xml>();
+ //return Gnome::Glade::Xml::create(glade_filename);
}
};
diff --git a/src/binary_location.h b/src/binary_location.h
index 58868a7..033dcae 100644
--- a/src/binary_location.h
+++ b/src/binary_location.h
@@ -1,5 +1,5 @@
/* Find the location of the program in the filesytem.
- * Copyright (C) 2008-2009 David Robillard <http://drobilla.net>
+ * Copyright (C) 2008-2010 David Robillard <http://drobilla.net>
*
* This 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
@@ -19,10 +19,10 @@
#define _GNU_SOURCE
#endif
-#include <dlfcn.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <assert.h>
#include <limits.h>
+#include <stdlib.h>
+#include <dlfcn.h>
/** Return the absolute path of the binary.
* Returned value must be freed by caller.
@@ -31,11 +31,11 @@ static char*
binary_location()
{
Dl_info dli;
- dladdr((void*)&binary_location, &dli);
-
- char* bin_loc = (char*)calloc(PATH_MAX, sizeof(char));
- realpath(dli.dli_fname, bin_loc);
-
- return bin_loc;
+ const int ret = dladdr((void*)&binary_location, &dli);
+ if (ret) {
+ char* const bin_loc = (char*)calloc(PATH_MAX, sizeof(char));
+ realpath(dli.dli_fname, bin_loc);
+ return bin_loc;
+ }
+ return NULL;
}
-
diff --git a/src/main.cpp b/src/main.cpp
index 2087e2a..7c90ea5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -36,13 +36,10 @@ main(int argc, char** argv)
app.run(*patchage.window());
} catch (std::exception& e) {
- Raul::error << "Caught exception, aborting. Error message was: "
- << e.what() << std::endl;
+ Raul::error << "patchage: error: " << e.what() << std::endl;
return 1;
-
} catch (Glib::Exception& e) {
- Raul::error << "Caught exception, aborting. Error message was: "
- << e.what() << std::endl;
+ Raul::error << "patchage: error: " << e.what() << std::endl;
return 1;
}
diff --git a/wscript b/wscript
index 799e52e..dc620e9 100644
--- a/wscript
+++ b/wscript
@@ -32,6 +32,8 @@ def options(opt):
help="Do not build Lash support")
opt.add_option('--no-alsa', action='store_true', default=False, dest='no_alsa',
help="Do not build Alsa Sequencer support")
+ opt.add_option('--no-binloc', action='store_true', default=False, dest='no_binloc',
+ help="Do not try to read files from executable's parent directory")
def configure(conf):
autowaf.configure(conf)
@@ -53,6 +55,13 @@ def configure(conf):
autowaf.check_pkg(conf, 'raul', uselib_store='RAUL',
atleast_version='0.5.1', mandatory=True)
+ # Check for dladdr
+ conf.check(function_name='dladdr',
+ header_name='dlfcn.h',
+ cflags='-D_GNU_SOURCE',
+ linkflags='-ldl',
+ define_name='HAVE_DLADDR')
+
# Use Jack D-Bus if requested (only one jack driver is allowed)
conf.env['HAVE_JACK_DBUS'] = conf.env['HAVE_DBUS'] == 1 and conf.env['HAVE_DBUS_GLIB'] == 1 and Options.options.jack_dbus
@@ -73,6 +82,10 @@ def configure(conf):
if not Options.options.no_lash and conf.env['HAVE_DBUS_GLIB']:
autowaf.define(conf, 'HAVE_LASH', 1)
+ # Find files at binary location if we have dladdr unless --no-binloc
+ if not Options.options.no_binloc and conf.env['HAVE_DLADDR']:
+ autowaf.define(conf, 'PATCHAGE_BINLOC', 1)
+
# Boost headers
autowaf.check_header(conf, 'boost/shared_ptr.hpp', mandatory=True)
autowaf.check_header(conf, 'boost/weak_ptr.hpp', mandatory=True)
@@ -131,13 +144,15 @@ def build(bld):
if bld.env['HAVE_ALSA'] == 1:
prog.source += ' src/AlsaDriver.cpp '
prog.uselib += ' ALSA '
+ if bld.env['PATCHAGE_BINLOC']:
+ prog.linkflags = '-ldl'
# Glade XML UI definition
bld(features = 'subst',
source = 'src/patchage.glade',
target = 'patchage.glade',
install_path = '${DATADIR}/' + bld.env['APP_INSTALL_NAME'],
- chmod = 0755,
+ chmod = 0644,
PATCHAGE_VERSION = PATCHAGE_VERSION)
# 'Desktop' file (menu entry, icon, etc)
@@ -145,7 +160,7 @@ def build(bld):
source = 'patchage.desktop.in',
target = 'patchage.desktop',
install_path = '${DATADIR}/applications',
- chmod = 0755,
+ chmod = 0644,
BINDIR = os.path.normpath(bld.env['BINDIR']),
APP_INSTALL_NAME = bld.env['APP_INSTALL_NAME'],
APP_HUMAN_NAME = bld.env['APP_HUMAN_NAME'])