0332cbfe0a672f3540317778035d48aa1b37fd42
[ncurses.git] / mk-1st.awk
1 # $Id: mk-1st.awk,v 1.69 2006/12/24 00:12:23 tom Exp $
2 ##############################################################################
3 # Copyright (c) 1998-2005,2006 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_termlib() {
56                 return ( subset ~ /^termlib(\+(ext_tinfo|programs))*$/ );
57         }
58 function symlink(src,dst) {
59                 if ( src != dst ) {
60                         printf "rm -f %s; ", dst
61                         printf "$(LN_S) %s %s; ", src, dst
62                 }
63         }
64 function rmlink(directory, dst) {
65                 printf "\t-rm -f %s/%s\n", directory, dst
66         }
67 function removelinks(directory) {
68                 rmlink(directory, end_name);
69                 if ( DoLinks == "reverse" ) {
70                         if ( ShlibVer == "rel" ) {
71                                 rmlink(directory, abi_name);
72                                 rmlink(directory, rel_name);
73                         } else if ( ShlibVer == "abi" ) {
74                                 rmlink(directory, abi_name);
75                         }
76                 } else {
77                         if ( ShlibVer == "rel" ) {
78                                 rmlink(directory, abi_name);
79                                 rmlink(directory, lib_name);
80                         } else if ( ShlibVer == "abi" ) {
81                                 rmlink(directory, lib_name);
82                         }
83                 }
84         }
85 function make_shlib(objs, shlib_list) {
86                 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(%s) $(LDFLAGS)\n", objs, shlib_list
87         }
88 function sharedlinks(directory) {
89                 if ( ShlibVer != "auto" && ShlibVer != "cygdll" ) {
90                         printf "\tcd %s && (", directory
91                         if ( DoLinks == "reverse" ) {
92                                 if ( ShlibVer == "rel" ) {
93                                         symlink(lib_name, abi_name);
94                                         symlink(abi_name, rel_name);
95                                 } else if ( ShlibVer == "abi" ) {
96                                         symlink(lib_name, abi_name);
97                                 }
98                         } else {
99                                 if ( ShlibVer == "rel" ) {
100                                         symlink(rel_name, abi_name);
101                                         symlink(abi_name, lib_name);
102                                 } else if ( ShlibVer == "abi" ) {
103                                         symlink(abi_name, lib_name);
104                                 }
105                         }
106                         printf ")\n"
107                 }
108         }
109 function shlib_rule(directory) {
110                 if ( ShlibVer == "cygdll" ) {
111                         dst_libs = sprintf("%s/$(SHARED_LIB) %s/$(IMPORT_LIB)", directory, directory);
112                 } else {
113                         dst_libs = sprintf("%s/%s", directory, end_name);
114                 }
115                 printf "%s : %s $(%s_OBJS)\n", dst_libs, directory, OBJS
116                 printf "\t@echo linking $@\n"
117                 print "\t-@rm -f %s", dst_libs;
118                 if ( is_termlib() ) {
119                         make_shlib(OBJS, "TINFO_LIST")
120                 } else {
121                         make_shlib(OBJS, "SHLIB_LIST")
122                 }
123                 sharedlinks(directory)
124         }
125 function install_dll(directory,filename) {
126                 src_name = sprintf("../lib/%s", filename);
127                 dst_name = sprintf("$(DESTDIR)%s/%s", directory, filename);
128                 printf "\t@echo installing %s as %s\n", src_name, dst_name
129                 printf "\t-@rm -f %s\n", dst_name
130                 if ( directory == "$(bindir)" ) {
131                         program = "$(INSTALL) -m 755";
132                 } else {
133                         program = "$(INSTALL_LIB)";
134                 }
135                 printf "\t%s %s %s\n", program, src_name, dst_name
136         }
137 BEGIN   {
138                 found = 0
139                 using = 0
140         }
141         /^@/ {
142                 using = 0
143                 if (subset == "none") {
144                         using = 1
145                 } else if (index(subset,$2) > 0) {
146                         if (using == 0) {
147                                 if (found == 0) {
148                                         print  ""
149                                         printf "# generated by mk-1st.awk (subset=%s)\n", subset
150                                         printf "#  name:          %s\n", name 
151                                         printf "#  traces:        %s\n", traces 
152                                         printf "#  MODEL:         %s\n", MODEL 
153                                         printf "#  model:         %s\n", model 
154                                         printf "#  prefix:        %s\n", prefix 
155                                         printf "#  suffix:        %s\n", suffix 
156                                         printf "#  subset:        %s\n", subset 
157                                         printf "#  ShlibVer:      %s\n", ShlibVer 
158                                         printf "#  ShlibVerInfix: %s\n", ShlibVerInfix 
159                                         printf "#  DoLinks:       %s\n", DoLinks 
160                                         printf "#  rmSoLocs:      %s\n", rmSoLocs 
161                                         printf "#  ldconfig:      %s\n", ldconfig 
162                                         printf "#  overwrite:     %s\n", overwrite 
163                                         printf "#  depend:        %s\n", depend 
164                                         printf "#  host:          %s\n", host 
165                                         print  ""
166                                 }
167                                 using = 1
168                         }
169                         if ( is_termlib() ) {
170                                 OBJS  = MODEL "_T"
171                         } else {
172                                 OBJS  = MODEL
173                         }
174                 }
175         }
176         /^[@#]/ {
177                 next
178         }
179         $1 ~ /trace/ {
180                 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
181                         next
182         }
183         {
184                 if (using \
185                  && ( $1 != "link_test" ) \
186                  && ( $2 == "lib" \
187                    || $2 == "progs" \
188                    || $2 == "c++" \
189                    || $2 == "tack" ))
190                 {
191                         if ( found == 0 )
192                         {
193                                 printf "%s_OBJS =", OBJS
194                                 if ( $2 == "lib" )
195                                         found = 1
196                                 else
197                                         found = 2
198                         }
199                         printf " \\\n\t../%s/%s$o", model, $1
200                 }
201         }
202 END     {
203                 print  ""
204                 if ( found != 0 )
205                 {
206                         printf "\n$(%s_OBJS) : %s\n", OBJS, depend
207                 }
208                 if ( found == 1 )
209                 {
210                         print  ""
211                         lib_name = sprintf("%s%s%s", prefix, name, suffix)
212                         if ( MODEL == "SHARED" )
213                         {
214                                 if (ShlibVerInfix == "cygdll") {
215                                         abi_name = sprintf("%s%s$(ABI_VERSION)%s", "cyg", name, suffix);
216                                         rel_name = sprintf("%s%s$(REL_VERSION)%s", "cyg", name, suffix);
217                                         imp_name = sprintf("%s%s%s.a", prefix, name, suffix);
218                                 } else if (ShlibVerInfix == "yes") {
219                                         abi_name = sprintf("%s%s.$(ABI_VERSION)%s", prefix, name, suffix);
220                                         rel_name = sprintf("%s%s.$(REL_VERSION)%s", prefix, name, suffix);
221                                 } else {
222                                         abi_name = sprintf("%s.$(ABI_VERSION)", lib_name);
223                                         rel_name = sprintf("%s.$(REL_VERSION)", lib_name);
224                                 }
225                                 if ( DoLinks == "reverse") {
226                                         end_name = lib_name;
227                                 } else {
228                                         if ( ShlibVer == "rel" ) {
229                                                 end_name = rel_name;
230                                         } else if ( ShlibVer == "abi" || ShlibVer == "cygdll" ) {
231                                                 end_name = abi_name;
232                                         } else {
233                                                 end_name = lib_name;
234                                         }
235                                 }
236
237                                 shlib_rule("../lib")
238
239                                 print  ""
240                                 print  "install \\"
241                                 print  "install.libs \\"
242
243                                 if ( ShlibVer == "cygdll" ) {
244
245                                         dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
246                                         printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs
247                                         install_dll("$(bindir)",end_name);
248                                         install_dll("$(libdir)",imp_name);
249
250                                 } else {
251
252                                         lib_dir = "$(DESTDIR)$(libdir)";
253                                         printf "install.%s :: %s/%s\n", name, lib_dir, end_name
254                                         print ""
255                                         shlib_rule(lib_dir)
256                                 }
257
258                                 if ( overwrite == "yes" && name == "ncurses" )
259                                 {
260                                         if ( ShlibVer == "cygdll" ) {
261                                                 ovr_name = sprintf("libcurses%s.a", suffix)
262                                                 printf "\t@echo linking %s to %s\n", imp_name, ovr_name
263                                                 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, imp_name, ovr_name
264                                         } else {
265                                                 ovr_name = sprintf("libcurses%s", suffix)
266                                                 printf "\t@echo linking %s to %s\n", end_name, ovr_name
267                                                 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, end_name, ovr_name
268                                         }
269                                 }
270                                 if ( ldconfig != "" && ldconfig != ":" ) {
271                                         printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
272                                 }
273                                 print  ""
274                                 print  "uninstall \\"
275                                 print  "uninstall.libs \\"
276                                 printf "uninstall.%s ::\n", name
277                                 if ( ShlibVer == "cygdll" ) {
278
279                                         printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
280                                         printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
281
282                                         printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
283                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
284
285                                 } else {
286                                         printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
287                                         removelinks("$(DESTDIR)$(libdir)")
288                                         if ( overwrite == "yes" && name == "ncurses" )
289                                         {
290                                                 if ( ShlibVer == "cygdll" ) {
291                                                         ovr_name = sprintf("libcurses%s.a", suffix)
292                                                 } else {
293                                                         ovr_name = sprintf("libcurses%s", suffix)
294                                                 }
295                                                 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
296                                         }
297                                 }
298                                 if ( rmSoLocs == "yes" ) {
299                                         print  ""
300                                         print  "mostlyclean \\"
301                                         print  "clean ::"
302                                         printf "\t-@rm -f so_locations\n"
303                                 }
304                         }
305                         else if ( MODEL == "LIBTOOL" )
306                         {
307                                 if ( $2 == "c++" ) {
308                                         compile="CXX"
309                                 } else {
310                                         compile="CC"
311                                 }
312                                 end_name = lib_name;
313                                 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
314                                 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
315                                 print  ""
316                                 print  "install \\"
317                                 print  "install.libs \\"
318                                 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
319                                 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
320                                 printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
321                                 print  ""
322                                 print  "uninstall \\"
323                                 print  "uninstall.libs \\"
324                                 printf "uninstall.%s ::\n", name
325                                 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
326                                 printf "\t-@$(LIBTOOL_UNINSTALL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
327                         }
328                         else
329                         {
330                                 end_name = lib_name;
331                                 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
332                                 printf "\t$(AR) $(AR_OPTS) $@ $?\n"
333                                 printf "\t$(RANLIB) $@\n"
334                                 if ( host == "vxworks" )
335                                 {
336                                         printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
337                                 }
338                                 print  ""
339                                 print  "install \\"
340                                 print  "install.libs \\"
341                                 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
342                                 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
343                                 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
344                                 if ( overwrite == "yes" && lib_name == "libncurses.a" )
345                                 {
346                                         printf "\t@echo linking libcurses.a to libncurses.a\n"
347                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
348                                         printf "\t(cd $(DESTDIR)$(libdir) && $(LN_S) libncurses.a libcurses.a)\n"
349                                 }
350                                 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
351                                 if ( host == "vxworks" )
352                                 {
353                                         printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name, name
354                                         printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name, name
355                                 }
356                                 print  ""
357                                 print  "uninstall \\"
358                                 print  "uninstall.libs \\"
359                                 printf "uninstall.%s ::\n", name
360                                 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
361                                 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
362                                 if ( overwrite == "yes" && lib_name == "libncurses.a" )
363                                 {
364                                         printf "\t@echo linking libcurses.a to libncurses.a\n"
365                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
366                                 }
367                                 if ( host == "vxworks" )
368                                 {
369                                         printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
370                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
371                                 }
372                         }
373                         print ""
374                         print "clean ::"
375                         removelinks("../lib");
376                         print ""
377                         print "mostlyclean::"
378                         printf "\t-rm -f $(%s_OBJS)\n", OBJS
379                         if ( MODEL == "LIBTOOL" ) {
380                                 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
381                         }
382                 }
383                 else if ( found == 2 )
384                 {
385                         print ""
386                         print "mostlyclean::"
387                         printf "\t-rm -f $(%s_OBJS)\n", OBJS
388                         if ( MODEL == "LIBTOOL" ) {
389                                 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
390                         }
391                         print ""
392                         print "clean ::"
393                         printf "\t-rm -f $(%s_OBJS)\n", OBJS
394                         if ( MODEL == "LIBTOOL" ) {
395                                 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
396                         }
397                 }
398         }
399 # vile:ts=4 sw=4