xref: /openbsd-src/gnu/usr.bin/perl/perl_inc_macro.h (revision ff0e7be1ebbcc809ea8ad2b6dafe215824da9e46)
1 /* just define a list of macros to push elements in INC
2 *  so we can easily use them and change order on demand
3 *
4 * list of available INCPUSH macros
5 * - INCPUSH_APPLLIB_EXP
6 * - INCPUSH_SITEARCH_EXP
7 * - INCPUSH_SITELIB_EXP
8 * - INCPUSH_PERL_VENDORARCH_EXP
9 * - INCPUSH_PERL_VENDORLIB_EXP
10 * - INCPUSH_ARCHLIB_EXP
11 * - INCPUSH_PRIVLIB_EXP
12 * - INCPUSH_PERL_OTHERLIBDIRS
13 * - INCPUSH_PERL5LIB
14 * - INCPUSH_APPLLIB_OLD_EXP
15 * - INCPUSH_SITELIB_STEM
16 * - INCPUSH_PERL_VENDORLIB_STEM
17 * - INCPUSH_PERL_OTHERLIBDIRS_ARCHONLY
18 */
19 
20 #ifndef DEFINE_INC_MACROS
21 
22 /* protect against multiple inclusions */
23 #define DEFINE_INC_MACROS 1
24 
25 #ifdef APPLLIB_EXP
26 #	define INCPUSH_APPLLIB_EXP  S_incpush_use_sep(aTHX_ STR_WITH_LEN(APPLLIB_EXP), \
27                       INCPUSH_ADD_SUB_DIRS|INCPUSH_CAN_RELOCATE);
28 #endif
29 
30 #ifdef SITEARCH_EXP
31     /* sitearch is always relative to sitelib on Windows for
32      * DLL-based path intuition to work correctly */
33 #  if !defined(WIN32)
34 #	define INCPUSH_SITEARCH_EXP S_incpush_use_sep(aTHX_ STR_WITH_LEN(SITEARCH_EXP), \
35                           INCPUSH_CAN_RELOCATE);
36 #  endif
37 #endif
38 
39 #ifdef SITELIB_EXP
40 #  if defined(WIN32)
41     /* this picks up sitearch as well */
42 #	  define INCPUSH_SITELIB_EXP s = PerlEnv_sitelib_path(PERL_FS_VERSION, &len); \
43                 if (s) incpush_use_sep(s, len, INCPUSH_ADD_SUB_DIRS|INCPUSH_CAN_RELOCATE);
44 #  else
45 #	  define INCPUSH_SITELIB_EXP S_incpush_use_sep(aTHX_ STR_WITH_LEN(SITELIB_EXP), \
46                 INCPUSH_CAN_RELOCATE);
47 #  endif
48 #endif
49 
50 #ifdef PERL_VENDORARCH_EXP
51     /* vendorarch is always relative to vendorlib on Windows for
52      * DLL-based path intuition to work correctly */
53 #  if !defined(WIN32)
54 #		define INCPUSH_PERL_VENDORARCH_EXP  S_incpush_use_sep(aTHX_ STR_WITH_LEN(PERL_VENDORARCH_EXP), INCPUSH_CAN_RELOCATE);
55 #  endif
56 #endif
57 
58 #ifdef PERL_VENDORLIB_EXP
59 #  if defined(WIN32)
60     /* this picks up vendorarch as well */
61 #		define INCPUSH_PERL_VENDORLIB_EXP s = PerlEnv_vendorlib_path(PERL_FS_VERSION, &len); \
62                         if (s) incpush_use_sep(s, len, INCPUSH_ADD_SUB_DIRS|INCPUSH_CAN_RELOCATE);
63 #  else
64 #		define INCPUSH_PERL_VENDORLIB_EXP S_incpush_use_sep(aTHX_ STR_WITH_LEN(PERL_VENDORLIB_EXP), INCPUSH_CAN_RELOCATE);
65 #  endif
66 #endif
67 
68 #ifdef ARCHLIB_EXP
69 #	define INCPUSH_ARCHLIB_EXP S_incpush_use_sep(aTHX_ STR_WITH_LEN(ARCHLIB_EXP), INCPUSH_CAN_RELOCATE);
70 #endif
71 
72 /* used by INCPUSH_PRIVLIB_EXP */
73 #ifndef PRIVLIB_EXP
74 #  define PRIVLIB_EXP "/usr/local/lib/perl5:/usr/local/lib/perl"
75 #endif
76 
77 #if defined(WIN32)
78 #	define INCPUSH_PRIVLIB_EXP s = PerlEnv_lib_path(PERL_FS_VERSION, &len); \
79     if (s) incpush_use_sep(s, len, INCPUSH_ADD_SUB_DIRS|INCPUSH_CAN_RELOCATE);
80 #else
81 #	define INCPUSH_PRIVLIB_EXP S_incpush_use_sep(aTHX_ STR_WITH_LEN(PRIVLIB_EXP), INCPUSH_CAN_RELOCATE);
82 #endif
83 
84 #ifdef PERL_OTHERLIBDIRS
85 #	define INCPUSH_PERL_OTHERLIBDIRS S_incpush_use_sep(aTHX_ STR_WITH_LEN(PERL_OTHERLIBDIRS), \
86                       INCPUSH_ADD_VERSIONED_SUB_DIRS|INCPUSH_NOT_BASEDIR|INCPUSH_CAN_RELOCATE);
87 #endif
88 
89 
90 /* submacros for INCPUSH_PERL5LIB */
91 
92 #if defined(PERL_USE_SAFE_PUTENV) && ! defined(HAS_UNSETENV)
93 # 	define _INCPUSH_PERL5LIB_IF	if (perl5lib && *perl5lib != '\0')
94 #else
95 # 	define _INCPUSH_PERL5LIB_IF	if (perl5lib)
96 #endif
97 
98 #ifndef VMS
99 /*
100  * It isn't possible to delete an environment variable with
101  * PERL_USE_SAFE_PUTENV set unless unsetenv() is also available, so in that
102  * case we treat PERL5LIB as undefined if it has a zero-length value.
103  */
104 # define _INCPUSH_PERL5LIB_ADD _INCPUSH_PERL5LIB_IF incpush_use_sep(perl5lib, 0, INCPUSH_ADD_OLD_VERS|INCPUSH_NOT_BASEDIR);
105 #else
106 /* VMS */
107         /* Treat PERL5?LIB as a possible search list logical name -- the
108          * "natural" VMS idiom for a Unix path string.  We allow each
109          * element to be a set of |-separated directories for compatibility.
110          */
111 # define _INCPUSH_PERL5LIB_ADD char buf[256]; \
112         int idx = 0; \
113         if (vmstrnenv("PERL5LIB",buf,0,NULL,0)) \
114             do { \
115                 incpush_use_sep(buf, 0, \
116                                 INCPUSH_ADD_OLD_VERS|INCPUSH_NOT_BASEDIR); \
117             } while (vmstrnenv("PERL5LIB",buf,++idx,NULL,0));
118 #endif
119 
120 /* this macro is special and use submacros from above */
121 #define INCPUSH_PERL5LIB if (!TAINTING_get) { _INCPUSH_PERL5LIB_ADD }
122 
123 /* Use the ~-expanded versions of APPLLIB (undocumented),
124     SITELIB and VENDORLIB for older versions
125 */
126 #ifdef APPLLIB_EXP
127 #	define INCPUSH_APPLLIB_OLD_EXP S_incpush_use_sep(aTHX_ STR_WITH_LEN(APPLLIB_EXP), \
128             INCPUSH_ADD_OLD_VERS|INCPUSH_NOT_BASEDIR|INCPUSH_CAN_RELOCATE);
129 #endif
130 
131 #if defined(SITELIB_STEM) && defined(PERL_INC_VERSION_LIST)
132     /* Search for version-specific dirs below here */
133 #	define INCPUSH_SITELIB_STEM   S_incpush_use_sep(aTHX_ STR_WITH_LEN(SITELIB_STEM), \
134                       INCPUSH_ADD_OLD_VERS|INCPUSH_CAN_RELOCATE);
135 #endif
136 
137 
138 #if defined(PERL_VENDORLIB_STEM) && defined(PERL_INC_VERSION_LIST)
139     /* Search for version-specific dirs below here */
140 #	define INCPUSH_PERL_VENDORLIB_STEM    S_incpush_use_sep(aTHX_ STR_WITH_LEN(PERL_VENDORLIB_STEM), \
141                       INCPUSH_ADD_OLD_VERS|INCPUSH_CAN_RELOCATE);
142 #endif
143 
144 #ifdef PERL_OTHERLIBDIRS
145 #	define INCPUSH_PERL_OTHERLIBDIRS_ARCHONLY  S_incpush_use_sep(aTHX_ STR_WITH_LEN(PERL_OTHERLIBDIRS), \
146                       INCPUSH_ADD_OLD_VERS|INCPUSH_ADD_ARCHONLY_SUB_DIRS|INCPUSH_CAN_RELOCATE);
147 #endif
148 
149 
150 /* define all undefined macros... */
151 #ifndef INCPUSH_APPLLIB_EXP
152 #define INCPUSH_APPLLIB_EXP
153 #endif
154 #ifndef INCPUSH_SITEARCH_EXP
155 #define INCPUSH_SITEARCH_EXP
156 #endif
157 #ifndef INCPUSH_SITELIB_EXP
158 #define INCPUSH_SITELIB_EXP
159 #endif
160 #ifndef INCPUSH_PERL_VENDORARCH_EXP
161 #define INCPUSH_PERL_VENDORARCH_EXP
162 #endif
163 #ifndef INCPUSH_PERL_VENDORLIB_EXP
164 #define INCPUSH_PERL_VENDORLIB_EXP
165 #endif
166 #ifndef INCPUSH_ARCHLIB_EXP
167 #define INCPUSH_ARCHLIB_EXP
168 #endif
169 #ifndef INCPUSH_PRIVLIB_EXP
170 #define INCPUSH_PRIVLIB_EXP
171 #endif
172 #ifndef INCPUSH_PERL_OTHERLIBDIRS
173 #define INCPUSH_PERL_OTHERLIBDIRS
174 #endif
175 #ifndef INCPUSH_PERL5LIB
176 #define INCPUSH_PERL5LIB
177 #endif
178 #ifndef INCPUSH_APPLLIB_OLD_EXP
179 #define INCPUSH_APPLLIB_OLD_EXP
180 #endif
181 #ifndef INCPUSH_SITELIB_STEM
182 #define INCPUSH_SITELIB_STEM
183 #endif
184 #ifndef INCPUSH_PERL_VENDORLIB_STEM
185 #define INCPUSH_PERL_VENDORLIB_STEM
186 #endif
187 #ifndef INCPUSH_PERL_OTHERLIBDIRS_ARCHONLY
188 #define INCPUSH_PERL_OTHERLIBDIRS_ARCHONLY
189 #endif
190 
191 #endif /* DEFINE_INC_MACROS */
192