]> ncurses.scripts.mit.edu Git - ncurses.git/blob - mk-1st.awk
ncurses 5.0
[ncurses.git] / mk-1st.awk
1 # $Id: mk-1st.awk,v 1.39 1998/05/09 21:54:02 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", "reverse" 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                         if ( DoLinks == "reverse" ) {
54                                 printf "rm -f %s; ", src
55                                 printf "$(LN_S) %s %s; ", dst, src
56                         } else {
57                                 printf "rm -f %s; ", dst
58                                 printf "$(LN_S) %s %s; ", src, dst
59                         }
60                 }
61         }
62 function sharedlinks(directory, add) {
63                 if ( end_name != lib_name ) {
64                         if ( DoLinks == "yes" ) {
65                                 abi_name = sprintf("%s.$(ABI_VERSION)", lib_name);
66                         } else {
67                                 abi_name = end_name;
68                         }
69                         if (add) {
70                                 printf "\tcd %s && (", directory
71                                 if ( abi_name != end_name ) {
72                                         symlink(end_name, abi_name);
73                                 }
74                                 symlink(abi_name, lib_name);
75                                 printf ")\n"
76                         } else {
77                                 if ( abi_name != end_name ) {
78                                         printf "\t-@rm -f %s/%s\n", directory, abi_name
79                                 }
80                                 printf "\t-@rm -f %s/%s\n", directory, lib_name
81                         }
82                 }
83         }
84 function removelinks() {
85                 if ( end_name != lib_name ) {
86                         if ( abi_name != end_name ) {
87                                 printf "\t-rm -f ../lib/%s\n", abi_name
88                         }
89                         printf "\t-rm -f ../lib/%s\n", end_name
90                 }
91         }
92 BEGIN   {
93                 found = 0
94                 using = 0
95         }
96         /^@/ {
97                 using = 0
98                 if (subset == "none") {
99                         using = 1
100                 } else if (index(subset,$2) > 0) {
101                         if (using == 0) {
102                                 if (found == 0) {
103                                         print  ""
104                                         print  "# generated by mk-1st.awk"
105                                         print  ""
106                                 }
107                                 using = 1
108                         }
109                         if ( subset == "termlib") {
110                                 name  = "tinfo"
111                                 OBJS  = MODEL "_T"
112                         } else {
113                                 OBJS  = MODEL
114                         }
115                 }
116         }
117         !/^[@#]/ {
118                 if (using \
119                  && ( $2 == "lib" \
120                    || $2 == "progs" \
121                    || $2 == "c++" \
122                    || $2 == "tack" ))
123                 {
124                         if ( found == 0 )
125                         {
126                                 printf "%s_OBJS =", OBJS
127                                 if ( $2 == "lib" )
128                                         found = 1
129                                 else
130                                         found = 2
131                         }
132                         printf " \\\n\t../%s/%s.o", model, $1
133                 }
134         }
135 END     {
136                 print  ""
137                 if ( found != 0 )
138                 {
139                         printf "\n$(%s_OBJS) : %s\n", OBJS, depend
140                 }
141                 if ( found == 1 )
142                 {
143                         print  ""
144                         lib_name = sprintf("%s%s%s", prefix, name, suffix)
145                         if ( MODEL == "SHARED" )
146                         {
147                                 if ( DoLinks == "yes" ) {
148                                         end_name = sprintf("%s.$(REL_VERSION)", lib_name);
149                                 } else if ( DoLinks == "reverse") {
150                                         tmp_name = sprintf("%s.$(ABI_VERSION)", lib_name);
151                                         end_name = lib_name;
152                                         lib_name = tmp_name;
153                                 } else {
154                                         end_name = lib_name;
155                                 }
156                                 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
157                                 print  "\t-@rm -f $@"
158                                 if ( subset == "termlib") {
159                                         printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(TINFO_LIST)\n", OBJS
160                                 } else {
161                                         printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(SHLIB_LIST)\n", OBJS
162                                 }
163                                 sharedlinks("../lib", 1)
164                                 print  ""
165                                 if ( end_name != lib_name ) {
166                                         printf "../lib/%s : ../lib/%s\n", end_name, lib_name
167                                 }
168                                 print  ""
169                                 print  "install \\"
170                                 print  "install.libs \\"
171                                 printf "install.%s :: $(INSTALL_PREFIX)$(libdir) ../lib/%s\n", name, end_name
172                                 printf "\t@echo installing ../lib/%s as $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name, end_name
173                                 if ( DoLinks == "reverse") {
174                                         printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name
175                                         printf "\t$(INSTALL_LIB) ../lib/%s $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name, lib_name
176                                 } else {
177                                         printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/%s \n", end_name
178                                         printf "\t$(INSTALL_LIB) ../lib/%s $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name, end_name
179                                 }
180                                 sharedlinks("$(INSTALL_PREFIX)$(libdir)", 1)
181                                 if ( overwrite == "yes" && name == "ncurses" )
182                                 {
183                                         ovr_name = sprintf("libcurses%s", suffix)
184                                         printf "\t@echo linking %s to %s\n", lib_name, ovr_name
185                                         printf "\tcd $(INSTALL_PREFIX)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, lib_name, ovr_name
186                                 }
187                                 if ( ldconfig != "" ) {
188                                         printf "\t- test -z \"$(INSTALL_PREFIX)\" && %s\n", ldconfig
189                                 }
190                                 print  ""
191                                 print  "uninstall \\"
192                                 print  "uninstall.libs \\"
193                                 printf "uninstall.%s ::\n", name
194                                 printf "\t@echo uninstalling $(INSTALL_PREFIX)$(libdir)/%s \n", end_name
195                                 printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/%s\n", end_name
196                                 sharedlinks("$(INSTALL_PREFIX)$(libdir)", 0)
197                                 if ( overwrite == "yes" && name == "ncurses" )
198                                 {
199                                         ovr_name = sprintf("libcurses%s", suffix)
200                                         printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/%s \n", ovr_name
201                                 }
202                                 if ( rmSoLocs == "yes" ) {
203                                         print  ""
204                                         print  "mostlyclean \\"
205                                         print  "clean ::"
206                                         printf "\t-@rm -f so_locations\n"
207                                 }
208                         }
209                         else
210                         {
211                                 end_name = lib_name;
212                                 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
213                                 printf "\t$(AR) $(AR_OPTS) $@ $?\n"
214                                 printf "\t$(RANLIB) $@\n"
215                                 if ( target == "vxworks" )
216                                 {
217                                         printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=.o)\n"
218                                 }
219                                 print  ""
220                                 print  "install \\"
221                                 print  "install.libs \\"
222                                 printf "install.%s :: $(INSTALL_PREFIX)$(libdir) ../lib/%s\n", name, lib_name
223                                 printf "\t@echo installing ../lib/%s as $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name, lib_name
224                                 printf "\t$(INSTALL_DATA) ../lib/%s $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name, lib_name
225                                 if ( overwrite == "yes" && lib_name == "libncurses.a" )
226                                 {
227                                         printf "\t@echo linking libcurses.a to libncurses.a \n"
228                                         printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/libcurses.a \n"
229                                         printf "\t(cd $(INSTALL_PREFIX)$(libdir) && $(LN_S) libncurses.a libcurses.a)\n"
230                                 }
231                                 printf "\t$(RANLIB) $(INSTALL_PREFIX)$(libdir)/%s\n", lib_name
232                                 if ( target == "vxworks" )
233                                 {
234                                         printf "\t@echo installing ../lib/lib%s.o as $(INSTALL_PREFIX)$(libdir)/lib%s.o\n", name, name
235                                         printf "\t$(INSTALL_DATA) ../lib/lib%s.o $(INSTALL_PREFIX)$(libdir)/lib%s.o\n", name, name
236                                 }
237                                 print  ""
238                                 print  "uninstall \\"
239                                 print  "uninstall.libs \\"
240                                 printf "uninstall.%s ::\n", name
241                                 printf "\t@echo uninstalling $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name
242                                 printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/%s\n", lib_name
243                                 if ( overwrite == "yes" && lib_name == "libncurses.a" )
244                                 {
245                                         printf "\t@echo linking libcurses.a to libncurses.a \n"
246                                         printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/libcurses.a \n"
247                                 }
248                                 if ( target == "vxworks" )
249                                 {
250                                         printf "\t@echo uninstalling $(INSTALL_PREFIX)$(libdir)/lib%s.o\n", name
251                                         printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/lib%s.o\n", name
252                                 }
253                         }
254                         print ""
255                         print "clean ::"
256                         printf "\t-rm -f ../lib/%s\n", lib_name
257                         print ""
258                         print "mostlyclean::"
259                         printf "\t-rm -f $(%s_OBJS)\n", OBJS
260                         print ""
261                         print "clean ::"
262                         removelinks();
263                 }
264                 else if ( found == 2 )
265                 {
266                         print ""
267                         print "mostlyclean::"
268                         printf "\t-rm -f $(%s_OBJS)\n", OBJS
269                         print ""
270                         print "clean ::"
271                         printf "\t-rm -f $(%s_OBJS)\n", OBJS
272                 }
273         }