1 # $Id: mk-1st.awk,v 1.125 2023/04/22 15:49:59 tom Exp $
2 ##############################################################################
3 # Copyright 2018-2021,2023 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 # USE_LIB_SUFFIX (e.g., "", "w", "t", "tw")
41 # model (directory into which we compile, e.g., "obj")
42 # prefix (e.g., "lib", for Unix-style libraries)
43 # suffix (e.g., "_g.a", for debug libraries)
44 # subset ("none", "base", "base+ext_funcs" or "termlib", etc.)
45 # driver ("yes" or "no", depends on --enable-term-driver)
46 # ShlibVer ("rel", "abi" or "auto", to augment DoLinks variable)
47 # ShlibVerInfix ("yes" or "no", determines location of version #)
48 # SymLink ("ln -s", etc)
49 # TermlibRoot ("tinfo" or other root for libterm.so)
50 # TermlibSuffix (".so" or other suffix for libterm.so)
51 # ReLink ("yes", or "no", flag to rebuild shared libs on install)
52 # ReRanlib ("yes", or "no", flag to rerun ranlib for installing static)
53 # DoLinks ("yes", "reverse" or "no", flag to add symbolic links)
54 # rmSoLocs ("yes" or "no", flag to add extra clean target)
55 # ldconfig (path for this tool, if used)
56 # make_phony ("yes" if the make-program accepts ".PHONY" directive.
57 # overwrite ("yes" or "no", flag to add link to libcurses.a
58 # depend (optional dependencies for all objects, e.g, ncurses_cfg.h)
59 # host (cross-compile host, if any)
60 # libtool_version (libtool "-version-info" or "-version-number")
63 # CLIXs nawk does not like underscores in command-line variable names.
64 # Mixed-case variable names are ok.
65 # HP-UX requires shared libraries to have executable permissions.
67 function is_ticlib() {
68 return ( subset ~ /^ticlib$/ );
70 function is_termlib() {
71 return ( subset ~ /^(ticlib\+)?termlib((\+[^+ ]+)*\+[a-z_]+_tinfo)?$/ );
74 function lib_name_of(a_name) {
75 return sprintf("%s%s%s", prefix, a_name, suffix)
78 function imp_name_of(a_name) {
79 if (ShlibVerInfix == "cygdll" || ShlibVerInfix == "msysdll" || ShlibVerInfix == "mingw") {
80 result = sprintf("%s%s%s.a", prefix, a_name, suffix);
81 } else if (ShlibVerInfix == "msvcdll") {
82 result = sprintf("%s%s%s.lib", prefix, a_name, suffix);
89 function abi_name_of(a_name) {
90 if (ShlibVerInfix == "cygdll") {
91 result = sprintf("%s%s$(ABI_VERSION)%s", "cyg", a_name, suffix);
92 } else if (ShlibVerInfix == "msysdll") {
93 result = sprintf("%s%s$(ABI_VERSION)%s", "msys-", a_name, suffix);
94 } else if (ShlibVerInfix == "mingw" || ShlibVerInfix == "msvcdll") {
95 result = sprintf("%s%s$(ABI_VERSION)%s", prefix, a_name, suffix);
96 } else if (ShlibVerInfix == "yes") {
97 result = sprintf("%s%s.$(ABI_VERSION)%s", prefix, a_name, suffix);
99 result = sprintf("%s.$(ABI_VERSION)", lib_name_of(a_name));
104 function rel_name_of(a_name) {
105 if (ShlibVerInfix == "cygdll") {
106 result = sprintf("%s%s$(REL_VERSION)%s", "cyg", a_name, suffix);
107 } else if (ShlibVerInfix == "msysdll") {
108 result = sprintf("%s%s$(ABI_VERSION)%s", "msys-", a_name, suffix);
109 } else if (ShlibVerInfix == "mingw" || ShlibVerInfix == "msvcdll") {
110 result = sprintf("%s%s$(REL_VERSION)%s", prefix, a_name, suffix);
111 } else if (ShlibVerInfix == "yes") {
112 result = sprintf("%s%s.$(REL_VERSION)%s", prefix, a_name, suffix);
114 result = sprintf("%s.$(REL_VERSION)", lib_name_of(a_name));
119 function end_name_of(a_name) {
120 if ( MODEL != "SHARED" ) {
121 result = lib_name_of(a_name);
122 } else if ( DoLinks == "reverse") {
123 result = lib_name_of(a_name);
125 if ( ShlibVer == "rel" ) {
126 result = rel_name_of(a_name);
127 } else if ( ShlibVer == "abi" || ShlibVer == "cygdll" || ShlibVer == "msysdll" || ShlibVer == "mingw" || ShlibVer == "msvcdll" ) {
128 result = abi_name_of(a_name);
130 result = lib_name_of(a_name);
135 function symlink(src,dst) {
137 if ( SymLink !~ /.*-f.*/ ) {
138 printf "rm -f %s; ", dst
140 printf "$(LN_S) %s %s; ", src, dst
143 function rmlink(directory, dst) {
145 printf "\t-rm -f %s/%s\n", directory, dst
148 function removelinks(directory) {
150 links[nlinks++] = end_name;
151 if ( DoLinks == "reverse" ) {
152 if ( ShlibVer == "rel" ) {
153 links[nlinks++] = abi_name;
154 links[nlinks++] = rel_name;
155 } else if ( ShlibVer == "abi" ) {
156 links[nlinks++] = abi_name;
159 if ( ShlibVer == "rel" ) {
160 links[nlinks++] = abi_name;
161 links[nlinks++] = lib_name;
162 } else if ( ShlibVer == "abi" ) {
163 links[nlinks++] = lib_name;
166 for (j = 0; j < nlinks; ++j) {
168 for (k = 0; k < j; ++k ) {
169 if ( links[j] == links[k] ) {
175 rmlink(directory, links[j]);
179 function make_shlib(objs, shlib_list) {
180 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(%s)\n", objs, shlib_list
182 function sharedlinks(directory) {
183 if ( ShlibVer != "auto" && ShlibVer != "cygdll" && ShlibVer != "msysdll" && ShlibVer != "mingw" && ShlibVer != "msvcdll" ) {
184 printf "\tcd %s && (", directory
185 if ( DoLinks == "reverse" ) {
186 if ( ShlibVer == "rel" ) {
187 symlink(lib_name, abi_name);
188 symlink(abi_name, rel_name);
189 } else if ( ShlibVer == "abi" ) {
190 symlink(lib_name, abi_name);
193 if ( ShlibVer == "rel" ) {
194 symlink(rel_name, abi_name);
195 symlink(abi_name, lib_name);
196 } else if ( ShlibVer == "abi" ) {
197 symlink(abi_name, lib_name);
203 # termlib may be named explicitly via "--with-termlib=XXX", which overrides
204 # any suffix. Temporarily override "suffix" to account for this.
205 function termlib_end_of() {
206 termlib_save_suffix = suffix;
207 suffix = TermlibSuffix;
208 termlib_temp_result = end_name_of(TermlibRoot);
209 suffix = termlib_save_suffix;
210 return termlib_temp_result;
212 function shlib_build(directory) {
213 dst_libs = sprintf("%s/%s", directory, end_name);
214 printf "%s : \\\n", dst_libs
215 if (subset == "ticlib" && driver == "yes" ) {
217 sub(/^tic/, "ncurses", base); # workaround for "w"
218 printf "\t\t%s/%s \\\n", directory, end_name_of(base);
220 if (subset ~ /^base/ || subset == "ticlib" ) {
222 sub(/^[^.]\./,".",suffix)
223 if (directory != "../lib") {
224 printf "\t\t%s/%s \\\n", "../lib", termlib_end_of();
226 printf "\t\t%s/%s \\\n", directory, termlib_end_of();
229 printf "\t\t$(RESULTING_SYMS) $(%s_OBJS)\n", OBJS
230 printf "\t@echo linking $@\n"
231 printf "\t@mkdir -p %s\n", directory
232 if ( ReLink != "yes" ) {
233 printf "\t@sleep 1\n"
236 make_shlib(OBJS, "TICS_LIST")
237 } else if ( is_termlib() ) {
238 make_shlib(OBJS, "TINFO_LIST")
240 make_shlib(OBJS, "SHLIB_LIST")
242 sharedlinks(directory)
244 function shlib_install(directory) {
245 src_lib1 = sprintf("../lib/%s", end_name);
246 dst_lib1 = sprintf("%s/%s", directory, end_name);
247 printf "%s : \\\n", dst_lib1
248 printf "\t\t%s \\\n", directory
249 printf "\t\t%s\n", src_lib1
250 printf "\t@echo installing $@\n"
251 printf "\t$(INSTALL_LIB) %s %s\n", src_lib1, dst_lib1;
252 sharedlinks(directory)
254 function install_dll(directory,filename) {
255 src_name = sprintf("../lib/%s", filename);
256 dst_name = sprintf("$(DESTDIR)%s/%s", directory, filename);
257 printf "\t@echo installing %s as %s\n", src_name, dst_name
258 if ( directory == "$(bindir)" ) {
259 program = "$(INSTALL) -m 755";
261 program = "$(INSTALL_LIB)";
263 printf "\t%s %s %s\n", program, src_name, dst_name
265 function in_subset(value) {
266 value = " " value " ";
268 gsub("[+]", " ", check);
269 check = " " check " ";
270 return index(check,value);
272 function trim_suffix(value) {
273 if (USE_LIB_SUFFIX != "" && length(value) > length(USE_LIB_SUFFIX)) {
274 check = substr(value, 1 + length(value) - length(USE_LIB_SUFFIX));
275 if (check == USE_LIB_SUFFIX) {
276 value = substr(value, 1, length(value) - length(USE_LIB_SUFFIX));
288 if (subset == "none") {
291 print "# generated by mk-1st.awk"
292 } else if (in_subset($2) > 0) {
295 if ( name ~ /^.*\+\+.*/ ) {
296 if ( CXX_MODEL == "NORMAL" && MODEL == "SHARED" ) {
298 printf "# overriding model from %s to match CXX_MODEL\n", MODEL;
305 printf "# generated by mk-1st.awk (subset=%s)\n", subset
306 printf "# name: %s\n", name
307 printf "# traces: %s\n", traces
308 printf "# MODEL: %s\n", MODEL
309 printf "# CXX_MODEL: %s\n", CXX_MODEL
310 printf "# LIB_SUFFIX: %s\n", LIB_SUFFIX
311 printf "# USE_LIB_SUFFIX: %s\n", USE_LIB_SUFFIX
312 printf "# model: %s\n", model
313 printf "# prefix: %s\n", prefix
314 printf "# suffix: %s\n", suffix
315 printf "# subset: %s\n", subset
316 printf "# driver: %s\n", driver
317 printf "# ShlibVer: %s\n", ShlibVer
318 printf "# ShlibVerInfix: %s\n", ShlibVerInfix
319 printf "# SymLink: %s\n", SymLink
320 printf "# TermlibRoot: %s\n", TermlibRoot
321 printf "# TermlibSuffix: %s\n", TermlibSuffix
322 printf "# ReLink: %s\n", ReLink
323 printf "# ReRanlib: %s\n", ReRanlib
324 printf "# DoLinks: %s\n", DoLinks
325 printf "# rmSoLocs: %s\n", rmSoLocs
326 printf "# ldconfig: %s\n", ldconfig
327 printf "# make_phony: %s\n", make_phony
328 printf "# overwrite: %s\n", overwrite
329 printf "# depend: %s\n", depend
330 printf "# host: %s\n", host
331 printf "# libtool_version: %s\n", libtool_version
338 } else if ( is_termlib() ) {
349 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
354 && ( $1 != "link_test" ) \
361 printf "%s_OBJS =", OBJS
364 } else if ( $2 == "c++" ) {
365 TOOL_PREFIX = "CXX_";
378 printf " \\\n\t../%s/%s$o", model, $1;
385 printf "\n$(%s_OBJS) : %s\n", OBJS, depend
390 lib_name = lib_name_of(name);
391 if ( MODEL == "SHARED" )
393 abi_name = abi_name_of(name);
394 rel_name = rel_name_of(name);
395 imp_name = imp_name_of(name);
396 end_name = end_name_of(name);
398 shlib_build("../lib")
402 print "install.libs \\"
404 if ( ShlibVer == "cygdll" || ShlibVer == "msysdll" || ShlibVer == "mingw" || ShlibVer == "msvcdll") {
406 dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
407 printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs
408 install_dll("$(bindir)",end_name);
409 install_dll("$(libdir)",imp_name);
413 lib_dir = "$(DESTDIR)$(libdir)";
414 printf "install.%s :: %s/%s\n", name, lib_dir, end_name
416 if ( ReLink == "yes" ) {
419 shlib_install(lib_dir)
423 if ( overwrite == "yes" && name == "ncurses" )
425 if ( ShlibVer == "cygdll" || ShlibVer == "msysdll" || ShlibVer == "mingw" || SlibVer == "msvcdll") {
426 if (ShlibVer == "msvcdll") {
429 curses_prefix = "lib"
431 ovr_name = sprintf("%scurses%s.a", curses_prefix, suffix)
432 printf "\t@echo linking %s to %s\n", imp_name, ovr_name
433 printf "\tcd $(DESTDIR)$(libdir) && ("
434 symlink(imp_name, ovr_name)
437 ovr_name = sprintf("libcurses%s", suffix)
438 printf "\t@echo linking %s to %s\n", end_name, ovr_name
439 printf "\tcd $(DESTDIR)$(libdir) && ("
440 symlink(end_name, ovr_name)
444 if ( ldconfig != "" && ldconfig != ":" ) {
445 printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
449 print "uninstall.libs \\"
450 printf "uninstall.%s ::\n", name
451 if ( ShlibVer == "cygdll" || ShlibVer == "msysdll" || ShlibVer == "mingw" || ShlibVer == "msvcdll") {
453 printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
454 printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
456 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
457 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
460 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
461 removelinks("$(DESTDIR)$(libdir)")
462 if ( overwrite == "yes" && name == "ncurses" )
464 ovr_name = sprintf("libcurses%s", suffix)
465 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
468 if ( rmSoLocs == "yes" ) {
470 print "mostlyclean \\"
472 printf "\t-@rm -f so_locations\n"
475 else if ( MODEL == "LIBTOOL" )
478 use_name = trim_suffix(TermlibRoot) USE_LIB_SUFFIX
479 printf "../lib/%s : \\\n", lib_name
480 if ( (name != use_name ) && ( index(name, "++") == 0 ) && ( index(name, "tic") == 1 || index(name, "ncurses") == 1 ) ) {
481 printf "\t\t../lib/lib%s.la \\\n", use_name;
482 if ( index(name, "tic") == 1 && index(TermlibRoot, "ncurses") != 1 ) {
483 printf "\t\t../lib/lib%s%s.la \\\n", "ncurses", USE_LIB_SUFFIX;
486 printf "\t\t$(%s_OBJS)\n", OBJS
488 which_list = "TICS_LIST";
489 } else if ( is_termlib() ) {
490 which_list = "TINFO_LIST";
492 which_list = "SHLIB_LIST";
494 printf "\tcd ../lib && $(LIBTOOL_LINK) $(%s) $(%s) \\\n", CC_NAME, CC_FLAG;
495 printf "\t\t-o %s $(%s_OBJS:$o=.lo) \\\n", lib_name, OBJS;
496 printf "\t\t-rpath $(libdir) \\\n";
497 printf "\t\t%s $(NCURSES_MAJOR):$(NCURSES_MINOR) $(LT_UNDEF) $(%s) $(LDFLAGS)\n", libtool_version, which_list;
498 if ( make_phony == "yes" ) {
500 printf ".PHONY :\tinstall.%s\n", trim_suffix(name);
504 print "install.libs \\"
505 printf "install.%s :: \\\n", trim_suffix(name);
506 printf "\t\t$(DESTDIR)$(libdir) \\\n";
507 use_name = TermlibRoot USE_LIB_SUFFIX
508 if ( (name != use_name ) && ( index(name, "++") == 0 ) && ( index(name, "tic") == 1 || index(name, "ncurses") == 1 ) ) {
509 if ( trim_suffix(TermlibRoot) != trim_suffix(name) ) {
510 printf "\t\tinstall.%s \\\n", trim_suffix(TermlibRoot);
512 if ( index(name, "tic") == 1 && index(TermlibRoot, "ncurses") != 1 && trim_suffix(name) != "ncurses" ) {
513 printf "\t\tinstall.%s \\\n", "ncurses";
516 printf "\t\t../lib/%s\n", lib_name
517 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
518 printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
521 print "uninstall.libs \\"
522 printf "uninstall.%s ::\n", trim_suffix(name)
523 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
524 printf "\t-@$(LIBTOOL_UNINSTALL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
529 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
530 # workaround: binutils' ranlib tries to be clever with
531 # timestamps, by pretending its update took no time, confusing
533 if ( ReLink != "yes" ) {
534 printf "\t@sleep 1\n"
536 printf "\t$(%sAR) $(%sARFLAGS) $@ $?\n", TOOL_PREFIX, TOOL_PREFIX;
537 printf "\t$(RANLIB) $@\n"
538 if ( host == "vxworks" )
540 printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
544 print "install.libs \\"
545 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
546 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
547 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
548 if ( overwrite == "yes" && lib_name == "libncurses.a" )
550 printf "\t@echo linking libcurses.a to libncurses.a\n"
551 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
552 printf "\t(cd $(DESTDIR)$(libdir) && "
553 symlink("libncurses.a", "libcurses.a")
556 if ( ReRanlib == "yes" )
558 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
560 if ( host == "vxworks" )
562 printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name, name
563 printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name, name
567 print "uninstall.libs \\"
568 printf "uninstall.%s ::\n", name
569 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
570 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
571 if ( overwrite == "yes" && lib_name == "libncurses.a" )
573 printf "\t@echo linking libcurses.a to libncurses.a\n"
574 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
576 if ( host == "vxworks" )
578 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
579 printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
584 removelinks("../lib");
586 print "mostlyclean::"
587 printf "\t-rm -f $(%s_OBJS)\n", OBJS
588 if ( MODEL == "LIBTOOL" ) {
589 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
592 else if ( found == 2 )
595 print "mostlyclean::"
596 printf "\t-rm -f $(%s_OBJS)\n", OBJS
597 if ( MODEL == "LIBTOOL" ) {
598 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
602 printf "\t-rm -f $(%s_OBJS)\n", OBJS
603 if ( MODEL == "LIBTOOL" ) {
604 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS