1 # $Id: mk-1st.awk,v 1.88 2012/02/25 20:22:09 tom Exp $
2 ##############################################################################
3 # Copyright (c) 1998-2011,2012 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 # model (directory into which we compile, e.g., "obj")
38 # prefix (e.g., "lib", for Unix-style libraries)
39 # suffix (e.g., "_g.a", for debug libraries)
40 # subset ("none", "base", "base+ext_funcs" or "termlib", etc.)
41 # driver ("yes" or "no", depends on --enable-term-driver)
42 # ShlibVer ("rel", "abi" or "auto", to augment DoLinks variable)
43 # ShlibVerInfix ("yes" or "no", determines location of version #)
44 # SymLink ("ln -s", etc)
45 # TermlibRoot ("tinfo" or other root for libterm.so)
46 # TermlibSuffix (".so" or other suffix for libterm.so)
47 # ReLink ("yes", or "no", flag to rebuild shared libs on install)
48 # DoLinks ("yes", "reverse" or "no", flag to add symbolic links)
49 # rmSoLocs ("yes" or "no", flag to add extra clean target)
50 # ldconfig (path for this tool, if used)
51 # overwrite ("yes" or "no", flag to add link to libcurses.a
52 # depend (optional dependencies for all objects, e.g, ncurses_cfg.h)
53 # host (cross-compile host, if any)
54 # libtool_version (libtool "-version-info" or "-version-number")
57 # CLIXs nawk does not like underscores in command-line variable names.
58 # Mixed-case variable names are ok.
59 # HP/UX requires shared libraries to have executable permissions.
61 function is_ticlib() {
62 return ( subset ~ /^ticlib$/ );
64 function is_termlib() {
65 return ( subset ~ /^(ticlib\+)?termlib((\+[^+ ]+)*\+[a-z_]+_tinfo)?$/ );
68 function lib_name_of(a_name) {
69 return sprintf("%s%s%s", prefix, a_name, suffix)
72 function imp_name_of(a_name) {
73 if (ShlibVerInfix == "cygdll" || ShlibVerInfix == "mingw") {
74 result = sprintf("%s%s%s.a", prefix, a_name, suffix);
81 function abi_name_of(a_name) {
82 if (ShlibVerInfix == "cygdll") {
83 result = sprintf("%s%s$(ABI_VERSION)%s", "cyg", a_name, suffix);
84 } else if (ShlibVerInfix == "mingw") {
85 result = sprintf("%s%s$(ABI_VERSION)%s", prefix, a_name, suffix);
86 } else if (ShlibVerInfix == "yes") {
87 result = sprintf("%s%s.$(ABI_VERSION)%s", prefix, a_name, suffix);
89 result = sprintf("%s.$(ABI_VERSION)", lib_name_of(a_name));
94 function rel_name_of(a_name) {
95 if (ShlibVerInfix == "cygdll") {
96 result = sprintf("%s%s$(REL_VERSION)%s", "cyg", a_name, suffix);
97 } else if (ShlibVerInfix == "mingw") {
98 result = sprintf("%s%s$(REL_VERSION)%s", prefix, a_name, suffix);
99 } else if (ShlibVerInfix == "yes") {
100 result = sprintf("%s%s.$(REL_VERSION)%s", prefix, a_name, suffix);
102 result = sprintf("%s.$(REL_VERSION)", lib_name_of(a_name));
107 function end_name_of(a_name) {
108 if ( MODEL != "SHARED" ) {
109 result = lib_name_of(a_name);
110 } else if ( DoLinks == "reverse") {
111 result = lib_name_of(a_name);
113 if ( ShlibVer == "rel" ) {
114 result = rel_name_of(a_name);
115 } else if ( ShlibVer == "abi" || ShlibVer == "cygdll" || ShlibVer == "mingw" ) {
116 result = abi_name_of(a_name);
118 result = lib_name_of(a_name);
123 function symlink(src,dst) {
125 if ( SymLink !~ /.*-f.*/ ) {
126 printf "rm -f %s; ", dst
128 printf "$(LN_S) %s %s; ", src, dst
131 function rmlink(directory, dst) {
132 printf "\t-rm -f %s/%s\n", directory, dst
134 function removelinks(directory) {
135 rmlink(directory, end_name);
136 if ( DoLinks == "reverse" ) {
137 if ( ShlibVer == "rel" ) {
138 rmlink(directory, abi_name);
139 rmlink(directory, rel_name);
140 } else if ( ShlibVer == "abi" ) {
141 rmlink(directory, abi_name);
144 if ( ShlibVer == "rel" ) {
145 rmlink(directory, abi_name);
146 rmlink(directory, lib_name);
147 } else if ( ShlibVer == "abi" ) {
148 rmlink(directory, lib_name);
152 function make_shlib(objs, shlib_list) {
153 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(%s) $(LDFLAGS)\n", objs, shlib_list
155 function sharedlinks(directory) {
156 if ( ShlibVer != "auto" && ShlibVer != "cygdll" && ShlibVer != "mingw" ) {
157 printf "\tcd %s && (", directory
158 if ( DoLinks == "reverse" ) {
159 if ( ShlibVer == "rel" ) {
160 symlink(lib_name, abi_name);
161 symlink(abi_name, rel_name);
162 } else if ( ShlibVer == "abi" ) {
163 symlink(lib_name, abi_name);
166 if ( ShlibVer == "rel" ) {
167 symlink(rel_name, abi_name);
168 symlink(abi_name, lib_name);
169 } else if ( ShlibVer == "abi" ) {
170 symlink(abi_name, lib_name);
176 # termlib may be named explicitly via "--with-termlib=XXX", which overrides
177 # any suffix. Temporarily override "suffix" to account for this.
178 function termlib_end_of() {
179 termlib_save_suffix = suffix;
180 suffix = TermlibSuffix;
181 termlib_temp_result = end_name_of(TermlibRoot);
182 suffix = termlib_save_suffix;
183 return termlib_temp_result;
185 function shlib_build(directory) {
186 dst_libs = sprintf("%s/%s", directory, end_name);
187 printf "%s : \\\n", dst_libs
188 printf "\t\t%s \\\n", directory
189 if (subset == "ticlib" && driver == "yes" ) {
191 sub(/^tic/, "ncurses", base); # workaround for "w"
192 printf "\t\t%s/%s \\\n", directory, end_name_of(base);
194 if (subset ~ /^base/ || subset == "ticlib" ) {
196 sub(/^[^.]\./,".",suffix)
197 if (directory != "../lib") {
198 printf "\t\t%s/%s \\\n", "../lib", termlib_end_of();
200 printf "\t\t%s/%s \\\n", directory, termlib_end_of();
203 printf "\t\t$(%s_OBJS)\n", OBJS
204 printf "\t@echo linking $@\n"
206 make_shlib(OBJS, "TICS_LIST")
207 } else if ( is_termlib() ) {
208 make_shlib(OBJS, "TINFO_LIST")
210 make_shlib(OBJS, "SHLIB_LIST")
212 sharedlinks(directory)
214 function shlib_install(directory) {
215 src_lib1 = sprintf("../lib/%s", end_name);
216 dst_lib1 = sprintf("%s/%s", directory, end_name);
217 printf "%s : \\\n", dst_lib1
218 printf "\t\t%s \\\n", directory
219 printf "\t\t%s\n", src_lib1
220 printf "\t@echo installing $@\n"
221 printf "\t$(INSTALL_LIB) %s %s\n", src_lib1, dst_lib1;
222 sharedlinks(directory)
224 function install_dll(directory,filename) {
225 src_name = sprintf("../lib/%s", filename);
226 dst_name = sprintf("$(DESTDIR)%s/%s", directory, filename);
227 printf "\t@echo installing %s as %s\n", src_name, dst_name
228 if ( directory == "$(bindir)" ) {
229 program = "$(INSTALL) -m 755";
231 program = "$(INSTALL_LIB)";
233 printf "\t%s %s %s\n", program, src_name, dst_name
241 if (subset == "none") {
243 } else if (index(subset,$2) > 0) {
247 printf "# generated by mk-1st.awk (subset=%s)\n", subset
248 printf "# name: %s\n", name
249 printf "# traces: %s\n", traces
250 printf "# MODEL: %s\n", MODEL
251 printf "# model: %s\n", model
252 printf "# prefix: %s\n", prefix
253 printf "# suffix: %s\n", suffix
254 printf "# subset: %s\n", subset
255 printf "# driver: %s\n", driver
256 printf "# ShlibVer: %s\n", ShlibVer
257 printf "# ShlibVerInfix: %s\n", ShlibVerInfix
258 printf "# SymLink: %s\n", SymLink
259 printf "# TermlibRoot: %s\n", TermlibRoot
260 printf "# TermlibSuffix: %s\n", TermlibSuffix
261 printf "# ReLink: %s\n", ReLink
262 printf "# DoLinks: %s\n", DoLinks
263 printf "# rmSoLocs: %s\n", rmSoLocs
264 printf "# ldconfig: %s\n", ldconfig
265 printf "# overwrite: %s\n", overwrite
266 printf "# depend: %s\n", depend
267 printf "# host: %s\n", host
274 } else if ( is_termlib() ) {
285 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
290 && ( $1 != "link_test" ) \
298 printf "%s_OBJS =", OBJS
304 printf " \\\n\t../%s/%s$o", model, $1
311 printf "\n$(%s_OBJS) : %s\n", OBJS, depend
316 lib_name = lib_name_of(name);
317 if ( MODEL == "SHARED" )
319 abi_name = abi_name_of(name);
320 rel_name = rel_name_of(name);
321 imp_name = imp_name_of(name);
322 end_name = end_name_of(name);
324 shlib_build("../lib")
328 print "install.libs \\"
330 if ( ShlibVer == "cygdll" || ShlibVer == "mingw") {
332 dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
333 printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs
334 install_dll("$(bindir)",end_name);
335 install_dll("$(libdir)",imp_name);
339 lib_dir = "$(DESTDIR)$(libdir)";
340 printf "install.%s :: %s/%s\n", name, lib_dir, end_name
342 if ( ReLink == "yes" ) {
345 shlib_install(lib_dir)
349 if ( overwrite == "yes" && name == "ncurses" )
351 if ( ShlibVer == "cygdll" || ShlibVer == "mingw") {
352 ovr_name = sprintf("libcurses%s.a", suffix)
353 printf "\t@echo linking %s to %s\n", imp_name, ovr_name
354 printf "\tcd $(DESTDIR)$(libdir) && ("
355 symlink(imp_name, ovr_name)
358 ovr_name = sprintf("libcurses%s", suffix)
359 printf "\t@echo linking %s to %s\n", end_name, ovr_name
360 printf "\tcd $(DESTDIR)$(libdir) && ("
361 symlink(end_name, ovr_name)
365 if ( ldconfig != "" && ldconfig != ":" ) {
366 printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
370 print "uninstall.libs \\"
371 printf "uninstall.%s ::\n", name
372 if ( ShlibVer == "cygdll" || ShlibVer == "mingw") {
374 printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
375 printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
377 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
378 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
381 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
382 removelinks("$(DESTDIR)$(libdir)")
383 if ( overwrite == "yes" && name == "ncurses" )
385 ovr_name = sprintf("libcurses%s", suffix)
386 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
389 if ( rmSoLocs == "yes" ) {
391 print "mostlyclean \\"
393 printf "\t-@rm -f so_locations\n"
396 else if ( MODEL == "LIBTOOL" )
404 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
406 which_list = "TICS_LIST";
407 } else if ( is_termlib() ) {
408 which_list = "TINFO_LIST";
410 which_list = "SHLIB_LIST";
412 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
415 print "install.libs \\"
416 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
417 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
418 printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
421 print "uninstall.libs \\"
422 printf "uninstall.%s ::\n", name
423 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
424 printf "\t-@$(LIBTOOL_UNINSTALL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
429 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
430 printf "\t$(AR) $(ARFLAGS) $@ $?\n"
431 printf "\t$(RANLIB) $@\n"
432 if ( host == "vxworks" )
434 printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
438 print "install.libs \\"
439 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
440 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
441 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
442 if ( overwrite == "yes" && lib_name == "libncurses.a" )
444 printf "\t@echo linking libcurses.a to libncurses.a\n"
445 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
446 printf "\t(cd $(DESTDIR)$(libdir) && "
447 symlink("libncurses.a", "libcurses.a")
450 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
451 if ( host == "vxworks" )
453 printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name, name
454 printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name, name
458 print "uninstall.libs \\"
459 printf "uninstall.%s ::\n", name
460 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
461 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
462 if ( overwrite == "yes" && lib_name == "libncurses.a" )
464 printf "\t@echo linking libcurses.a to libncurses.a\n"
465 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
467 if ( host == "vxworks" )
469 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
470 printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
475 removelinks("../lib");
477 print "mostlyclean::"
478 printf "\t-rm -f $(%s_OBJS)\n", OBJS
479 if ( MODEL == "LIBTOOL" ) {
480 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
483 else if ( found == 2 )
486 print "mostlyclean::"
487 printf "\t-rm -f $(%s_OBJS)\n", OBJS
488 if ( MODEL == "LIBTOOL" ) {
489 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
493 printf "\t-rm -f $(%s_OBJS)\n", OBJS
494 if ( MODEL == "LIBTOOL" ) {
495 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS