1 # $Id: mk-1st.awk,v 1.77 2007/03/11 13:37:22 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 dst_libs = sprintf("%s/%s", directory, end_name);
168 printf "%s : \\\n", dst_libs
169 printf "\t\t%s \\\n", directory
170 if (subset ~ /^base/ || subset == "ticlib" ) {
172 sub(/^[^.]\./,".",suffix)
173 if (directory != "../lib") {
174 printf "\t\t%s/%s \\\n", "../lib", end_name_of(TermlibRoot);
176 printf "\t\t%s/%s \\\n", directory, end_name_of(TermlibRoot);
179 printf "\t\t$(%s_OBJS)\n", OBJS
180 printf "\t@echo linking $@\n"
182 make_shlib(OBJS, "TICS_LIST")
183 } else if ( is_termlib() ) {
184 make_shlib(OBJS, "TINFO_LIST")
186 make_shlib(OBJS, "SHLIB_LIST")
188 sharedlinks(directory)
190 function shlib_install(directory) {
191 src_lib1 = sprintf("../lib/%s", end_name);
192 dst_lib1 = sprintf("%s/%s", directory, end_name);
193 printf "%s : \\\n", dst_lib1
194 printf "\t\t%s \\\n", directory
195 printf "\t\t%s\n", src_lib1
196 printf "\t@echo installing $@\n"
197 printf "\t$(INSTALL_LIB) %s %s\n", src_lib1, dst_lib1;
198 sharedlinks(directory)
200 function install_dll(directory,filename) {
201 src_name = sprintf("../lib/%s", filename);
202 dst_name = sprintf("$(DESTDIR)%s/%s", directory, filename);
203 printf "\t@echo installing %s as %s\n", src_name, dst_name
204 if ( directory == "$(bindir)" ) {
205 program = "$(INSTALL) -m 755";
207 program = "$(INSTALL_LIB)";
209 printf "\t%s %s %s\n", program, src_name, dst_name
217 if (subset == "none") {
219 } else if (index(subset,$2) > 0) {
223 printf "# generated by mk-1st.awk (subset=%s)\n", subset
224 printf "# name: %s\n", name
225 printf "# traces: %s\n", traces
226 printf "# MODEL: %s\n", MODEL
227 printf "# model: %s\n", model
228 printf "# prefix: %s\n", prefix
229 printf "# suffix: %s\n", suffix
230 printf "# subset: %s\n", subset
231 printf "# ShlibVer: %s\n", ShlibVer
232 printf "# ShlibVerInfix: %s\n", ShlibVerInfix
233 printf "# TermlibRoot: %s\n", TermlibRoot
234 printf "# ReLink: %s\n", ReLink
235 printf "# DoLinks: %s\n", DoLinks
236 printf "# rmSoLocs: %s\n", rmSoLocs
237 printf "# ldconfig: %s\n", ldconfig
238 printf "# overwrite: %s\n", overwrite
239 printf "# depend: %s\n", depend
240 printf "# host: %s\n", host
247 } else if ( is_termlib() ) {
258 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
263 && ( $1 != "link_test" ) \
271 printf "%s_OBJS =", OBJS
277 printf " \\\n\t../%s/%s$o", model, $1
284 printf "\n$(%s_OBJS) : %s\n", OBJS, depend
289 lib_name = lib_name_of(name);
290 if ( MODEL == "SHARED" )
292 abi_name = abi_name_of(name);
293 rel_name = rel_name_of(name);
294 imp_name = imp_name_of(name);
295 end_name = end_name_of(name);
297 shlib_build("../lib")
301 print "install.libs \\"
303 if ( ShlibVer == "cygdll" ) {
305 dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
306 printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs
307 install_dll("$(bindir)",end_name);
308 install_dll("$(libdir)",imp_name);
312 lib_dir = "$(DESTDIR)$(libdir)";
313 printf "install.%s :: %s/%s\n", name, lib_dir, end_name
315 if ( ReLink == "yes" ) {
318 shlib_install(lib_dir)
322 if ( overwrite == "yes" && name == "ncurses" )
324 if ( ShlibVer == "cygdll" ) {
325 ovr_name = sprintf("libcurses%s.a", suffix)
326 printf "\t@echo linking %s to %s\n", imp_name, ovr_name
327 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, imp_name, ovr_name
329 ovr_name = sprintf("libcurses%s", suffix)
330 printf "\t@echo linking %s to %s\n", end_name, ovr_name
331 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, end_name, ovr_name
334 if ( ldconfig != "" && ldconfig != ":" ) {
335 printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
339 print "uninstall.libs \\"
340 printf "uninstall.%s ::\n", name
341 if ( ShlibVer == "cygdll" ) {
343 printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
344 printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
346 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
347 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
350 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
351 removelinks("$(DESTDIR)$(libdir)")
352 if ( overwrite == "yes" && name == "ncurses" )
354 if ( ShlibVer == "cygdll" ) {
355 ovr_name = sprintf("libcurses%s.a", suffix)
357 ovr_name = sprintf("libcurses%s", suffix)
359 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
362 if ( rmSoLocs == "yes" ) {
364 print "mostlyclean \\"
366 printf "\t-@rm -f so_locations\n"
369 else if ( MODEL == "LIBTOOL" )
377 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
378 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
381 print "install.libs \\"
382 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
383 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
384 printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
387 print "uninstall.libs \\"
388 printf "uninstall.%s ::\n", name
389 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
390 printf "\t-@$(LIBTOOL_UNINSTALL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
395 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
396 printf "\t$(AR) $(AR_OPTS) $@ $?\n"
397 printf "\t$(RANLIB) $@\n"
398 if ( host == "vxworks" )
400 printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
404 print "install.libs \\"
405 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
406 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
407 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
408 if ( overwrite == "yes" && lib_name == "libncurses.a" )
410 printf "\t@echo linking libcurses.a to libncurses.a\n"
411 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
412 printf "\t(cd $(DESTDIR)$(libdir) && $(LN_S) libncurses.a libcurses.a)\n"
414 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
415 if ( host == "vxworks" )
417 printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name, name
418 printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name, name
422 print "uninstall.libs \\"
423 printf "uninstall.%s ::\n", name
424 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
425 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
426 if ( overwrite == "yes" && lib_name == "libncurses.a" )
428 printf "\t@echo linking libcurses.a to libncurses.a\n"
429 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
431 if ( host == "vxworks" )
433 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
434 printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
439 removelinks("../lib");
441 print "mostlyclean::"
442 printf "\t-rm -f $(%s_OBJS)\n", OBJS
443 if ( MODEL == "LIBTOOL" ) {
444 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
447 else if ( found == 2 )
450 print "mostlyclean::"
451 printf "\t-rm -f $(%s_OBJS)\n", OBJS
452 if ( MODEL == "LIBTOOL" ) {
453 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
457 printf "\t-rm -f $(%s_OBJS)\n", OBJS
458 if ( MODEL == "LIBTOOL" ) {
459 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS