ncurses 5.9 - patch 20120121
[ncurses.git] / mk-1st.awk
1 # $Id: mk-1st.awk,v 1.87 2011/12/17 20:27:27 tom Exp $
2 ##############################################################################
3 # Copyright (c) 1998-2010,2011 Free Software Foundation, Inc.                #
4 #                                                                            #
5 # Permission is hereby granted, free of charge, to any person obtaining a    #
6 # copy of this software and associated documentation files (the "Software"), #
7 # to deal in the Software without restriction, including without limitation  #
8 # the rights to use, copy, modify, merge, publish, distribute, distribute    #
9 # with modifications, sublicense, and/or sell copies of the Software, and to #
10 # permit persons to whom the Software is furnished to do so, subject to the  #
11 # following conditions:                                                      #
12 #                                                                            #
13 # The above copyright notice and this permission notice shall be included in #
14 # all copies or substantial portions of the Software.                        #
15 #                                                                            #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   #
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    #
19 # THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      #
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING    #
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER        #
22 # DEALINGS IN THE SOFTWARE.                                                  #
23 #                                                                            #
24 # Except as contained in this notice, the name(s) of the above copyright     #
25 # holders shall not be used in advertising or otherwise to promote the sale, #
26 # use or other dealings in this Software without prior written               #
27 # authorization.                                                             #
28 ##############################################################################
29 #
30 # Author: Thomas E. Dickey
31 #
32 # Generate list of objects for a given model library
33 # Variables:
34 #       name              (library name, e.g., "ncurses", "panel", "forms", "menus")
35 #       traces            ("all" or "DEBUG", to control whether tracing is compiled in)
36 #       MODEL             (e.g., "DEBUG", uppercase; toupper is not portable)
37 #       model             (directory into which we compile, e.g., "obj")
38 #       prefix            (e.g., "lib", for Unix-style libraries)
39 #       suffix            (e.g., "_g.a", for debug libraries)
40 #       subset            ("none", "base", "base+ext_funcs" or "termlib", etc.)
41 #       driver            ("yes" or "no", depends on --enable-term-driver)
42 #       ShlibVer          ("rel", "abi" or "auto", to augment DoLinks variable)
43 #       ShlibVerInfix ("yes" or "no", determines location of version #)
44 #       SymLink           ("ln -s", etc)
45 #       TermlibRoot       ("tinfo" or other root for libterm.so)
46 #       TermlibSuffix (".so" or other suffix for libterm.so)
47 #       ReLink            ("yes", or "no", flag to rebuild shared libs on install)
48 #       DoLinks           ("yes", "reverse" or "no", flag to add symbolic links)
49 #       rmSoLocs          ("yes" or "no", flag to add extra clean target)
50 #       ldconfig          (path for this tool, if used)
51 #       overwrite         ("yes" or "no", flag to add link to libcurses.a
52 #       depend            (optional dependencies for all objects, e.g, ncurses_cfg.h)
53 #       host              (cross-compile host, if any)
54 #       libtool_version (libtool "-version-info" or "-version-number")
55 #
56 # Notes:
57 #       CLIXs nawk does not like underscores in command-line variable names.
58 #       Mixed-case variable names are ok.
59 #       HP/UX requires shared libraries to have executable permissions.
60 #
61 function is_ticlib() {
62                 return ( subset ~ /^ticlib$/ );
63         }
64 function is_termlib() {
65                 return ( subset ~ /^(ticlib\+)?termlib((\+[^+ ]+)*\+[a-z_]+_tinfo)?$/ );
66         }
67 # see lib_name
68 function lib_name_of(a_name) {
69                 return sprintf("%s%s%s", prefix, a_name, suffix)
70         }
71 # see imp_name
72 function imp_name_of(a_name) {
73                 if (ShlibVerInfix == "cygdll") {
74                         result = sprintf("%s%s%s.a", prefix, a_name, suffix);
75                 } else {
76                         result = "";
77                 }
78                 return result;
79         }
80 # see abi_name
81 function abi_name_of(a_name) {
82                 if (ShlibVerInfix == "cygdll") {
83                         result = sprintf("%s%s$(ABI_VERSION)%s", "cyg", a_name, suffix);
84                 } else if (ShlibVerInfix == "yes") {
85                         result = sprintf("%s%s.$(ABI_VERSION)%s", prefix, a_name, suffix);
86                 } else {
87                         result = sprintf("%s.$(ABI_VERSION)", lib_name_of(a_name));
88                 }
89                 return result;
90         }
91 # see rel_name
92 function rel_name_of(a_name) {
93                 if (ShlibVerInfix == "cygdll") {
94                         result = sprintf("%s%s$(REL_VERSION)%s", "cyg", a_name, suffix);
95                 } else if (ShlibVerInfix == "yes") {
96                         result = sprintf("%s%s.$(REL_VERSION)%s", prefix, a_name, suffix);
97                 } else {
98                         result = sprintf("%s.$(REL_VERSION)", lib_name_of(a_name));
99                 }
100                 return result;
101         }
102 # see end_name
103 function end_name_of(a_name) {
104                 if ( MODEL != "SHARED" ) {
105                         result = lib_name_of(a_name);
106                 } else if ( DoLinks == "reverse") {
107                         result = lib_name_of(a_name);
108                 } else {
109                         if ( ShlibVer == "rel" ) {
110                                 result = rel_name_of(a_name);
111                         } else if ( ShlibVer == "abi" || ShlibVer == "cygdll" ) {
112                                 result = abi_name_of(a_name);
113                         } else {
114                                 result = lib_name_of(a_name);
115                         }
116                 }
117                 return result
118         }
119 function symlink(src,dst) {
120                 if ( src != dst ) {
121                         if ( SymLink !~ /.*-f.*/ ) {
122                                 printf "rm -f %s; ", dst
123                         }
124                         printf "$(LN_S) %s %s; ", src, dst
125                 }
126         }
127 function rmlink(directory, dst) {
128                 printf "\t-rm -f %s/%s\n", directory, dst
129         }
130 function removelinks(directory) {
131                 rmlink(directory, end_name);
132                 if ( DoLinks == "reverse" ) {
133                         if ( ShlibVer == "rel" ) {
134                                 rmlink(directory, abi_name);
135                                 rmlink(directory, rel_name);
136                         } else if ( ShlibVer == "abi" ) {
137                                 rmlink(directory, abi_name);
138                         }
139                 } else {
140                         if ( ShlibVer == "rel" ) {
141                                 rmlink(directory, abi_name);
142                                 rmlink(directory, lib_name);
143                         } else if ( ShlibVer == "abi" ) {
144                                 rmlink(directory, lib_name);
145                         }
146                 }
147         }
148 function make_shlib(objs, shlib_list) {
149                 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(%s) $(LDFLAGS)\n", objs, shlib_list
150         }
151 function sharedlinks(directory) {
152                 if ( ShlibVer != "auto" && ShlibVer != "cygdll" ) {
153                         printf "\tcd %s && (", directory
154                         if ( DoLinks == "reverse" ) {
155                                 if ( ShlibVer == "rel" ) {
156                                         symlink(lib_name, abi_name);
157                                         symlink(abi_name, rel_name);
158                                 } else if ( ShlibVer == "abi" ) {
159                                         symlink(lib_name, abi_name);
160                                 }
161                         } else {
162                                 if ( ShlibVer == "rel" ) {
163                                         symlink(rel_name, abi_name);
164                                         symlink(abi_name, lib_name);
165                                 } else if ( ShlibVer == "abi" ) {
166                                         symlink(abi_name, lib_name);
167                                 }
168                         }
169                         printf ")\n"
170                 }
171         }
172 # termlib may be named explicitly via "--with-termlib=XXX", which overrides
173 # any suffix.  Temporarily override "suffix" to account for this.
174 function termlib_end_of() {
175         termlib_save_suffix = suffix;
176         suffix = TermlibSuffix;
177         termlib_temp_result = end_name_of(TermlibRoot);
178         suffix = termlib_save_suffix;
179         return termlib_temp_result;
180 }
181 function shlib_build(directory) {
182                 dst_libs = sprintf("%s/%s", directory, end_name);
183                 printf "%s : \\\n", dst_libs
184                 printf "\t\t%s \\\n", directory
185                 if (subset == "ticlib" && driver == "yes" ) {
186                         base = name;
187                         sub(/^tic/, "ncurses", base); # workaround for "w"
188                         printf "\t\t%s/%s \\\n", directory, end_name_of(base);
189                 }
190                 if (subset ~ /^base/ || subset == "ticlib" ) {
191                         save_suffix = suffix
192                         sub(/^[^.]\./,".",suffix)
193                         if (directory != "../lib") {
194                                 printf "\t\t%s/%s \\\n", "../lib", termlib_end_of();
195                         }
196                         printf "\t\t%s/%s \\\n", directory, termlib_end_of();
197                         suffix = save_suffix
198                 }
199                 printf "\t\t$(%s_OBJS)\n", OBJS
200                 printf "\t@echo linking $@\n"
201                 if ( is_ticlib() ) {
202                         make_shlib(OBJS, "TICS_LIST")
203                 } else if ( is_termlib() ) {
204                         make_shlib(OBJS, "TINFO_LIST")
205                 } else {
206                         make_shlib(OBJS, "SHLIB_LIST")
207                 }
208                 sharedlinks(directory)
209         }
210 function shlib_install(directory) {
211                 src_lib1 = sprintf("../lib/%s", end_name);
212                 dst_lib1 = sprintf("%s/%s", directory, end_name);
213                 printf "%s : \\\n", dst_lib1
214                 printf "\t\t%s \\\n", directory
215                 printf "\t\t%s\n", src_lib1
216                 printf "\t@echo installing $@\n"
217                 printf "\t$(INSTALL_LIB) %s %s\n", src_lib1, dst_lib1;
218                 sharedlinks(directory)
219         }
220 function install_dll(directory,filename) {
221                 src_name = sprintf("../lib/%s", filename);
222                 dst_name = sprintf("$(DESTDIR)%s/%s", directory, filename);
223                 printf "\t@echo installing %s as %s\n", src_name, dst_name
224                 if ( directory == "$(bindir)" ) {
225                         program = "$(INSTALL) -m 755";
226                 } else {
227                         program = "$(INSTALL_LIB)";
228                 }
229                 printf "\t%s %s %s\n", program, src_name, dst_name
230         }
231 BEGIN   {
232                 found = 0
233                 using = 0
234         }
235         /^@/ {
236                 using = 0
237                 if (subset == "none") {
238                         using = 1
239                 } else if (index(subset,$2) > 0) {
240                         if (using == 0) {
241                                 if (found == 0) {
242                                         print  ""
243                                         printf "# generated by mk-1st.awk (subset=%s)\n", subset
244                                         printf "#  name:          %s\n", name 
245                                         printf "#  traces:        %s\n", traces 
246                                         printf "#  MODEL:         %s\n", MODEL 
247                                         printf "#  model:         %s\n", model 
248                                         printf "#  prefix:        %s\n", prefix 
249                                         printf "#  suffix:        %s\n", suffix 
250                                         printf "#  subset:        %s\n", subset 
251                                         printf "#  driver:        %s\n", driver 
252                                         printf "#  ShlibVer:      %s\n", ShlibVer 
253                                         printf "#  ShlibVerInfix: %s\n", ShlibVerInfix 
254                                         printf "#  SymLink:       %s\n", SymLink 
255                                         printf "#  TermlibRoot:   %s\n", TermlibRoot 
256                                         printf "#  TermlibSuffix: %s\n", TermlibSuffix 
257                                         printf "#  ReLink:        %s\n", ReLink 
258                                         printf "#  DoLinks:       %s\n", DoLinks 
259                                         printf "#  rmSoLocs:      %s\n", rmSoLocs 
260                                         printf "#  ldconfig:      %s\n", ldconfig 
261                                         printf "#  overwrite:     %s\n", overwrite 
262                                         printf "#  depend:        %s\n", depend 
263                                         printf "#  host:          %s\n", host 
264                                         print  ""
265                                 }
266                                 using = 1
267                         }
268                         if ( is_ticlib() ) {
269                                 OBJS  = MODEL "_P"
270                         } else if ( is_termlib() ) {
271                                 OBJS  = MODEL "_T"
272                         } else {
273                                 OBJS  = MODEL
274                         }
275                 }
276         }
277         /^[@#]/ {
278                 next
279         }
280         $1 ~ /trace/ {
281                 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
282                         next
283         }
284         {
285                 if (using \
286                  && ( $1 != "link_test" ) \
287                  && ( $2 == "lib" \
288                    || $2 == "progs" \
289                    || $2 == "c++" \
290                    || $2 == "tack" ))
291                 {
292                         if ( found == 0 )
293                         {
294                                 printf "%s_OBJS =", OBJS
295                                 if ( $2 == "lib" )
296                                         found = 1
297                                 else
298                                         found = 2
299                         }
300                         printf " \\\n\t../%s/%s$o", model, $1
301                 }
302         }
303 END     {
304                 print  ""
305                 if ( found != 0 )
306                 {
307                         printf "\n$(%s_OBJS) : %s\n", OBJS, depend
308                 }
309                 if ( found == 1 )
310                 {
311                         print  ""
312                         lib_name = lib_name_of(name);
313                         if ( MODEL == "SHARED" )
314                         {
315                                 abi_name = abi_name_of(name);
316                                 rel_name = rel_name_of(name);
317                                 imp_name = imp_name_of(name);
318                                 end_name = end_name_of(name);
319
320                                 shlib_build("../lib")
321
322                                 print  ""
323                                 print  "install \\"
324                                 print  "install.libs \\"
325
326                                 if ( ShlibVer == "cygdll" ) {
327
328                                         dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
329                                         printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs
330                                         install_dll("$(bindir)",end_name);
331                                         install_dll("$(libdir)",imp_name);
332
333                                 } else {
334
335                                         lib_dir = "$(DESTDIR)$(libdir)";
336                                         printf "install.%s :: %s/%s\n", name, lib_dir, end_name
337                                         print ""
338                                         if ( ReLink == "yes" ) {
339                                                 shlib_build(lib_dir)
340                                         } else {
341                                                 shlib_install(lib_dir)
342                                         }
343                                 }
344
345                                 if ( overwrite == "yes" && name == "ncurses" )
346                                 {
347                                         if ( ShlibVer == "cygdll" ) {
348                                                 ovr_name = sprintf("libcurses%s.a", suffix)
349                                                 printf "\t@echo linking %s to %s\n", imp_name, ovr_name
350                                                 printf "\tcd $(DESTDIR)$(libdir) && ("
351                                                 symlink(imp_name, ovr_name)
352                                                 printf ")\n"
353                                         } else {
354                                                 ovr_name = sprintf("libcurses%s", suffix)
355                                                 printf "\t@echo linking %s to %s\n", end_name, ovr_name
356                                                 printf "\tcd $(DESTDIR)$(libdir) && ("
357                                                 symlink(end_name, ovr_name)
358                                                 printf ")\n"
359                                         }
360                                 }
361                                 if ( ldconfig != "" && ldconfig != ":" ) {
362                                         printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
363                                 }
364                                 print  ""
365                                 print  "uninstall \\"
366                                 print  "uninstall.libs \\"
367                                 printf "uninstall.%s ::\n", name
368                                 if ( ShlibVer == "cygdll" ) {
369
370                                         printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
371                                         printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
372
373                                         printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
374                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
375
376                                 } else {
377                                         printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
378                                         removelinks("$(DESTDIR)$(libdir)")
379                                         if ( overwrite == "yes" && name == "ncurses" )
380                                         {
381                                                 if ( ShlibVer == "cygdll" ) {
382                                                         ovr_name = sprintf("libcurses%s.a", suffix)
383                                                 } else {
384                                                         ovr_name = sprintf("libcurses%s", suffix)
385                                                 }
386                                                 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
387                                         }
388                                 }
389                                 if ( rmSoLocs == "yes" ) {
390                                         print  ""
391                                         print  "mostlyclean \\"
392                                         print  "clean ::"
393                                         printf "\t-@rm -f so_locations\n"
394                                 }
395                         }
396                         else if ( MODEL == "LIBTOOL" )
397                         {
398                                 if ( $2 == "c++" ) {
399                                         compile="CXX"
400                                 } else {
401                                         compile="CC"
402                                 }
403                                 end_name = lib_name;
404                                 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
405                                 if ( is_ticlib() ) {
406                                         which_list = "TICS_LIST";
407                                 } else if ( is_termlib() ) {
408                                         which_list = "TINFO_LIST";
409                                 } else {
410                                         which_list = "SHLIB_LIST";
411                                 }
412                                 printf "\tcd ../lib && $(LIBTOOL_LINK) $(%s) -o %s $(%s_OBJS:$o=.lo) -rpath $(DESTDIR)$(libdir) %s $(NCURSES_MAJOR):$(NCURSES_MINOR) $(LT_UNDEF) $(%s) $(LDFLAGS)\n", compile, lib_name, OBJS, libtool_version, which_list
413                                 print  ""
414                                 print  "install \\"
415                                 print  "install.libs \\"
416                                 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
417                                 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
418                                 printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
419                                 print  ""
420                                 print  "uninstall \\"
421                                 print  "uninstall.libs \\"
422                                 printf "uninstall.%s ::\n", name
423                                 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
424                                 printf "\t-@$(LIBTOOL_UNINSTALL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
425                         }
426                         else
427                         {
428                                 end_name = lib_name;
429                                 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
430                                 printf "\t$(AR) $(ARFLAGS) $@ $?\n"
431                                 printf "\t$(RANLIB) $@\n"
432                                 if ( host == "vxworks" )
433                                 {
434                                         printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
435                                 }
436                                 print  ""
437                                 print  "install \\"
438                                 print  "install.libs \\"
439                                 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
440                                 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
441                                 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
442                                 if ( overwrite == "yes" && lib_name == "libncurses.a" )
443                                 {
444                                         printf "\t@echo linking libcurses.a to libncurses.a\n"
445                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
446                                         printf "\t(cd $(DESTDIR)$(libdir) && "
447                                         symlink("libncurses.a", "libcurses.a")
448                                         printf ")\n"
449                                 }
450                                 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
451                                 if ( host == "vxworks" )
452                                 {
453                                         printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name, name
454                                         printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name, name
455                                 }
456                                 print  ""
457                                 print  "uninstall \\"
458                                 print  "uninstall.libs \\"
459                                 printf "uninstall.%s ::\n", name
460                                 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
461                                 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
462                                 if ( overwrite == "yes" && lib_name == "libncurses.a" )
463                                 {
464                                         printf "\t@echo linking libcurses.a to libncurses.a\n"
465                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
466                                 }
467                                 if ( host == "vxworks" )
468                                 {
469                                         printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
470                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
471                                 }
472                         }
473                         print ""
474                         print "clean ::"
475                         removelinks("../lib");
476                         print ""
477                         print "mostlyclean::"
478                         printf "\t-rm -f $(%s_OBJS)\n", OBJS
479                         if ( MODEL == "LIBTOOL" ) {
480                                 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
481                         }
482                 }
483                 else if ( found == 2 )
484                 {
485                         print ""
486                         print "mostlyclean::"
487                         printf "\t-rm -f $(%s_OBJS)\n", OBJS
488                         if ( MODEL == "LIBTOOL" ) {
489                                 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
490                         }
491                         print ""
492                         print "clean ::"
493                         printf "\t-rm -f $(%s_OBJS)\n", OBJS
494                         if ( MODEL == "LIBTOOL" ) {
495                                 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
496                         }
497                 }
498         }
499 # vile:ts=4 sw=4