]> ncurses.scripts.mit.edu Git - ncurses.git/blob - mk-1st.awk
c14219cd529a85b61ea70f2db6faa35f48e49413
[ncurses.git] / mk-1st.awk
1 # $Id: mk-1st.awk,v 1.46 2000/10/14 17:57:02 Johnny.C.Lam Exp $
2 ##############################################################################
3 # Copyright (c) 1998,2000 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 <dickey@clark.net> 1996,1997,2000
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 #       target (cross-compile target, if any)
42 #       ShlibVer ("rel", "abi" or "auto", to augment DoLinks variable)
43 #       DoLinks ("yes", "reverse" or "no", flag to add symbolic links)
44 #       rmSoLocs ("yes" or "no", flag to add extra clean target)
45 #       overwrite ("yes" or "no", flag to add link to libcurses.a
46 #
47 # Notes:
48 #       CLIXs nawk does not like underscores in command-line variable names.
49 #       Mixed-case is ok.
50 #       HP/UX requires shared libraries to have executable permissions.
51 #
52 function symlink(src,dst) {
53                 if ( src != dst ) {
54                         printf "rm -f %s; ", dst
55                         printf "$(LN_S) %s %s; ", src, dst
56                 }
57         }
58 function rmlink(directory, dst) {
59                 printf "\t-rm -f %s/%s\n", directory, dst
60 }
61 function removelinks(directory) {
62                 rmlink(directory, end_name);
63                 if ( DoLinks == "reverse" ) {
64                                 if ( ShlibVer == "rel" ) {
65                                         rmlink(directory, abi_name);
66                                         rmlink(directory, rel_name);
67                                 } else if ( ShlibVer == "abi" ) {
68                                         rmlink(directory, abi_name);
69                                 }
70                 } else {
71                                 if ( ShlibVer == "rel" ) {
72                                         rmlink(directory, abi_name);
73                                         rmlink(directory, lib_name);
74                                 } else if ( ShlibVer == "abi" ) {
75                                         rmlink(directory, lib_name);
76                                 }
77                 }
78         }
79 function sharedlinks(directory) {
80                 if ( ShlibVer != "auto" ) {
81                         printf "\tcd %s && (", directory
82                         if ( DoLinks == "reverse" ) {
83                                 if ( ShlibVer == "rel" ) {
84                                         symlink(lib_name, abi_name);
85                                         symlink(abi_name, rel_name);
86                                 } else if ( ShlibVer == "abi" ) {
87                                         symlink(lib_name, abi_name);
88                                 }
89                         } else {
90                                 if ( ShlibVer == "rel" ) {
91                                         symlink(rel_name, abi_name);
92                                         symlink(abi_name, lib_name);
93                                 } else if ( ShlibVer == "abi" ) {
94                                         symlink(abi_name, lib_name);
95                                 }
96                         }
97                         printf ")\n"
98                 }
99         }
100 BEGIN   {
101                 found = 0
102                 using = 0
103         }
104         /^@/ {
105                 using = 0
106                 if (subset == "none") {
107                         using = 1
108                 } else if (index(subset,$2) > 0) {
109                         if (using == 0) {
110                                 if (found == 0) {
111                                         print  ""
112                                         print  "# generated by mk-1st.awk"
113                                         print  ""
114                                 }
115                                 using = 1
116                         }
117                         if ( subset == "termlib") {
118                                 name  = "tinfo"
119                                 OBJS  = MODEL "_T"
120                         } else {
121                                 OBJS  = MODEL
122                         }
123                 }
124         }
125         /^[@#]/ {
126                 next
127         }
128         $1 ~ /trace/ {
129                 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
130                         next
131         }
132         {
133                 if (using \
134                  && ( $2 == "lib" \
135                    || $2 == "progs" \
136                    || $2 == "c++" \
137                    || $2 == "tack" ))
138                 {
139                         if ( found == 0 )
140                         {
141                                 printf "%s_OBJS =", OBJS
142                                 if ( $2 == "lib" )
143                                         found = 1
144                                 else
145                                         found = 2
146                         }
147                         printf " \\\n\t../%s/%s.o", model, $1
148                 }
149         }
150 END     {
151                 print  ""
152                 if ( found != 0 )
153                 {
154                         printf "\n$(%s_OBJS) : %s\n", OBJS, depend
155                 }
156                 if ( found == 1 )
157                 {
158                         print  ""
159                         lib_name = sprintf("%s%s%s", prefix, name, suffix)
160                         if ( MODEL == "SHARED" )
161                         {
162                                 abi_name = sprintf("%s.$(ABI_VERSION)", lib_name);
163                                 rel_name = sprintf("%s.$(REL_VERSION)", lib_name);
164                                 if ( DoLinks == "reverse") {
165                                         end_name = lib_name;
166                                 } else {
167                                         if ( ShlibVer == "rel" ) {
168                                                 end_name = rel_name;
169                                         } else if ( ShlibVer == "abi" ) {
170                                                 end_name = abi_name;
171                                         } else {
172                                                 end_name = lib_name;
173                                         }
174                                 }
175                                 printf "../lib/%s : $(%s_OBJS)\n", end_name, OBJS
176                                 print  "\t-@rm -f $@"
177                                 if ( subset == "termlib") {
178                                         printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(TINFO_LIST)\n", OBJS
179                                 } else {
180                                         printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(SHLIB_LIST)\n", OBJS
181                                 }
182                                 sharedlinks("../lib")
183                                 print  ""
184                                 print  "install \\"
185                                 print  "install.libs \\"
186                                 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, end_name
187                                 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", end_name, end_name
188                                 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", end_name
189                                 printf "\t$(INSTALL_LIB) ../lib/%s $(DESTDIR)$(libdir)/%s\n", end_name, end_name
190                                 sharedlinks("$(DESTDIR)$(libdir)")
191                                 if ( overwrite == "yes" && name == "ncurses" )
192                                 {
193                                         ovr_name = sprintf("libcurses%s", suffix)
194                                         printf "\t@echo linking %s to %s\n", end_name, ovr_name
195                                         printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, end_name, ovr_name
196                                 }
197                                 if ( ldconfig != "" ) {
198                                         printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
199                                 }
200                                 print  ""
201                                 print  "uninstall \\"
202                                 print  "uninstall.libs \\"
203                                 printf "uninstall.%s ::\n", name
204                                 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
205                                 removelinks("$(DESTDIR)$(libdir)")
206                                 if ( overwrite == "yes" && name == "ncurses" )
207                                 {
208                                         ovr_name = sprintf("libcurses%s", suffix)
209                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
210                                 }
211                                 if ( rmSoLocs == "yes" ) {
212                                         print  ""
213                                         print  "mostlyclean \\"
214                                         print  "clean ::"
215                                         printf "\t-@rm -f so_locations\n"
216                                 }
217                         }
218                         else if ( MODEL == "LIBTOOL" )
219                         {
220                                 if ( $2 == "c++" ) {
221                                         compile="CXX"
222                                 } else {
223                                         compile="CC"
224                                 }
225                                 end_name = lib_name;
226                                 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
227                                 printf "\tcd ../lib && $(LIBTOOL) $(%s) -o %s $(%s_OBJS:.o=.lo) -rpath $(DESTDIR)$(libdir) -version-info $(NCURSES_MAJOR):$(NCURSES_MINOR)\n", compile, lib_name, OBJS
228                                 print  ""
229                                 print  "install \\"
230                                 print  "install.libs \\"
231                                 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
232                                 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
233                                 printf "\tcd ../lib; $(LIBTOOL) $(INSTALL_DATA) %s $(DESTDIR)$(libdir)\n", lib_name
234                                 print  ""
235                                 print  "uninstall \\"
236                                 print  "uninstall.libs \\"
237                                 printf "uninstall.%s ::\n", name
238                                 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
239                                 printf "\t-@$(LIBTOOL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
240                         }
241                         else
242                         {
243                                 end_name = lib_name;
244                                 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
245                                 printf "\t$(AR) $(AR_OPTS) $@ $?\n"
246                                 printf "\t$(RANLIB) $@\n"
247                                 if ( target == "vxworks" )
248                                 {
249                                         printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=.o)\n"
250                                 }
251                                 print  ""
252                                 print  "install \\"
253                                 print  "install.libs \\"
254                                 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
255                                 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
256                                 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
257                                 if ( overwrite == "yes" && lib_name == "libncurses.a" )
258                                 {
259                                         printf "\t@echo linking libcurses.a to libncurses.a\n"
260                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
261                                         printf "\t(cd $(DESTDIR)$(libdir) && $(LN_S) libncurses.a libcurses.a)\n"
262                                 }
263                                 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
264                                 if ( target == "vxworks" )
265                                 {
266                                         printf "\t@echo installing ../lib/lib%s.o as $(DESTDIR)$(libdir)/lib%s.o\n", name, name
267                                         printf "\t$(INSTALL_DATA) ../lib/lib%s.o $(DESTDIR)$(libdir)/lib%s.o\n", name, name
268                                 }
269                                 print  ""
270                                 print  "uninstall \\"
271                                 print  "uninstall.libs \\"
272                                 printf "uninstall.%s ::\n", name
273                                 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
274                                 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
275                                 if ( overwrite == "yes" && lib_name == "libncurses.a" )
276                                 {
277                                         printf "\t@echo linking libcurses.a to libncurses.a\n"
278                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
279                                 }
280                                 if ( target == "vxworks" )
281                                 {
282                                         printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s.o\n", name
283                                         printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s.o\n", name
284                                 }
285                         }
286                         print ""
287                         print "clean ::"
288                         removelinks("../lib");
289                         print ""
290                         print "mostlyclean::"
291                         printf "\t-rm -f $(%s_OBJS)\n", OBJS
292                         if ( MODEL == "LIBTOOL" ) {
293                                 printf "\t-rm -f $(%s_OBJS:.o=.lo)\n", OBJS
294                         }
295                 }
296                 else if ( found == 2 )
297                 {
298                         print ""
299                         print "mostlyclean::"
300                         printf "\t-rm -f $(%s_OBJS)\n", OBJS
301                         if ( MODEL == "LIBTOOL" ) {
302                                 printf "\t-rm -f $(%s_OBJS:.o=.lo)\n", OBJS
303                         }
304                         print ""
305                         print "clean ::"
306                         printf "\t-rm -f $(%s_OBJS)\n", OBJS
307                         if ( MODEL == "LIBTOOL" ) {
308                                 printf "\t-rm -f $(%s_OBJS:.o=.lo)\n", OBJS
309                         }
310                 }
311         }