Skip to content

Commit

Permalink
Add snogpaths.cc and snogpaths.h
Browse files Browse the repository at this point in the history
These just define some functions to return the install paths
determined at build-time.
  • Loading branch information
snogglethorpe committed Feb 26, 2012
1 parent 1a19bf2 commit 16d294a
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -19,6 +19,7 @@ teapot.msh
# Ignore generated sources
#
version.cc
snogpaths-data.h
snograw_lua_wrap.cc
swigluarun.h

Expand Down
27 changes: 23 additions & 4 deletions Makefile.am
Expand Up @@ -75,7 +75,7 @@ dist-hook:

# Some extra stuff that needs cleaning up
#
CLEANFILES = liblua.a snograw.so version.cc
CLEANFILES = liblua.a snograw.so version.cc snogpaths-data.h

# We only clean up "snograw_lua_wrap.cc" and "swigluarun.h" if it's
# possible to regenerate them.
Expand Down Expand Up @@ -396,9 +396,28 @@ libsnogutil_a_SOURCES = compiler.h cond-var.h excepts.h file-funs.cc \
nice-io.cc nice-io.h num-cores.cc num-cores.h pool.h \
radical-inverse.h random.h random-boost.h random-std.h \
random-rand.h random-tr1.h ref.h rusage.h snogassert.cc \
snogassert.h snogmath.h string-funs.cc string-funs.h thread.h \
threading.h threading-boost.h threading-std.h timeval.cc \
timeval.h val-table.cc unique-ptr.h val-table.h
snogassert.h snogmath.h snogpaths.cc snogpaths.h \
string-funs.cc string-funs.h thread.h threading.h \
threading-boost.h threading-std.h timeval.cc timeval.h \
val-table.cc unique-ptr.h val-table.h


snogpaths.cc: snogpaths-data.h

# automagically-computed paths
#
snogpaths-data.h: Makefile
$(snogpaths_verbose)( \
echo '// this file is automatically generated'; \
echo '#define SNOGRAY_PREFIX "$(prefix)"'; \
echo '#define SNOGRAY_BINDIR "$(bindir)"'; \
echo '#define SNOGRAY_PKGDATADIR "$(pkgdatadir)"' ) > "$@"

# automake "silent-rules" hook for snogpaths-data.h
#
snogpaths_verbose = $(snogpaths_verbose_$(V))
snogpaths_verbose_ = $(snogpaths_verbose_$(AM_DEFAULT_VERBOSITY))
snogpaths_verbose_0 = @echo " PATHS " $@;


################################################################
Expand Down
63 changes: 63 additions & 0 deletions snogpaths.cc
@@ -0,0 +1,63 @@
// snogpaths.cc -- Handling of installation paths
//
// Copyright (C) 2012 Miles Bader <miles@gnu.org>
//
// This source code 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 3, or (at
// your option) any later version. See the file COPYING for more details.
//
// Written by Miles Bader <miles@gnu.org>
//

#include "snogpaths-data.h"

#include "snogpaths.h"


//
// Currently these functions just return the statically configured
// install paths.
//
// A better method would be try and make everything "relocatable", by
// detecting the run-time install prefix, and making other names
// relative to that. This can be done as follows:
//
// 1. Determine the absolute runtime name of the executable.
// There should be a function that main calls to pass in
// argv[0]; it can be used as-is if absolute, or searched for
// in PATH if not.
//
// 2. Determine the relative bindir suffix by removing the static
// install prefix from the static bindir (if the static bindir
// is not relative to the static prefix, give up).
//
// 3. Remove the filename and relative bindir suffix from the end
// of the absolute runtime executable name (if they don't
// match, give up), yielding the runtime prefix.
//
// 4. Determine the relative suffixes for other paths (datadir,
// etc) by removing the static prefix from their static
// versions, as in (2).
//
// 5. Append the runtime prefix and the relative suffixes
// determined in (4) to yield the absolute runtime paths.
//

std::string
snogray::installed_prefix ()
{
return SNOGRAY_PREFIX;
}

std::string
snogray::installed_bindir ()
{
return SNOGRAY_BINDIR;
}

std::string
snogray::installed_pkgdatadir ()
{
return SNOGRAY_PKGDATADIR;
}
27 changes: 27 additions & 0 deletions snogpaths.h
@@ -0,0 +1,27 @@
// snogpaths.h -- Handling of installation paths
//
// Copyright (C) 2012 Miles Bader <miles@gnu.org>
//
// This source code 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 3, or (at
// your option) any later version. See the file COPYING for more details.
//
// Written by Miles Bader <miles@gnu.org>
//

#ifndef SNOGRAY_SNOGPATHS_H
#define SNOGRAY_SNOGPATHS_H

#include <string>


namespace snogray {

std::string installed_prefix ();
std::string installed_bindir ();
std::string installed_pkgdatadir ();

}

#endif // SNOGRAY_SNOGPATHS_H

0 comments on commit 16d294a

Please sign in to comment.