annotate lib/relocatable.h @ 8265:20006894dae4

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