8ce72f5c6bdf31ea67f7fd3fe2a044b6ad82a8ab
[ncurses.git] / mk-1st.awk
1 # $Id: mk-1st.awk,v 1.62 2004/01/10 20:48:43 tom Exp $
2 ##############################################################################
3 # Copyright (c) 1998-2003,2004 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 #       model (directory into which we compile, e.g., "obj")
36 #       prefix (e.g., "lib", for Unix-style libraries)
37 #       suffix (e.g., "_g.a", for debug libraries)
38 #       MODEL (e.g., "DEBUG", uppercase; toupper is not portable)
39 #       depend (optional dependencies for all objects, e.g, ncurses_cfg.h)
40 #       subset ("none", "base", "base+ext_funcs" or "termlib")
41 #       host (cross-compile host, if any)
42 #       ShlibVer ("rel", "abi" or "auto", to augment DoLinks variable)
43 #       ShlibVerInfix ("yes" or "no", determines location of version #)
44 #       DoLinks ("yes", "reverse" or "no", flag to add symbolic links)
45 #       rmSoLocs ("yes" or "no", flag to add extra clean target)
46 #       overwrite ("yes" or "no", flag to add link to libcurses.a
47 #
48 # Notes:
49 #       CLIXs nawk does not like underscores in command-line variable names.
50 #       Mixed-case is ok.
51 #       HP/UX requires shared libraries to have executable permissions.
52 #
53 function symlink(src,dst) {
54                 if ( src != dst ) {
55                         printf "rm -f %s; ", dst
56                         printf "$(LN_S) %s %s; ", src, dst
57                 }
58         }
59 function rmlink(directory, dst) {
60                 printf "\t-rm -f %s/%s\n", directory, dst
61 }
62 function removelinks(directory) {
63                 rmlink(directory, end_name);
64                 if ( DoLinks == "reverse" ) {
65                                 if ( ShlibVer == "rel" ) {
66                                         rmlink(directory, abi_name);
67                                         rmlink(directory, rel_name);
68                                 } else if ( ShlibVer == "abi" ) {
69                                         rmlink(directory, abi_name);
70                                 }
71                 } else {
72                                 if ( ShlibVer == "rel" ) {
73                                         rmlink(directory, abi_name);
74                                         rmlink(directory, lib_name);
75                                 } else if ( ShlibVer == "abi" ) {
76                                         rmlink(directory, lib_name);
77                                 }
78                 }
79         }
80 function sharedlinks(directory) {
81                 if ( ShlibVer != "auto" && ShlibVer != "cygdll" ) {
82                         printf "\tcd %s && (", directory
83                         if ( DoLinks == "reverse" ) {
84                                 if ( ShlibVer == "rel" ) {
85                                         symlink(lib_name, abi_name);
86                                         symlink(abi_name, rel_name);
87                                 } else if ( ShlibVer == "abi" ) {
88                                         symlink(lib_name, abi_name);
89                                 }
90                         } else {
91                                 if ( ShlibVer == "rel" ) {
92                                         symlink(rel_name, abi_name);
93                                         symlink(abi_name, lib_name);
94                                 } else if ( ShlibVer == "abi" ) {
95                                         symlink(abi_name, lib_name);
96                                 }
97                         }
98                         printf ")\n"
99                 }
100         }
101 BEGIN   {
102                 found = 0
103                 using = 0
104         }
105         /^@/ {
106                 using = 0
107                 if (subset == "none") {
108                         using = 1
109                 } else if (index(subset,$2) > 0) {
110                         if (using == 0) {
111                                 if (found == 0) {
112                                         print  ""
113                                         printf "# generated by mk-1st.awk (subset=%s)\n", subset
114                                         print  ""
115                                 }
116                                 using = 1
117                         }
118                         if ( subset == "termlib" || subset == "termlib+ext_tinfo" ) {
119                                 name  = "tinfo"
120                                 OBJS  = MODEL "_T"
121                         } else {
122                                 OBJS  = MODEL
123                         }
124                 }
125         }
126         /^[@#]/ {
127                 next
128         }
129         $1 ~ /trace/ {
130                 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
131                         next
132         }
133         {
134                 if (using \
135                  && ( $1 != "link_test" ) \
136                  && ( $2 == "lib" \
137                    || $2 == "progs" \
138                    || $2 == "c++" \
139                    || $2 == "tack" ))
140                 {
141                         if ( found == 0 )
142                         {
143                                 printf "%s_OBJS =", OBJS
144                                 if ( $2 == "lib" )
145                                         found = 1
146                                 else
147                                         found = 2
148                         }
149                         printf " \\\n\t../%s/%s$o", model, $1
150                 }
151         }
152 END     {
153                 print  ""
154                 if ( found != 0 )
155                 {
156                         printf "\n$(%s_OBJS) : %s\n", OBJS, depend
157                 }
158                 if ( found == 1 )
159                 {
160                         print  ""
161                         lib_name = sprintf("%s%s%s", prefix, name, suffix)
162                         if ( MODEL == "SHARED" )
163                         {
164                                 if (ShlibVerInfix == "cygdll") {
165                                         abi_name = sprintf("%s%s$(ABI_VERSION)%s", "cyg", name, suffix);
166                                         rel_name = sprintf("%s%s$(REL_VERSION)%s", "cyg", name, suffix);
167                                         imp_name = sprintf("%s%s%s.a", prefix, name, suffix);
168                                 } else if (ShlibVerInfix == "yes") {
169                                         abi_name = sprintf("%s%s.$(ABI_VERSION)%s", prefix, name, suffix);
170                                         rel_name = sprintf("%s%s.$(REL_VERSION)%s", prefix, name, suffix);
171                                 } else {
172                                         abi_name = sprintf("%s.$(ABI_VERSION)", lib_name);
173                                         rel_name = sprintf("%s.$(REL_VERSION)", lib_name);
174                                 }
175                                 if ( DoLinks == "reverse") {
176                                         end_name = lib_name;
177                                 } else {
178                                         if ( ShlibVer == "rel" ) {
179                                                 end_name = rel_name;
180                                         } else if ( ShlibVer == "abi" || ShlibVer == "cygdll" ) {
181                                                 end_name = abi_name;
182                                         } else {
183                                                 end_name = lib_name;
184                                         }
185                                 }
186
187                                 if ( ShlibVer == "cygdll" ) {
188                                         dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
189                                         printf "$(SHARED_LIB) $(IMPORT_LIB) : $(%s_OBJS)\n", OBJS;
190                                         print "\t-@rm -f $(SHARED_LIB) $(IMPORT_LIB)";
191                                 } else {
192                                         dst_dirs = "$(DESTDIR)$(libdir)";
193                                         printf "../lib/%s : $(%s_OBJS)\n", end_name, OBJS
194                                         print "\t-@rm -f $@";
195                                 }
196                                 if ( subset == "termlib" || subset == "termlib+ext_tinfo" ) {
197                                         printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(TINFO_LIST) $(LDFLAGS)\n", OBJS
198                                 } else {
199                                         printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(SHLIB_LIST) $(LDFLAGS)\n", OBJS
200                                 }
201                                 sharedlinks("../lib")
202
203                                 print  ""
204                                 print  "install \\"
205                                 print  "install.libs \\"
206                                 printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs
207
208                                 if ( ShlibVer == "cygdll" ) {
209
210                                         src_name = sprintf("../lib/%s", end_name);
211                                         dst_name = sprintf("$(DESTDIR)$(bindir)/%s", end_name);
212                                         printf "\t@echo installing %s as %s\n", src_name, dst_name
213                                         printf "\t-@rm -f %s\n", dst_name
214                                         printf "\t$(INSTALL_LIB) %s %s\n", src_name, dst_name
215
216                                         src_name = sprintf("../lib/%s", imp_name);
217                                         dst_name = sprintf("$(DESTDIR)$(libdir)/%s", imp_name);
218                                         printf "\t@echo installing %s as %s\n", src_name, dst_name
219                                         printf "\t-@rm -f %s\n", dst_name
220                                         printf "\t$(INSTALL_LIB) %s %s\n", src_name, dst_name
221
222                                 } else {
223
224                                         src_name = sprintf("../lib/%s", end_name);
225                                         dst_name = sprintf("$(DESTDIR)$(libdir)/%s", end_name);
226                                         printf "\t@echo installing %s as %s\n", src_name, dst_name
227                                         printf "\t-@rm -f %s\n", dst_name
228                                         printf "\t$(INSTALL_LIB) %s %s\n", src_name, dst_name
229
230                                         sharedlinks("$(DESTDIR)$(libdir)")
231
232                                 }
233
234                                 if ( overwrite == "yes" && name == "ncurses" )
235                                 {
236                                         if ( ShlibVer == "cygdll" ) {
237                                                 ovr_name = sprintf("libcurses%s.a", suffix)
238                                                 printf "\t@echo linking %s to %s\n", imp_name, ovr_name
239                                                 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, imp_name, ovr_name
240                                         } else {
241                                                 ovr_name = sprintf("libcurses%s", suffix)
242                                                 printf "\t@echo linking %s to %s\n", end_name, ovr_name
243                                                 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, end_name, ovr_name
244                                         }
245                                 }
246                                 if ( ldconfig != "" ) {
247                                         printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
248                                 }
249                                 print  ""
250                                 print  "uninstall \\"
251                                 print  "uninstall.libs \\"
252                                 printf "uninstall.%s ::\n", name
253                                 if ( ShlibVer == "cygdll" ) {
254
255                                         printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
256                                         printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
257
258                                         printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
259                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
260
261                                 } else {
262                                         printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
263                                         removelinks("$(DESTDIR)$(libdir)")
264                                         if ( overwrite == "yes" && name == "ncurses" )
265                                         {
266                                                 if ( ShlibVer == "cygdll" ) {
267                                                         ovr_name = sprintf("libcurses%s.a", suffix)
268                                                 } else {
269                                                         ovr_name = sprintf("libcurses%s", suffix)
270                                                 }
271                                                 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
272                                         }
273                                 }
274                                 if ( rmSoLocs == "yes" ) {
275                                         print  ""
276                                         print  "mostlyclean \\"
277                                         print  "clean ::"
278                                         printf "\t-@rm -f so_locations\n"
279                                 }
280                         }
281                         else if ( MODEL == "LIBTOOL" )
282                         {
283                                 if ( $2 == "c++" ) {
284                                         compile="CXX"
285                                 } else {
286                                         compile="CC"
287                                 }
288                                 end_name = lib_name;
289                                 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
290                                 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
291                                 print  ""
292                                 print  "install \\"
293                                 print  "install.libs \\"
294                                 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
295                                 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
296                                 printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
297                                 print  ""
298                                 print  "uninstall \\"
299                                 print  "uninstall.libs \\"
300                                 printf "uninstall.%s ::\n", name
301                                 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
302                                 printf "\t-@$(LIBTOOL_CLEAN) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
303                         }
304                         else
305                         {
306                                 end_name = lib_name;
307                                 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
308                                 printf "\t$(AR) $(AR_OPTS) $@ $?\n"
309                                 printf "\t$(RANLIB) $@\n"
310                                 if ( host == "vxworks" )
311                                 {
312                                         printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
313                                 }
314                                 print  ""
315                                 print  "install \\"
316                                 print  "install.libs \\"
317                                 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
318                                 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
319                                 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
320                                 if ( overwrite == "yes" && lib_name == "libncurses.a" )
321                                 {
322                                         printf "\t@echo linking libcurses.a to libncurses.a\n"
323                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
324                                         printf "\t(cd $(DESTDIR)$(libdir) && $(LN_S) libncurses.a libcurses.a)\n"
325                                 }
326                                 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
327                                 if ( host == "vxworks" )
328                                 {
329                                         printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name, name
330                                         printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name, name
331                                 }
332                                 print  ""
333                                 print  "uninstall \\"
334                                 print  "uninstall.libs \\"
335                                 printf "uninstall.%s ::\n", name
336                                 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
337                                 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
338                                 if ( overwrite == "yes" && lib_name == "libncurses.a" )
339                                 {
340                                         printf "\t@echo linking libcurses.a to libncurses.a\n"
341                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
342                                 }
343                                 if ( host == "vxworks" )
344                                 {
345                                         printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
346                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
347                                 }
348                         }
349                         print ""
350                         print "clean ::"
351                         removelinks("../lib");
352                         print ""
353                         print "mostlyclean::"
354                         printf "\t-rm -f $(%s_OBJS)\n", OBJS
355                         if ( MODEL == "LIBTOOL" ) {
356                                 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
357                         }
358                 }
359                 else if ( found == 2 )
360                 {
361                         print ""
362                         print "mostlyclean::"
363                         printf "\t-rm -f $(%s_OBJS)\n", OBJS
364                         if ( MODEL == "LIBTOOL" ) {
365                                 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
366                         }
367                         print ""
368                         print "clean ::"
369                         printf "\t-rm -f $(%s_OBJS)\n", OBJS
370                         if ( MODEL == "LIBTOOL" ) {
371                                 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
372                         }
373                 }
374         }