ncurses 5.9 - patch 20120421
[ncurses.git] / mk-1st.awk
1 # $Id: mk-1st.awk,v 1.88 2012/02/25 20:22:09 tom Exp $
2 ##############################################################################
3 # Copyright (c) 1998-2011,2012 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" || ShlibVerInfix == "mingw") {
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 == "mingw") {
85                         result = sprintf("%s%s$(ABI_VERSION)%s", prefix, a_name, suffix);
86                 } else if (ShlibVerInfix == "yes") {
87                         result = sprintf("%s%s.$(ABI_VERSION)%s", prefix, a_name, suffix);
88                 } else {
89                         result = sprintf("%s.$(ABI_VERSION)", lib_name_of(a_name));
90                 }
91                 return result;
92         }
93 # see rel_name
94 function rel_name_of(a_name) {
95                 if (ShlibVerInfix == "cygdll") {
96                         result = sprintf("%s%s$(REL_VERSION)%s", "cyg", a_name, suffix);
97                 } else if (ShlibVerInfix == "mingw") {
98                         result = sprintf("%s%s$(REL_VERSION)%s", prefix, a_name, suffix);
99                 } else if (ShlibVerInfix == "yes") {
100                         result = sprintf("%s%s.$(REL_VERSION)%s", prefix, a_name, suffix);
101                 } else {
102                         result = sprintf("%s.$(REL_VERSION)", lib_name_of(a_name));
103                 }
104                 return result;
105         }
106 # see end_name
107 function end_name_of(a_name) {
108                 if ( MODEL != "SHARED" ) {
109                         result = lib_name_of(a_name);
110                 } else if ( DoLinks == "reverse") {
111                         result = lib_name_of(a_name);
112                 } else {
113                         if ( ShlibVer == "rel" ) {
114                                 result = rel_name_of(a_name);
115                         } else if ( ShlibVer == "abi" || ShlibVer == "cygdll" || ShlibVer == "mingw" ) {
116                                 result = abi_name_of(a_name);
117                         } else {
118                                 result = lib_name_of(a_name);
119                         }
120                 }
121                 return result
122         }
123 function symlink(src,dst) {
124                 if ( src != dst ) {
125                         if ( SymLink !~ /.*-f.*/ ) {
126                                 printf "rm -f %s; ", dst
127                         }
128                         printf "$(LN_S) %s %s; ", src, dst
129                 }
130         }
131 function rmlink(directory, dst) {
132                 printf "\t-rm -f %s/%s\n", directory, dst
133         }
134 function removelinks(directory) {
135                 rmlink(directory, end_name);
136                 if ( DoLinks == "reverse" ) {
137                         if ( ShlibVer == "rel" ) {
138                                 rmlink(directory, abi_name);
139                                 rmlink(directory, rel_name);
140                         } else if ( ShlibVer == "abi" ) {
141                                 rmlink(directory, abi_name);
142                         }
143                 } else {
144                         if ( ShlibVer == "rel" ) {
145                                 rmlink(directory, abi_name);
146                                 rmlink(directory, lib_name);
147                         } else if ( ShlibVer == "abi" ) {
148                                 rmlink(directory, lib_name);
149                         }
150                 }
151         }
152 function make_shlib(objs, shlib_list) {
153                 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(%s) $(LDFLAGS)\n", objs, shlib_list
154         }
155 function sharedlinks(directory) {
156                 if ( ShlibVer != "auto" && ShlibVer != "cygdll" && ShlibVer != "mingw" ) {
157                         printf "\tcd %s && (", directory
158                         if ( DoLinks == "reverse" ) {
159                                 if ( ShlibVer == "rel" ) {
160                                         symlink(lib_name, abi_name);
161                                         symlink(abi_name, rel_name);
162                                 } else if ( ShlibVer == "abi" ) {
163                                         symlink(lib_name, abi_name);
164                                 }
165                         } else {
166                                 if ( ShlibVer == "rel" ) {
167                                         symlink(rel_name, abi_name);
168                                         symlink(abi_name, lib_name);
169                                 } else if ( ShlibVer == "abi" ) {
170                                         symlink(abi_name, lib_name);
171                                 }
172                         }
173                         printf ")\n"
174                 }
175         }
176 # termlib may be named explicitly via "--with-termlib=XXX", which overrides
177 # any suffix.  Temporarily override "suffix" to account for this.
178 function termlib_end_of() {
179         termlib_save_suffix = suffix;
180         suffix = TermlibSuffix;
181         termlib_temp_result = end_name_of(TermlibRoot);
182         suffix = termlib_save_suffix;
183         return termlib_temp_result;
184 }
185 function shlib_build(directory) {
186                 dst_libs = sprintf("%s/%s", directory, end_name);
187                 printf "%s : \\\n", dst_libs
188                 printf "\t\t%s \\\n", directory
189                 if (subset == "ticlib" && driver == "yes" ) {
190                         base = name;
191                         sub(/^tic/, "ncurses", base); # workaround for "w"
192                         printf "\t\t%s/%s \\\n", directory, end_name_of(base);
193                 }
194                 if (subset ~ /^base/ || subset == "ticlib" ) {
195                         save_suffix = suffix
196                         sub(/^[^.]\./,".",suffix)
197                         if (directory != "../lib") {
198                                 printf "\t\t%s/%s \\\n", "../lib", termlib_end_of();
199                         }
200                         printf "\t\t%s/%s \\\n", directory, termlib_end_of();
201                         suffix = save_suffix
202                 }
203                 printf "\t\t$(%s_OBJS)\n", OBJS
204                 printf "\t@echo linking $@\n"
205                 if ( is_ticlib() ) {
206                         make_shlib(OBJS, "TICS_LIST")
207                 } else if ( is_termlib() ) {
208                         make_shlib(OBJS, "TINFO_LIST")
209                 } else {
210                         make_shlib(OBJS, "SHLIB_LIST")
211                 }
212                 sharedlinks(directory)
213         }
214 function shlib_install(directory) {
215                 src_lib1 = sprintf("../lib/%s", end_name);
216                 dst_lib1 = sprintf("%s/%s", directory, end_name);
217                 printf "%s : \\\n", dst_lib1
218                 printf "\t\t%s \\\n", directory
219                 printf "\t\t%s\n", src_lib1
220                 printf "\t@echo installing $@\n"
221                 printf "\t$(INSTALL_LIB) %s %s\n", src_lib1, dst_lib1;
222                 sharedlinks(directory)
223         }
224 function install_dll(directory,filename) {
225                 src_name = sprintf("../lib/%s", filename);
226                 dst_name = sprintf("$(DESTDIR)%s/%s", directory, filename);
227                 printf "\t@echo installing %s as %s\n", src_name, dst_name
228                 if ( directory == "$(bindir)" ) {
229                         program = "$(INSTALL) -m 755";
230                 } else {
231                         program = "$(INSTALL_LIB)";
232                 }
233                 printf "\t%s %s %s\n", program, src_name, dst_name
234         }
235 BEGIN   {
236                 found = 0
237                 using = 0
238         }
239         /^@/ {
240                 using = 0
241                 if (subset == "none") {
242                         using = 1
243                 } else if (index(subset,$2) > 0) {
244                         if (using == 0) {
245                                 if (found == 0) {
246                                         print  ""
247                                         printf "# generated by mk-1st.awk (subset=%s)\n", subset
248                                         printf "#  name:          %s\n", name 
249                                         printf "#  traces:        %s\n", traces 
250                                         printf "#  MODEL:         %s\n", MODEL 
251                                         printf "#  model:         %s\n", model 
252                                         printf "#  prefix:        %s\n", prefix 
253                                         printf "#  suffix:        %s\n", suffix 
254                                         printf "#  subset:        %s\n", subset 
255                                         printf "#  driver:        %s\n", driver 
256                                         printf "#  ShlibVer:      %s\n", ShlibVer 
257                                         printf "#  ShlibVerInfix: %s\n", ShlibVerInfix 
258                                         printf "#  SymLink:       %s\n", SymLink 
259                                         printf "#  TermlibRoot:   %s\n", TermlibRoot 
260                                         printf "#  TermlibSuffix: %s\n", TermlibSuffix 
261                                         printf "#  ReLink:        %s\n", ReLink 
262                                         printf "#  DoLinks:       %s\n", DoLinks 
263                                         printf "#  rmSoLocs:      %s\n", rmSoLocs 
264                                         printf "#  ldconfig:      %s\n", ldconfig 
265                                         printf "#  overwrite:     %s\n", overwrite 
266                                         printf "#  depend:        %s\n", depend 
267                                         printf "#  host:          %s\n", host 
268                                         print  ""
269                                 }
270                                 using = 1
271                         }
272                         if ( is_ticlib() ) {
273                                 OBJS  = MODEL "_P"
274                         } else if ( is_termlib() ) {
275                                 OBJS  = MODEL "_T"
276                         } else {
277                                 OBJS  = MODEL
278                         }
279                 }
280         }
281         /^[@#]/ {
282                 next
283         }
284         $1 ~ /trace/ {
285                 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
286                         next
287         }
288         {
289                 if (using \
290                  && ( $1 != "link_test" ) \
291                  && ( $2 == "lib" \
292                    || $2 == "progs" \
293                    || $2 == "c++" \
294                    || $2 == "tack" ))
295                 {
296                         if ( found == 0 )
297                         {
298                                 printf "%s_OBJS =", OBJS
299                                 if ( $2 == "lib" )
300                                         found = 1
301                                 else
302                                         found = 2
303                         }
304                         printf " \\\n\t../%s/%s$o", model, $1
305                 }
306         }
307 END     {
308                 print  ""
309                 if ( found != 0 )
310                 {
311                         printf "\n$(%s_OBJS) : %s\n", OBJS, depend
312                 }
313                 if ( found == 1 )
314                 {
315                         print  ""
316                         lib_name = lib_name_of(name);
317                         if ( MODEL == "SHARED" )
318                         {
319                                 abi_name = abi_name_of(name);
320                                 rel_name = rel_name_of(name);
321                                 imp_name = imp_name_of(name);
322                                 end_name = end_name_of(name);
323
324                                 shlib_build("../lib")
325
326                                 print  ""
327                                 print  "install \\"
328                                 print  "install.libs \\"
329
330                                 if ( ShlibVer == "cygdll" || ShlibVer == "mingw") {
331
332                                         dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
333                                         printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs
334                                         install_dll("$(bindir)",end_name);
335                                         install_dll("$(libdir)",imp_name);
336
337                                 } else {
338
339                                         lib_dir = "$(DESTDIR)$(libdir)";
340                                         printf "install.%s :: %s/%s\n", name, lib_dir, end_name
341                                         print ""
342                                         if ( ReLink == "yes" ) {
343                                                 shlib_build(lib_dir)
344                                         } else {
345                                                 shlib_install(lib_dir)
346                                         }
347                                 }
348
349                                 if ( overwrite == "yes" && name == "ncurses" )
350                                 {
351                                         if ( ShlibVer == "cygdll" || ShlibVer == "mingw") {
352                                                 ovr_name = sprintf("libcurses%s.a", suffix)
353                                                 printf "\t@echo linking %s to %s\n", imp_name, ovr_name
354                                                 printf "\tcd $(DESTDIR)$(libdir) && ("
355                                                 symlink(imp_name, ovr_name)
356                                                 printf ")\n"
357                                         } else {
358                                                 ovr_name = sprintf("libcurses%s", suffix)
359                                                 printf "\t@echo linking %s to %s\n", end_name, ovr_name
360                                                 printf "\tcd $(DESTDIR)$(libdir) && ("
361                                                 symlink(end_name, ovr_name)
362                                                 printf ")\n"
363                                         }
364                                 }
365                                 if ( ldconfig != "" && ldconfig != ":" ) {
366                                         printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
367                                 }
368                                 print  ""
369                                 print  "uninstall \\"
370                                 print  "uninstall.libs \\"
371                                 printf "uninstall.%s ::\n", name
372                                 if ( ShlibVer == "cygdll" || ShlibVer == "mingw") {
373
374                                         printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
375                                         printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
376
377                                         printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
378                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
379
380                                 } else {
381                                         printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
382                                         removelinks("$(DESTDIR)$(libdir)")
383                                         if ( overwrite == "yes" && name == "ncurses" )
384                                         {
385                                                 ovr_name = sprintf("libcurses%s", suffix)
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