1 # $Id: mk-1st.awk,v 1.95 2013/03/12 11:09:40 tom Exp $
2 ##############################################################################
3 # Copyright (c) 1998-2012,2013 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 # DoLinks ("yes", "reverse" or "no", flag to add symbolic links)
50 # rmSoLocs ("yes" or "no", flag to add extra clean target)
51 # ldconfig (path for this tool, if used)
52 # overwrite ("yes" or "no", flag to add link to libcurses.a
53 # depend (optional dependencies for all objects, e.g, ncurses_cfg.h)
54 # host (cross-compile host, if any)
55 # libtool_version (libtool "-version-info" or "-version-number")
58 # CLIXs nawk does not like underscores in command-line variable names.
59 # Mixed-case variable names are ok.
60 # HP/UX requires shared libraries to have executable permissions.
62 function is_ticlib() {
63 return ( subset ~ /^ticlib$/ );
65 function is_termlib() {
66 return ( subset ~ /^(ticlib\+)?termlib((\+[^+ ]+)*\+[a-z_]+_tinfo)?$/ );
69 function lib_name_of(a_name) {
70 return sprintf("%s%s%s", prefix, a_name, suffix)
73 function imp_name_of(a_name) {
74 if (ShlibVerInfix == "cygdll" || ShlibVerInfix == "mingw") {
75 result = sprintf("%s%s%s.a", prefix, a_name, suffix);
82 function abi_name_of(a_name) {
83 if (ShlibVerInfix == "cygdll") {
84 result = sprintf("%s%s$(ABI_VERSION)%s", "cyg", a_name, suffix);
85 } else if (ShlibVerInfix == "mingw") {
86 result = sprintf("%s%s$(ABI_VERSION)%s", prefix, a_name, suffix);
87 } else if (ShlibVerInfix == "yes") {
88 result = sprintf("%s%s.$(ABI_VERSION)%s", prefix, a_name, suffix);
90 result = sprintf("%s.$(ABI_VERSION)", lib_name_of(a_name));
95 function rel_name_of(a_name) {
96 if (ShlibVerInfix == "cygdll") {
97 result = sprintf("%s%s$(REL_VERSION)%s", "cyg", a_name, suffix);
98 } else if (ShlibVerInfix == "mingw") {
99 result = sprintf("%s%s$(REL_VERSION)%s", prefix, a_name, suffix);
100 } else if (ShlibVerInfix == "yes") {
101 result = sprintf("%s%s.$(REL_VERSION)%s", prefix, a_name, suffix);
103 result = sprintf("%s.$(REL_VERSION)", lib_name_of(a_name));
108 function end_name_of(a_name) {
109 if ( MODEL != "SHARED" ) {
110 result = lib_name_of(a_name);
111 } else if ( DoLinks == "reverse") {
112 result = lib_name_of(a_name);
114 if ( ShlibVer == "rel" ) {
115 result = rel_name_of(a_name);
116 } else if ( ShlibVer == "abi" || ShlibVer == "cygdll" || ShlibVer == "mingw" ) {
117 result = abi_name_of(a_name);
119 result = lib_name_of(a_name);
124 function symlink(src,dst) {
126 if ( SymLink !~ /.*-f.*/ ) {
127 printf "rm -f %s; ", dst
129 printf "$(LN_S) %s %s; ", src, dst
132 function rmlink(directory, dst) {
134 printf "\t-rm -f %s/%s\n", directory, dst
137 function removelinks(directory) {
139 links[nlinks++] = end_name;
140 if ( DoLinks == "reverse" ) {
141 if ( ShlibVer == "rel" ) {
142 links[nlinks++] = abi_name;
143 links[nlinks++] = rel_name;
144 } else if ( ShlibVer == "abi" ) {
145 links[nlinks++] = abi_name;
148 if ( ShlibVer == "rel" ) {
149 links[nlinks++] = abi_name;
150 links[nlinks++] = lib_name;
151 } else if ( ShlibVer == "abi" ) {
152 links[nlinks++] = lib_name;
155 for (j = 0; j < nlinks; ++j) {
157 for (k = 0; k < j; ++k ) {
158 if ( links[j] == links[k] ) {
164 rmlink(directory, links[j]);
168 function make_shlib(objs, shlib_list) {
169 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(%s) $(LDFLAGS)\n", objs, shlib_list
171 function sharedlinks(directory) {
172 if ( ShlibVer != "auto" && ShlibVer != "cygdll" && ShlibVer != "mingw" ) {
173 printf "\tcd %s && (", directory
174 if ( DoLinks == "reverse" ) {
175 if ( ShlibVer == "rel" ) {
176 symlink(lib_name, abi_name);
177 symlink(abi_name, rel_name);
178 } else if ( ShlibVer == "abi" ) {
179 symlink(lib_name, abi_name);
182 if ( ShlibVer == "rel" ) {
183 symlink(rel_name, abi_name);
184 symlink(abi_name, lib_name);
185 } else if ( ShlibVer == "abi" ) {
186 symlink(abi_name, lib_name);
192 # termlib may be named explicitly via "--with-termlib=XXX", which overrides
193 # any suffix. Temporarily override "suffix" to account for this.
194 function termlib_end_of() {
195 termlib_save_suffix = suffix;
196 suffix = TermlibSuffix;
197 termlib_temp_result = end_name_of(TermlibRoot);
198 suffix = termlib_save_suffix;
199 return termlib_temp_result;
201 function shlib_build(directory) {
202 dst_libs = sprintf("%s/%s", directory, end_name);
203 printf "%s : \\\n", dst_libs
204 printf "\t\t%s \\\n", directory
205 if (subset == "ticlib" && driver == "yes" ) {
207 sub(/^tic/, "ncurses", base); # workaround for "w"
208 printf "\t\t%s/%s \\\n", directory, end_name_of(base);
210 if (subset ~ /^base/ || subset == "ticlib" ) {
212 sub(/^[^.]\./,".",suffix)
213 if (directory != "../lib") {
214 printf "\t\t%s/%s \\\n", "../lib", termlib_end_of();
216 printf "\t\t%s/%s \\\n", directory, termlib_end_of();
219 printf "\t\t$(%s_OBJS)\n", OBJS
220 printf "\t@echo linking $@\n"
222 make_shlib(OBJS, "TICS_LIST")
223 } else if ( is_termlib() ) {
224 make_shlib(OBJS, "TINFO_LIST")
226 make_shlib(OBJS, "SHLIB_LIST")
228 sharedlinks(directory)
230 function shlib_install(directory) {
231 src_lib1 = sprintf("../lib/%s", end_name);
232 dst_lib1 = sprintf("%s/%s", directory, end_name);
233 printf "%s : \\\n", dst_lib1
234 printf "\t\t%s \\\n", directory
235 printf "\t\t%s\n", src_lib1
236 printf "\t@echo installing $@\n"
237 printf "\t$(INSTALL_LIB) %s %s\n", src_lib1, dst_lib1;
238 sharedlinks(directory)
240 function install_dll(directory,filename) {
241 src_name = sprintf("../lib/%s", filename);
242 dst_name = sprintf("$(DESTDIR)%s/%s", directory, filename);
243 printf "\t@echo installing %s as %s\n", src_name, dst_name
244 if ( directory == "$(bindir)" ) {
245 program = "$(INSTALL) -m 755";
247 program = "$(INSTALL_LIB)";
249 printf "\t%s %s %s\n", program, src_name, dst_name
258 if (subset == "none") {
260 } else if (index(subset,$2) > 0) {
263 if ( name ~ /^.*\+\+.*/ ) {
264 if ( CXX_MODEL == "NORMAL" && MODEL == "SHARED" ) {
266 printf "# overriding model from %s to match CXX_MODEL\n", MODEL;
273 printf "# generated by mk-1st.awk (subset=%s)\n", subset
274 printf "# name: %s\n", name
275 printf "# traces: %s\n", traces
276 printf "# MODEL: %s\n", MODEL
277 printf "# CXX_MODEL: %s\n", CXX_MODEL
278 printf "# model: %s\n", model
279 printf "# prefix: %s\n", prefix
280 printf "# suffix: %s\n", suffix
281 printf "# subset: %s\n", subset
282 printf "# driver: %s\n", driver
283 printf "# ShlibVer: %s\n", ShlibVer
284 printf "# ShlibVerInfix: %s\n", ShlibVerInfix
285 printf "# SymLink: %s\n", SymLink
286 printf "# TermlibRoot: %s\n", TermlibRoot
287 printf "# TermlibSuffix: %s\n", TermlibSuffix
288 printf "# ReLink: %s\n", ReLink
289 printf "# DoLinks: %s\n", DoLinks
290 printf "# rmSoLocs: %s\n", rmSoLocs
291 printf "# ldconfig: %s\n", ldconfig
292 printf "# overwrite: %s\n", overwrite
293 printf "# depend: %s\n", depend
294 printf "# host: %s\n", host
301 } else if ( is_termlib() ) {
312 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
317 && ( $1 != "link_test" ) \
325 printf "%s_OBJS =", OBJS
328 } else if ( $2 == "c++" ) {
329 TOOL_PREFIX = "CXX_";
342 printf " \\\n\t../%s/%s$o", model, $1;
349 printf "\n$(%s_OBJS) : %s\n", OBJS, depend
354 lib_name = lib_name_of(name);
355 if ( MODEL == "SHARED" )
357 abi_name = abi_name_of(name);
358 rel_name = rel_name_of(name);
359 imp_name = imp_name_of(name);
360 end_name = end_name_of(name);
362 shlib_build("../lib")
366 print "install.libs \\"
368 if ( ShlibVer == "cygdll" || ShlibVer == "mingw") {
370 dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
371 printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs
372 install_dll("$(bindir)",end_name);
373 install_dll("$(libdir)",imp_name);
377 lib_dir = "$(DESTDIR)$(libdir)";
378 printf "install.%s :: %s/%s\n", name, lib_dir, end_name
380 if ( ReLink == "yes" ) {
383 shlib_install(lib_dir)
387 if ( overwrite == "yes" && name == "ncurses" )
389 if ( ShlibVer == "cygdll" || ShlibVer == "mingw") {
390 ovr_name = sprintf("libcurses%s.a", suffix)
391 printf "\t@echo linking %s to %s\n", imp_name, ovr_name
392 printf "\tcd $(DESTDIR)$(libdir) && ("
393 symlink(imp_name, ovr_name)
396 ovr_name = sprintf("libcurses%s", suffix)
397 printf "\t@echo linking %s to %s\n", end_name, ovr_name
398 printf "\tcd $(DESTDIR)$(libdir) && ("
399 symlink(end_name, ovr_name)
403 if ( ldconfig != "" && ldconfig != ":" ) {
404 printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
408 print "uninstall.libs \\"
409 printf "uninstall.%s ::\n", name
410 if ( ShlibVer == "cygdll" || ShlibVer == "mingw") {
412 printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
413 printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
415 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
416 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
419 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
420 removelinks("$(DESTDIR)$(libdir)")
421 if ( overwrite == "yes" && name == "ncurses" )
423 ovr_name = sprintf("libcurses%s", suffix)
424 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
427 if ( rmSoLocs == "yes" ) {
429 print "mostlyclean \\"
431 printf "\t-@rm -f so_locations\n"
434 else if ( MODEL == "LIBTOOL" )
437 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
439 which_list = "TICS_LIST";
440 } else if ( is_termlib() ) {
441 which_list = "TINFO_LIST";
443 which_list = "SHLIB_LIST";
445 printf "\tcd ../lib && $(LIBTOOL_LINK) $(%s) $(%s) \\\n", CC_NAME, CC_FLAG;
446 printf "\t\t-o %s $(%s_OBJS:$o=.lo) \\\n", lib_name, OBJS;
447 printf "\t\t-rpath $(DESTDIR)$(libdir) \\\n";
448 printf "\t\t%s $(NCURSES_MAJOR):$(NCURSES_MINOR) $(LT_UNDEF) $(%s) $(LDFLAGS)\n", libtool_version, which_list;
451 print "install.libs \\"
452 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
453 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
454 printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
457 print "uninstall.libs \\"
458 printf "uninstall.%s ::\n", name
459 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
460 printf "\t-@$(LIBTOOL_UNINSTALL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
465 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
466 printf "\t$(%sAR) $(%sARFLAGS) $@ $?\n", TOOL_PREFIX, TOOL_PREFIX;
467 printf "\t$(RANLIB) $@\n"
468 if ( host == "vxworks" )
470 printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
474 print "install.libs \\"
475 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
476 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
477 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
478 if ( overwrite == "yes" && lib_name == "libncurses.a" )
480 printf "\t@echo linking libcurses.a to libncurses.a\n"
481 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
482 printf "\t(cd $(DESTDIR)$(libdir) && "
483 symlink("libncurses.a", "libcurses.a")
486 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
487 if ( host == "vxworks" )
489 printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name, name
490 printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name, name
494 print "uninstall.libs \\"
495 printf "uninstall.%s ::\n", name
496 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
497 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
498 if ( overwrite == "yes" && lib_name == "libncurses.a" )
500 printf "\t@echo linking libcurses.a to libncurses.a\n"
501 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
503 if ( host == "vxworks" )
505 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
506 printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
511 removelinks("../lib");
513 print "mostlyclean::"
514 printf "\t-rm -f $(%s_OBJS)\n", OBJS
515 if ( MODEL == "LIBTOOL" ) {
516 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
519 else if ( found == 2 )
522 print "mostlyclean::"
523 printf "\t-rm -f $(%s_OBJS)\n", OBJS
524 if ( MODEL == "LIBTOOL" ) {
525 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
529 printf "\t-rm -f $(%s_OBJS)\n", OBJS
530 if ( MODEL == "LIBTOOL" ) {
531 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS