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