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