1 # $Id: mk-1st.awk,v 1.73 2007/02/17 21:31:09 tom Exp $
2 ##############################################################################
3 # Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. #
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: #
13 # The above copyright notice and this permission notice shall be included in #
14 # all copies or substantial portions of the Software. #
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. #
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 #
28 ##############################################################################
30 # Author: Thomas E. Dickey
32 # Generate list of objects for a given model library
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", etc.)
41 # ShlibVer ("rel", "abi" or "auto", to augment DoLinks variable)
42 # ShlibVerInfix ("yes" or "no", determines location of version #)
43 # TermlibRoot ("tinfo" or other root for libterm.so)
44 # ReLink ("yes", or "no", flag to rebuild shared libs on install)
45 # DoLinks ("yes", "reverse" or "no", flag to add symbolic links)
46 # rmSoLocs ("yes" or "no", flag to add extra clean target)
47 # ldconfig (path for this tool, if used)
48 # overwrite ("yes" or "no", flag to add link to libcurses.a
49 # depend (optional dependencies for all objects, e.g, ncurses_cfg.h)
50 # host (cross-compile host, if any)
53 # CLIXs nawk does not like underscores in command-line variable names.
54 # Mixed-case variable names are ok.
55 # HP/UX requires shared libraries to have executable permissions.
57 function is_ticlib() {
58 return ( subset ~ /^ticlib$/ );
60 function is_termlib() {
61 return ( subset ~ /^(ticlib\+)?termlib(\+ext_tinfo)?$/ );
64 function lib_name_of(a_name) {
65 return sprintf("%s%s%s", prefix, a_name, suffix)
68 function imp_name_of(a_name) {
69 if (ShlibVerInfix == "cygdll") {
70 result = sprintf("%s%s%s.a", prefix, a_name, suffix);
77 function abi_name_of(a_name) {
78 if (ShlibVerInfix == "cygdll") {
79 result = sprintf("%s%s$(ABI_VERSION)%s", "cyg", a_name, suffix);
80 } else if (ShlibVerInfix == "yes") {
81 result = sprintf("%s%s.$(ABI_VERSION)%s", prefix, a_name, suffix);
83 result = sprintf("%s.$(ABI_VERSION)", lib_name_of(a_name));
88 function rel_name_of(a_name) {
89 if (ShlibVerInfix == "cygdll") {
90 result = sprintf("%s%s$(REL_VERSION)%s", "cyg", a_name, suffix);
91 } else if (ShlibVerInfix == "yes") {
92 result = sprintf("%s%s.$(REL_VERSION)%s", prefix, a_name, suffix);
94 result = sprintf("%s.$(REL_VERSION)", lib_name_of(a_name));
99 function end_name_of(a_name) {
100 if ( MODEL != "SHARED" ) {
101 result = lib_name_of(a_name);
102 } else if ( DoLinks == "reverse") {
103 result = lib_name_of(a_name);
105 if ( ShlibVer == "rel" ) {
106 result = rel_name_of(a_name);
107 } else if ( ShlibVer == "abi" || ShlibVer == "cygdll" ) {
108 result = abi_name_of(a_name);
110 result = lib_name_of(a_name);
115 function symlink(src,dst) {
117 printf "rm -f %s; ", dst
118 printf "$(LN_S) %s %s; ", src, dst
121 function rmlink(directory, dst) {
122 printf "\t-rm -f %s/%s\n", directory, dst
124 function removelinks(directory) {
125 rmlink(directory, end_name);
126 if ( DoLinks == "reverse" ) {
127 if ( ShlibVer == "rel" ) {
128 rmlink(directory, abi_name);
129 rmlink(directory, rel_name);
130 } else if ( ShlibVer == "abi" ) {
131 rmlink(directory, abi_name);
134 if ( ShlibVer == "rel" ) {
135 rmlink(directory, abi_name);
136 rmlink(directory, lib_name);
137 } else if ( ShlibVer == "abi" ) {
138 rmlink(directory, lib_name);
142 function make_shlib(objs, shlib_list) {
143 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(%s) $(LDFLAGS)\n", objs, shlib_list
145 function sharedlinks(directory) {
146 if ( ShlibVer != "auto" && ShlibVer != "cygdll" ) {
147 printf "\tcd %s && (", directory
148 if ( DoLinks == "reverse" ) {
149 if ( ShlibVer == "rel" ) {
150 symlink(lib_name, abi_name);
151 symlink(abi_name, rel_name);
152 } else if ( ShlibVer == "abi" ) {
153 symlink(lib_name, abi_name);
156 if ( ShlibVer == "rel" ) {
157 symlink(rel_name, abi_name);
158 symlink(abi_name, lib_name);
159 } else if ( ShlibVer == "abi" ) {
160 symlink(abi_name, lib_name);
166 function shlib_build(directory) {
167 if ( ShlibVer == "cygdll" ) {
168 dst_libs = sprintf("%s/$(SHARED_LIB) %s/$(IMPORT_LIB)", directory, directory);
170 dst_libs = sprintf("%s/%s", directory, end_name);
172 printf "%s : \\\n", dst_libs
173 printf "\t\t%s \\\n", directory
174 if (subset ~ /^base/ || subset == "ticlib" ) {
176 sub(/^[^.]\./,".",suffix)
177 if (directory != "../lib") {
178 printf "\t\t%s/%s \\\n", "../lib", end_name_of(TermlibRoot);
180 printf "\t\t%s/%s \\\n", directory, end_name_of(TermlibRoot);
183 printf "\t\t$(%s_OBJS)\n", OBJS
184 printf "\t@echo linking $@\n"
185 print "\t-@rm -f %s", dst_libs;
187 make_shlib(OBJS, "TICS_LIST")
188 } else if ( is_termlib() ) {
189 make_shlib(OBJS, "TINFO_LIST")
191 make_shlib(OBJS, "SHLIB_LIST")
193 sharedlinks(directory)
195 function shlib_install(directory) {
196 if ( ShlibVer == "cygdll" ) {
197 src_lib1 = sprintf("%s/$(SHARED_LIB)", "../lib");
198 src_lib2 = sprintf("%s/$(IMPORT_LIB)", "../lib");
199 src_libs = sprintf("%s %s", src_lib1, src_lib2);
200 dst_lib1 = sprintf("%s/$(SHARED_LIB)", directory);
201 dst_lib2 = sprintf("%s/$(IMPORT_LIB)", directory);
202 dst_libs = sprintf("%s %s", dst_lib1, dst_lib2);
204 src_lib1 = sprintf("../lib/%s", end_name);
207 dst_lib1 = sprintf("%s/%s", directory, end_name);
210 printf "%s : \\\n", dst_libs
211 printf "\t\t%s \\\n", directory
212 printf "\t\t%s\n", src_libs
213 printf "\t@echo installing $@\n"
214 print "\t-@rm -f %s", dst_libs;
215 printf "\t$(INSTALL_LIB) %s %s\n", src_lib1, dst_lib1;
216 if ( src_lib2 != "" ) {
217 printf "\t$(INSTALL_LIB) %s %s\n", src_lib2, dst_lib2;
219 sharedlinks(directory)
221 function install_dll(directory,filename) {
222 src_name = sprintf("../lib/%s", filename);
223 dst_name = sprintf("$(DESTDIR)%s/%s", directory, filename);
224 printf "\t@echo installing %s as %s\n", src_name, dst_name
225 printf "\t-@rm -f %s\n", dst_name
226 if ( directory == "$(bindir)" ) {
227 program = "$(INSTALL) -m 755";
229 program = "$(INSTALL_LIB)";
231 printf "\t%s %s %s\n", program, src_name, dst_name
239 if (subset == "none") {
241 } else if (index(subset,$2) > 0) {
245 printf "# generated by mk-1st.awk (subset=%s)\n", subset
246 printf "# name: %s\n", name
247 printf "# traces: %s\n", traces
248 printf "# MODEL: %s\n", MODEL
249 printf "# model: %s\n", model
250 printf "# prefix: %s\n", prefix
251 printf "# suffix: %s\n", suffix
252 printf "# subset: %s\n", subset
253 printf "# ShlibVer: %s\n", ShlibVer
254 printf "# ShlibVerInfix: %s\n", ShlibVerInfix
255 printf "# TermlibRoot: %s\n", TermlibRoot
256 printf "# ReLink: %s\n", ReLink
257 printf "# DoLinks: %s\n", DoLinks
258 printf "# rmSoLocs: %s\n", rmSoLocs
259 printf "# ldconfig: %s\n", ldconfig
260 printf "# overwrite: %s\n", overwrite
261 printf "# depend: %s\n", depend
262 printf "# host: %s\n", host
269 } else if ( is_termlib() ) {
280 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
285 && ( $1 != "link_test" ) \
293 printf "%s_OBJS =", OBJS
299 printf " \\\n\t../%s/%s$o", model, $1
306 printf "\n$(%s_OBJS) : %s\n", OBJS, depend
311 lib_name = lib_name_of(name);
312 if ( MODEL == "SHARED" )
314 abi_name = abi_name_of(name);
315 rel_name = rel_name_of(name);
316 imp_name = imp_name_of(name);
317 end_name = end_name_of(name);
319 shlib_build("../lib")
323 print "install.libs \\"
325 if ( ShlibVer == "cygdll" ) {
327 dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
328 printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs
329 install_dll("$(bindir)",end_name);
330 install_dll("$(libdir)",imp_name);
334 lib_dir = "$(DESTDIR)$(libdir)";
335 printf "install.%s :: %s/%s\n", name, lib_dir, end_name
337 if ( ReLink == "yes" ) {
340 shlib_install(lib_dir)
344 if ( overwrite == "yes" && name == "ncurses" )
346 if ( ShlibVer == "cygdll" ) {
347 ovr_name = sprintf("libcurses%s.a", suffix)
348 printf "\t@echo linking %s to %s\n", imp_name, ovr_name
349 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, imp_name, ovr_name
351 ovr_name = sprintf("libcurses%s", suffix)
352 printf "\t@echo linking %s to %s\n", end_name, ovr_name
353 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, end_name, ovr_name
356 if ( ldconfig != "" && ldconfig != ":" ) {
357 printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
361 print "uninstall.libs \\"
362 printf "uninstall.%s ::\n", name
363 if ( ShlibVer == "cygdll" ) {
365 printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
366 printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
368 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
369 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
372 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
373 removelinks("$(DESTDIR)$(libdir)")
374 if ( overwrite == "yes" && name == "ncurses" )
376 if ( ShlibVer == "cygdll" ) {
377 ovr_name = sprintf("libcurses%s.a", suffix)
379 ovr_name = sprintf("libcurses%s", suffix)
381 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
384 if ( rmSoLocs == "yes" ) {
386 print "mostlyclean \\"
388 printf "\t-@rm -f so_locations\n"
391 else if ( MODEL == "LIBTOOL" )
399 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
400 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
403 print "install.libs \\"
404 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
405 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
406 printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
409 print "uninstall.libs \\"
410 printf "uninstall.%s ::\n", name
411 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
412 printf "\t-@$(LIBTOOL_UNINSTALL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
417 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
418 printf "\t$(AR) $(AR_OPTS) $@ $?\n"
419 printf "\t$(RANLIB) $@\n"
420 if ( host == "vxworks" )
422 printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
426 print "install.libs \\"
427 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
428 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
429 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
430 if ( overwrite == "yes" && lib_name == "libncurses.a" )
432 printf "\t@echo linking libcurses.a to libncurses.a\n"
433 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
434 printf "\t(cd $(DESTDIR)$(libdir) && $(LN_S) libncurses.a libcurses.a)\n"
436 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
437 if ( host == "vxworks" )
439 printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name, name
440 printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name, name
444 print "uninstall.libs \\"
445 printf "uninstall.%s ::\n", name
446 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
447 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
448 if ( overwrite == "yes" && lib_name == "libncurses.a" )
450 printf "\t@echo linking libcurses.a to libncurses.a\n"
451 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
453 if ( host == "vxworks" )
455 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
456 printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
461 removelinks("../lib");
463 print "mostlyclean::"
464 printf "\t-rm -f $(%s_OBJS)\n", OBJS
465 if ( MODEL == "LIBTOOL" ) {
466 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
469 else if ( found == 2 )
472 print "mostlyclean::"
473 printf "\t-rm -f $(%s_OBJS)\n", OBJS
474 if ( MODEL == "LIBTOOL" ) {
475 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
479 printf "\t-rm -f $(%s_OBJS)\n", OBJS
480 if ( MODEL == "LIBTOOL" ) {
481 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS