ncurses 5.6 - patch 20070311
[ncurses.git] / mk-1st.awk
1 # $Id: mk-1st.awk,v 1.77 2007/03/11 13:37:22 tom Exp $
2 ##############################################################################
3 # Copyright (c) 1998-2006,2007 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 #       ShlibVer          ("rel", "abi" or "auto", to augment DoLinks variable)
42 #       ShlibVerInfix ("yes" or "no", determines location of version #)
43 #   TermlibRoot   ("tinfo" or other root for libterm.so)
44 #       ReLink            ("yes", or "no", flag to rebuild shared libs on install)
45 #       DoLinks           ("yes", "reverse" or "no", flag to add symbolic links)
46 #       rmSoLocs          ("yes" or "no", flag to add extra clean target)
47 #       ldconfig          (path for this tool, if used)
48 #       overwrite         ("yes" or "no", flag to add link to libcurses.a
49 #       depend            (optional dependencies for all objects, e.g, ncurses_cfg.h)
50 #       host              (cross-compile host, if any)
51 #
52 # Notes:
53 #       CLIXs nawk does not like underscores in command-line variable names.
54 #       Mixed-case variable names are ok.
55 #       HP/UX requires shared libraries to have executable permissions.
56 #
57 function is_ticlib() {
58                 return ( subset ~ /^ticlib$/ );
59         }
60 function is_termlib() {
61                 return ( subset ~ /^(ticlib\+)?termlib(\+ext_tinfo)?$/ );
62         }
63 # see lib_name
64 function lib_name_of(a_name) {
65                 return sprintf("%s%s%s", prefix, a_name, suffix)
66         }
67 # see imp_name
68 function imp_name_of(a_name) {
69                 if (ShlibVerInfix == "cygdll") {
70                         result = sprintf("%s%s%s.a", prefix, a_name, suffix);
71                 } else {
72                         result = "";
73                 }
74                 return result;
75         }
76 # see abi_name
77 function abi_name_of(a_name) {
78                 if (ShlibVerInfix == "cygdll") {
79                         result = sprintf("%s%s$(ABI_VERSION)%s", "cyg", a_name, suffix);
80                 } else if (ShlibVerInfix == "yes") {
81                         result = sprintf("%s%s.$(ABI_VERSION)%s", prefix, a_name, suffix);
82                 } else {
83                         result = sprintf("%s.$(ABI_VERSION)", lib_name_of(a_name));
84                 }
85                 return result;
86         }
87 # see rel_name
88 function rel_name_of(a_name) {
89                 if (ShlibVerInfix == "cygdll") {
90                         result = sprintf("%s%s$(REL_VERSION)%s", "cyg", a_name, suffix);
91                 } else if (ShlibVerInfix == "yes") {
92                         result = sprintf("%s%s.$(REL_VERSION)%s", prefix, a_name, suffix);
93                 } else {
94                         result = sprintf("%s.$(REL_VERSION)", lib_name_of(a_name));
95                 }
96                 return result;
97         }
98 # see end_name
99 function end_name_of(a_name) {
100                 if ( MODEL != "SHARED" ) {
101                         result = lib_name_of(a_name);
102                 } else if ( DoLinks == "reverse") {
103                         result = lib_name_of(a_name);
104                 } else {
105                         if ( ShlibVer == "rel" ) {
106                                 result = rel_name_of(a_name);
107                         } else if ( ShlibVer == "abi" || ShlibVer == "cygdll" ) {
108                                 result = abi_name_of(a_name);
109                         } else {
110                                 result = lib_name_of(a_name);
111                         }
112                 }
113                 return result
114         }
115 function symlink(src,dst) {
116                 if ( src != dst ) {
117                         printf "rm -f %s; ", dst
118                         printf "$(LN_S) %s %s; ", src, dst
119                 }
120         }
121 function rmlink(directory, dst) {
122                 printf "\t-rm -f %s/%s\n", directory, dst
123         }
124 function removelinks(directory) {
125                 rmlink(directory, end_name);
126                 if ( DoLinks == "reverse" ) {
127                         if ( ShlibVer == "rel" ) {
128                                 rmlink(directory, abi_name);
129                                 rmlink(directory, rel_name);
130                         } else if ( ShlibVer == "abi" ) {
131                                 rmlink(directory, abi_name);
132                         }
133                 } else {
134                         if ( ShlibVer == "rel" ) {
135                                 rmlink(directory, abi_name);
136                                 rmlink(directory, lib_name);
137                         } else if ( ShlibVer == "abi" ) {
138                                 rmlink(directory, lib_name);
139                         }
140                 }
141         }
142 function make_shlib(objs, shlib_list) {
143                 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(%s) $(LDFLAGS)\n", objs, shlib_list
144         }
145 function sharedlinks(directory) {
146                 if ( ShlibVer != "auto" && ShlibVer != "cygdll" ) {
147                         printf "\tcd %s && (", directory
148                         if ( DoLinks == "reverse" ) {
149                                 if ( ShlibVer == "rel" ) {
150                                         symlink(lib_name, abi_name);
151                                         symlink(abi_name, rel_name);
152                                 } else if ( ShlibVer == "abi" ) {
153                                         symlink(lib_name, abi_name);
154                                 }
155                         } else {
156                                 if ( ShlibVer == "rel" ) {
157                                         symlink(rel_name, abi_name);
158                                         symlink(abi_name, lib_name);
159                                 } else if ( ShlibVer == "abi" ) {
160                                         symlink(abi_name, lib_name);
161                                 }
162                         }
163                         printf ")\n"
164                 }
165         }
166 function shlib_build(directory) {
167                 dst_libs = sprintf("%s/%s", directory, end_name);
168                 printf "%s : \\\n", dst_libs
169                 printf "\t\t%s \\\n", directory
170                 if (subset ~ /^base/ || subset == "ticlib" ) {
171                         save_suffix = suffix
172                         sub(/^[^.]\./,".",suffix)
173                         if (directory != "../lib") {
174                                 printf "\t\t%s/%s \\\n", "../lib", end_name_of(TermlibRoot);
175                         }
176                         printf "\t\t%s/%s \\\n", directory, end_name_of(TermlibRoot);
177                         suffix = save_suffix
178                 }
179                 printf "\t\t$(%s_OBJS)\n", OBJS
180                 printf "\t@echo linking $@\n"
181                 if ( is_ticlib() ) {
182                         make_shlib(OBJS, "TICS_LIST")
183                 } else if ( is_termlib() ) {
184                         make_shlib(OBJS, "TINFO_LIST")
185                 } else {
186                         make_shlib(OBJS, "SHLIB_LIST")
187                 }
188                 sharedlinks(directory)
189         }
190 function shlib_install(directory) {
191                 src_lib1 = sprintf("../lib/%s", end_name);
192                 dst_lib1 = sprintf("%s/%s", directory, end_name);
193                 printf "%s : \\\n", dst_lib1
194                 printf "\t\t%s \\\n", directory
195                 printf "\t\t%s\n", src_lib1
196                 printf "\t@echo installing $@\n"
197                 printf "\t$(INSTALL_LIB) %s %s\n", src_lib1, dst_lib1;
198                 sharedlinks(directory)
199         }
200 function install_dll(directory,filename) {
201                 src_name = sprintf("../lib/%s", filename);
202                 dst_name = sprintf("$(DESTDIR)%s/%s", directory, filename);
203                 printf "\t@echo installing %s as %s\n", src_name, dst_name
204                 if ( directory == "$(bindir)" ) {
205                         program = "$(INSTALL) -m 755";
206                 } else {
207                         program = "$(INSTALL_LIB)";
208                 }
209                 printf "\t%s %s %s\n", program, src_name, dst_name
210         }
211 BEGIN   {
212                 found = 0
213                 using = 0
214         }
215         /^@/ {
216                 using = 0
217                 if (subset == "none") {
218                         using = 1
219                 } else if (index(subset,$2) > 0) {
220                         if (using == 0) {
221                                 if (found == 0) {
222                                         print  ""
223                                         printf "# generated by mk-1st.awk (subset=%s)\n", subset
224                                         printf "#  name:          %s\n", name 
225                                         printf "#  traces:        %s\n", traces 
226                                         printf "#  MODEL:         %s\n", MODEL 
227                                         printf "#  model:         %s\n", model 
228                                         printf "#  prefix:        %s\n", prefix 
229                                         printf "#  suffix:        %s\n", suffix 
230                                         printf "#  subset:        %s\n", subset 
231                                         printf "#  ShlibVer:      %s\n", ShlibVer 
232                                         printf "#  ShlibVerInfix: %s\n", ShlibVerInfix 
233                                         printf "#  TermlibRoot:   %s\n", TermlibRoot 
234                                         printf "#  ReLink:        %s\n", ReLink 
235                                         printf "#  DoLinks:       %s\n", DoLinks 
236                                         printf "#  rmSoLocs:      %s\n", rmSoLocs 
237                                         printf "#  ldconfig:      %s\n", ldconfig 
238                                         printf "#  overwrite:     %s\n", overwrite 
239                                         printf "#  depend:        %s\n", depend 
240                                         printf "#  host:          %s\n", host 
241                                         print  ""
242                                 }
243                                 using = 1
244                         }
245                         if ( is_ticlib() ) {
246                                 OBJS  = MODEL "_P"
247                         } else if ( is_termlib() ) {
248                                 OBJS  = MODEL "_T"
249                         } else {
250                                 OBJS  = MODEL
251                         }
252                 }
253         }
254         /^[@#]/ {
255                 next
256         }
257         $1 ~ /trace/ {
258                 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
259                         next
260         }
261         {
262                 if (using \
263                  && ( $1 != "link_test" ) \
264                  && ( $2 == "lib" \
265                    || $2 == "progs" \
266                    || $2 == "c++" \
267                    || $2 == "tack" ))
268                 {
269                         if ( found == 0 )
270                         {
271                                 printf "%s_OBJS =", OBJS
272                                 if ( $2 == "lib" )
273                                         found = 1
274                                 else
275                                         found = 2
276                         }
277                         printf " \\\n\t../%s/%s$o", model, $1
278                 }
279         }
280 END     {
281                 print  ""
282                 if ( found != 0 )
283                 {
284                         printf "\n$(%s_OBJS) : %s\n", OBJS, depend
285                 }
286                 if ( found == 1 )
287                 {
288                         print  ""
289                         lib_name = lib_name_of(name);
290                         if ( MODEL == "SHARED" )
291                         {
292                                 abi_name = abi_name_of(name);
293                                 rel_name = rel_name_of(name);
294                                 imp_name = imp_name_of(name);
295                                 end_name = end_name_of(name);
296
297                                 shlib_build("../lib")
298
299                                 print  ""
300                                 print  "install \\"
301                                 print  "install.libs \\"
302
303                                 if ( ShlibVer == "cygdll" ) {
304
305                                         dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
306                                         printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs
307                                         install_dll("$(bindir)",end_name);
308                                         install_dll("$(libdir)",imp_name);
309
310                                 } else {
311
312                                         lib_dir = "$(DESTDIR)$(libdir)";
313                                         printf "install.%s :: %s/%s\n", name, lib_dir, end_name
314                                         print ""
315                                         if ( ReLink == "yes" ) {
316                                                 shlib_build(lib_dir)
317                                         } else {
318                                                 shlib_install(lib_dir)
319                                         }
320                                 }
321
322                                 if ( overwrite == "yes" && name == "ncurses" )
323                                 {
324                                         if ( ShlibVer == "cygdll" ) {
325                                                 ovr_name = sprintf("libcurses%s.a", suffix)
326                                                 printf "\t@echo linking %s to %s\n", imp_name, ovr_name
327                                                 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, imp_name, ovr_name
328                                         } else {
329                                                 ovr_name = sprintf("libcurses%s", suffix)
330                                                 printf "\t@echo linking %s to %s\n", end_name, ovr_name
331                                                 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, end_name, ovr_name
332                                         }
333                                 }
334                                 if ( ldconfig != "" && ldconfig != ":" ) {
335                                         printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
336                                 }
337                                 print  ""
338                                 print  "uninstall \\"
339                                 print  "uninstall.libs \\"
340                                 printf "uninstall.%s ::\n", name
341                                 if ( ShlibVer == "cygdll" ) {
342
343                                         printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
344                                         printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
345
346                                         printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
347                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
348
349                                 } else {
350                                         printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
351                                         removelinks("$(DESTDIR)$(libdir)")
352                                         if ( overwrite == "yes" && name == "ncurses" )
353                                         {
354                                                 if ( ShlibVer == "cygdll" ) {
355                                                         ovr_name = sprintf("libcurses%s.a", suffix)
356                                                 } else {
357                                                         ovr_name = sprintf("libcurses%s", suffix)
358                                                 }
359                                                 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
360                                         }
361                                 }
362                                 if ( rmSoLocs == "yes" ) {
363                                         print  ""
364                                         print  "mostlyclean \\"
365                                         print  "clean ::"
366                                         printf "\t-@rm -f so_locations\n"
367                                 }
368                         }
369                         else if ( MODEL == "LIBTOOL" )
370                         {
371                                 if ( $2 == "c++" ) {
372                                         compile="CXX"
373                                 } else {
374                                         compile="CC"
375                                 }
376                                 end_name = lib_name;
377                                 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
378                                 printf "\tcd ../lib && $(LIBTOOL_LINK) $(%s) -o %s $(%s_OBJS:$o=.lo) -rpath $(DESTDIR)$(libdir) -version-info $(NCURSES_MAJOR):$(NCURSES_MINOR) $(SHLIB_LIST)\n", compile, lib_name, OBJS
379                                 print  ""
380                                 print  "install \\"
381                                 print  "install.libs \\"
382                                 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
383                                 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
384                                 printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
385                                 print  ""
386                                 print  "uninstall \\"
387                                 print  "uninstall.libs \\"
388                                 printf "uninstall.%s ::\n", name
389                                 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
390                                 printf "\t-@$(LIBTOOL_UNINSTALL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
391                         }
392                         else
393                         {
394                                 end_name = lib_name;
395                                 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
396                                 printf "\t$(AR) $(AR_OPTS) $@ $?\n"
397                                 printf "\t$(RANLIB) $@\n"
398                                 if ( host == "vxworks" )
399                                 {
400                                         printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
401                                 }
402                                 print  ""
403                                 print  "install \\"
404                                 print  "install.libs \\"
405                                 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
406                                 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
407                                 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
408                                 if ( overwrite == "yes" && lib_name == "libncurses.a" )
409                                 {
410                                         printf "\t@echo linking libcurses.a to libncurses.a\n"
411                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
412                                         printf "\t(cd $(DESTDIR)$(libdir) && $(LN_S) libncurses.a libcurses.a)\n"
413                                 }
414                                 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
415                                 if ( host == "vxworks" )
416                                 {
417                                         printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name, name
418                                         printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name, name
419                                 }
420                                 print  ""
421                                 print  "uninstall \\"
422                                 print  "uninstall.libs \\"
423                                 printf "uninstall.%s ::\n", name
424                                 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
425                                 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
426                                 if ( overwrite == "yes" && lib_name == "libncurses.a" )
427                                 {
428                                         printf "\t@echo linking libcurses.a to libncurses.a\n"
429                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
430                                 }
431                                 if ( host == "vxworks" )
432                                 {
433                                         printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
434                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
435                                 }
436                         }
437                         print ""
438                         print "clean ::"
439                         removelinks("../lib");
440                         print ""
441                         print "mostlyclean::"
442                         printf "\t-rm -f $(%s_OBJS)\n", OBJS
443                         if ( MODEL == "LIBTOOL" ) {
444                                 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
445                         }
446                 }
447                 else if ( found == 2 )
448                 {
449                         print ""
450                         print "mostlyclean::"
451                         printf "\t-rm -f $(%s_OBJS)\n", OBJS
452                         if ( MODEL == "LIBTOOL" ) {
453                                 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
454                         }
455                         print ""
456                         print "clean ::"
457                         printf "\t-rm -f $(%s_OBJS)\n", OBJS
458                         if ( MODEL == "LIBTOOL" ) {
459                                 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
460                         }
461                 }
462         }
463 # vile:ts=4 sw=4