1 # $Id: mk-1st.awk,v 1.87 2011/12/17 20:27:27 tom Exp $
2 ##############################################################################
3 # Copyright (c) 1998-2010,2011 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 # driver ("yes" or "no", depends on --enable-term-driver)
42 # ShlibVer ("rel", "abi" or "auto", to augment DoLinks variable)
43 # ShlibVerInfix ("yes" or "no", determines location of version #)
44 # SymLink ("ln -s", etc)
45 # TermlibRoot ("tinfo" or other root for libterm.so)
46 # TermlibSuffix (".so" or other suffix for libterm.so)
47 # ReLink ("yes", or "no", flag to rebuild shared libs on install)
48 # DoLinks ("yes", "reverse" or "no", flag to add symbolic links)
49 # rmSoLocs ("yes" or "no", flag to add extra clean target)
50 # ldconfig (path for this tool, if used)
51 # overwrite ("yes" or "no", flag to add link to libcurses.a
52 # depend (optional dependencies for all objects, e.g, ncurses_cfg.h)
53 # host (cross-compile host, if any)
54 # libtool_version (libtool "-version-info" or "-version-number")
57 # CLIXs nawk does not like underscores in command-line variable names.
58 # Mixed-case variable names are ok.
59 # HP/UX requires shared libraries to have executable permissions.
61 function is_ticlib() {
62 return ( subset ~ /^ticlib$/ );
64 function is_termlib() {
65 return ( subset ~ /^(ticlib\+)?termlib((\+[^+ ]+)*\+[a-z_]+_tinfo)?$/ );
68 function lib_name_of(a_name) {
69 return sprintf("%s%s%s", prefix, a_name, suffix)
72 function imp_name_of(a_name) {
73 if (ShlibVerInfix == "cygdll") {
74 result = sprintf("%s%s%s.a", prefix, a_name, suffix);
81 function abi_name_of(a_name) {
82 if (ShlibVerInfix == "cygdll") {
83 result = sprintf("%s%s$(ABI_VERSION)%s", "cyg", a_name, suffix);
84 } else if (ShlibVerInfix == "yes") {
85 result = sprintf("%s%s.$(ABI_VERSION)%s", prefix, a_name, suffix);
87 result = sprintf("%s.$(ABI_VERSION)", lib_name_of(a_name));
92 function rel_name_of(a_name) {
93 if (ShlibVerInfix == "cygdll") {
94 result = sprintf("%s%s$(REL_VERSION)%s", "cyg", a_name, suffix);
95 } else if (ShlibVerInfix == "yes") {
96 result = sprintf("%s%s.$(REL_VERSION)%s", prefix, a_name, suffix);
98 result = sprintf("%s.$(REL_VERSION)", lib_name_of(a_name));
103 function end_name_of(a_name) {
104 if ( MODEL != "SHARED" ) {
105 result = lib_name_of(a_name);
106 } else if ( DoLinks == "reverse") {
107 result = lib_name_of(a_name);
109 if ( ShlibVer == "rel" ) {
110 result = rel_name_of(a_name);
111 } else if ( ShlibVer == "abi" || ShlibVer == "cygdll" ) {
112 result = abi_name_of(a_name);
114 result = lib_name_of(a_name);
119 function symlink(src,dst) {
121 if ( SymLink !~ /.*-f.*/ ) {
122 printf "rm -f %s; ", dst
124 printf "$(LN_S) %s %s; ", src, dst
127 function rmlink(directory, dst) {
128 printf "\t-rm -f %s/%s\n", directory, dst
130 function removelinks(directory) {
131 rmlink(directory, end_name);
132 if ( DoLinks == "reverse" ) {
133 if ( ShlibVer == "rel" ) {
134 rmlink(directory, abi_name);
135 rmlink(directory, rel_name);
136 } else if ( ShlibVer == "abi" ) {
137 rmlink(directory, abi_name);
140 if ( ShlibVer == "rel" ) {
141 rmlink(directory, abi_name);
142 rmlink(directory, lib_name);
143 } else if ( ShlibVer == "abi" ) {
144 rmlink(directory, lib_name);
148 function make_shlib(objs, shlib_list) {
149 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(%s) $(LDFLAGS)\n", objs, shlib_list
151 function sharedlinks(directory) {
152 if ( ShlibVer != "auto" && ShlibVer != "cygdll" ) {
153 printf "\tcd %s && (", directory
154 if ( DoLinks == "reverse" ) {
155 if ( ShlibVer == "rel" ) {
156 symlink(lib_name, abi_name);
157 symlink(abi_name, rel_name);
158 } else if ( ShlibVer == "abi" ) {
159 symlink(lib_name, abi_name);
162 if ( ShlibVer == "rel" ) {
163 symlink(rel_name, abi_name);
164 symlink(abi_name, lib_name);
165 } else if ( ShlibVer == "abi" ) {
166 symlink(abi_name, lib_name);
172 # termlib may be named explicitly via "--with-termlib=XXX", which overrides
173 # any suffix. Temporarily override "suffix" to account for this.
174 function termlib_end_of() {
175 termlib_save_suffix = suffix;
176 suffix = TermlibSuffix;
177 termlib_temp_result = end_name_of(TermlibRoot);
178 suffix = termlib_save_suffix;
179 return termlib_temp_result;
181 function shlib_build(directory) {
182 dst_libs = sprintf("%s/%s", directory, end_name);
183 printf "%s : \\\n", dst_libs
184 printf "\t\t%s \\\n", directory
185 if (subset == "ticlib" && driver == "yes" ) {
187 sub(/^tic/, "ncurses", base); # workaround for "w"
188 printf "\t\t%s/%s \\\n", directory, end_name_of(base);
190 if (subset ~ /^base/ || subset == "ticlib" ) {
192 sub(/^[^.]\./,".",suffix)
193 if (directory != "../lib") {
194 printf "\t\t%s/%s \\\n", "../lib", termlib_end_of();
196 printf "\t\t%s/%s \\\n", directory, termlib_end_of();
199 printf "\t\t$(%s_OBJS)\n", OBJS
200 printf "\t@echo linking $@\n"
202 make_shlib(OBJS, "TICS_LIST")
203 } else if ( is_termlib() ) {
204 make_shlib(OBJS, "TINFO_LIST")
206 make_shlib(OBJS, "SHLIB_LIST")
208 sharedlinks(directory)
210 function shlib_install(directory) {
211 src_lib1 = sprintf("../lib/%s", end_name);
212 dst_lib1 = sprintf("%s/%s", directory, end_name);
213 printf "%s : \\\n", dst_lib1
214 printf "\t\t%s \\\n", directory
215 printf "\t\t%s\n", src_lib1
216 printf "\t@echo installing $@\n"
217 printf "\t$(INSTALL_LIB) %s %s\n", src_lib1, dst_lib1;
218 sharedlinks(directory)
220 function install_dll(directory,filename) {
221 src_name = sprintf("../lib/%s", filename);
222 dst_name = sprintf("$(DESTDIR)%s/%s", directory, filename);
223 printf "\t@echo installing %s as %s\n", src_name, dst_name
224 if ( directory == "$(bindir)" ) {
225 program = "$(INSTALL) -m 755";
227 program = "$(INSTALL_LIB)";
229 printf "\t%s %s %s\n", program, src_name, dst_name
237 if (subset == "none") {
239 } else if (index(subset,$2) > 0) {
243 printf "# generated by mk-1st.awk (subset=%s)\n", subset
244 printf "# name: %s\n", name
245 printf "# traces: %s\n", traces
246 printf "# MODEL: %s\n", MODEL
247 printf "# model: %s\n", model
248 printf "# prefix: %s\n", prefix
249 printf "# suffix: %s\n", suffix
250 printf "# subset: %s\n", subset
251 printf "# driver: %s\n", driver
252 printf "# ShlibVer: %s\n", ShlibVer
253 printf "# ShlibVerInfix: %s\n", ShlibVerInfix
254 printf "# SymLink: %s\n", SymLink
255 printf "# TermlibRoot: %s\n", TermlibRoot
256 printf "# TermlibSuffix: %s\n", TermlibSuffix
257 printf "# ReLink: %s\n", ReLink
258 printf "# DoLinks: %s\n", DoLinks
259 printf "# rmSoLocs: %s\n", rmSoLocs
260 printf "# ldconfig: %s\n", ldconfig
261 printf "# overwrite: %s\n", overwrite
262 printf "# depend: %s\n", depend
263 printf "# host: %s\n", host
270 } else if ( is_termlib() ) {
281 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
286 && ( $1 != "link_test" ) \
294 printf "%s_OBJS =", OBJS
300 printf " \\\n\t../%s/%s$o", model, $1
307 printf "\n$(%s_OBJS) : %s\n", OBJS, depend
312 lib_name = lib_name_of(name);
313 if ( MODEL == "SHARED" )
315 abi_name = abi_name_of(name);
316 rel_name = rel_name_of(name);
317 imp_name = imp_name_of(name);
318 end_name = end_name_of(name);
320 shlib_build("../lib")
324 print "install.libs \\"
326 if ( ShlibVer == "cygdll" ) {
328 dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
329 printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs
330 install_dll("$(bindir)",end_name);
331 install_dll("$(libdir)",imp_name);
335 lib_dir = "$(DESTDIR)$(libdir)";
336 printf "install.%s :: %s/%s\n", name, lib_dir, end_name
338 if ( ReLink == "yes" ) {
341 shlib_install(lib_dir)
345 if ( overwrite == "yes" && name == "ncurses" )
347 if ( ShlibVer == "cygdll" ) {
348 ovr_name = sprintf("libcurses%s.a", suffix)
349 printf "\t@echo linking %s to %s\n", imp_name, ovr_name
350 printf "\tcd $(DESTDIR)$(libdir) && ("
351 symlink(imp_name, ovr_name)
354 ovr_name = sprintf("libcurses%s", suffix)
355 printf "\t@echo linking %s to %s\n", end_name, ovr_name
356 printf "\tcd $(DESTDIR)$(libdir) && ("
357 symlink(end_name, ovr_name)
361 if ( ldconfig != "" && ldconfig != ":" ) {
362 printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
366 print "uninstall.libs \\"
367 printf "uninstall.%s ::\n", name
368 if ( ShlibVer == "cygdll" ) {
370 printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
371 printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
373 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
374 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
377 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
378 removelinks("$(DESTDIR)$(libdir)")
379 if ( overwrite == "yes" && name == "ncurses" )
381 if ( ShlibVer == "cygdll" ) {
382 ovr_name = sprintf("libcurses%s.a", suffix)
384 ovr_name = sprintf("libcurses%s", suffix)
386 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
389 if ( rmSoLocs == "yes" ) {
391 print "mostlyclean \\"
393 printf "\t-@rm -f so_locations\n"
396 else if ( MODEL == "LIBTOOL" )
404 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
406 which_list = "TICS_LIST";
407 } else if ( is_termlib() ) {
408 which_list = "TINFO_LIST";
410 which_list = "SHLIB_LIST";
412 printf "\tcd ../lib && $(LIBTOOL_LINK) $(%s) -o %s $(%s_OBJS:$o=.lo) -rpath $(DESTDIR)$(libdir) %s $(NCURSES_MAJOR):$(NCURSES_MINOR) $(LT_UNDEF) $(%s) $(LDFLAGS)\n", compile, lib_name, OBJS, libtool_version, which_list
415 print "install.libs \\"
416 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
417 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
418 printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
421 print "uninstall.libs \\"
422 printf "uninstall.%s ::\n", name
423 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
424 printf "\t-@$(LIBTOOL_UNINSTALL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
429 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
430 printf "\t$(AR) $(ARFLAGS) $@ $?\n"
431 printf "\t$(RANLIB) $@\n"
432 if ( host == "vxworks" )
434 printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
438 print "install.libs \\"
439 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
440 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
441 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
442 if ( overwrite == "yes" && lib_name == "libncurses.a" )
444 printf "\t@echo linking libcurses.a to libncurses.a\n"
445 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
446 printf "\t(cd $(DESTDIR)$(libdir) && "
447 symlink("libncurses.a", "libcurses.a")
450 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
451 if ( host == "vxworks" )
453 printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name, name
454 printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name, name
458 print "uninstall.libs \\"
459 printf "uninstall.%s ::\n", name
460 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
461 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
462 if ( overwrite == "yes" && lib_name == "libncurses.a" )
464 printf "\t@echo linking libcurses.a to libncurses.a\n"
465 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
467 if ( host == "vxworks" )
469 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
470 printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
475 removelinks("../lib");
477 print "mostlyclean::"
478 printf "\t-rm -f $(%s_OBJS)\n", OBJS
479 if ( MODEL == "LIBTOOL" ) {
480 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
483 else if ( found == 2 )
486 print "mostlyclean::"
487 printf "\t-rm -f $(%s_OBJS)\n", OBJS
488 if ( MODEL == "LIBTOOL" ) {
489 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
493 printf "\t-rm -f $(%s_OBJS)\n", OBJS
494 if ( MODEL == "LIBTOOL" ) {
495 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS