summaryrefslogtreecommitdiff
path: root/make/utilities.pm
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-01-13 23:29:40 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-01-13 23:29:40 +0000
commitad4d207905fa3ae5cec09163d7ac462e3120ad4b (patch)
treee2ddaebfa397f2581c081ec25fefcbd0308b978e /make/utilities.pm
parent568018bdbd1f35f494c3cbf5194bbb40394dcb4d (diff)
Tidy up the buildsystem a lot by encapsulating repeated detection routines for lib dirs and header dirs in make/utilities.pm.
See the pl files in src/modules/extra for how to use the functions. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6305 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'make/utilities.pm')
-rw-r--r--make/utilities.pm86
1 files changed, 86 insertions, 0 deletions
diff --git a/make/utilities.pm b/make/utilities.pm
new file mode 100644
index 000000000..a7e0eb794
--- /dev/null
+++ b/make/utilities.pm
@@ -0,0 +1,86 @@
+package make::utilities;
+use Exporter 'import';
+@EXPORT = qw(make_rpath pkgconfig_get_include_dirs pkgconfig_get_lib_dirs);
+
+# Parse the output of a *_config program,
+# such as pcre_config, take out the -L
+# directive and return an rpath for it.
+
+sub make_rpath($)
+{
+ my ($executable) = @_;
+ $data = `$executable`;
+ $data =~ /-L(\S+)\s/;
+ $libpath = $1;
+ return "-Wl,--rpath -Wl,$libpath";
+}
+
+sub extend_pkg_path()
+{
+ if (!exists $ENV{PKG_CONFIG_PATH})
+ {
+ $ENV{PKG_CONFIG_PATH} = "/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/libdata/pkgconfig:/usr/X11R6/libdata/pkgconfig";
+ }
+ else
+ {
+ $ENV{PKG_CONFIG_PATH} .= ":/usr/local/lib/pkgconfig:/usr/local/libdata/pkgconfig:/usr/X11R6/libdata/pkgconfig";
+ }
+}
+
+sub pkgconfig_get_include_dirs($$$)
+{
+ my ($packagename, $headername, $defaults) = @_;
+ extend_pkg_path();
+
+ $ret = `pkg-config --cflags $packagename 2>/dev/null`;
+ if ((!defined $ret) || ($ret eq ""))
+ {
+ $foo = `locate "$headername" | head -n 1`;
+ $foo =~ /(.+)\Q$headername\E/;
+ if (defined $1)
+ {
+ $foo = "-I$1";
+ }
+ else
+ {
+ $foo = "";
+ }
+ $ret = "$foo";
+ }
+ if (($defaults ne "") && (($ret eq "") || (!defined $ret)))
+ {
+ $ret = "$foo " . $defaults;
+ }
+ return $ret;
+}
+
+sub pkgconfig_get_lib_dirs($$$)
+{
+ my ($packagename, $libname, $defaults) = @_;
+ extend_pkg_path();
+
+ $ret = `pkg-config --libs $packagename 2>/dev/null`;
+ if ((!defined $ret) || ($ret eq ""))
+ {
+ $foo = `locate "$libname" | head -n 1`;
+ $foo =~ /(.+)\Q$libname\E/;
+ if (defined $1)
+ {
+ $foo = "-L$1";
+ }
+ else
+ {
+ $foo = "";
+ }
+ $ret = "$foo";
+ }
+
+ if (($defaults ne "") && (($ret eq "") || (!defined $ret)))
+ {
+ $ret = "$foo " . $defaults;
+ }
+ return $ret;
+}
+
+1;
+