1 # $Id: mk-1st.awk,v 1.90 2013/03/10 00:09:14 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) {
133 printf "\t-rm -f %s/%s\n", directory, dst
135 function removelinks(directory) {
136 rmlink(directory, end_name);
137 if ( DoLinks == "reverse" ) {
138 if ( ShlibVer == "rel" ) {
139 rmlink(directory, abi_name);
140 rmlink(directory, rel_name);
141 } else if ( ShlibVer == "abi" ) {
142 rmlink(directory, abi_name);
145 if ( ShlibVer == "rel" ) {
146 rmlink(directory, abi_name);
147 rmlink(directory, lib_name);
148 } else if ( ShlibVer == "abi" ) {
149 rmlink(directory, lib_name);
153 function make_shlib(objs, shlib_list) {
154 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(%s) $(LDFLAGS)\n", objs, shlib_list
156 function sharedlinks(directory) {
157 if ( ShlibVer != "auto" && ShlibVer != "cygdll" && ShlibVer != "mingw" ) {
158 printf "\tcd %s && (", directory
159 if ( DoLinks == "reverse" ) {
160 if ( ShlibVer == "rel" ) {
161 symlink(lib_name, abi_name);
162 symlink(abi_name, rel_name);
163 } else if ( ShlibVer == "abi" ) {
164 symlink(lib_name, abi_name);
167 if ( ShlibVer == "rel" ) {
168 symlink(rel_name, abi_name);
169 symlink(abi_name, lib_name);
170 } else if ( ShlibVer == "abi" ) {
171 symlink(abi_name, lib_name);
177 # termlib may be named explicitly via "--with-termlib=XXX", which overrides
178 # any suffix. Temporarily override "suffix" to account for this.
179 function termlib_end_of() {
180 termlib_save_suffix = suffix;
181 suffix = TermlibSuffix;
182 termlib_temp_result = end_name_of(TermlibRoot);
183 suffix = termlib_save_suffix;
184 return termlib_temp_result;
186 function shlib_build(directory) {
187 dst_libs = sprintf("%s/%s", directory, end_name);
188 printf "%s : \\\n", dst_libs
189 printf "\t\t%s \\\n", directory
190 if (subset == "ticlib" && driver == "yes" ) {
192 sub(/^tic/, "ncurses", base); # workaround for "w"
193 printf "\t\t%s/%s \\\n", directory, end_name_of(base);
195 if (subset ~ /^base/ || subset == "ticlib" ) {
197 sub(/^[^.]\./,".",suffix)
198 if (directory != "../lib") {
199 printf "\t\t%s/%s \\\n", "../lib", termlib_end_of();
201 printf "\t\t%s/%s \\\n", directory, termlib_end_of();
204 printf "\t\t$(%s_OBJS)\n", OBJS
205 printf "\t@echo linking $@\n"
207 make_shlib(OBJS, "TICS_LIST")
208 } else if ( is_termlib() ) {
209 make_shlib(OBJS, "TINFO_LIST")
211 make_shlib(OBJS, "SHLIB_LIST")
213 sharedlinks(directory)
215 function shlib_install(directory) {
216 src_lib1 = sprintf("../lib/%s", end_name);
217 dst_lib1 = sprintf("%s/%s", directory, end_name);
218 printf "%s : \\\n", dst_lib1
219 printf "\t\t%s \\\n", directory
220 printf "\t\t%s\n", src_lib1
221 printf "\t@echo installing $@\n"
222 printf "\t$(INSTALL_LIB) %s %s\n", src_lib1, dst_lib1;
223 sharedlinks(directory)
225 function install_dll(directory,filename) {
226 src_name = sprintf("../lib/%s", filename);
227 dst_name = sprintf("$(DESTDIR)%s/%s", directory, filename);
228 printf "\t@echo installing %s as %s\n", src_name, dst_name
229 if ( directory == "$(bindir)" ) {
230 program = "$(INSTALL) -m 755";
232 program = "$(INSTALL_LIB)";
234 printf "\t%s %s %s\n", program, src_name, dst_name
242 if (subset == "none") {
244 } else if (index(subset,$2) > 0) {
248 printf "# generated by mk-1st.awk (subset=%s)\n", subset
249 printf "# name: %s\n", name
250 printf "# traces: %s\n", traces
251 printf "# MODEL: %s\n", MODEL
252 printf "# CXX_MODEL: %s\n", CXX_MODEL
253 printf "# model: %s\n", model
254 printf "# prefix: %s\n", prefix
255 printf "# suffix: %s\n", suffix
256 printf "# subset: %s\n", subset
257 printf "# driver: %s\n", driver
258 printf "# ShlibVer: %s\n", ShlibVer
259 printf "# ShlibVerInfix: %s\n", ShlibVerInfix
260 printf "# SymLink: %s\n", SymLink
261 printf "# TermlibRoot: %s\n", TermlibRoot
262 printf "# TermlibSuffix: %s\n", TermlibSuffix
263 printf "# ReLink: %s\n", ReLink
264 printf "# DoLinks: %s\n", DoLinks
265 printf "# rmSoLocs: %s\n", rmSoLocs
266 printf "# ldconfig: %s\n", ldconfig
267 printf "# overwrite: %s\n", overwrite
268 printf "# depend: %s\n", depend
269 printf "# host: %s\n", host
276 } else if ( is_termlib() ) {
287 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
292 && ( $1 != "link_test" ) \
300 printf "%s_OBJS =", OBJS
303 } else if ( $2 == "c++" && CXX_MODEL == "SHARED" ) {
309 printf " \\\n\t../%s/%s$o", model, $1;
316 printf "\n$(%s_OBJS) : %s\n", OBJS, depend
321 lib_name = lib_name_of(name);
322 if ( MODEL == "SHARED" )
324 abi_name = abi_name_of(name);
325 rel_name = rel_name_of(name);
326 imp_name = imp_name_of(name);
327 end_name = end_name_of(name);
329 shlib_build("../lib")
333 print "install.libs \\"
335 if ( ShlibVer == "cygdll" || ShlibVer == "mingw") {
337 dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
338 printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs
339 install_dll("$(bindir)",end_name);
340 install_dll("$(libdir)",imp_name);
344 lib_dir = "$(DESTDIR)$(libdir)";
345 printf "install.%s :: %s/%s\n", name, lib_dir, end_name
347 if ( ReLink == "yes" ) {
350 shlib_install(lib_dir)
354 if ( overwrite == "yes" && name == "ncurses" )
356 if ( ShlibVer == "cygdll" || ShlibVer == "mingw") {
357 ovr_name = sprintf("libcurses%s.a", suffix)
358 printf "\t@echo linking %s to %s\n", imp_name, ovr_name
359 printf "\tcd $(DESTDIR)$(libdir) && ("
360 symlink(imp_name, ovr_name)
363 ovr_name = sprintf("libcurses%s", suffix)
364 printf "\t@echo linking %s to %s\n", end_name, ovr_name
365 printf "\tcd $(DESTDIR)$(libdir) && ("
366 symlink(end_name, ovr_name)
370 if ( ldconfig != "" && ldconfig != ":" ) {
371 printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
375 print "uninstall.libs \\"
376 printf "uninstall.%s ::\n", name
377 if ( ShlibVer == "cygdll" || ShlibVer == "mingw") {
379 printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
380 printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
382 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
383 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
386 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
387 removelinks("$(DESTDIR)$(libdir)")
388 if ( overwrite == "yes" && name == "ncurses" )
390 ovr_name = sprintf("libcurses%s", suffix)
391 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
394 if ( rmSoLocs == "yes" ) {
396 print "mostlyclean \\"
398 printf "\t-@rm -f so_locations\n"
401 else if ( MODEL == "LIBTOOL" )
409 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
411 which_list = "TICS_LIST";
412 } else if ( is_termlib() ) {
413 which_list = "TINFO_LIST";
415 which_list = "SHLIB_LIST";
417 printf "\tcd ../lib && $(LIBTOOL_LINK) $(%s) -o %s $(%s_OBJS:$o=.lo) -rpath $(DESTDIR)$(libdir) %s $(NCURSES_MAJOR):$(NCURSES_MINOR) $(LT_UNDEF) $(%s) $(LDFLAGS)\n", compile, lib_name, OBJS, libtool_version, which_list
420 print "install.libs \\"
421 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
422 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
423 printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
426 print "uninstall.libs \\"
427 printf "uninstall.%s ::\n", name
428 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
429 printf "\t-@$(LIBTOOL_UNINSTALL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
434 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
435 printf "\t$(AR) $(ARFLAGS) $@ $?\n"
436 printf "\t$(RANLIB) $@\n"
437 if ( host == "vxworks" )
439 printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
443 print "install.libs \\"
444 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
445 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
446 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
447 if ( overwrite == "yes" && lib_name == "libncurses.a" )
449 printf "\t@echo linking libcurses.a to libncurses.a\n"
450 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
451 printf "\t(cd $(DESTDIR)$(libdir) && "
452 symlink("libncurses.a", "libcurses.a")
455 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
456 if ( host == "vxworks" )
458 printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name, name
459 printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name, name
463 print "uninstall.libs \\"
464 printf "uninstall.%s ::\n", name
465 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
466 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
467 if ( overwrite == "yes" && lib_name == "libncurses.a" )
469 printf "\t@echo linking libcurses.a to libncurses.a\n"
470 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
472 if ( host == "vxworks" )
474 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
475 printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
480 removelinks("../lib");
482 print "mostlyclean::"
483 printf "\t-rm -f $(%s_OBJS)\n", OBJS
484 if ( MODEL == "LIBTOOL" ) {
485 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
488 else if ( found == 2 )
491 print "mostlyclean::"
492 printf "\t-rm -f $(%s_OBJS)\n", OBJS
493 if ( MODEL == "LIBTOOL" ) {
494 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
498 printf "\t-rm -f $(%s_OBJS)\n", OBJS
499 if ( MODEL == "LIBTOOL" ) {
500 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS