ncurses 5.6 - patch 20070310
[ncurses.git] / mk-1st.awk
1 # $Id: mk-1st.awk,v 1.76 2007/03/03 20:26:06 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_libs
194                 printf "\t\t%s \\\n", directory
195                 printf "\t\t%s\n", src_libs
196                 printf "\t@echo installing $@\n"
197                 printf "\t$(INSTALL_LIB) %s %s\n", src_lib1, dst_lib1;
198                 if ( src_lib2 != "" ) {
199                         printf "\t$(INSTALL_LIB) %s %s\n", src_lib2, dst_lib2;
200                 }
201                 sharedlinks(directory)
202         }
203 function install_dll(directory,filename) {
204                 src_name = sprintf("../lib/%s", filename);
205                 dst_name = sprintf("$(DESTDIR)%s/%s", directory, filename);
206                 printf "\t@echo installing %s as %s\n", src_name, dst_name
207                 if ( directory == "$(bindir)" ) {
208                         program = "$(INSTALL) -m 755";
209                 } else {
210                         program = "$(INSTALL_LIB)";
211                 }
212                 printf "\t%s %s %s\n", program, src_name, dst_name
213         }
214 BEGIN   {
215                 found = 0
216                 using = 0
217         }
218         /^@/ {
219                 using = 0
220                 if (subset == "none") {
221                         using = 1
222                 } else if (index(subset,$2) > 0) {
223                         if (using == 0) {
224                                 if (found == 0) {
225                                         print  ""
226                                         printf "# generated by mk-1st.awk (subset=%s)\n", subset
227                                         printf "#  name:          %s\n", name 
228                                         printf "#  traces:        %s\n", traces 
229                                         printf "#  MODEL:         %s\n", MODEL 
230                                         printf "#  model:         %s\n", model 
231                                         printf "#  prefix:        %s\n", prefix 
232                                         printf "#  suffix:        %s\n", suffix 
233                                         printf "#  subset:        %s\n", subset 
234                                         printf "#  ShlibVer:      %s\n", ShlibVer 
235                                         printf "#  ShlibVerInfix: %s\n", ShlibVerInfix 
236                                         printf "#  TermlibRoot:   %s\n", TermlibRoot 
237                                         printf "#  ReLink:        %s\n", ReLink 
238                                         printf "#  DoLinks:       %s\n", DoLinks 
239                                         printf "#  rmSoLocs:      %s\n", rmSoLocs 
240                                         printf "#  ldconfig:      %s\n", ldconfig 
241                                         printf "#  overwrite:     %s\n", overwrite 
242                                         printf "#  depend:        %s\n", depend 
243                                         printf "#  host:          %s\n", host 
244                                         print  ""
245                                 }
246                                 using = 1
247                         }
248                         if ( is_ticlib() ) {
249                                 OBJS  = MODEL "_P"
250                         } else if ( is_termlib() ) {
251                                 OBJS  = MODEL "_T"
252                         } else {
253                                 OBJS  = MODEL
254                         }
255                 }
256         }
257         /^[@#]/ {
258                 next
259         }
260         $1 ~ /trace/ {
261                 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
262                         next
263         }
264         {
265                 if (using \
266                  && ( $1 != "link_test" ) \
267                  && ( $2 == "lib" \
268                    || $2 == "progs" \
269                    || $2 == "c++" \
270                    || $2 == "tack" ))
271                 {
272                         if ( found == 0 )
273                         {
274                                 printf "%s_OBJS =", OBJS
275                                 if ( $2 == "lib" )
276                                         found = 1
277                                 else
278                                         found = 2
279                         }
280                         printf " \\\n\t../%s/%s$o", model, $1
281                 }
282         }
283 END     {
284                 print  ""
285                 if ( found != 0 )
286                 {
287                         printf "\n$(%s_OBJS) : %s\n", OBJS, depend
288                 }
289                 if ( found == 1 )
290                 {
291                         print  ""
292                         lib_name = lib_name_of(name);
293                         if ( MODEL == "SHARED" )
294                         {
295                                 abi_name = abi_name_of(name);
296                                 rel_name = rel_name_of(name);
297                                 imp_name = imp_name_of(name);
298                                 end_name = end_name_of(name);
299
300                                 shlib_build("../lib")
301
302                                 print  ""
303                                 print  "install \\"
304                                 print  "install.libs \\"
305
306                                 if ( ShlibVer == "cygdll" ) {
307
308                                         dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
309                                         printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs
310                                         install_dll("$(bindir)",end_name);
311                                         install_dll("$(libdir)",imp_name);
312
313                                 } else {
314
315                                         lib_dir = "$(DESTDIR)$(libdir)";
316                                         printf "install.%s :: %s/%s\n", name, lib_dir, end_name
317                                         print ""
318                                         if ( ReLink == "yes" ) {
319                                                 shlib_build(lib_dir)
320                                         } else {
321                                                 shlib_install(lib_dir)
322                                         }
323                                 }
324
325                                 if ( overwrite == "yes" && name == "ncurses" )
326                                 {
327                                         if ( ShlibVer == "cygdll" ) {
328                                                 ovr_name = sprintf("libcurses%s.a", suffix)
329                                                 printf "\t@echo linking %s to %s\n", imp_name, ovr_name
330                                                 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, imp_name, ovr_name
331                                         } else {
332                                                 ovr_name = sprintf("libcurses%s", suffix)
333                                                 printf "\t@echo linking %s to %s\n", end_name, ovr_name
334                                                 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, end_name, ovr_name
335                                         }
336                                 }
337                                 if ( ldconfig != "" && ldconfig != ":" ) {
338                                         printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
339                                 }
340                                 print  ""
341                                 print  "uninstall \\"
342                                 print  "uninstall.libs \\"
343                                 printf "uninstall.%s ::\n", name
344                                 if ( ShlibVer == "cygdll" ) {
345
346                                         printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
347                                         printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
348
349                                         printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
350                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
351
352                                 } else {
353                                         printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
354                                         removelinks("$(DESTDIR)$(libdir)")
355                                         if ( overwrite == "yes" && name == "ncurses" )
356                                         {
357                                                 if ( ShlibVer == "cygdll" ) {
358                                                         ovr_name = sprintf("libcurses%s.a", suffix)
359                                                 } else {
360                                                         ovr_name = sprintf("libcurses%s", suffix)
361                                                 }
362                                                 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
363                                         }
364                                 }
365                                 if ( rmSoLocs == "yes" ) {
366                                         print  ""
367                                         print  "mostlyclean \\"
368                                         print  "clean ::"
369                                         printf "\t-@rm -f so_locations\n"
370                                 }
371                         }
372                         else if ( MODEL == "LIBTOOL" )
373                         {
374                                 if ( $2 == "c++" ) {
375                                         compile="CXX"
376                                 } else {
377                                         compile="CC"
378                                 }
379                                 end_name = lib_name;
380                                 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
381                                 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
382                                 print  ""
383                                 print  "install \\"
384                                 print  "install.libs \\"
385                                 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
386                                 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
387                                 printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
388                                 print  ""
389                                 print  "uninstall \\"
390                                 print  "uninstall.libs \\"
391                                 printf "uninstall.%s ::\n", name
392                                 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
393                                 printf "\t-@$(LIBTOOL_UNINSTALL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
394                         }
395                         else
396                         {
397                                 end_name = lib_name;
398                                 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
399                                 printf "\t$(AR) $(AR_OPTS) $@ $?\n"
400                                 printf "\t$(RANLIB) $@\n"
401                                 if ( host == "vxworks" )
402                                 {
403                                         printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
404                                 }
405                                 print  ""
406                                 print  "install \\"
407                                 print  "install.libs \\"
408                                 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
409                                 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
410                                 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
411                                 if ( overwrite == "yes" && lib_name == "libncurses.a" )
412                                 {
413                                         printf "\t@echo linking libcurses.a to libncurses.a\n"
414                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
415                                         printf "\t(cd $(DESTDIR)$(libdir) && $(LN_S) libncurses.a libcurses.a)\n"
416                                 }
417                                 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
418                                 if ( host == "vxworks" )
419                                 {
420                                         printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name, name
421                                         printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name, name
422                                 }
423                                 print  ""
424                                 print  "uninstall \\"
425                                 print  "uninstall.libs \\"
426                                 printf "uninstall.%s ::\n", name
427                                 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
428                                 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
429                                 if ( overwrite == "yes" && lib_name == "libncurses.a" )
430                                 {
431                                         printf "\t@echo linking libcurses.a to libncurses.a\n"
432                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
433                                 }
434                                 if ( host == "vxworks" )
435                                 {
436                                         printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
437                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
438                                 }
439                         }
440                         print ""
441                         print "clean ::"
442                         removelinks("../lib");
443                         print ""
444                         print "mostlyclean::"
445                         printf "\t-rm -f $(%s_OBJS)\n", OBJS
446                         if ( MODEL == "LIBTOOL" ) {
447                                 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
448                         }
449                 }
450                 else if ( found == 2 )
451                 {
452                         print ""
453                         print "mostlyclean::"
454                         printf "\t-rm -f $(%s_OBJS)\n", OBJS
455                         if ( MODEL == "LIBTOOL" ) {
456                                 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
457                         }
458                         print ""
459                         print "clean ::"
460                         printf "\t-rm -f $(%s_OBJS)\n", OBJS
461                         if ( MODEL == "LIBTOOL" ) {
462                                 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
463                         }
464                 }
465         }
466 # vile:ts=4 sw=4