r23801: The FSF has moved around a lot. This fixes their Mass Ave address.
[tprouty/samba.git] / source3 / script / mkbuildoptions.awk
1 BEGIN {
2         print "/* ";
3         print "   Unix SMB/CIFS implementation.";
4         print "   Build Options for Samba Suite";
5         print "   Copyright (C) Vance Lankhaar <vlankhaar@linux.ca> 2003";
6         print "   Copyright (C) Andrew Bartlett <abartlet@samba.org> 2001";
7         print "   ";
8         print "   This program is free software; you can redistribute it and/or modify";
9         print "   it under the terms of the GNU General Public License as published by";
10         print "   the Free Software Foundation; either version 3 of the License, or";
11         print "   (at your option) any later version.";
12         print "   ";
13         print "   This program is distributed in the hope that it will be useful,";
14         print "   but WITHOUT ANY WARRANTY; without even the implied warranty of";
15         print "   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the";
16         print "   GNU General Public License for more details.";
17         print "   ";
18         print "   You should have received a copy of the GNU General Public License";
19         print "   along with this program; if not, see <http://www.gnu.org/licenses/>";
20         print "*/";
21         print "";
22         print "#include \"includes.h\"";
23         print "#include \"build_env.h\"";
24         print "#include \"dynconfig.h\"";
25         print "";
26         print "static void output(BOOL screen, const char *format, ...) PRINTF_ATTRIBUTE(2,3);";
27         print "void build_options(BOOL screen);";
28         print "";
29         print "";
30         print "/****************************************************************************";
31         print "helper function for build_options";
32         print "****************************************************************************/";
33         print "static void output(BOOL screen, const char *format, ...)";
34         print "{";
35         print "       char *ptr;";
36         print "       va_list ap;";
37         print "       ";
38         print "       va_start(ap, format);";
39         print "       vasprintf(&ptr,format,ap);";
40         print "       va_end(ap);";
41         print "";
42         print "       if (screen) {";
43         print "              d_printf(\"%s\", ptr);";
44         print "       } else {";
45         print "        DEBUG(4,(\"%s\", ptr));";
46         print "       }";
47         print "       ";
48         print "       SAFE_FREE(ptr);";
49         print "}";
50         print "";
51         print "/****************************************************************************";
52         print "options set at build time for the samba suite";
53         print "****************************************************************************/";
54         print "void build_options(BOOL screen)";
55         print "{";
56         print "       if ((DEBUGLEVEL < 4) && (!screen)) {";
57         print "        return;";
58         print "       }";
59         print "";
60         print "#ifdef _BUILD_ENV_H";
61         print "       /* Output information about the build environment */";
62         print "       output(screen,\"Build environment:\\n\");";
63         print "       output(screen,\"   Built by:    %s@%s\\n\",BUILD_ENV_USER,BUILD_ENV_HOST);";
64         print "       output(screen,\"   Built on:    %s\\n\",BUILD_ENV_DATE);";
65         print "";
66         print "       output(screen,\"   Built using: %s\\n\",BUILD_ENV_COMPILER);";
67         print "       output(screen,\"   Build host:  %s\\n\",BUILD_ENV_UNAME);";
68         print "       output(screen,\"   SRCDIR:      %s\\n\",BUILD_ENV_SRCDIR);";
69         print "       output(screen,\"   BUILDDIR:    %s\\n\",BUILD_ENV_BUILDDIR);";
70         print "";
71         print "     ";  
72         print "#endif";
73         print "";
74
75         print "       /* Output various paths to files and directories */";
76         print "       output(screen,\"\\nPaths:\\n\");";
77
78         print "       output(screen,\"   SBINDIR: %s\\n\", dyn_SBINDIR);";
79         print "       output(screen,\"   BINDIR: %s\\n\", dyn_BINDIR);";
80         print "       output(screen,\"   SWATDIR: %s\\n\", dyn_SWATDIR);";
81
82         print "       output(screen,\"   CONFIGFILE: %s\\n\", dyn_CONFIGFILE);";
83         print "       output(screen,\"   LOGFILEBASE: %s\\n\", dyn_LOGFILEBASE);";
84         print "       output(screen,\"   LMHOSTSFILE: %s\\n\",dyn_LMHOSTSFILE);";
85
86         print "       output(screen,\"   LIBDIR: %s\\n\",dyn_LIBDIR);";
87         print "       output(screen,\"   SHLIBEXT: %s\\n\",dyn_SHLIBEXT);";
88
89         print "       output(screen,\"   LOCKDIR: %s\\n\",dyn_LOCKDIR);";
90         print "       output(screen,\"   PIDDIR: %s\\n\", dyn_PIDDIR);";
91
92         print "       output(screen,\"   SMB_PASSWD_FILE: %s\\n\",dyn_SMB_PASSWD_FILE);";
93         print "       output(screen,\"   PRIVATE_DIR: %s\\n\",dyn_PRIVATE_DIR);";
94         print "";
95
96
97 ##################################################
98 # predefine first element of *_ary
99 # predefine *_i (num of elements in *_ary)
100         with_ary[0]="";
101         with_i=0;
102         have_ary[0]="";
103         have_i=0;
104         utmp_ary[0]="";
105         utmp_i=0;
106         misc_ary[0]="";
107         misc_i=0;
108         sys_ary[0]="";
109         sys_i=0;
110         headers_ary[0]="";
111         headers_i=0;
112         in_comment = 0;
113 }
114
115 # capture single line comments
116 /^\/\* (.*?)\*\// {
117         last_comment = $0;
118         next;
119 }
120
121 # end capture multi-line comments
122 /(.*?)\*\// {
123         last_comment = last_comment $0; 
124         in_comment = 0;
125         next;
126 }
127
128 # capture middle lines of multi-line comments
129 in_comment {
130         last_comment = last_comment $0; 
131         next;
132 }
133
134 # begin capture multi-line comments
135 /^\/\* (.*?)/ {
136         last_comment = $0;
137         in_comment = 1;
138         next
139 }
140
141 ##################################################
142 # if we have an #undef and a last_comment, store it
143 /^\#undef/ {
144         split($0,a);
145         comments_ary[a[2]] = last_comment;
146         last_comment = "";
147 }
148
149 ##################################################
150 # for each line, sort into appropriate section
151 # then move on
152
153 /^\#undef WITH/ {
154         with_ary[with_i++] = a[2];
155         # we want (I think) to allow --with to show up in more than one place, so no next
156 }
157
158
159 /^\#undef HAVE_UT_UT_/ || /^\#undef .*UTMP/ {
160         utmp_ary[utmp_i++] = a[2];
161         next;
162 }
163
164 /^\#undef HAVE_SYS_.*?_H$/ {
165         sys_ary[sys_i++] = a[2];
166         next;
167 }
168
169 /^\#undef HAVE_.*?_H$/ {
170         headers_ary[headers_i++] = a[2];
171         next;
172 }
173
174 /^\#undef HAVE_/ {
175         have_ary[have_i++] = a[2];
176         next;
177 }
178
179 /^\#undef/ {
180         misc_ary[misc_i++] = a[2];
181         next;
182 }
183
184
185 ##################################################
186 # simple sort function
187 function sort(ARRAY, ELEMENTS) {
188         for (i = 1; i <= ELEMENTS; ++i) {
189                 for (j = i; (j-1) in ARRAY && (j) in ARRAY && ARRAY[j-1] > ARRAY[j]; --j) {
190                         temp = ARRAY[j];
191                         ARRAY[j] = ARRAY[j-1];
192                         ARRAY[j-1] = temp;
193                 }
194         }
195         return;
196 }    
197
198
199 ##################################################
200 # output code from list of defined
201 # expects: ARRAY     an array of things defined
202 #          ELEMENTS  number of elements in ARRAY
203 #          TITLE     title for section
204 # returns: nothing 
205 function output(ARRAY, ELEMENTS, TITLE) {
206         
207         # add section header
208         print "\n\t/* Show " TITLE " */";
209         print "\toutput(screen, \"\\n " TITLE ":\\n\");\n";
210         
211
212         # sort element using bubble sort (slow, but easy)
213         sort(ARRAY, ELEMENTS);
214
215         # loop through array of defines, outputting code
216         for (i = 0; i < ELEMENTS; i++) {
217                 print "#ifdef " ARRAY[i];
218                 
219                 # I don't know which one to use....
220                 
221                 print "\toutput(screen, \"   " ARRAY[i] "\\n\");";
222                 #printf "\toutput(screen, \"   %s\\n   %s\\n\\n\");\n", comments_ary[ARRAY[i]], ARRAY[i];
223                 #printf "\toutput(screen, \"   %-35s   %s\\n\");\n", ARRAY[i], comments_ary[ARRAY[i]];
224
225                 print "#endif";
226         }
227         return;
228 }
229
230 END {
231         ##################################################
232         # add code to show various options
233         print "/* Output various other options (as gleaned from include/config.h.in) */";
234         output(sys_ary,     sys_i,     "System Headers");
235         output(headers_ary, headers_i, "Headers");
236         output(utmp_ary,    utmp_i,    "UTMP Options");
237         output(have_ary,    have_i,    "HAVE_* Defines");
238         output(with_ary,    with_i,    "--with Options");
239         output(misc_ary,    misc_i,    "Build Options");
240
241         ##################################################
242         # add code to display the various type sizes
243         print "       /* Output the sizes of the various types */";
244         print "       output(screen, \"\\nType sizes:\\n\");";
245         print "       output(screen, \"   sizeof(char):         %lu\\n\",(unsigned long)sizeof(char));";
246         print "       output(screen, \"   sizeof(int):          %lu\\n\",(unsigned long)sizeof(int));";
247         print "       output(screen, \"   sizeof(long):         %lu\\n\",(unsigned long)sizeof(long));";
248         print "#if HAVE_LONGLONG"
249         print "       output(screen, \"   sizeof(long long):    %lu\\n\",(unsigned long)sizeof(long long));";
250         print "#endif"
251         print "       output(screen, \"   sizeof(uint8):        %lu\\n\",(unsigned long)sizeof(uint8));";
252         print "       output(screen, \"   sizeof(uint16):       %lu\\n\",(unsigned long)sizeof(uint16));";
253         print "       output(screen, \"   sizeof(uint32):       %lu\\n\",(unsigned long)sizeof(uint32));";
254         print "       output(screen, \"   sizeof(short):        %lu\\n\",(unsigned long)sizeof(short));";
255         print "       output(screen, \"   sizeof(void*):        %lu\\n\",(unsigned long)sizeof(void*));";
256         print "       output(screen, \"   sizeof(size_t):       %lu\\n\",(unsigned long)sizeof(size_t));";
257         print "       output(screen, \"   sizeof(off_t):        %lu\\n\",(unsigned long)sizeof(off_t));";
258         print "       output(screen, \"   sizeof(ino_t):        %lu\\n\",(unsigned long)sizeof(ino_t));";
259         print "       output(screen, \"   sizeof(dev_t):        %lu\\n\",(unsigned long)sizeof(dev_t));";
260
261         ##################################################
262         # add code to give information about modules
263         print "       output(screen, \"\\nBuiltin modules:\\n\");";
264         print "       output(screen, \"   %s\\n\", STRING_STATIC_MODULES);";
265
266         print "}";
267
268 }
269