1 # $Id: mk-1st.awk,v 1.105 2018/08/18 16:03:51 tom Exp $
2 ##############################################################################
3 # Copyright (c) 1998-2017,2018 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 # CXX_MODEL (e.g., "DEBUG", uppercase)
38 # model (directory into which we compile, e.g., "obj")
39 # prefix (e.g., "lib", for Unix-style libraries)
40 # suffix (e.g., "_g.a", for debug libraries)
41 # subset ("none", "base", "base+ext_funcs" or "termlib", etc.)
42 # driver ("yes" or "no", depends on --enable-term-driver)
43 # ShlibVer ("rel", "abi" or "auto", to augment DoLinks variable)
44 # ShlibVerInfix ("yes" or "no", determines location of version #)
45 # SymLink ("ln -s", etc)
46 # TermlibRoot ("tinfo" or other root for libterm.so)
47 # TermlibSuffix (".so" or other suffix for libterm.so)
48 # ReLink ("yes", or "no", flag to rebuild shared libs on install)
49 # ReRanlib ("yes", or "no", flag to rerun ranlib for installing static)
50 # DoLinks ("yes", "reverse" or "no", flag to add symbolic links)
51 # rmSoLocs ("yes" or "no", flag to add extra clean target)
52 # ldconfig (path for this tool, if used)
53 # overwrite ("yes" or "no", flag to add link to libcurses.a
54 # depend (optional dependencies for all objects, e.g, ncurses_cfg.h)
55 # host (cross-compile host, if any)
56 # libtool_version (libtool "-version-info" or "-version-number")
59 # CLIXs nawk does not like underscores in command-line variable names.
60 # Mixed-case variable names are ok.
61 # HP/UX requires shared libraries to have executable permissions.
63 function is_ticlib() {
64 return ( subset ~ /^ticlib$/ );
66 function is_termlib() {
67 return ( subset ~ /^(ticlib\+)?termlib((\+[^+ ]+)*\+[a-z_]+_tinfo)?$/ );
70 function lib_name_of(a_name) {
71 return sprintf("%s%s%s", prefix, a_name, suffix)
74 function imp_name_of(a_name) {
75 if (ShlibVerInfix == "cygdll" || ShlibVerInfix == "msysdll" || ShlibVerInfix == "mingw") {
76 result = sprintf("%s%s%s.a", prefix, a_name, suffix);
83 function abi_name_of(a_name) {
84 if (ShlibVerInfix == "cygdll") {
85 result = sprintf("%s%s$(ABI_VERSION)%s", "cyg", a_name, suffix);
86 } else if (ShlibVerInfix == "msysdll") {
87 result = sprintf("%s%s$(ABI_VERSION)%s", "msys-", a_name, suffix);
88 } else if (ShlibVerInfix == "mingw") {
89 result = sprintf("%s%s$(ABI_VERSION)%s", prefix, a_name, suffix);
90 } else if (ShlibVerInfix == "yes") {
91 result = sprintf("%s%s.$(ABI_VERSION)%s", prefix, a_name, suffix);
93 result = sprintf("%s.$(ABI_VERSION)", lib_name_of(a_name));
98 function rel_name_of(a_name) {
99 if (ShlibVerInfix == "cygdll") {
100 result = sprintf("%s%s$(REL_VERSION)%s", "cyg", a_name, suffix);
101 } else if (ShlibVerInfix == "msysdll") {
102 result = sprintf("%s%s$(ABI_VERSION)%s", "msys-", a_name, suffix);
103 } else if (ShlibVerInfix == "mingw") {
104 result = sprintf("%s%s$(REL_VERSION)%s", prefix, a_name, suffix);
105 } else if (ShlibVerInfix == "yes") {
106 result = sprintf("%s%s.$(REL_VERSION)%s", prefix, a_name, suffix);
108 result = sprintf("%s.$(REL_VERSION)", lib_name_of(a_name));
113 function end_name_of(a_name) {
114 if ( MODEL != "SHARED" ) {
115 result = lib_name_of(a_name);
116 } else if ( DoLinks == "reverse") {
117 result = lib_name_of(a_name);
119 if ( ShlibVer == "rel" ) {
120 result = rel_name_of(a_name);
121 } else if ( ShlibVer == "abi" || ShlibVer == "cygdll" || ShlibVer == "msysdll" || ShlibVer == "mingw" ) {
122 result = abi_name_of(a_name);
124 result = lib_name_of(a_name);
129 function symlink(src,dst) {
131 if ( SymLink !~ /.*-f.*/ ) {
132 printf "rm -f %s; ", dst
134 printf "$(LN_S) %s %s; ", src, dst
137 function rmlink(directory, dst) {
139 printf "\t-rm -f %s/%s\n", directory, dst
142 function removelinks(directory) {
144 links[nlinks++] = end_name;
145 if ( DoLinks == "reverse" ) {
146 if ( ShlibVer == "rel" ) {
147 links[nlinks++] = abi_name;
148 links[nlinks++] = rel_name;
149 } else if ( ShlibVer == "abi" ) {
150 links[nlinks++] = abi_name;
153 if ( ShlibVer == "rel" ) {
154 links[nlinks++] = abi_name;
155 links[nlinks++] = lib_name;
156 } else if ( ShlibVer == "abi" ) {
157 links[nlinks++] = lib_name;
160 for (j = 0; j < nlinks; ++j) {
162 for (k = 0; k < j; ++k ) {
163 if ( links[j] == links[k] ) {
169 rmlink(directory, links[j]);
173 function make_shlib(objs, shlib_list) {
174 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(%s)\n", objs, shlib_list
176 function sharedlinks(directory) {
177 if ( ShlibVer != "auto" && ShlibVer != "cygdll" && ShlibVer != "msysdll" && ShlibVer != "mingw" ) {
178 printf "\tcd %s && (", directory
179 if ( DoLinks == "reverse" ) {
180 if ( ShlibVer == "rel" ) {
181 symlink(lib_name, abi_name);
182 symlink(abi_name, rel_name);
183 } else if ( ShlibVer == "abi" ) {
184 symlink(lib_name, abi_name);
187 if ( ShlibVer == "rel" ) {
188 symlink(rel_name, abi_name);
189 symlink(abi_name, lib_name);
190 } else if ( ShlibVer == "abi" ) {
191 symlink(abi_name, lib_name);
197 # termlib may be named explicitly via "--with-termlib=XXX", which overrides
198 # any suffix. Temporarily override "suffix" to account for this.
199 function termlib_end_of() {
200 termlib_save_suffix = suffix;
201 suffix = TermlibSuffix;
202 termlib_temp_result = end_name_of(TermlibRoot);
203 suffix = termlib_save_suffix;
204 return termlib_temp_result;
206 function shlib_build(directory) {
207 dst_libs = sprintf("%s/%s", directory, end_name);
208 printf "%s : \\\n", dst_libs
209 if (subset == "ticlib" && driver == "yes" ) {
211 sub(/^tic/, "ncurses", base); # workaround for "w"
212 printf "\t\t%s/%s \\\n", directory, end_name_of(base);
214 if (subset ~ /^base/ || subset == "ticlib" ) {
216 sub(/^[^.]\./,".",suffix)
217 if (directory != "../lib") {
218 printf "\t\t%s/%s \\\n", "../lib", termlib_end_of();
220 printf "\t\t%s/%s \\\n", directory, termlib_end_of();
223 printf "\t\t$(RESULTING_SYMS) $(%s_OBJS)\n", OBJS
224 printf "\t@echo linking $@\n"
225 printf "\t@mkdir -p %s\n", directory
226 if ( ReLink != "yes" ) {
227 printf "\t@sleep 1\n"
230 make_shlib(OBJS, "TICS_LIST")
231 } else if ( is_termlib() ) {
232 make_shlib(OBJS, "TINFO_LIST")
234 make_shlib(OBJS, "SHLIB_LIST")
236 sharedlinks(directory)
238 function shlib_install(directory) {
239 src_lib1 = sprintf("../lib/%s", end_name);
240 dst_lib1 = sprintf("%s/%s", directory, end_name);
241 printf "%s : \\\n", dst_lib1
242 printf "\t\t%s \\\n", directory
243 printf "\t\t%s\n", src_lib1
244 printf "\t@echo installing $@\n"
245 printf "\t$(INSTALL_LIB) %s %s\n", src_lib1, dst_lib1;
246 sharedlinks(directory)
248 function install_dll(directory,filename) {
249 src_name = sprintf("../lib/%s", filename);
250 dst_name = sprintf("$(DESTDIR)%s/%s", directory, filename);
251 printf "\t@echo installing %s as %s\n", src_name, dst_name
252 if ( directory == "$(bindir)" ) {
253 program = "$(INSTALL) -m 755";
255 program = "$(INSTALL_LIB)";
257 printf "\t%s %s %s\n", program, src_name, dst_name
266 if (subset == "none") {
268 } else if (index(subset,$2) > 0) {
271 if ( name ~ /^.*\+\+.*/ ) {
272 if ( CXX_MODEL == "NORMAL" && MODEL == "SHARED" ) {
274 printf "# overriding model from %s to match CXX_MODEL\n", MODEL;
281 printf "# generated by mk-1st.awk (subset=%s)\n", subset
282 printf "# name: %s\n", name
283 printf "# traces: %s\n", traces
284 printf "# MODEL: %s\n", MODEL
285 printf "# CXX_MODEL: %s\n", CXX_MODEL
286 printf "# model: %s\n", model
287 printf "# prefix: %s\n", prefix
288 printf "# suffix: %s\n", suffix
289 printf "# subset: %s\n", subset
290 printf "# driver: %s\n", driver
291 printf "# ShlibVer: %s\n", ShlibVer
292 printf "# ShlibVerInfix: %s\n", ShlibVerInfix
293 printf "# SymLink: %s\n", SymLink
294 printf "# TermlibRoot: %s\n", TermlibRoot
295 printf "# TermlibSuffix: %s\n", TermlibSuffix
296 printf "# ReLink: %s\n", ReLink
297 printf "# ReRanlib: %s\n", ReRanlib
298 printf "# DoLinks: %s\n", DoLinks
299 printf "# rmSoLocs: %s\n", rmSoLocs
300 printf "# ldconfig: %s\n", ldconfig
301 printf "# overwrite: %s\n", overwrite
302 printf "# depend: %s\n", depend
303 printf "# host: %s\n", host
310 } else if ( is_termlib() ) {
321 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
326 && ( $1 != "link_test" ) \
334 printf "%s_OBJS =", OBJS
337 } else if ( $2 == "c++" ) {
338 TOOL_PREFIX = "CXX_";
351 printf " \\\n\t../%s/%s$o", model, $1;
358 printf "\n$(%s_OBJS) : %s\n", OBJS, depend
363 lib_name = lib_name_of(name);
364 if ( MODEL == "SHARED" )
366 abi_name = abi_name_of(name);
367 rel_name = rel_name_of(name);
368 imp_name = imp_name_of(name);
369 end_name = end_name_of(name);
371 shlib_build("../lib")
375 print "install.libs \\"
377 if ( ShlibVer == "cygdll" || ShlibVer == "msysdll" || ShlibVer == "mingw") {
379 dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
380 printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs
381 install_dll("$(bindir)",end_name);
382 install_dll("$(libdir)",imp_name);
386 lib_dir = "$(DESTDIR)$(libdir)";
387 printf "install.%s :: %s/%s\n", name, lib_dir, end_name
389 if ( ReLink == "yes" ) {
392 shlib_install(lib_dir)
396 if ( overwrite == "yes" && name == "ncurses" )
398 if ( ShlibVer == "cygdll" || ShlibVer == "msysdll" || ShlibVer == "mingw") {
399 ovr_name = sprintf("libcurses%s.a", suffix)
400 printf "\t@echo linking %s to %s\n", imp_name, ovr_name
401 printf "\tcd $(DESTDIR)$(libdir) && ("
402 symlink(imp_name, ovr_name)
405 ovr_name = sprintf("libcurses%s", suffix)
406 printf "\t@echo linking %s to %s\n", end_name, ovr_name
407 printf "\tcd $(DESTDIR)$(libdir) && ("
408 symlink(end_name, ovr_name)
412 if ( ldconfig != "" && ldconfig != ":" ) {
413 printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
417 print "uninstall.libs \\"
418 printf "uninstall.%s ::\n", name
419 if ( ShlibVer == "cygdll" || ShlibVer == "msysdll" || ShlibVer == "mingw") {
421 printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
422 printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
424 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
425 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
428 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
429 removelinks("$(DESTDIR)$(libdir)")
430 if ( overwrite == "yes" && name == "ncurses" )
432 ovr_name = sprintf("libcurses%s", suffix)
433 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
436 if ( rmSoLocs == "yes" ) {
438 print "mostlyclean \\"
440 printf "\t-@rm -f so_locations\n"
443 else if ( MODEL == "LIBTOOL" )
446 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
448 which_list = "TICS_LIST";
449 } else if ( is_termlib() ) {
450 which_list = "TINFO_LIST";
452 which_list = "SHLIB_LIST";
454 printf "\tcd ../lib && $(LIBTOOL_LINK) $(%s) $(%s) \\\n", CC_NAME, CC_FLAG;
455 printf "\t\t-o %s $(%s_OBJS:$o=.lo) \\\n", lib_name, OBJS;
456 printf "\t\t-rpath $(libdir) \\\n";
457 printf "\t\t%s $(NCURSES_MAJOR):$(NCURSES_MINOR) $(LT_UNDEF) $(%s) $(LDFLAGS)\n", libtool_version, which_list;
460 print "install.libs \\"
461 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
462 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
463 printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
466 print "uninstall.libs \\"
467 printf "uninstall.%s ::\n", name
468 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
469 printf "\t-@$(LIBTOOL_UNINSTALL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
474 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
475 # workaround: binutils' ranlib tries to be clever with
476 # timestamps, by pretending its update took no time, confusing
478 if ( ReLink != "yes" ) {
479 printf "\t@sleep 1\n"
481 printf "\t$(%sAR) $(%sARFLAGS) $@ $?\n", TOOL_PREFIX, TOOL_PREFIX;
482 printf "\t$(RANLIB) $@\n"
483 if ( host == "vxworks" )
485 printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
489 print "install.libs \\"
490 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
491 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
492 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
493 if ( overwrite == "yes" && lib_name == "libncurses.a" )
495 printf "\t@echo linking libcurses.a to libncurses.a\n"
496 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
497 printf "\t(cd $(DESTDIR)$(libdir) && "
498 symlink("libncurses.a", "libcurses.a")
501 if ( ReRanlib == "yes" )
503 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
505 if ( host == "vxworks" )
507 printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name, name
508 printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name, name
512 print "uninstall.libs \\"
513 printf "uninstall.%s ::\n", name
514 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
515 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
516 if ( overwrite == "yes" && lib_name == "libncurses.a" )
518 printf "\t@echo linking libcurses.a to libncurses.a\n"
519 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
521 if ( host == "vxworks" )
523 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
524 printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
529 removelinks("../lib");
531 print "mostlyclean::"
532 printf "\t-rm -f $(%s_OBJS)\n", OBJS
533 if ( MODEL == "LIBTOOL" ) {
534 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
537 else if ( found == 2 )
540 print "mostlyclean::"
541 printf "\t-rm -f $(%s_OBJS)\n", OBJS
542 if ( MODEL == "LIBTOOL" ) {
543 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
547 printf "\t-rm -f $(%s_OBJS)\n", OBJS
548 if ( MODEL == "LIBTOOL" ) {
549 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS