relocatable.h 2.8 KB

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