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