1 # $Id: mk-1st.awk,v 1.78 2007/03/24 22:10:55 tom Exp $
2 ##############################################################################
3 # Copyright (c) 1998-2006,2007 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 # ShlibVer ("rel", "abi" or "auto", to augment DoLinks variable)
42 # ShlibVerInfix ("yes" or "no", determines location of version #)
43 # TermlibRoot ("tinfo" or other root for libterm.so)
44 # TermlibSuffix (".so" or other suffix for libterm.so)
45 # ReLink ("yes", or "no", flag to rebuild shared libs on install)
46 # DoLinks ("yes", "reverse" or "no", flag to add symbolic links)
47 # rmSoLocs ("yes" or "no", flag to add extra clean target)
48 # ldconfig (path for this tool, if used)
49 # overwrite ("yes" or "no", flag to add link to libcurses.a
50 # depend (optional dependencies for all objects, e.g, ncurses_cfg.h)
51 # host (cross-compile host, if any)
54 # CLIXs nawk does not like underscores in command-line variable names.
55 # Mixed-case variable names are ok.
56 # HP/UX requires shared libraries to have executable permissions.
58 function is_ticlib() {
59 return ( subset ~ /^ticlib$/ );
61 function is_termlib() {
62 return ( subset ~ /^(ticlib\+)?termlib(\+ext_tinfo)?$/ );
65 function lib_name_of(a_name) {
66 return sprintf("%s%s%s", prefix, a_name, suffix)
69 function imp_name_of(a_name) {
70 if (ShlibVerInfix == "cygdll") {
71 result = sprintf("%s%s%s.a", prefix, a_name, suffix);
78 function abi_name_of(a_name) {
79 if (ShlibVerInfix == "cygdll") {
80 result = sprintf("%s%s$(ABI_VERSION)%s", "cyg", a_name, suffix);
81 } else if (ShlibVerInfix == "yes") {
82 result = sprintf("%s%s.$(ABI_VERSION)%s", prefix, a_name, suffix);
84 result = sprintf("%s.$(ABI_VERSION)", lib_name_of(a_name));
89 function rel_name_of(a_name) {
90 if (ShlibVerInfix == "cygdll") {
91 result = sprintf("%s%s$(REL_VERSION)%s", "cyg", a_name, suffix);
92 } else if (ShlibVerInfix == "yes") {
93 result = sprintf("%s%s.$(REL_VERSION)%s", prefix, a_name, suffix);
95 result = sprintf("%s.$(REL_VERSION)", lib_name_of(a_name));
100 function end_name_of(a_name) {
101 if ( MODEL != "SHARED" ) {
102 result = lib_name_of(a_name);
103 } else if ( DoLinks == "reverse") {
104 result = lib_name_of(a_name);
106 if ( ShlibVer == "rel" ) {
107 result = rel_name_of(a_name);
108 } else if ( ShlibVer == "abi" || ShlibVer == "cygdll" ) {
109 result = abi_name_of(a_name);
111 result = lib_name_of(a_name);
116 function symlink(src,dst) {
118 printf "rm -f %s; ", dst
119 printf "$(LN_S) %s %s; ", src, dst
122 function rmlink(directory, dst) {
123 printf "\t-rm -f %s/%s\n", directory, dst
125 function removelinks(directory) {
126 rmlink(directory, end_name);
127 if ( DoLinks == "reverse" ) {
128 if ( ShlibVer == "rel" ) {
129 rmlink(directory, abi_name);
130 rmlink(directory, rel_name);
131 } else if ( ShlibVer == "abi" ) {
132 rmlink(directory, abi_name);
135 if ( ShlibVer == "rel" ) {
136 rmlink(directory, abi_name);
137 rmlink(directory, lib_name);
138 } else if ( ShlibVer == "abi" ) {
139 rmlink(directory, lib_name);
143 function make_shlib(objs, shlib_list) {
144 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(%s) $(LDFLAGS)\n", objs, shlib_list
146 function sharedlinks(directory) {
147 if ( ShlibVer != "auto" && ShlibVer != "cygdll" ) {
148 printf "\tcd %s && (", directory
149 if ( DoLinks == "reverse" ) {
150 if ( ShlibVer == "rel" ) {
151 symlink(lib_name, abi_name);
152 symlink(abi_name, rel_name);
153 } else if ( ShlibVer == "abi" ) {
154 symlink(lib_name, abi_name);
157 if ( ShlibVer == "rel" ) {
158 symlink(rel_name, abi_name);
159 symlink(abi_name, lib_name);
160 } else if ( ShlibVer == "abi" ) {
161 symlink(abi_name, lib_name);
167 # termlib may be named explicitly via "--with-termlib=XXX", which overrides
168 # any suffix. Temporarily override "suffix" to account for this.
169 function termlib_end_of() {
170 termlib_save_suffix = suffix;
171 suffix = TermlibSuffix;
172 termlib_temp_result = end_name_of(TermlibRoot);
173 suffix = termlib_save_suffix;
174 return termlib_temp_result;
176 function shlib_build(directory) {
177 dst_libs = sprintf("%s/%s", directory, end_name);
178 printf "%s : \\\n", dst_libs
179 printf "\t\t%s \\\n", directory
180 if (subset ~ /^base/ || subset == "ticlib" ) {
182 sub(/^[^.]\./,".",suffix)
183 if (directory != "../lib") {
184 printf "\t\t%s/%s \\\n", "../lib", termlib_end_of();
186 printf "\t\t%s/%s \\\n", directory, termlib_end_of();
189 printf "\t\t$(%s_OBJS)\n", OBJS
190 printf "\t@echo linking $@\n"
192 make_shlib(OBJS, "TICS_LIST")
193 } else if ( is_termlib() ) {
194 make_shlib(OBJS, "TINFO_LIST")
196 make_shlib(OBJS, "SHLIB_LIST")
198 sharedlinks(directory)
200 function shlib_install(directory) {
201 src_lib1 = sprintf("../lib/%s", end_name);
202 dst_lib1 = sprintf("%s/%s", directory, end_name);
203 printf "%s : \\\n", dst_lib1
204 printf "\t\t%s \\\n", directory
205 printf "\t\t%s\n", src_lib1
206 printf "\t@echo installing $@\n"
207 printf "\t$(INSTALL_LIB) %s %s\n", src_lib1, dst_lib1;
208 sharedlinks(directory)
210 function install_dll(directory,filename) {
211 src_name = sprintf("../lib/%s", filename);
212 dst_name = sprintf("$(DESTDIR)%s/%s", directory, filename);
213 printf "\t@echo installing %s as %s\n", src_name, dst_name
214 if ( directory == "$(bindir)" ) {
215 program = "$(INSTALL) -m 755";
217 program = "$(INSTALL_LIB)";
219 printf "\t%s %s %s\n", program, src_name, dst_name
227 if (subset == "none") {
229 } else if (index(subset,$2) > 0) {
233 printf "# generated by mk-1st.awk (subset=%s)\n", subset
234 printf "# name: %s\n", name
235 printf "# traces: %s\n", traces
236 printf "# MODEL: %s\n", MODEL
237 printf "# model: %s\n", model
238 printf "# prefix: %s\n", prefix
239 printf "# suffix: %s\n", suffix
240 printf "# subset: %s\n", subset
241 printf "# ShlibVer: %s\n", ShlibVer
242 printf "# ShlibVerInfix: %s\n", ShlibVerInfix
243 printf "# TermlibRoot: %s\n", TermlibRoot
244 printf "# TermlibSuffix: %s\n", TermlibSuffix
245 printf "# ReLink: %s\n", ReLink
246 printf "# DoLinks: %s\n", DoLinks
247 printf "# rmSoLocs: %s\n", rmSoLocs
248 printf "# ldconfig: %s\n", ldconfig
249 printf "# overwrite: %s\n", overwrite
250 printf "# depend: %s\n", depend
251 printf "# host: %s\n", host
258 } else if ( is_termlib() ) {
269 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
274 && ( $1 != "link_test" ) \
282 printf "%s_OBJS =", OBJS
288 printf " \\\n\t../%s/%s$o", model, $1
295 printf "\n$(%s_OBJS) : %s\n", OBJS, depend
300 lib_name = lib_name_of(name);
301 if ( MODEL == "SHARED" )
303 abi_name = abi_name_of(name);
304 rel_name = rel_name_of(name);
305 imp_name = imp_name_of(name);
306 end_name = end_name_of(name);
308 shlib_build("../lib")
312 print "install.libs \\"
314 if ( ShlibVer == "cygdll" ) {
316 dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
317 printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs
318 install_dll("$(bindir)",end_name);
319 install_dll("$(libdir)",imp_name);
323 lib_dir = "$(DESTDIR)$(libdir)";
324 printf "install.%s :: %s/%s\n", name, lib_dir, end_name
326 if ( ReLink == "yes" ) {
329 shlib_install(lib_dir)
333 if ( overwrite == "yes" && name == "ncurses" )
335 if ( ShlibVer == "cygdll" ) {
336 ovr_name = sprintf("libcurses%s.a", suffix)
337 printf "\t@echo linking %s to %s\n", imp_name, ovr_name
338 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, imp_name, ovr_name
340 ovr_name = sprintf("libcurses%s", suffix)
341 printf "\t@echo linking %s to %s\n", end_name, ovr_name
342 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, end_name, ovr_name
345 if ( ldconfig != "" && ldconfig != ":" ) {
346 printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
350 print "uninstall.libs \\"
351 printf "uninstall.%s ::\n", name
352 if ( ShlibVer == "cygdll" ) {
354 printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
355 printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
357 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
358 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
361 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
362 removelinks("$(DESTDIR)$(libdir)")
363 if ( overwrite == "yes" && name == "ncurses" )
365 if ( ShlibVer == "cygdll" ) {
366 ovr_name = sprintf("libcurses%s.a", suffix)
368 ovr_name = sprintf("libcurses%s", suffix)
370 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
373 if ( rmSoLocs == "yes" ) {
375 print "mostlyclean \\"
377 printf "\t-@rm -f so_locations\n"
380 else if ( MODEL == "LIBTOOL" )
388 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
389 printf "\tcd ../lib && $(LIBTOOL_LINK) $(%s) -o %s $(%s_OBJS:$o=.lo) -rpath $(DESTDIR)$(libdir) -version-info $(NCURSES_MAJOR):$(NCURSES_MINOR) $(SHLIB_LIST)\n", compile, lib_name, OBJS
392 print "install.libs \\"
393 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
394 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
395 printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
398 print "uninstall.libs \\"
399 printf "uninstall.%s ::\n", name
400 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
401 printf "\t-@$(LIBTOOL_UNINSTALL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
406 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
407 printf "\t$(AR) $(AR_OPTS) $@ $?\n"
408 printf "\t$(RANLIB) $@\n"
409 if ( host == "vxworks" )
411 printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
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 "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
419 if ( overwrite == "yes" && lib_name == "libncurses.a" )
421 printf "\t@echo linking libcurses.a to libncurses.a\n"
422 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
423 printf "\t(cd $(DESTDIR)$(libdir) && $(LN_S) libncurses.a libcurses.a)\n"
425 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
426 if ( host == "vxworks" )
428 printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name, name
429 printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name, name
433 print "uninstall.libs \\"
434 printf "uninstall.%s ::\n", name
435 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
436 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
437 if ( overwrite == "yes" && lib_name == "libncurses.a" )
439 printf "\t@echo linking libcurses.a to libncurses.a\n"
440 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
442 if ( host == "vxworks" )
444 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
445 printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
450 removelinks("../lib");
452 print "mostlyclean::"
453 printf "\t-rm -f $(%s_OBJS)\n", OBJS
454 if ( MODEL == "LIBTOOL" ) {
455 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
458 else if ( found == 2 )
461 print "mostlyclean::"
462 printf "\t-rm -f $(%s_OBJS)\n", OBJS
463 if ( MODEL == "LIBTOOL" ) {
464 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
468 printf "\t-rm -f $(%s_OBJS)\n", OBJS
469 if ( MODEL == "LIBTOOL" ) {
470 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS