1 # $Id: mk-1st.awk,v 1.83 2010/05/15 19:14:44 tom Exp $
2 ##############################################################################
3 # Copyright (c) 1998-2009,2010 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 # TermlibSuffix (".so" or other suffix for libterm.so)
45 # ReLink ("yes", or "no", flag to rebuild shared libs on install)
46 # DoLinks ("yes", "reverse" or "no", flag to add symbolic links)
47 # rmSoLocs ("yes" or "no", flag to add extra clean target)
48 # ldconfig (path for this tool, if used)
49 # overwrite ("yes" or "no", flag to add link to libcurses.a
50 # depend (optional dependencies for all objects, e.g, ncurses_cfg.h)
51 # host (cross-compile host, if any)
52 # libtool_version (libtool "-version-info" or "-version-number")
55 # CLIXs nawk does not like underscores in command-line variable names.
56 # Mixed-case variable names are ok.
57 # HP/UX requires shared libraries to have executable permissions.
59 function is_ticlib() {
60 return ( subset ~ /^ticlib$/ );
62 function is_termlib() {
63 return ( subset ~ /^(ticlib\+)?termlib((\+[^+ ]+)*\+[a-z_]+_tinfo)?$/ );
66 function lib_name_of(a_name) {
67 return sprintf("%s%s%s", prefix, a_name, suffix)
70 function imp_name_of(a_name) {
71 if (ShlibVerInfix == "cygdll") {
72 result = sprintf("%s%s%s.a", prefix, a_name, suffix);
79 function abi_name_of(a_name) {
80 if (ShlibVerInfix == "cygdll") {
81 result = sprintf("%s%s$(ABI_VERSION)%s", "cyg", a_name, suffix);
82 } else if (ShlibVerInfix == "yes") {
83 result = sprintf("%s%s.$(ABI_VERSION)%s", prefix, a_name, suffix);
85 result = sprintf("%s.$(ABI_VERSION)", lib_name_of(a_name));
90 function rel_name_of(a_name) {
91 if (ShlibVerInfix == "cygdll") {
92 result = sprintf("%s%s$(REL_VERSION)%s", "cyg", a_name, suffix);
93 } else if (ShlibVerInfix == "yes") {
94 result = sprintf("%s%s.$(REL_VERSION)%s", prefix, a_name, suffix);
96 result = sprintf("%s.$(REL_VERSION)", lib_name_of(a_name));
101 function end_name_of(a_name) {
102 if ( MODEL != "SHARED" ) {
103 result = lib_name_of(a_name);
104 } else if ( DoLinks == "reverse") {
105 result = lib_name_of(a_name);
107 if ( ShlibVer == "rel" ) {
108 result = rel_name_of(a_name);
109 } else if ( ShlibVer == "abi" || ShlibVer == "cygdll" ) {
110 result = abi_name_of(a_name);
112 result = lib_name_of(a_name);
117 function symlink(src,dst) {
119 printf "rm -f %s; ", dst
120 printf "$(LN_S) %s %s; ", src, dst
123 function rmlink(directory, dst) {
124 printf "\t-rm -f %s/%s\n", directory, dst
126 function removelinks(directory) {
127 rmlink(directory, end_name);
128 if ( DoLinks == "reverse" ) {
129 if ( ShlibVer == "rel" ) {
130 rmlink(directory, abi_name);
131 rmlink(directory, rel_name);
132 } else if ( ShlibVer == "abi" ) {
133 rmlink(directory, abi_name);
136 if ( ShlibVer == "rel" ) {
137 rmlink(directory, abi_name);
138 rmlink(directory, lib_name);
139 } else if ( ShlibVer == "abi" ) {
140 rmlink(directory, lib_name);
144 function make_shlib(objs, shlib_list) {
145 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(%s) $(LDFLAGS)\n", objs, shlib_list
147 function sharedlinks(directory) {
148 if ( ShlibVer != "auto" && ShlibVer != "cygdll" ) {
149 printf "\tcd %s && (", directory
150 if ( DoLinks == "reverse" ) {
151 if ( ShlibVer == "rel" ) {
152 symlink(lib_name, abi_name);
153 symlink(abi_name, rel_name);
154 } else if ( ShlibVer == "abi" ) {
155 symlink(lib_name, abi_name);
158 if ( ShlibVer == "rel" ) {
159 symlink(rel_name, abi_name);
160 symlink(abi_name, lib_name);
161 } else if ( ShlibVer == "abi" ) {
162 symlink(abi_name, lib_name);
168 # termlib may be named explicitly via "--with-termlib=XXX", which overrides
169 # any suffix. Temporarily override "suffix" to account for this.
170 function termlib_end_of() {
171 termlib_save_suffix = suffix;
172 suffix = TermlibSuffix;
173 termlib_temp_result = end_name_of(TermlibRoot);
174 suffix = termlib_save_suffix;
175 return termlib_temp_result;
177 function shlib_build(directory) {
178 dst_libs = sprintf("%s/%s", directory, end_name);
179 printf "%s : \\\n", dst_libs
180 printf "\t\t%s \\\n", directory
181 if (subset ~ /^base/ || subset == "ticlib" ) {
183 sub(/^[^.]\./,".",suffix)
184 if (directory != "../lib") {
185 printf "\t\t%s/%s \\\n", "../lib", termlib_end_of();
187 printf "\t\t%s/%s \\\n", directory, termlib_end_of();
190 printf "\t\t$(%s_OBJS)\n", OBJS
191 printf "\t@echo linking $@\n"
193 make_shlib(OBJS, "TICS_LIST")
194 } else if ( is_termlib() ) {
195 make_shlib(OBJS, "TINFO_LIST")
197 make_shlib(OBJS, "SHLIB_LIST")
199 sharedlinks(directory)
201 function shlib_install(directory) {
202 src_lib1 = sprintf("../lib/%s", end_name);
203 dst_lib1 = sprintf("%s/%s", directory, end_name);
204 printf "%s : \\\n", dst_lib1
205 printf "\t\t%s \\\n", directory
206 printf "\t\t%s\n", src_lib1
207 printf "\t@echo installing $@\n"
208 printf "\t$(INSTALL_LIB) %s %s\n", src_lib1, dst_lib1;
209 sharedlinks(directory)
211 function install_dll(directory,filename) {
212 src_name = sprintf("../lib/%s", filename);
213 dst_name = sprintf("$(DESTDIR)%s/%s", directory, filename);
214 printf "\t@echo installing %s as %s\n", src_name, dst_name
215 if ( directory == "$(bindir)" ) {
216 program = "$(INSTALL) -m 755";
218 program = "$(INSTALL_LIB)";
220 printf "\t%s %s %s\n", program, src_name, dst_name
228 if (subset == "none") {
230 } else if (index(subset,$2) > 0) {
234 printf "# generated by mk-1st.awk (subset=%s)\n", subset
235 printf "# name: %s\n", name
236 printf "# traces: %s\n", traces
237 printf "# MODEL: %s\n", MODEL
238 printf "# model: %s\n", model
239 printf "# prefix: %s\n", prefix
240 printf "# suffix: %s\n", suffix
241 printf "# subset: %s\n", subset
242 printf "# ShlibVer: %s\n", ShlibVer
243 printf "# ShlibVerInfix: %s\n", ShlibVerInfix
244 printf "# TermlibRoot: %s\n", TermlibRoot
245 printf "# TermlibSuffix: %s\n", TermlibSuffix
246 printf "# ReLink: %s\n", ReLink
247 printf "# DoLinks: %s\n", DoLinks
248 printf "# rmSoLocs: %s\n", rmSoLocs
249 printf "# ldconfig: %s\n", ldconfig
250 printf "# overwrite: %s\n", overwrite
251 printf "# depend: %s\n", depend
252 printf "# host: %s\n", host
259 } else if ( is_termlib() ) {
270 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
275 && ( $1 != "link_test" ) \
283 printf "%s_OBJS =", OBJS
289 printf " \\\n\t../%s/%s$o", model, $1
296 printf "\n$(%s_OBJS) : %s\n", OBJS, depend
301 lib_name = lib_name_of(name);
302 if ( MODEL == "SHARED" )
304 abi_name = abi_name_of(name);
305 rel_name = rel_name_of(name);
306 imp_name = imp_name_of(name);
307 end_name = end_name_of(name);
309 shlib_build("../lib")
313 print "install.libs \\"
315 if ( ShlibVer == "cygdll" ) {
317 dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
318 printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs
319 install_dll("$(bindir)",end_name);
320 install_dll("$(libdir)",imp_name);
324 lib_dir = "$(DESTDIR)$(libdir)";
325 printf "install.%s :: %s/%s\n", name, lib_dir, end_name
327 if ( ReLink == "yes" ) {
330 shlib_install(lib_dir)
334 if ( overwrite == "yes" && name == "ncurses" )
336 if ( ShlibVer == "cygdll" ) {
337 ovr_name = sprintf("libcurses%s.a", suffix)
338 printf "\t@echo linking %s to %s\n", imp_name, ovr_name
339 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, imp_name, ovr_name
341 ovr_name = sprintf("libcurses%s", suffix)
342 printf "\t@echo linking %s to %s\n", end_name, ovr_name
343 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, end_name, ovr_name
346 if ( ldconfig != "" && ldconfig != ":" ) {
347 printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
351 print "uninstall.libs \\"
352 printf "uninstall.%s ::\n", name
353 if ( ShlibVer == "cygdll" ) {
355 printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
356 printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
358 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
359 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
362 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
363 removelinks("$(DESTDIR)$(libdir)")
364 if ( overwrite == "yes" && name == "ncurses" )
366 if ( ShlibVer == "cygdll" ) {
367 ovr_name = sprintf("libcurses%s.a", suffix)
369 ovr_name = sprintf("libcurses%s", suffix)
371 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
374 if ( rmSoLocs == "yes" ) {
376 print "mostlyclean \\"
378 printf "\t-@rm -f so_locations\n"
381 else if ( MODEL == "LIBTOOL" )
389 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
391 printf "\tcd ../lib && $(LIBTOOL_LINK) $(%s) -o %s $(%s_OBJS:$o=.lo) -rpath $(DESTDIR)$(libdir) %s $(NCURSES_MAJOR):$(NCURSES_MINOR) $(LT_UNDEF) $(TICS_LIST)\n", compile, lib_name, OBJS, libtool_version
392 } else if ( is_termlib() ) {
393 printf "\tcd ../lib && $(LIBTOOL_LINK) $(%s) -o %s $(%s_OBJS:$o=.lo) -rpath $(DESTDIR)$(libdir) %s $(NCURSES_MAJOR):$(NCURSES_MINOR) $(LT_UNDEF) $(TINFO_LIST)\n", compile, lib_name, OBJS, libtool_version
395 printf "\tcd ../lib && $(LIBTOOL_LINK) $(%s) -o %s $(%s_OBJS:$o=.lo) -rpath $(DESTDIR)$(libdir) %s $(NCURSES_MAJOR):$(NCURSES_MINOR) $(LT_UNDEF) $(SHLIB_LIST)\n", compile, lib_name, OBJS, libtool_version
399 print "install.libs \\"
400 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
401 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
402 printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
405 print "uninstall.libs \\"
406 printf "uninstall.%s ::\n", name
407 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
408 printf "\t-@$(LIBTOOL_UNINSTALL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
413 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
414 printf "\t$(AR) $(ARFLAGS) $@ $?\n"
415 printf "\t$(RANLIB) $@\n"
416 if ( host == "vxworks" )
418 printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
422 print "install.libs \\"
423 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
424 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
425 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, 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"
430 printf "\t(cd $(DESTDIR)$(libdir) && $(LN_S) libncurses.a libcurses.a)\n"
432 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
433 if ( host == "vxworks" )
435 printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name, name
436 printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name, name
440 print "uninstall.libs \\"
441 printf "uninstall.%s ::\n", name
442 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
443 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
444 if ( overwrite == "yes" && lib_name == "libncurses.a" )
446 printf "\t@echo linking libcurses.a to libncurses.a\n"
447 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
449 if ( host == "vxworks" )
451 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
452 printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
457 removelinks("../lib");
459 print "mostlyclean::"
460 printf "\t-rm -f $(%s_OBJS)\n", OBJS
461 if ( MODEL == "LIBTOOL" ) {
462 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
465 else if ( found == 2 )
468 print "mostlyclean::"
469 printf "\t-rm -f $(%s_OBJS)\n", OBJS
470 if ( MODEL == "LIBTOOL" ) {
471 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
475 printf "\t-rm -f $(%s_OBJS)\n", OBJS
476 if ( MODEL == "LIBTOOL" ) {
477 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS