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