c35933bdb23a6153ea1c75980356505f520a5a76
[ncurses.git] / mk-1st.awk
1 # $Id: mk-1st.awk,v 1.35 1998/02/11 12:13:53 tom Exp $
2 ##############################################################################
3 # Copyright (c) 1998 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
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 #       DoLinks ("yes" or "no", flag to add symbolic links)
43 #       rmSoLocs ("yes" or "no", flag to add extra clean target)
44 #       overwrite ("yes" or "no", flag to add link to libcurses.a
45 #
46 # Notes:
47 #       CLIXs nawk does not like underscores in command-line variable names.
48 #       Mixed-case is ok.
49 #       HP/UX requires shared libraries to have executable permissions.
50 #
51 function symlink(src,dst) {
52                 if ( src != dst ) {
53                         printf "rm -f %s; ", dst
54                         printf "$(LN_S) %s %s; ", src, dst
55                 }
56         }
57 function sharedlinks(directory, add) {
58                 if ( end_name != lib_name ) {
59                         abi_name = sprintf("%s.$(ABI_VERSION)", lib_name);
60                         if (add) {
61                                 printf "\tcd %s && (", directory
62                                 symlink(end_name, abi_name);
63                                 symlink(abi_name, lib_name);
64                                 printf ")\n"
65                         } else {
66                                 printf "\t-@rm -f %s/%s\n", directory, abi_name
67                                 printf "\t-@rm -f %s/%s\n", directory, lib_name
68                         }
69                 }
70         }
71 function removelinks() {
72                 if ( end_name != lib_name ) {
73                         printf "\trm -f ../lib/%s ../lib/%s\n", abi_name, end_name
74                 }
75         }
76 function installed_name() {
77                 if ( DO_LINKS == "yes" ) {
78                         return sprintf("%s.$(REL_VERSION)", lib_name);
79                 } else {
80                         return lib_name;
81                 }
82         }
83 BEGIN   {
84                 found = 0
85                 using = 0
86         }
87         /^@/ {
88                 using = 0
89                 if (subset == "none") {
90                         using = 1
91                 } else if (index(subset,$2) > 0) {
92                         if (using == 0) {
93                                 if (found == 0) {
94                                         print  ""
95                                         print  "# generated by mk-1st.awk"
96                                         print  ""
97                                 }
98                                 using = 1
99                         }
100                         if ( subset == "termlib") {
101                                 name  = "tinfo"
102                                 OBJS  = MODEL "_T"
103                         } else {
104                                 OBJS  = MODEL
105                         }
106                 }
107         }
108         !/^[@#]/ {
109                 if (using \
110                  && ( $2 == "lib" \
111                    || $2 == "progs" \
112                    || $2 == "c++" \
113                    || $2 == "tack" ))
114                 {
115                         if ( found == 0 )
116                         {
117                                 printf "%s_OBJS =", OBJS
118                                 if ( $2 == "lib" )
119                                         found = 1
120                                 else
121                                         found = 2
122                         }
123                         printf " \\\n\t../%s/%s.o", model, $1
124                 }
125         }
126 END     {
127                 print  ""
128                 if ( found != 0 )
129                 {
130                         printf "\n$(%s_OBJS) : %s\n", OBJS, depend
131                 }
132                 if ( found == 1 )
133                 {
134                         print  ""
135                         lib_name = sprintf("%s%s%s", prefix, name, suffix)
136                         if ( MODEL == "SHARED" )
137                         {
138                                 if ( DoLinks == "yes" ) {
139                                         end_name = sprintf("%s.$(REL_VERSION)", lib_name);
140                                 } else {
141                                         end_name = lib_name;
142                                 }
143                                 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
144                                 print  "\t-@rm -f $@"
145                                 printf "\t$(MK_SHARED_LIB) $(%s_OBJS)\n", OBJS
146                                 sharedlinks("../lib", 1)
147                                 print  ""
148                                 if ( end_name != lib_name ) {
149                                         printf "../lib/%s : ../lib/%s\n", end_name, lib_name
150                                 }
151                                 print  ""
152                                 print  "install \\"
153                                 print  "install.libs \\"
154                                 printf "install.%s :: $(INSTALL_PREFIX)$(libdir) ../lib/%s\n", name, end_name
155                                 printf "\t@echo installing ../lib/%s as $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name, end_name
156                                 printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/%s \n", end_name
157                                 printf "\t$(INSTALL_LIB) ../lib/%s $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name, end_name
158                                 sharedlinks("$(INSTALL_PREFIX)$(libdir)", 1)
159                                 if ( overwrite == "yes" && name == "ncurses" )
160                                 {
161                                         ovr_name = sprintf("libcurses%s", suffix)
162                                         printf "\t@echo linking %s to %s\n", ovr_name, lib_name
163                                         printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/%s \n", ovr_name
164                                         printf "\t(cd $(INSTALL_PREFIX)$(libdir) && $(LN_S) %s %s)\n", lib_name, ovr_name
165                                 }
166                                 if ( ldconfig != "" ) {
167                                         printf "\t- test -z \"$(INSTALL_PREFIX)\" && %s\n", ldconfig
168                                 }
169                                 print  ""
170                                 print  "uninstall \\"
171                                 print  "uninstall.libs \\"
172                                 printf "uninstall.%s ::\n", name
173                                 printf "\t@echo uninstalling $(INSTALL_PREFIX)$(libdir)/%s \n", end_name
174                                 printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/%s\n", end_name
175                                 sharedlinks("$(INSTALL_PREFIX)$(libdir)", 0)
176                                 if ( overwrite == "yes" && name == "ncurses" )
177                                 {
178                                         ovr_name = sprintf("libcurses%s", suffix)
179                                         printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/%s \n", ovr_name
180                                 }
181                                 if ( rmSoLocs == "yes" ) {
182                                         print  ""
183                                         print  "mostlyclean \\"
184                                         print  "clean ::"
185                                         printf "\t-@rm -f so_locations\n"
186                                 }
187                         }
188                         else
189                         {
190                                 end_name = lib_name;
191                                 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
192                                 printf "\t$(AR) $(AR_OPTS) $@ $?\n"
193                                 printf "\t$(RANLIB) $@\n"
194                                 if ( target == "vxworks" )
195                                 {
196                                         printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=.o)\n"
197                                 }
198                                 print  ""
199                                 print  "install \\"
200                                 print  "install.libs \\"
201                                 printf "install.%s :: $(INSTALL_PREFIX)$(libdir) ../lib/%s\n", name, lib_name
202                                 printf "\t@echo installing ../lib/%s as $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name, lib_name
203                                 printf "\t$(INSTALL_DATA) ../lib/%s $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name, lib_name
204                                 if ( overwrite == "yes" && lib_name == "libncurses.a" )
205                                 {
206                                         printf "\t@echo linking libcurses.a to libncurses.a \n"
207                                         printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/libcurses.a \n"
208                                         printf "\t(cd $(INSTALL_PREFIX)$(libdir) && $(LN_S) libncurses.a libcurses.a)\n"
209                                 }
210                                 printf "\t$(RANLIB) $(INSTALL_PREFIX)$(libdir)/%s\n", lib_name
211                                 if ( target == "vxworks" )
212                                 {
213                                         printf "\t@echo installing ../lib/lib%s.o as $(INSTALL_PREFIX)$(libdir)/lib%s.o\n", name, name
214                                         printf "\t$(INSTALL_DATA) ../lib/lib%s.o $(INSTALL_PREFIX)$(libdir)/lib%s.o\n", name, name
215                                 }
216                                 print  ""
217                                 print  "uninstall \\"
218                                 print  "uninstall.libs \\"
219                                 printf "uninstall.%s ::\n", name
220                                 printf "\t@echo uninstalling $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name
221                                 printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/%s\n", lib_name
222                                 if ( overwrite == "yes" && lib_name == "libncurses.a" )
223                                 {
224                                         printf "\t@echo linking libcurses.a to libncurses.a \n"
225                                         printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/libcurses.a \n"
226                                 }
227                                 if ( target == "vxworks" )
228                                 {
229                                         printf "\t@echo uninstalling $(INSTALL_PREFIX)$(libdir)/lib%s.o\n", name
230                                         printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/lib%s.o\n", name
231                                 }
232                         }
233                         print ""
234                         print "clean ::"
235                         printf "\trm -f ../lib/%s\n", lib_name
236                         print ""
237                         print "mostlyclean::"
238                         printf "\trm -f $(%s_OBJS)\n", OBJS
239                         print ""
240                         print "clean ::"
241                         printf "\trm -f $(%s_OBJS)\n", OBJS
242                         removelinks();
243                 }
244                 else if ( found == 2 )
245                 {
246                         print ""
247                         print "mostlyclean::"
248                         printf "\trm -f $(%s_OBJS)\n", OBJS
249                         print ""
250                         print "clean ::"
251                         printf "\trm -f $(%s_OBJS)\n", OBJS
252                 }
253         }