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