1 # $Id: mk-1st.awk,v 1.114 2021/07/03 20:05:20 tom Exp $
2 ##############################################################################
3 # Copyright 2018-2020,2021 Thomas E. Dickey #
4 # Copyright 1998-2016,2017 Free Software Foundation, Inc. #
6 # Permission is hereby granted, free of charge, to any person obtaining a #
7 # copy of this software and associated documentation files (the "Software"), #
8 # to deal in the Software without restriction, including without limitation #
9 # the rights to use, copy, modify, merge, publish, distribute, distribute #
10 # with modifications, sublicense, and/or sell copies of the Software, and to #
11 # permit persons to whom the Software is furnished to do so, subject to the #
12 # following conditions: #
14 # The above copyright notice and this permission notice shall be included in #
15 # all copies or substantial portions of the Software. #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
20 # THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
23 # DEALINGS IN THE SOFTWARE. #
25 # Except as contained in this notice, the name(s) of the above copyright #
26 # holders shall not be used in advertising or otherwise to promote the sale, #
27 # use or other dealings in this Software without prior written #
29 ##############################################################################
31 # Author: Thomas E. Dickey
33 # Generate list of objects for a given model library
35 # name (library name, e.g., "ncurses", "panel", "forms", "menus")
36 # traces ("all" or "DEBUG", to control whether tracing is compiled in)
37 # MODEL (e.g., "DEBUG", uppercase; toupper is not portable)
38 # CXX_MODEL (e.g., "DEBUG", uppercase)
39 # LIB_SUFFIX (e.g., "", "w", "t", "tw")
40 # model (directory into which we compile, e.g., "obj")
41 # prefix (e.g., "lib", for Unix-style libraries)
42 # suffix (e.g., "_g.a", for debug libraries)
43 # subset ("none", "base", "base+ext_funcs" or "termlib", etc.)
44 # driver ("yes" or "no", depends on --enable-term-driver)
45 # ShlibVer ("rel", "abi" or "auto", to augment DoLinks variable)
46 # ShlibVerInfix ("yes" or "no", determines location of version #)
47 # SymLink ("ln -s", etc)
48 # TermlibRoot ("tinfo" or other root for libterm.so)
49 # TermlibSuffix (".so" or other suffix for libterm.so)
50 # ReLink ("yes", or "no", flag to rebuild shared libs on install)
51 # ReRanlib ("yes", or "no", flag to rerun ranlib for installing static)
52 # DoLinks ("yes", "reverse" or "no", flag to add symbolic links)
53 # rmSoLocs ("yes" or "no", flag to add extra clean target)
54 # ldconfig (path for this tool, if used)
55 # make_phony ("yes" if the make-program accepts ".PHONY" directive.
56 # overwrite ("yes" or "no", flag to add link to libcurses.a
57 # depend (optional dependencies for all objects, e.g, ncurses_cfg.h)
58 # host (cross-compile host, if any)
59 # libtool_version (libtool "-version-info" or "-version-number")
62 # CLIXs nawk does not like underscores in command-line variable names.
63 # Mixed-case variable names are ok.
64 # HP/UX requires shared libraries to have executable permissions.
66 function is_ticlib() {
67 return ( subset ~ /^ticlib$/ );
69 function is_termlib() {
70 return ( subset ~ /^(ticlib\+)?termlib((\+[^+ ]+)*\+[a-z_]+_tinfo)?$/ );
73 function lib_name_of(a_name) {
74 return sprintf("%s%s%s", prefix, a_name, suffix)
77 function imp_name_of(a_name) {
78 if (ShlibVerInfix == "cygdll" || ShlibVerInfix == "msysdll" || ShlibVerInfix == "mingw") {
79 result = sprintf("%s%s%s.a", prefix, a_name, suffix);
80 } else if (ShlibVerInfix == "msvcdll") {
81 result = sprintf("%s%s%s.lib", prefix, a_name, suffix);
88 function abi_name_of(a_name) {
89 if (ShlibVerInfix == "cygdll") {
90 result = sprintf("%s%s$(ABI_VERSION)%s", "cyg", a_name, suffix);
91 } else if (ShlibVerInfix == "msysdll") {
92 result = sprintf("%s%s$(ABI_VERSION)%s", "msys-", a_name, suffix);
93 } else if (ShlibVerInfix == "mingw" || ShlibVerInfix == "msvcdll") {
94 result = sprintf("%s%s$(ABI_VERSION)%s", prefix, a_name, suffix);
95 } else if (ShlibVerInfix == "yes") {
96 result = sprintf("%s%s.$(ABI_VERSION)%s", prefix, a_name, suffix);
98 result = sprintf("%s.$(ABI_VERSION)", lib_name_of(a_name));
103 function rel_name_of(a_name) {
104 if (ShlibVerInfix == "cygdll") {
105 result = sprintf("%s%s$(REL_VERSION)%s", "cyg", a_name, suffix);
106 } else if (ShlibVerInfix == "msysdll") {
107 result = sprintf("%s%s$(ABI_VERSION)%s", "msys-", a_name, suffix);
108 } else if (ShlibVerInfix == "mingw" || ShlibVerInfix == "msvcdll") {
109 result = sprintf("%s%s$(REL_VERSION)%s", prefix, a_name, suffix);
110 } else if (ShlibVerInfix == "yes") {
111 result = sprintf("%s%s.$(REL_VERSION)%s", prefix, a_name, suffix);
113 result = sprintf("%s.$(REL_VERSION)", lib_name_of(a_name));
118 function end_name_of(a_name) {
119 if ( MODEL != "SHARED" ) {
120 result = lib_name_of(a_name);
121 } else if ( DoLinks == "reverse") {
122 result = lib_name_of(a_name);
124 if ( ShlibVer == "rel" ) {
125 result = rel_name_of(a_name);
126 } else if ( ShlibVer == "abi" || ShlibVer == "cygdll" || ShlibVer == "msysdll" || ShlibVer == "mingw" || ShlibVer == "msvcdll" ) {
127 result = abi_name_of(a_name);
129 result = lib_name_of(a_name);
134 function symlink(src,dst) {
136 if ( SymLink !~ /.*-f.*/ ) {
137 printf "rm -f %s; ", dst
139 printf "$(LN_S) %s %s; ", src, dst
142 function rmlink(directory, dst) {
144 printf "\t-rm -f %s/%s\n", directory, dst
147 function removelinks(directory) {
149 links[nlinks++] = end_name;
150 if ( DoLinks == "reverse" ) {
151 if ( ShlibVer == "rel" ) {
152 links[nlinks++] = abi_name;
153 links[nlinks++] = rel_name;
154 } else if ( ShlibVer == "abi" ) {
155 links[nlinks++] = abi_name;
158 if ( ShlibVer == "rel" ) {
159 links[nlinks++] = abi_name;
160 links[nlinks++] = lib_name;
161 } else if ( ShlibVer == "abi" ) {
162 links[nlinks++] = lib_name;
165 for (j = 0; j < nlinks; ++j) {
167 for (k = 0; k < j; ++k ) {
168 if ( links[j] == links[k] ) {
174 rmlink(directory, links[j]);
178 function make_shlib(objs, shlib_list) {
179 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(%s)\n", objs, shlib_list
181 function sharedlinks(directory) {
182 if ( ShlibVer != "auto" && ShlibVer != "cygdll" && ShlibVer != "msysdll" && ShlibVer != "mingw" && ShlibVer != "msvcdll" ) {
183 printf "\tcd %s && (", directory
184 if ( DoLinks == "reverse" ) {
185 if ( ShlibVer == "rel" ) {
186 symlink(lib_name, abi_name);
187 symlink(abi_name, rel_name);
188 } else if ( ShlibVer == "abi" ) {
189 symlink(lib_name, abi_name);
192 if ( ShlibVer == "rel" ) {
193 symlink(rel_name, abi_name);
194 symlink(abi_name, lib_name);
195 } else if ( ShlibVer == "abi" ) {
196 symlink(abi_name, lib_name);
202 # termlib may be named explicitly via "--with-termlib=XXX", which overrides
203 # any suffix. Temporarily override "suffix" to account for this.
204 function termlib_end_of() {
205 termlib_save_suffix = suffix;
206 suffix = TermlibSuffix;
207 termlib_temp_result = end_name_of(TermlibRoot);
208 suffix = termlib_save_suffix;
209 return termlib_temp_result;
211 function shlib_build(directory) {
212 dst_libs = sprintf("%s/%s", directory, end_name);
213 printf "%s : \\\n", dst_libs
214 if (subset == "ticlib" && driver == "yes" ) {
216 sub(/^tic/, "ncurses", base); # workaround for "w"
217 printf "\t\t%s/%s \\\n", directory, end_name_of(base);
219 if (subset ~ /^base/ || subset == "ticlib" ) {
221 sub(/^[^.]\./,".",suffix)
222 if (directory != "../lib") {
223 printf "\t\t%s/%s \\\n", "../lib", termlib_end_of();
225 printf "\t\t%s/%s \\\n", directory, termlib_end_of();
228 printf "\t\t$(RESULTING_SYMS) $(%s_OBJS)\n", OBJS
229 printf "\t@echo linking $@\n"
230 printf "\t@mkdir -p %s\n", directory
231 if ( ReLink != "yes" ) {
232 printf "\t@sleep 1\n"
235 make_shlib(OBJS, "TICS_LIST")
236 } else if ( is_termlib() ) {
237 make_shlib(OBJS, "TINFO_LIST")
239 make_shlib(OBJS, "SHLIB_LIST")
241 sharedlinks(directory)
243 function shlib_install(directory) {
244 src_lib1 = sprintf("../lib/%s", end_name);
245 dst_lib1 = sprintf("%s/%s", directory, end_name);
246 printf "%s : \\\n", dst_lib1
247 printf "\t\t%s \\\n", directory
248 printf "\t\t%s\n", src_lib1
249 printf "\t@echo installing $@\n"
250 printf "\t$(INSTALL_LIB) %s %s\n", src_lib1, dst_lib1;
251 sharedlinks(directory)
253 function install_dll(directory,filename) {
254 src_name = sprintf("../lib/%s", filename);
255 dst_name = sprintf("$(DESTDIR)%s/%s", directory, filename);
256 printf "\t@echo installing %s as %s\n", src_name, dst_name
257 if ( directory == "$(bindir)" ) {
258 program = "$(INSTALL) -m 755";
260 program = "$(INSTALL_LIB)";
262 printf "\t%s %s %s\n", program, src_name, dst_name
264 function in_subset(value) {
265 value = " " value " ";
267 gsub("[+]", " ", check);
268 check = " " check " ";
269 return index(check,value);
278 if (subset == "none") {
281 print "# generated by mk-1st.awk"
282 } else if (in_subset($2) > 0) {
285 if ( name ~ /^.*\+\+.*/ ) {
286 if ( CXX_MODEL == "NORMAL" && MODEL == "SHARED" ) {
288 printf "# overriding model from %s to match CXX_MODEL\n", MODEL;
295 printf "# generated by mk-1st.awk (subset=%s)\n", subset
296 printf "# name: %s\n", name
297 printf "# traces: %s\n", traces
298 printf "# MODEL: %s\n", MODEL
299 printf "# CXX_MODEL: %s\n", CXX_MODEL
300 printf "# LIB_SUFFIX: %s\n", LIB_SUFFIX
301 printf "# model: %s\n", model
302 printf "# prefix: %s\n", prefix
303 printf "# suffix: %s\n", suffix
304 printf "# subset: %s\n", subset
305 printf "# driver: %s\n", driver
306 printf "# ShlibVer: %s\n", ShlibVer
307 printf "# ShlibVerInfix: %s\n", ShlibVerInfix
308 printf "# SymLink: %s\n", SymLink
309 printf "# TermlibRoot: %s\n", TermlibRoot
310 printf "# TermlibSuffix: %s\n", TermlibSuffix
311 printf "# ReLink: %s\n", ReLink
312 printf "# ReRanlib: %s\n", ReRanlib
313 printf "# DoLinks: %s\n", DoLinks
314 printf "# rmSoLocs: %s\n", rmSoLocs
315 printf "# ldconfig: %s\n", ldconfig
316 printf "# make_phony: %s\n", make_phony
317 printf "# overwrite: %s\n", overwrite
318 printf "# depend: %s\n", depend
319 printf "# host: %s\n", host
320 printf "# libtool_version: %s\n", libtool_version
327 } else if ( is_termlib() ) {
338 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
343 && ( $1 != "link_test" ) \
351 printf "%s_OBJS =", OBJS
354 } else if ( $2 == "c++" ) {
355 TOOL_PREFIX = "CXX_";
368 printf " \\\n\t../%s/%s$o", model, $1;
375 printf "\n$(%s_OBJS) : %s\n", OBJS, depend
380 lib_name = lib_name_of(name);
381 if ( MODEL == "SHARED" )
383 abi_name = abi_name_of(name);
384 rel_name = rel_name_of(name);
385 imp_name = imp_name_of(name);
386 end_name = end_name_of(name);
388 shlib_build("../lib")
392 print "install.libs \\"
394 if ( ShlibVer == "cygdll" || ShlibVer == "msysdll" || ShlibVer == "mingw" || ShlibVer == "msvcdll") {
396 dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
397 printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs
398 install_dll("$(bindir)",end_name);
399 install_dll("$(libdir)",imp_name);
403 lib_dir = "$(DESTDIR)$(libdir)";
404 printf "install.%s :: %s/%s\n", name, lib_dir, end_name
406 if ( ReLink == "yes" ) {
409 shlib_install(lib_dir)
413 if ( overwrite == "yes" && name == "ncurses" )
415 if ( ShlibVer == "cygdll" || ShlibVer == "msysdll" || ShlibVer == "mingw" || SlibVer == "msvcdll") {
416 if (ShlibVer == "msvcdll") {
419 curses_prefix = "lib"
421 ovr_name = sprintf("%scurses%s.a", curses_prefix, suffix)
422 printf "\t@echo linking %s to %s\n", imp_name, ovr_name
423 printf "\tcd $(DESTDIR)$(libdir) && ("
424 symlink(imp_name, ovr_name)
427 ovr_name = sprintf("libcurses%s", suffix)
428 printf "\t@echo linking %s to %s\n", end_name, ovr_name
429 printf "\tcd $(DESTDIR)$(libdir) && ("
430 symlink(end_name, ovr_name)
434 if ( ldconfig != "" && ldconfig != ":" ) {
435 printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
439 print "uninstall.libs \\"
440 printf "uninstall.%s ::\n", name
441 if ( ShlibVer == "cygdll" || ShlibVer == "msysdll" || ShlibVer == "mingw" || ShlibVer == "msvcdll") {
443 printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
444 printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
446 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
447 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
450 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
451 removelinks("$(DESTDIR)$(libdir)")
452 if ( overwrite == "yes" && name == "ncurses" )
454 ovr_name = sprintf("libcurses%s", suffix)
455 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
458 if ( rmSoLocs == "yes" ) {
460 print "mostlyclean \\"
462 printf "\t-@rm -f so_locations\n"
465 else if ( MODEL == "LIBTOOL" )
468 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
470 which_list = "TICS_LIST";
471 } else if ( is_termlib() ) {
472 which_list = "TINFO_LIST";
474 which_list = "SHLIB_LIST";
476 printf "\tcd ../lib && $(LIBTOOL_LINK) $(%s) $(%s) \\\n", CC_NAME, CC_FLAG;
477 printf "\t\t-o %s $(%s_OBJS:$o=.lo) \\\n", lib_name, OBJS;
478 printf "\t\t-rpath $(libdir) \\\n";
479 printf "\t\t%s $(NCURSES_MAJOR):$(NCURSES_MINOR) $(LT_UNDEF) $(%s) $(LDFLAGS)\n", libtool_version, which_list;
480 if ( make_phony == "yes" ) {
482 printf ".PHONY :\tinstall.%s\n", name;
486 print "install.libs \\"
487 printf "install.%s :: \\\n", name;
488 printf "\t\t$(DESTDIR)$(libdir) \\\n";
489 if ( (name != TermlibRoot ) && ( index(name, "++") == 0 ) && ( index(name, "tic") == 1 || index(name, "ncurses") == 1 ) ) {
490 printf "\t\tinstall.%s \\\n", TermlibRoot;
491 if ( index(name, "tic") == 1 && index(TermlibRoot, "ncurses") != 1 ) {
492 printf "\t\tinstall.%s%s \\\n", "ncurses", LIB_SUFFIX;
495 printf "\t\t../lib/%s\n", lib_name
496 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
497 printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
500 print "uninstall.libs \\"
501 printf "uninstall.%s ::\n", name
502 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
503 printf "\t-@$(LIBTOOL_UNINSTALL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
508 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
509 # workaround: binutils' ranlib tries to be clever with
510 # timestamps, by pretending its update took no time, confusing
512 if ( ReLink != "yes" ) {
513 printf "\t@sleep 1\n"
515 printf "\t$(%sAR) $(%sARFLAGS) $@ $?\n", TOOL_PREFIX, TOOL_PREFIX;
516 printf "\t$(RANLIB) $@\n"
517 if ( host == "vxworks" )
519 printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
523 print "install.libs \\"
524 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
525 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
526 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
527 if ( overwrite == "yes" && lib_name == "libncurses.a" )
529 printf "\t@echo linking libcurses.a to libncurses.a\n"
530 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
531 printf "\t(cd $(DESTDIR)$(libdir) && "
532 symlink("libncurses.a", "libcurses.a")
535 if ( ReRanlib == "yes" )
537 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
539 if ( host == "vxworks" )
541 printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name, name
542 printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name, name
546 print "uninstall.libs \\"
547 printf "uninstall.%s ::\n", name
548 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
549 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
550 if ( overwrite == "yes" && lib_name == "libncurses.a" )
552 printf "\t@echo linking libcurses.a to libncurses.a\n"
553 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
555 if ( host == "vxworks" )
557 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
558 printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
563 removelinks("../lib");
565 print "mostlyclean::"
566 printf "\t-rm -f $(%s_OBJS)\n", OBJS
567 if ( MODEL == "LIBTOOL" ) {
568 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
571 else if ( found == 2 )
574 print "mostlyclean::"
575 printf "\t-rm -f $(%s_OBJS)\n", OBJS
576 if ( MODEL == "LIBTOOL" ) {
577 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
581 printf "\t-rm -f $(%s_OBJS)\n", OBJS
582 if ( MODEL == "LIBTOOL" ) {
583 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS