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