Commit 59d04065 59d04065ca15481321ac59e1d6c2a022c3e09318 by Sergey Poznyakoff

Added --info option (prints and tests the values of compilation

options). Improved help output.
1 parent c80b10de
...@@ -22,23 +22,30 @@ ...@@ -22,23 +22,30 @@
22 #include <mailutils/argp.h> 22 #include <mailutils/argp.h>
23 23
24 const char *argp_program_version = "mailutils-config (" PACKAGE_STRING ")"; 24 const char *argp_program_version = "mailutils-config (" PACKAGE_STRING ")";
25 static char doc[] = "GNU mailutils-config"; 25 static char doc[] = "GNU mailutils-config -- Display compiler and loader options needed for building a program with mailutils";
26 static char args_doc[] = "[arg...]"; 26 static char args_doc[] = "[arg...]";
27 27
28 static struct argp_option options[] = { 28 static struct argp_option options[] = {
29 {"link", 'l', NULL, 0, "print libraries to link with", 1}, 29 {"compile", 'c', NULL, 0, "print C compiler flags to compile with", 0},
30 {NULL, 0, NULL, 0, 30 {"link", 'l', NULL, 0,
31 "Up to two args can be given. Each arg is " 31 "print libraries to link with. Up to two args can be given. Arguments are: "
32 "a string \"auth\" or \"guile\"." 32 "auth, to display libraries needed for linking against libmuauth, and "
33 , 2}, 33 "guile, to display libraries needed for linking against libmu_scm. "
34 {"compile", 'c', NULL, 0, "print C compiler flags to compile with", 3}, 34 "Both can be given simultaneously", 0},
35 {"info", 'i', NULL, 0,
36 "print a list of compilation options used to build mailutils. If arguments "
37 "are given, they are interpreted as a list of compilation options to check "
38 "for. In this case the program prints those options from this list that "
39 "have been defined. It exits with zero status if all of the "
40 "specified options are defined. Otherwise, the exit status is 1.", 0},
35 {0, 0, 0, 0} 41 {0, 0, 0, 0}
36 }; 42 };
37 43
38 enum config_mode { 44 enum config_mode {
39 MODE_VOID, 45 MODE_VOID,
40 MODE_COMPILE, 46 MODE_COMPILE,
41 MODE_LINK 47 MODE_LINK,
48 MODE_INFO
42 }; 49 };
43 50
44 enum config_mode mode; 51 enum config_mode mode;
...@@ -56,6 +63,10 @@ parse_opt (int key, char *arg, struct argp_state *state) ...@@ -56,6 +63,10 @@ parse_opt (int key, char *arg, struct argp_state *state)
56 mode = MODE_COMPILE; 63 mode = MODE_COMPILE;
57 break; 64 break;
58 65
66 case 'i':
67 mode = MODE_INFO;
68 break;
69
59 default: 70 default:
60 return ARGP_ERR_UNKNOWN; 71 return ARGP_ERR_UNKNOWN;
61 } 72 }
...@@ -132,6 +143,7 @@ main (int argc, char **argv) ...@@ -132,6 +143,7 @@ main (int argc, char **argv)
132 } 143 }
133 } 144 }
134 145
146 /* Sort the entires by their level. */
135 for (j = 0; j < n; j++) 147 for (j = 0; j < n; j++)
136 { 148 {
137 int i; 149 int i;
...@@ -157,6 +169,26 @@ main (int argc, char **argv) ...@@ -157,6 +169,26 @@ main (int argc, char **argv)
157 break; 169 break;
158 printf ("%s\n", COMPILE_FLAGS); 170 printf ("%s\n", COMPILE_FLAGS);
159 return 0; 171 return 0;
172
173 case MODE_INFO:
174 if (argc == 0)
175 mu_print_options ();
176 else
177 {
178 int i, found = 0;
179
180 for (i = 0; i < argc; i++)
181 {
182 const char *val = mu_check_option (argv[i]);
183 if (val)
184 {
185 found++;
186 printf ("%s\n", val);
187 }
188 }
189 return found == argc ? 0 : 1;
190 }
191 return 0;
160 } 192 }
161 193
162 argp_help (&argp, stdout, ARGP_HELP_USAGE, 194 argp_help (&argp, stdout, ARGP_HELP_USAGE,
......