11541Srgrimes/* Provide relocatable packages.
21541Srgrimes   Copyright (C) 2003 Free Software Foundation, Inc.
3139823Simp   Written by Bruno Haible <bruno@clisp.org>, 2003.
4139823Simp
51541Srgrimes   This program is free software; you can redistribute it and/or modify it
61541Srgrimes   under the terms of the GNU Library General Public License as published
71541Srgrimes   by the Free Software Foundation; either version 2, or (at your option)
81541Srgrimes   any later version.
91541Srgrimes
101541Srgrimes   This program is distributed in the hope that it will be useful,
111541Srgrimes   but WITHOUT ANY WARRANTY; without even the implied warranty of
121541Srgrimes   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
131541Srgrimes   Library General Public License for more details.
141541Srgrimes
151541Srgrimes   You should have received a copy of the GNU Library General Public
161541Srgrimes   License along with this program; if not, write to the Free Software
171541Srgrimes   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
181541Srgrimes   USA.  */
191541Srgrimes
201541Srgrimes#ifndef _RELOCATABLE_H
211541Srgrimes#define _RELOCATABLE_H
221541Srgrimes
231541Srgrimes/* This can be enabled through the configure --enable-relocatable option.  */
241541Srgrimes#if ENABLE_RELOCATABLE
251541Srgrimes
261541Srgrimes/* When building a DLL, we must export some functions.  Note that because
271541Srgrimes   this is a private .h file, we don't need to use __declspec(dllimport)
281541Srgrimes   in any case.  */
291541Srgrimes#if defined _MSC_VER && BUILDING_DLL
301541Srgrimes# define RELOCATABLE_DLL_EXPORTED __declspec(dllexport)
311541Srgrimes#else
321541Srgrimes# define RELOCATABLE_DLL_EXPORTED
331541Srgrimes#endif
3450477Speter
351541Srgrimes/* Sets the original and the current installation prefix of the package.
361541Srgrimes   Relocation simply replaces a pathname starting with the original prefix
372192Spaul   by the corresponding pathname with the current prefix instead.  Both
382168Spaul   prefixes should be directory names without trailing slash (i.e. use ""
392168Spaul   instead of "/").  */
401541Srgrimesextern RELOCATABLE_DLL_EXPORTED void
4158982Sgj       set_relocation_prefix (const char *orig_prefix,
421541Srgrimes			      const char *curr_prefix);
431541Srgrimes
441541Srgrimes/* Returns the pathname, relocated according to the current installation
451541Srgrimes   directory.  */
461541Srgrimesextern const char * relocate (const char *pathname);
471541Srgrimes
481541Srgrimes/* Memory management: relocate() leaks memory, because it has to construct
491541Srgrimes   a fresh pathname.  If this is a problem because your program calls
501541Srgrimes   relocate() frequently, think about caching the result.  */
511541Srgrimes
521541Srgrimes/* Convenience function:
531541Srgrimes   Computes the current installation prefix, based on the original
541541Srgrimes   installation prefix, the original installation directory of a particular
558876Srgrimes   file, and the current pathname of this file.  Returns NULL upon failure.  */
561541Srgrimesextern const char * compute_curr_prefix (const char *orig_installprefix,
571541Srgrimes					 const char *orig_installdir,
5813765Smpp					 const char *curr_pathname);
591541Srgrimes
601541Srgrimes#else
611541Srgrimes
621541Srgrimes/* By default, we use the hardwired pathnames.  */
631541Srgrimes#define relocate(pathname) (pathname)
641541Srgrimes
651541Srgrimes#endif
661541Srgrimes
671541Srgrimes#endif /* _RELOCATABLE_H */
681541Srgrimes