1 /*=========================================================================
3 Program: KWSys - Kitware System Library
4 Module: $RCSfile: SharedForward.h.in,v $
6 Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved.
7 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notices for more information.
13 =========================================================================*/
14 #ifndef @KWSYS_NAMESPACE@_SharedForward_h
15 #define @KWSYS_NAMESPACE@_SharedForward_h
18 This header is used to create a forwarding executable sets up the
19 shared library search path and replaces itself with a real
20 executable. This is useful when creating installations on UNIX with
21 shared libraries that will run from any install directory. Typical
24 #if defined(CMAKE_INTDIR)
25 # define CONFIG_DIR_PRE CMAKE_INTDIR "/"
26 # define CONFIG_DIR_POST "/" CMAKE_INTDIR
28 # define CONFIG_DIR_PRE ""
29 # define CONFIG_DIR_POST ""
31 #define @KWSYS_NAMESPACE@_SHARED_FORWARD_DIR_BUILD "/path/to/foo-build/bin"
32 #define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_BUILD "." CONFIG_DIR_POST
33 #define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_INSTALL "../lib/foo-1.2"
34 #define @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_BUILD CONFIG_DIR_PRE "foo-real"
35 #define @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_INSTALL "../lib/foo-1.2/foo-real"
36 #define @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_COMMAND "--command"
37 #define @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_PRINT "--print"
38 #define @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_LDD "--ldd"
39 #if defined(CMAKE_INTDIR)
40 # define @KWSYS_NAMESPACE@_SHARED_FORWARD_CONFIG_NAME CMAKE_INTDIR
42 #include <@KWSYS_NAMESPACE@/SharedForward.h>
43 int main(int argc, char** argv)
45 return @KWSYS_NAMESPACE@_shared_forward_to_real(argc, argv);
48 Specify search and executable paths relative to the forwarding
49 executable location or as full paths. Include no trailing slash.
50 In the case of a multi-configuration build, when CMAKE_INTDIR is
51 defined, the DIR_BUILD setting should point at the directory above
52 the executable (the one containing the per-configuration
53 subdirectory specified by CMAKE_INTDIR). Then PATH_BUILD entries
54 and EXE_BUILD should be specified relative to this location and use
55 CMAKE_INTDIR as necessary. In the above example imagine appending
56 the PATH_BUILD or EXE_BUILD setting to the DIR_BUILD setting. The
57 result should form a valid path with per-configuration subdirectory.
59 Additional paths may be specified in the PATH_BUILD and PATH_INSTALL
60 variables by using comma-separated strings. For example:
62 #define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_BUILD \
63 "." CONFIG_DIR_POST, "/path/to/bar-build" CONFIG_DIR_POST
64 #define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_INSTALL \
65 "../lib/foo-1.2", "../lib/bar-4.5"
67 See the comments below for specific explanations of each macro.
70 /*--------------------------------------------------------------------------*/
72 /* Full path to the directory in which this executable is built. Do
73 not include a trailing slash. */
74 #if !defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_DIR_BUILD)
75 # error "Must define @KWSYS_NAMESPACE@_SHARED_FORWARD_DIR_BUILD"
77 #if !defined(KWSYS_SHARED_FORWARD_DIR_BUILD)
78 # define KWSYS_SHARED_FORWARD_DIR_BUILD @KWSYS_NAMESPACE@_SHARED_FORWARD_DIR_BUILD
81 /* Library search path for build tree. */
82 #if !defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_BUILD)
83 # error "Must define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_BUILD"
85 #if !defined(KWSYS_SHARED_FORWARD_PATH_BUILD)
86 # define KWSYS_SHARED_FORWARD_PATH_BUILD @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_BUILD
89 /* Library search path for install tree. */
90 #if !defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_INSTALL)
91 # error "Must define @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_INSTALL"
93 #if !defined(KWSYS_SHARED_FORWARD_PATH_INSTALL)
94 # define KWSYS_SHARED_FORWARD_PATH_INSTALL @KWSYS_NAMESPACE@_SHARED_FORWARD_PATH_INSTALL
97 /* The real executable to which to forward in the build tree. */
98 #if !defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_BUILD)
99 # error "Must define @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_BUILD"
101 #if !defined(KWSYS_SHARED_FORWARD_EXE_BUILD)
102 # define KWSYS_SHARED_FORWARD_EXE_BUILD @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_BUILD
105 /* The real executable to which to forward in the install tree. */
106 #if !defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_INSTALL)
107 # error "Must define @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_INSTALL"
109 #if !defined(KWSYS_SHARED_FORWARD_EXE_INSTALL)
110 # define KWSYS_SHARED_FORWARD_EXE_INSTALL @KWSYS_NAMESPACE@_SHARED_FORWARD_EXE_INSTALL
113 /* The configuration name with which this executable was built (Debug/Release). */
114 #if defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_CONFIG_NAME)
115 # define KWSYS_SHARED_FORWARD_CONFIG_NAME @KWSYS_NAMESPACE@_SHARED_FORWARD_CONFIG_NAME
117 # undef KWSYS_SHARED_FORWARD_CONFIG_NAME
120 /* Create command line option to replace executable. */
121 #if defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_COMMAND)
122 # if !defined(KWSYS_SHARED_FORWARD_OPTION_COMMAND)
123 # define KWSYS_SHARED_FORWARD_OPTION_COMMAND @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_COMMAND
126 # undef KWSYS_SHARED_FORWARD_OPTION_COMMAND
129 /* Create command line option to print environment setting and exit. */
130 #if defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_PRINT)
131 # if !defined(KWSYS_SHARED_FORWARD_OPTION_PRINT)
132 # define KWSYS_SHARED_FORWARD_OPTION_PRINT @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_PRINT
135 # undef KWSYS_SHARED_FORWARD_OPTION_PRINT
138 /* Create command line option to run ldd or equivalent. */
139 #if defined(@KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_LDD)
140 # if !defined(KWSYS_SHARED_FORWARD_OPTION_LDD)
141 # define KWSYS_SHARED_FORWARD_OPTION_LDD @KWSYS_NAMESPACE@_SHARED_FORWARD_OPTION_LDD
144 # undef KWSYS_SHARED_FORWARD_OPTION_LDD
147 /*--------------------------------------------------------------------------*/
148 /* Include needed system headers. */
156 #if defined(_WIN32) && !defined(__CYGWIN__)
158 # include <windows.h>
159 # include <process.h>
164 /*--------------------------------------------------------------------------*/
165 /* Configuration for this platform. */
167 /* The path separator for this platform. */
168 #if defined(_WIN32) && !defined(__CYGWIN__)
169 # define KWSYS_SHARED_FORWARD_PATH_SEP ';'
170 # define KWSYS_SHARED_FORWARD_PATH_SLASH '\\'
172 # define KWSYS_SHARED_FORWARD_PATH_SEP ':'
173 # define KWSYS_SHARED_FORWARD_PATH_SLASH '/'
175 static const char kwsys_shared_forward_path_sep
[2] = {KWSYS_SHARED_FORWARD_PATH_SEP
, 0};
176 static const char kwsys_shared_forward_path_slash
[2] = {KWSYS_SHARED_FORWARD_PATH_SLASH
, 0};
178 /* The maximum length of a file name. */
179 #if defined(PATH_MAX)
180 # define KWSYS_SHARED_FORWARD_MAXPATH PATH_MAX
181 #elif defined(MAXPATHLEN)
182 # define KWSYS_SHARED_FORWARD_MAXPATH MAXPATHLEN
184 # define KWSYS_SHARED_FORWARD_MAXPATH 16384
187 /* Select the environment variable holding the shared library runtime
188 search path for this platform and build configuration. Also select
189 ldd command equivalent. */
193 # define KWSYS_SHARED_FORWARD_LDD "ldd"
194 # define KWSYS_SHARED_FORWARD_LDD_N 1
195 # define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH"
199 #if defined(__FreeBSD__)
200 # define KWSYS_SHARED_FORWARD_LDD "ldd"
201 # define KWSYS_SHARED_FORWARD_LDD_N 1
202 # define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH"
206 #if defined(__APPLE__)
207 # define KWSYS_SHARED_FORWARD_LDD "otool", "-L"
208 # define KWSYS_SHARED_FORWARD_LDD_N 2
209 # define KWSYS_SHARED_FORWARD_LDPATH "DYLD_LIBRARY_PATH"
214 # define KWSYS_SHARED_FORWARD_LDD "dump", "-H"
215 # define KWSYS_SHARED_FORWARD_LDD_N 2
216 # define KWSYS_SHARED_FORWARD_LDPATH "LIBPATH"
221 # define KWSYS_SHARED_FORWARD_LDD "ldd"
222 # define KWSYS_SHARED_FORWARD_LDD_N 1
223 # include <sys/isa_defs.h>
225 # define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH"
226 # elif defined(_LP64)
227 # define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH_64"
233 # define KWSYS_SHARED_FORWARD_LDD "chatr"
234 # define KWSYS_SHARED_FORWARD_LDD_N 1
235 # if defined(__LP64__)
236 # define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH"
238 # define KWSYS_SHARED_FORWARD_LDPATH "SHLIB_PATH"
243 #if defined(__sgi) && defined(_MIPS_SIM)
244 # define KWSYS_SHARED_FORWARD_LDD "ldd"
245 # define KWSYS_SHARED_FORWARD_LDD_N 1
246 # if _MIPS_SIM == _ABIO32
247 # define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH"
248 # elif _MIPS_SIM == _ABIN32
249 # define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARYN32_PATH"
250 # elif _MIPS_SIM == _ABI64
251 # define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY64_PATH"
257 # if defined(__CYGWIN__)
258 # define KWSYS_SHARED_FORWARD_LDD "cygcheck"
259 # define KWSYS_SHARED_FORWARD_LDD_N 1
261 # define KWSYS_SHARED_FORWARD_LDPATH "PATH"
264 /* Guess on this unknown system. */
265 #if !defined(KWSYS_SHARED_FORWARD_LDPATH)
266 # define KWSYS_SHARED_FORWARD_LDD "ldd"
267 # define KWSYS_SHARED_FORWARD_LDD_N 1
268 # define KWSYS_SHARED_FORWARD_LDPATH "LD_LIBRARY_PATH"
271 /*--------------------------------------------------------------------------*/
272 /* Function to convert a logical or relative path to a physical full path. */
273 static int kwsys_shared_forward_realpath(const char* in_path
, char* out_path
)
275 #if defined(_WIN32) && !defined(__CYGWIN__)
276 /* Implementation for Windows. */
277 DWORD n
= GetFullPathName(in_path
, KWSYS_SHARED_FORWARD_MAXPATH
,
279 return n
> 0 && n
<= KWSYS_SHARED_FORWARD_MAXPATH
;
281 /* Implementation for UNIX. */
282 return realpath(in_path
, out_path
) != 0;
286 /*--------------------------------------------------------------------------*/
287 /* Function to report a system error message. */
288 static void kwsys_shared_forward_strerror(char* message
)
290 #if defined(_WIN32) && !defined(__CYGWIN__)
291 /* Implementation for Windows. */
292 DWORD original
= GetLastError();
293 DWORD length
= FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
|
294 FORMAT_MESSAGE_IGNORE_INSERTS
, 0, original
,
295 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
296 message
, KWSYS_SHARED_FORWARD_MAXPATH
, 0);
297 if(length
< 1 || length
> KWSYS_SHARED_FORWARD_MAXPATH
)
299 /* FormatMessage failed. Use a default message. */
300 _snprintf(message
, KWSYS_SHARED_FORWARD_MAXPATH
,
301 "Error 0x%X (FormatMessage failed with error 0x%X)",
302 original
, GetLastError());
305 /* Implementation for UNIX. */
306 strcpy(message
, strerror(errno
));
310 /*--------------------------------------------------------------------------*/
311 /* Functions to execute a child process. */
312 static void kwsys_shared_forward_execvp(const char* cmd
, char* const argv
[])
314 #if defined(_MSC_VER)
321 /*--------------------------------------------------------------------------*/
322 /* Function to get the directory containing the given file or directory. */
323 static void kwsys_shared_forward_dirname(const char* begin
, char* result
)
325 /* Find the location of the last slash. */
326 int last_slash_index
= -1;
327 const char* end
= begin
+ strlen(begin
);
328 for(;begin
<= end
&& last_slash_index
< 0; --end
)
330 if(*end
== '/' || *end
== '\\')
332 last_slash_index
= end
-begin
;
336 /* Handle each case of the index of the last slash. */
337 if(last_slash_index
< 0)
342 else if(last_slash_index
== 0)
344 /* Only one leading slash. */
345 strcpy(result
, kwsys_shared_forward_path_slash
);
348 else if(last_slash_index
== 2 && begin
[1] == ':')
350 /* Only one leading drive letter and slash. */
351 strncpy(result
, begin
, last_slash_index
);
352 result
[last_slash_index
] = KWSYS_SHARED_FORWARD_PATH_SLASH
;
353 result
[last_slash_index
+1] = 0;
358 /* A non-leading slash. */
359 strncpy(result
, begin
, last_slash_index
);
360 result
[last_slash_index
] = 0;
364 /*--------------------------------------------------------------------------*/
365 /* Function to check if a file exists and is executable. */
366 static int kwsys_shared_forward_is_executable(const char* f
)
368 #if defined(_MSC_VER)
369 # define KWSYS_SHARED_FORWARD_ACCESS _access
371 # define KWSYS_SHARED_FORWARD_ACCESS access
374 # define KWSYS_SHARED_FORWARD_ACCESS_OK X_OK
376 # define KWSYS_SHARED_FORWARD_ACCESS_OK 04
378 if(KWSYS_SHARED_FORWARD_ACCESS(f
, KWSYS_SHARED_FORWARD_ACCESS_OK
) == 0)
388 /*--------------------------------------------------------------------------*/
389 /* Function to locate the executable currently running. */
390 static int kwsys_shared_forward_self_path(const char* argv0
, char* result
)
392 /* Check whether argv0 has a slash. */
394 const char* p
= argv0
;
395 for(;*p
&& !has_slash
; ++p
)
397 if(*p
== '/' || *p
== '\\')
405 /* There is a slash. Use the dirname of the given location. */
406 kwsys_shared_forward_dirname(argv0
, result
);
411 /* There is no slash. Search the PATH for the executable. */
412 const char* path
= getenv("PATH");
413 const char* begin
= path
;
414 const char* end
= begin
+ (begin
?strlen(begin
):0);
415 const char* first
= begin
;
418 /* Store the end of this path entry. */
421 /* Skip all path separators. */
422 for(;*first
&& *first
== KWSYS_SHARED_FORWARD_PATH_SEP
; ++first
);
424 /* Find the next separator. */
425 for(last
= first
;*last
&& *last
!= KWSYS_SHARED_FORWARD_PATH_SEP
; ++last
);
427 /* If we got a non-empty directory, look for the executable there. */
430 /* Determine the length without trailing slash. */
431 int length
= last
-first
;
432 if(*(last
-1) == '/' || *(last
-1) == '\\')
437 /* Construct the name of the executable in this location. */
438 strncpy(result
, first
, length
);
439 result
[length
] = KWSYS_SHARED_FORWARD_PATH_SLASH
;
440 strcpy(result
+(length
)+1, argv0
);
442 /* Check if it exists and is executable. */
443 if(kwsys_shared_forward_is_executable(result
))
451 /* Move to the next directory in the path. */
456 /* We could not find the executable. */
460 /*--------------------------------------------------------------------------*/
461 /* Function to convert a specified path to a full path. If it is not
462 already full, it is taken relative to the self path. */
463 static int kwsys_shared_forward_fullpath(const char* self_path
,
468 /* Check the specified path type. */
469 if(in_path
[0] == '/')
471 /* Already a full path. */
472 strcpy(result
, in_path
);
475 else if(in_path
[0] && in_path
[1] == ':')
477 /* Already a full path. */
478 strcpy(result
, in_path
);
483 /* Relative to self path. */
484 char temp_path
[KWSYS_SHARED_FORWARD_MAXPATH
];
485 strcpy(temp_path
, self_path
);
486 strcat(temp_path
, kwsys_shared_forward_path_slash
);
487 strcat(temp_path
, in_path
);
488 if(!kwsys_shared_forward_realpath(temp_path
, result
))
492 char msgbuf
[KWSYS_SHARED_FORWARD_MAXPATH
];
493 kwsys_shared_forward_strerror(msgbuf
);
494 fprintf(stderr
, "Error converting %s \"%s\" to real path: %s\n",
495 desc
, temp_path
, msgbuf
);
503 /*--------------------------------------------------------------------------*/
504 /* Function to compute the library search path and executable name
505 based on the self path. */
506 static int kwsys_shared_forward_get_settings(const char* self_path
,
507 char* ldpath
, char* exe
)
509 /* Possible search paths. */
510 static const char* search_path_build
[] = {KWSYS_SHARED_FORWARD_PATH_BUILD
, 0};
511 static const char* search_path_install
[] = {KWSYS_SHARED_FORWARD_PATH_INSTALL
, 0};
514 const char** search_path
;
515 const char* exe_path
;
517 /* Get the real name of the build and self paths. */
518 #if defined(KWSYS_SHARED_FORWARD_CONFIG_NAME)
519 char build_path
[] = KWSYS_SHARED_FORWARD_DIR_BUILD
"/" KWSYS_SHARED_FORWARD_CONFIG_NAME
;
520 char self_path_logical
[KWSYS_SHARED_FORWARD_MAXPATH
];
522 char build_path
[] = KWSYS_SHARED_FORWARD_DIR_BUILD
;
523 const char* self_path_logical
= self_path
;
525 char build_path_real
[KWSYS_SHARED_FORWARD_MAXPATH
];
526 char self_path_real
[KWSYS_SHARED_FORWARD_MAXPATH
];
527 if(!kwsys_shared_forward_realpath(self_path
, self_path_real
))
529 char msgbuf
[KWSYS_SHARED_FORWARD_MAXPATH
];
530 kwsys_shared_forward_strerror(msgbuf
);
531 fprintf(stderr
, "Error converting self path \"%s\" to real path: %s\n",
536 /* Check whether we are running in the build tree or an install tree. */
537 if(kwsys_shared_forward_realpath(build_path
, build_path_real
) &&
538 strcmp(self_path_real
, build_path_real
) == 0)
540 /* Running in build tree. Use the build path and exe. */
541 search_path
= search_path_build
;
543 exe_path
= KWSYS_SHARED_FORWARD_EXE_BUILD
".exe";
545 exe_path
= KWSYS_SHARED_FORWARD_EXE_BUILD
;
548 #if defined(KWSYS_SHARED_FORWARD_CONFIG_NAME)
549 /* Remove the configuration directory from self_path. */
550 kwsys_shared_forward_dirname(self_path
, self_path_logical
);
555 /* Running in install tree. Use the install path and exe. */
556 search_path
= search_path_install
;
558 exe_path
= KWSYS_SHARED_FORWARD_EXE_INSTALL
".exe";
560 exe_path
= KWSYS_SHARED_FORWARD_EXE_INSTALL
;
563 #if defined(KWSYS_SHARED_FORWARD_CONFIG_NAME)
564 /* Use the original self path directory. */
565 strcpy(self_path_logical
, self_path
);
569 /* Construct the runtime search path. */
572 for(dir
= search_path
; *dir
; ++dir
)
574 /* Add seperator between path components. */
575 if(dir
!= search_path
)
577 strcat(ldpath
, kwsys_shared_forward_path_sep
);
580 /* Add this path component. */
581 if(!kwsys_shared_forward_fullpath(self_path_logical
, *dir
,
582 ldpath
+strlen(ldpath
),
583 "runtime path entry"))
590 /* Construct the executable location. */
591 if(!kwsys_shared_forward_fullpath(self_path_logical
, exe_path
, exe
,
599 /*--------------------------------------------------------------------------*/
600 /* Function to print why execution of a command line failed. */
601 static void kwsys_shared_forward_print_failure(char** argv
)
603 char msg
[KWSYS_SHARED_FORWARD_MAXPATH
];
605 kwsys_shared_forward_strerror(msg
);
606 fprintf(stderr
, "Error running");
609 fprintf(stderr
, " \"%s\"", *arg
);
611 fprintf(stderr
, ": %s\n", msg
);
614 /* Static storage space to store the updated environment variable. */
615 static char kwsys_shared_forward_ldpath
[KWSYS_SHARED_FORWARD_MAXPATH
*16] = KWSYS_SHARED_FORWARD_LDPATH
"=";
617 /*--------------------------------------------------------------------------*/
618 /* Main driver function to be called from main. */
619 static int @KWSYS_NAMESPACE@
_shared_forward_to_real(int argc
, char** argv
)
621 /* Get the directory containing this executable. */
622 char self_path
[KWSYS_SHARED_FORWARD_MAXPATH
];
623 if(kwsys_shared_forward_self_path(argv
[0], self_path
))
625 /* Found this executable. Use it to get the library directory. */
626 char exe
[KWSYS_SHARED_FORWARD_MAXPATH
];
627 if(kwsys_shared_forward_get_settings(self_path
,
628 kwsys_shared_forward_ldpath
, exe
))
630 /* Append the old runtime search path. */
631 const char* old_ldpath
= getenv(KWSYS_SHARED_FORWARD_LDPATH
);
634 strcat(kwsys_shared_forward_ldpath
, kwsys_shared_forward_path_sep
);
635 strcat(kwsys_shared_forward_ldpath
, old_ldpath
);
638 /* Store the environment variable. */
639 putenv(kwsys_shared_forward_ldpath
);
641 #if defined(KWSYS_SHARED_FORWARD_OPTION_COMMAND)
642 /* Look for the command line replacement option. */
643 if(argc
> 1 && strcmp(argv
[1], KWSYS_SHARED_FORWARD_OPTION_COMMAND
) == 0)
647 /* Use the command line given. */
648 strcpy(exe
, argv
[2]);
654 /* The option was not given an executable. */
655 fprintf(stderr
, "Option " KWSYS_SHARED_FORWARD_OPTION_COMMAND
656 " must be followed by a command line.\n");
662 #if defined(KWSYS_SHARED_FORWARD_OPTION_PRINT)
663 /* Look for the print command line option. */
664 if(argc
> 1 && strcmp(argv
[1], KWSYS_SHARED_FORWARD_OPTION_PRINT
) == 0)
666 fprintf(stdout
, "%s\n", kwsys_shared_forward_ldpath
);
667 fprintf(stdout
, "%s\n", exe
);
672 #if defined(KWSYS_SHARED_FORWARD_OPTION_LDD)
673 /* Look for the ldd command line option. */
674 if(argc
> 1 && strcmp(argv
[1], KWSYS_SHARED_FORWARD_OPTION_LDD
) == 0)
676 # if defined(KWSYS_SHARED_FORWARD_LDD)
677 /* Use the named ldd-like executable and arguments. */
678 char* ldd_argv
[] = {KWSYS_SHARED_FORWARD_LDD
, 0, 0};
679 ldd_argv
[KWSYS_SHARED_FORWARD_LDD_N
] = exe
;
680 kwsys_shared_forward_execvp(ldd_argv
[0], ldd_argv
);
682 /* Report why execution failed. */
683 kwsys_shared_forward_print_failure(ldd_argv
);
686 /* We have no ldd-like executable available on this platform. */
687 fprintf(stderr
, "No ldd-like tool is known to this executable.\n");
693 /* Replace this process with the real executable. */
695 kwsys_shared_forward_execvp(argv
[0], argv
);
697 /* Report why execution failed. */
698 kwsys_shared_forward_print_failure(argv
);
702 /* Could not convert self path to the library directory. */
707 /* Could not find this executable. */
708 fprintf(stderr
, "Error locating executable \"%s\".\n", argv
[0]);
711 /* Avoid unused argument warning. */
714 /* Exit with failure. */
719 # error "@KWSYS_NAMESPACE@/SharedForward.h should be included only once."