1 # $Id: mk-1st.awk,v 1.109 2020/08/31 23:49:24 tom Exp $
2 ##############################################################################
3 # Copyright 2018,2020 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 # model (directory into which we compile, e.g., "obj")
40 # prefix (e.g., "lib", for Unix-style libraries)
41 # suffix (e.g., "_g.a", for debug libraries)
42 # subset ("none", "base", "base+ext_funcs" or "termlib", etc.)
43 # driver ("yes" or "no", depends on --enable-term-driver)
44 # ShlibVer ("rel", "abi" or "auto", to augment DoLinks variable)
45 # ShlibVerInfix ("yes" or "no", determines location of version #)
46 # SymLink ("ln -s", etc)
47 # TermlibRoot ("tinfo" or other root for libterm.so)
48 # TermlibSuffix (".so" or other suffix for libterm.so)
49 # ReLink ("yes", or "no", flag to rebuild shared libs on install)
50 # ReRanlib ("yes", or "no", flag to rerun ranlib for installing static)
51 # DoLinks ("yes", "reverse" or "no", flag to add symbolic links)
52 # rmSoLocs ("yes" or "no", flag to add extra clean target)
53 # ldconfig (path for this tool, if used)
54 # overwrite ("yes" or "no", flag to add link to libcurses.a
55 # depend (optional dependencies for all objects, e.g, ncurses_cfg.h)
56 # host (cross-compile host, if any)
57 # libtool_version (libtool "-version-info" or "-version-number")
60 # CLIXs nawk does not like underscores in command-line variable names.
61 # Mixed-case variable names are ok.
62 # HP/UX requires shared libraries to have executable permissions.
64 function is_ticlib() {
65 return ( subset ~ /^ticlib$/ );
67 function is_termlib() {
68 return ( subset ~ /^(ticlib\+)?termlib((\+[^+ ]+)*\+[a-z_]+_tinfo)?$/ );
71 function lib_name_of(a_name) {
72 return sprintf("%s%s%s", prefix, a_name, suffix)
75 function imp_name_of(a_name) {
76 if (ShlibVerInfix == "cygdll" || ShlibVerInfix == "msysdll" || ShlibVerInfix == "mingw") {
77 result = sprintf("%s%s%s.a", prefix, a_name, suffix);
78 } else if (ShlibVerInfix == "msvcdll") {
79 result = sprintf("%s%s%s.lib", prefix, a_name, suffix);
86 function abi_name_of(a_name) {
87 if (ShlibVerInfix == "cygdll") {
88 result = sprintf("%s%s$(ABI_VERSION)%s", "cyg", a_name, suffix);
89 } else if (ShlibVerInfix == "msysdll") {
90 result = sprintf("%s%s$(ABI_VERSION)%s", "msys-", a_name, suffix);
91 } else if (ShlibVerInfix == "mingw" || ShlibVerInfix == "msvcdll") {
92 result = sprintf("%s%s$(ABI_VERSION)%s", prefix, a_name, suffix);
93 } else if (ShlibVerInfix == "yes") {
94 result = sprintf("%s%s.$(ABI_VERSION)%s", prefix, a_name, suffix);
96 result = sprintf("%s.$(ABI_VERSION)", lib_name_of(a_name));
101 function rel_name_of(a_name) {
102 if (ShlibVerInfix == "cygdll") {
103 result = sprintf("%s%s$(REL_VERSION)%s", "cyg", a_name, suffix);
104 } else if (ShlibVerInfix == "msysdll") {
105 result = sprintf("%s%s$(ABI_VERSION)%s", "msys-", a_name, suffix);
106 } else if (ShlibVerInfix == "mingw" || ShlibVerInfix == "msvcdll") {
107 result = sprintf("%s%s$(REL_VERSION)%s", prefix, a_name, suffix);
108 } else if (ShlibVerInfix == "yes") {
109 result = sprintf("%s%s.$(REL_VERSION)%s", prefix, a_name, suffix);
111 result = sprintf("%s.$(REL_VERSION)", lib_name_of(a_name));
116 function end_name_of(a_name) {
117 if ( MODEL != "SHARED" ) {
118 result = lib_name_of(a_name);
119 } else if ( DoLinks == "reverse") {
120 result = lib_name_of(a_name);
122 if ( ShlibVer == "rel" ) {
123 result = rel_name_of(a_name);
124 } else if ( ShlibVer == "abi" || ShlibVer == "cygdll" || ShlibVer == "msysdll" || ShlibVer == "mingw" || ShlibVer == "msvcdll" ) {
125 result = abi_name_of(a_name);
127 result = lib_name_of(a_name);
132 function symlink(src,dst) {
134 if ( SymLink !~ /.*-f.*/ ) {
135 printf "rm -f %s; ", dst
137 printf "$(LN_S) %s %s; ", src, dst
140 function rmlink(directory, dst) {
142 printf "\t-rm -f %s/%s\n", directory, dst
145 function removelinks(directory) {
147 links[nlinks++] = end_name;
148 if ( DoLinks == "reverse" ) {
149 if ( ShlibVer == "rel" ) {
150 links[nlinks++] = abi_name;
151 links[nlinks++] = rel_name;
152 } else if ( ShlibVer == "abi" ) {
153 links[nlinks++] = abi_name;
156 if ( ShlibVer == "rel" ) {
157 links[nlinks++] = abi_name;
158 links[nlinks++] = lib_name;
159 } else if ( ShlibVer == "abi" ) {
160 links[nlinks++] = lib_name;
163 for (j = 0; j < nlinks; ++j) {
165 for (k = 0; k < j; ++k ) {
166 if ( links[j] == links[k] ) {
172 rmlink(directory, links[j]);
176 function make_shlib(objs, shlib_list) {
177 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(%s)\n", objs, shlib_list
179 function sharedlinks(directory) {
180 if ( ShlibVer != "auto" && ShlibVer != "cygdll" && ShlibVer != "msysdll" && ShlibVer != "mingw" && ShlibVer != "msvcdll" ) {
181 printf "\tcd %s && (", directory
182 if ( DoLinks == "reverse" ) {
183 if ( ShlibVer == "rel" ) {
184 symlink(lib_name, abi_name);
185 symlink(abi_name, rel_name);
186 } else if ( ShlibVer == "abi" ) {
187 symlink(lib_name, abi_name);
190 if ( ShlibVer == "rel" ) {
191 symlink(rel_name, abi_name);
192 symlink(abi_name, lib_name);
193 } else if ( ShlibVer == "abi" ) {
194 symlink(abi_name, lib_name);
200 # termlib may be named explicitly via "--with-termlib=XXX", which overrides
201 # any suffix. Temporarily override "suffix" to account for this.
202 function termlib_end_of() {
203 termlib_save_suffix = suffix;
204 suffix = TermlibSuffix;
205 termlib_temp_result = end_name_of(TermlibRoot);
206 suffix = termlib_save_suffix;
207 return termlib_temp_result;
209 function shlib_build(directory) {
210 dst_libs = sprintf("%s/%s", directory, end_name);
211 printf "%s : \\\n", dst_libs
212 if (subset == "ticlib" && driver == "yes" ) {
214 sub(/^tic/, "ncurses", base); # workaround for "w"
215 printf "\t\t%s/%s \\\n", directory, end_name_of(base);
217 if (subset ~ /^base/ || subset == "ticlib" ) {
219 sub(/^[^.]\./,".",suffix)
220 if (directory != "../lib") {
221 printf "\t\t%s/%s \\\n", "../lib", termlib_end_of();
223 printf "\t\t%s/%s \\\n", directory, termlib_end_of();
226 printf "\t\t$(RESULTING_SYMS) $(%s_OBJS)\n", OBJS
227 printf "\t@echo linking $@\n"
228 printf "\t@mkdir -p %s\n", directory
229 if ( ReLink != "yes" ) {
230 printf "\t@sleep 1\n"
233 make_shlib(OBJS, "TICS_LIST")
234 } else if ( is_termlib() ) {
235 make_shlib(OBJS, "TINFO_LIST")
237 make_shlib(OBJS, "SHLIB_LIST")
239 sharedlinks(directory)
241 function shlib_install(directory) {
242 src_lib1 = sprintf("../lib/%s", end_name);
243 dst_lib1 = sprintf("%s/%s", directory, end_name);
244 printf "%s : \\\n", dst_lib1
245 printf "\t\t%s \\\n", directory
246 printf "\t\t%s\n", src_lib1
247 printf "\t@echo installing $@\n"
248 printf "\t$(INSTALL_LIB) %s %s\n", src_lib1, dst_lib1;
249 sharedlinks(directory)
251 function install_dll(directory,filename) {
252 src_name = sprintf("../lib/%s", filename);
253 dst_name = sprintf("$(DESTDIR)%s/%s", directory, filename);
254 printf "\t@echo installing %s as %s\n", src_name, dst_name
255 if ( directory == "$(bindir)" ) {
256 program = "$(INSTALL) -m 755";
258 program = "$(INSTALL_LIB)";
260 printf "\t%s %s %s\n", program, src_name, dst_name
262 function in_subset(value) {
263 value = " " value " ";
265 gsub("[+]", " ", check);
266 check = " " check " ";
267 return index(check,value);
276 if (subset == "none") {
278 } else if (in_subset($2) > 0) {
281 if ( name ~ /^.*\+\+.*/ ) {
282 if ( CXX_MODEL == "NORMAL" && MODEL == "SHARED" ) {
284 printf "# overriding model from %s to match CXX_MODEL\n", MODEL;
291 printf "# generated by mk-1st.awk (subset=%s)\n", subset
292 printf "# name: %s\n", name
293 printf "# traces: %s\n", traces
294 printf "# MODEL: %s\n", MODEL
295 printf "# CXX_MODEL: %s\n", CXX_MODEL
296 printf "# model: %s\n", model
297 printf "# prefix: %s\n", prefix
298 printf "# suffix: %s\n", suffix
299 printf "# subset: %s\n", subset
300 printf "# driver: %s\n", driver
301 printf "# ShlibVer: %s\n", ShlibVer
302 printf "# ShlibVerInfix: %s\n", ShlibVerInfix
303 printf "# SymLink: %s\n", SymLink
304 printf "# TermlibRoot: %s\n", TermlibRoot
305 printf "# TermlibSuffix: %s\n", TermlibSuffix
306 printf "# ReLink: %s\n", ReLink
307 printf "# ReRanlib: %s\n", ReRanlib
308 printf "# DoLinks: %s\n", DoLinks
309 printf "# rmSoLocs: %s\n", rmSoLocs
310 printf "# ldconfig: %s\n", ldconfig
311 printf "# overwrite: %s\n", overwrite
312 printf "# depend: %s\n", depend
313 printf "# host: %s\n", host
320 } else if ( is_termlib() ) {
331 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
336 && ( $1 != "link_test" ) \
344 printf "%s_OBJS =", OBJS
347 } else if ( $2 == "c++" ) {
348 TOOL_PREFIX = "CXX_";
361 printf " \\\n\t../%s/%s$o", model, $1;
368 printf "\n$(%s_OBJS) : %s\n", OBJS, depend
373 lib_name = lib_name_of(name);
374 if ( MODEL == "SHARED" )
376 abi_name = abi_name_of(name);
377 rel_name = rel_name_of(name);
378 imp_name = imp_name_of(name);
379 end_name = end_name_of(name);
381 shlib_build("../lib")
385 print "install.libs \\"
387 if ( ShlibVer == "cygdll" || ShlibVer == "msysdll" || ShlibVer == "mingw" || ShlibVer == "msvcdll") {
389 dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
390 printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs
391 install_dll("$(bindir)",end_name);
392 install_dll("$(libdir)",imp_name);
396 lib_dir = "$(DESTDIR)$(libdir)";
397 printf "install.%s :: %s/%s\n", name, lib_dir, end_name
399 if ( ReLink == "yes" ) {
402 shlib_install(lib_dir)
406 if ( overwrite == "yes" && name == "ncurses" )
408 if ( ShlibVer == "cygdll" || ShlibVer == "msysdll" || ShlibVer == "mingw" || SlibVer == "msvcdll") {
409 if (ShlibVer == "msvcdll") {
412 curses_prefix = "lib"
414 ovr_name = sprintf("%scurses%s.a", curses_prefix, suffix)
415 printf "\t@echo linking %s to %s\n", imp_name, ovr_name
416 printf "\tcd $(DESTDIR)$(libdir) && ("
417 symlink(imp_name, ovr_name)
420 ovr_name = sprintf("libcurses%s", suffix)
421 printf "\t@echo linking %s to %s\n", end_name, ovr_name
422 printf "\tcd $(DESTDIR)$(libdir) && ("
423 symlink(end_name, ovr_name)
427 if ( ldconfig != "" && ldconfig != ":" ) {
428 printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
432 print "uninstall.libs \\"
433 printf "uninstall.%s ::\n", name
434 if ( ShlibVer == "cygdll" || ShlibVer == "msysdll" || ShlibVer == "mingw" || ShlibVer == "msvcdll") {
436 printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
437 printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
439 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
440 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
443 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
444 removelinks("$(DESTDIR)$(libdir)")
445 if ( overwrite == "yes" && name == "ncurses" )
447 ovr_name = sprintf("libcurses%s", suffix)
448 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
451 if ( rmSoLocs == "yes" ) {
453 print "mostlyclean \\"
455 printf "\t-@rm -f so_locations\n"
458 else if ( MODEL == "LIBTOOL" )
461 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
463 which_list = "TICS_LIST";
464 } else if ( is_termlib() ) {
465 which_list = "TINFO_LIST";
467 which_list = "SHLIB_LIST";
469 printf "\tcd ../lib && $(LIBTOOL_LINK) $(%s) $(%s) \\\n", CC_NAME, CC_FLAG;
470 printf "\t\t-o %s $(%s_OBJS:$o=.lo) \\\n", lib_name, OBJS;
471 printf "\t\t-rpath $(libdir) \\\n";
472 printf "\t\t%s $(NCURSES_MAJOR):$(NCURSES_MINOR) $(LT_UNDEF) $(%s) $(LDFLAGS)\n", libtool_version, which_list;
475 print "install.libs \\"
476 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
477 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
478 printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
481 print "uninstall.libs \\"
482 printf "uninstall.%s ::\n", name
483 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
484 printf "\t-@$(LIBTOOL_UNINSTALL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
489 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
490 # workaround: binutils' ranlib tries to be clever with
491 # timestamps, by pretending its update took no time, confusing
493 if ( ReLink != "yes" ) {
494 printf "\t@sleep 1\n"
496 printf "\t$(%sAR) $(%sARFLAGS) $@ $?\n", TOOL_PREFIX, TOOL_PREFIX;
497 printf "\t$(RANLIB) $@\n"
498 if ( host == "vxworks" )
500 printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
504 print "install.libs \\"
505 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
506 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
507 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
508 if ( overwrite == "yes" && lib_name == "libncurses.a" )
510 printf "\t@echo linking libcurses.a to libncurses.a\n"
511 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
512 printf "\t(cd $(DESTDIR)$(libdir) && "
513 symlink("libncurses.a", "libcurses.a")
516 if ( ReRanlib == "yes" )
518 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
520 if ( host == "vxworks" )
522 printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name, name
523 printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name, name
527 print "uninstall.libs \\"
528 printf "uninstall.%s ::\n", name
529 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
530 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
531 if ( overwrite == "yes" && lib_name == "libncurses.a" )
533 printf "\t@echo linking libcurses.a to libncurses.a\n"
534 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
536 if ( host == "vxworks" )
538 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
539 printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
544 removelinks("../lib");
546 print "mostlyclean::"
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
552 else if ( found == 2 )
555 print "mostlyclean::"
556 printf "\t-rm -f $(%s_OBJS)\n", OBJS
557 if ( MODEL == "LIBTOOL" ) {
558 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
562 printf "\t-rm -f $(%s_OBJS)\n", OBJS
563 if ( MODEL == "LIBTOOL" ) {
564 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS