Commit d52f07da d52f07da8f87d6e86541f9a373be5497dfdc7885 by Sergey Poznyakoff

New file. A utility

program that prints compiler and loader flags
necessary to build a program using mailutils
libraries.
1 parent ee9fcbe9
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21 #include <mailutils/mailutils.h>
22 #include <mailutils/argp.h>
23
24 const char *argp_program_version = "mailutils-config (" PACKAGE_STRING ")";
25 static char doc[] = "GNU mailutils-config";
26 static char args_doc[] = "[arg...]";
27
28 static struct argp_option options[] = {
29 {"link", 'l', NULL, 0, "print libraries to link with", 1},
30 {NULL, 0, NULL, 0,
31 "Up to two args can be given. Each arg is "
32 "a string \"auth\" or \"guile\"."
33 , 2},
34 {"compile", 'c', NULL, 0, "print C compiler flags to compile with", 3},
35 {0, 0, 0, 0}
36 };
37
38 enum config_mode {
39 MODE_VOID,
40 MODE_COMPILE,
41 MODE_LINK
42 };
43
44 enum config_mode mode;
45
46 static error_t
47 parse_opt (int key, char *arg, struct argp_state *state)
48 {
49 switch (key)
50 {
51 case 'l':
52 mode = MODE_LINK;
53 break;
54
55 case 'c':
56 mode = MODE_COMPILE;
57 break;
58
59 default:
60 return ARGP_ERR_UNKNOWN;
61 }
62 return 0;
63 }
64
65 static struct argp argp = {
66 options,
67 parse_opt,
68 args_doc,
69 doc,
70 NULL,
71 NULL, NULL
72 };
73
74 static const char *argp_capa[] = {
75 "common",
76 "license",
77 NULL
78 };
79
80 int
81 main (int argc, char **argv)
82 {
83 int index;
84
85 if (mu_argp_parse (&argp, &argc, &argv, 0, argp_capa, &index, NULL))
86 {
87 argp_help (&argp, stdout, ARGP_HELP_SEE,
88 program_invocation_short_name);
89 return 1;
90 }
91
92 argc -= index;
93 argv += index;
94
95 switch (mode)
96 {
97 case MODE_VOID:
98 break;
99
100 case MODE_LINK:
101 {
102 int n = 0, j;
103 struct entry {
104 int level;
105 char *ptr;
106 } entry[4];
107
108 entry[n].level = 1;
109 asprintf (&entry[n].ptr, " %s -lmailbox", LINK_FLAGS);
110 n++;
111
112 for (; n < sizeof(entry)/sizeof(entry[0]) && argc > 0;
113 argc--, argv++, n++)
114 {
115 if (strcmp (argv[0], "auth") == 0)
116 {
117 entry[n].level = 2;
118 asprintf (&entry[n].ptr, " -lmuauth %s", AUTHLIBS);
119 }
120 #ifdef WITH_GUILE
121 else if (strcmp (argv[0], "guile") == 0)
122 {
123 entry[n].level = -1;
124 asprintf (&entry[n].ptr, " -lmu_scm %s", GUILE_LIBS);
125 }
126 #endif
127 else
128 {
129 argp_help (&argp, stdout, ARGP_HELP_USAGE,
130 program_invocation_short_name);
131 return 1;
132 }
133 }
134
135 for (j = 0; j < n; j++)
136 {
137 int i;
138
139 for (i = j; i < n; i++)
140 if (entry[j].level > entry[i].level)
141 {
142 struct entry tmp;
143 tmp = entry[i];
144 entry[i] = entry[j];
145 entry[j] = tmp;
146 }
147 }
148
149 for (j = 0; j < n; j++)
150 printf ("%s", entry[j].ptr);
151 printf ("\n");
152 return 0;
153 }
154
155 case MODE_COMPILE:
156 if (argc != 0)
157 break;
158 printf ("%s\n", COMPILE_FLAGS);
159 return 0;
160 }
161
162 argp_help (&argp, stdout, ARGP_HELP_USAGE,
163 program_invocation_short_name);
164 return 0;
165 }
166
167