1 # Try to execute a main program, and if it fails, try adding some
4 AC_DEFUN([LSH_RPATH_FIX],
5 [if test $cross_compiling = no -a "x$RPATHFLAG" != x ; then
7 AC_TRY_RUN([int main(int argc, char **argv) { return 0; }],
8 ac_success=yes, ac_success=no, :)
10 if test $ac_success = no ; then
11 AC_MSG_CHECKING([Running simple test program failed. Trying -R flags])
12 dnl echo RPATH_CANDIDATE_DIRS = $RPATH_CANDIDATE_DIRS
14 ac_rpath_save_LDFLAGS="$LDFLAGS"
15 for d in $RPATH_CANDIDATE_DIRS ; do
16 if test $ac_success = yes ; then
17 ac_remaining_dirs="$ac_remaining_dirs $d"
19 LDFLAGS="$RPATHFLAG$d $LDFLAGS"
20 dnl echo LDFLAGS = $LDFLAGS
21 AC_TRY_RUN([int main(int argc, char **argv) { return 0; }],
23 ac_rpath_save_LDFLAGS="$LDFLAGS"
24 AC_MSG_RESULT([adding $RPATHFLAG$d])
26 [ac_remaining_dirs="$ac_remaining_dirs $d"], :)
27 LDFLAGS="$ac_rpath_save_LDFLAGS"
30 RPATH_CANDIDATE_DIRS=$ac_remaining_dirs
32 if test $ac_success = no ; then
38 # AC_LIB_ARGP(ACTION-IF-OK, ACTION-IF-BAD)
39 AC_DEFUN([AC_LIB_ARGP],
40 [ ac_argp_save_LIBS="$LIBS"
41 ac_argp_save_LDFLAGS="$LDFLAGS"
43 # First check if we can link with argp.
44 AC_SEARCH_LIBS(argp_parse, argp,
46 AC_CACHE_CHECK([for working argp],
47 lsh_cv_lib_argp_works,
52 static const struct argp_option
55 { NULL, 0, NULL, 0, NULL, 0 }
64 child_parser(int key, char *arg, struct argp_state *state)
66 struct child_state *input = (struct child_state *) state->input;
71 return ARGP_ERR_UNKNOWN;
80 const struct argp child_argp =
84 NULL, NULL, NULL, NULL, NULL
89 struct child_state child;
94 main_parser(int key, char *arg, struct argp_state *state)
96 struct main_state *input = (struct main_state *) state->input;
101 return ARGP_ERR_UNKNOWN;
103 state->child_inputs[0] = &input->child;
107 input->m = input->child.n;
114 static const struct argp_child
117 { &child_argp, 0, "", 0 },
121 static const struct argp
123 { options, main_parser,
130 int main(int argc, char **argv)
132 struct main_state input = { { 0 }, 0 };
133 char *v[2] = { "foo", NULL };
135 argp_parse(&main_argp, 1, v, 0, NULL, &input);
137 if ( (input.m == 1) && (input.child.n == 1) )
142 ], lsh_cv_lib_argp_works=yes,
143 lsh_cv_lib_argp_works=no,
144 lsh_cv_lib_argp_works=no)])
146 if test x$lsh_cv_lib_argp_works = xyes ; then
150 LIBS="$ac_argp_save_LIBS"
151 LDFLAGS="$ac_argp_save_LDFLAGS"
154 if test x$ac_argp_ok = xyes ; then
155 ifelse([$1],, true, [$1])
157 ifelse([$2],, true, [$2])