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