1*946379e7Schristos /* Provide relocatable packages. 2*946379e7Schristos Copyright (C) 2003, 2005 Free Software Foundation, Inc. 3*946379e7Schristos Written by Bruno Haible <bruno@clisp.org>, 2003. 4*946379e7Schristos 5*946379e7Schristos This program is free software; you can redistribute it and/or modify it 6*946379e7Schristos under the terms of the GNU Library General Public License as published 7*946379e7Schristos by the Free Software Foundation; either version 2, or (at your option) 8*946379e7Schristos any later version. 9*946379e7Schristos 10*946379e7Schristos This program is distributed in the hope that it will be useful, 11*946379e7Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 12*946379e7Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13*946379e7Schristos Library General Public License for more details. 14*946379e7Schristos 15*946379e7Schristos You should have received a copy of the GNU Library General Public 16*946379e7Schristos License along with this program; if not, write to the Free Software 17*946379e7Schristos Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 18*946379e7Schristos USA. */ 19*946379e7Schristos 20*946379e7Schristos #ifndef _RELOCATABLE_H 21*946379e7Schristos #define _RELOCATABLE_H 22*946379e7Schristos 23*946379e7Schristos #ifdef __cplusplus 24*946379e7Schristos extern "C" { 25*946379e7Schristos #endif 26*946379e7Schristos 27*946379e7Schristos 28*946379e7Schristos /* This can be enabled through the configure --enable-relocatable option. */ 29*946379e7Schristos #if ENABLE_RELOCATABLE 30*946379e7Schristos 31*946379e7Schristos /* When building a DLL, we must export some functions. Note that because 32*946379e7Schristos this is a private .h file, we don't need to use __declspec(dllimport) 33*946379e7Schristos in any case. */ 34*946379e7Schristos #if HAVE_VISIBILITY && BUILDING_DLL 35*946379e7Schristos # define RELOCATABLE_DLL_EXPORTED __attribute__((__visibility__("default"))) 36*946379e7Schristos #elif defined _MSC_VER && BUILDING_DLL 37*946379e7Schristos # define RELOCATABLE_DLL_EXPORTED __declspec(dllexport) 38*946379e7Schristos #else 39*946379e7Schristos # define RELOCATABLE_DLL_EXPORTED 40*946379e7Schristos #endif 41*946379e7Schristos 42*946379e7Schristos /* Sets the original and the current installation prefix of the package. 43*946379e7Schristos Relocation simply replaces a pathname starting with the original prefix 44*946379e7Schristos by the corresponding pathname with the current prefix instead. Both 45*946379e7Schristos prefixes should be directory names without trailing slash (i.e. use "" 46*946379e7Schristos instead of "/"). */ 47*946379e7Schristos extern RELOCATABLE_DLL_EXPORTED void 48*946379e7Schristos set_relocation_prefix (const char *orig_prefix, 49*946379e7Schristos const char *curr_prefix); 50*946379e7Schristos 51*946379e7Schristos /* Returns the pathname, relocated according to the current installation 52*946379e7Schristos directory. */ 53*946379e7Schristos extern const char * relocate (const char *pathname); 54*946379e7Schristos 55*946379e7Schristos /* Memory management: relocate() leaks memory, because it has to construct 56*946379e7Schristos a fresh pathname. If this is a problem because your program calls 57*946379e7Schristos relocate() frequently, think about caching the result. */ 58*946379e7Schristos 59*946379e7Schristos /* Convenience function: 60*946379e7Schristos Computes the current installation prefix, based on the original 61*946379e7Schristos installation prefix, the original installation directory of a particular 62*946379e7Schristos file, and the current pathname of this file. Returns NULL upon failure. */ 63*946379e7Schristos extern const char * compute_curr_prefix (const char *orig_installprefix, 64*946379e7Schristos const char *orig_installdir, 65*946379e7Schristos const char *curr_pathname); 66*946379e7Schristos 67*946379e7Schristos #else 68*946379e7Schristos 69*946379e7Schristos /* By default, we use the hardwired pathnames. */ 70*946379e7Schristos #define relocate(pathname) (pathname) 71*946379e7Schristos 72*946379e7Schristos #endif 73*946379e7Schristos 74*946379e7Schristos 75*946379e7Schristos #ifdef __cplusplus 76*946379e7Schristos } 77*946379e7Schristos #endif 78*946379e7Schristos 79*946379e7Schristos #endif /* _RELOCATABLE_H */ 80