1 # $Id: mk-1st.awk,v 1.75 2007/02/24 22:10:21 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 # ReLink ("yes", or "no", flag to rebuild shared libs on install)
45 # DoLinks ("yes", "reverse" or "no", flag to add symbolic links)
46 # rmSoLocs ("yes" or "no", flag to add extra clean target)
47 # ldconfig (path for this tool, if used)
48 # overwrite ("yes" or "no", flag to add link to libcurses.a
49 # depend (optional dependencies for all objects, e.g, ncurses_cfg.h)
50 # host (cross-compile host, if any)
53 # CLIXs nawk does not like underscores in command-line variable names.
54 # Mixed-case variable names are ok.
55 # HP/UX requires shared libraries to have executable permissions.
57 function is_ticlib() {
58 return ( subset ~ /^ticlib$/ );
60 function is_termlib() {
61 return ( subset ~ /^(ticlib\+)?termlib(\+ext_tinfo)?$/ );
64 function lib_name_of(a_name) {
65 return sprintf("%s%s%s", prefix, a_name, suffix)
68 function imp_name_of(a_name) {
69 if (ShlibVerInfix == "cygdll") {
70 result = sprintf("%s%s%s.a", prefix, a_name, suffix);
77 function abi_name_of(a_name) {
78 if (ShlibVerInfix == "cygdll") {
79 result = sprintf("%s%s$(ABI_VERSION)%s", "cyg", a_name, suffix);
80 } else if (ShlibVerInfix == "yes") {
81 result = sprintf("%s%s.$(ABI_VERSION)%s", prefix, a_name, suffix);
83 result = sprintf("%s.$(ABI_VERSION)", lib_name_of(a_name));
88 function rel_name_of(a_name) {
89 if (ShlibVerInfix == "cygdll") {
90 result = sprintf("%s%s$(REL_VERSION)%s", "cyg", a_name, suffix);
91 } else if (ShlibVerInfix == "yes") {
92 result = sprintf("%s%s.$(REL_VERSION)%s", prefix, a_name, suffix);
94 result = sprintf("%s.$(REL_VERSION)", lib_name_of(a_name));
99 function end_name_of(a_name) {
100 if ( MODEL != "SHARED" ) {
101 result = lib_name_of(a_name);
102 } else if ( DoLinks == "reverse") {
103 result = lib_name_of(a_name);
105 if ( ShlibVer == "rel" ) {
106 result = rel_name_of(a_name);
107 } else if ( ShlibVer == "abi" || ShlibVer == "cygdll" ) {
108 result = abi_name_of(a_name);
110 result = lib_name_of(a_name);
115 function symlink(src,dst) {
117 printf "rm -f %s; ", dst
118 printf "$(LN_S) %s %s; ", src, dst
121 function rmlink(directory, dst) {
122 printf "\t-rm -f %s/%s\n", directory, dst
124 function removelinks(directory) {
125 rmlink(directory, end_name);
126 if ( DoLinks == "reverse" ) {
127 if ( ShlibVer == "rel" ) {
128 rmlink(directory, abi_name);
129 rmlink(directory, rel_name);
130 } else if ( ShlibVer == "abi" ) {
131 rmlink(directory, abi_name);
134 if ( ShlibVer == "rel" ) {
135 rmlink(directory, abi_name);
136 rmlink(directory, lib_name);
137 } else if ( ShlibVer == "abi" ) {
138 rmlink(directory, lib_name);
142 function make_shlib(objs, shlib_list) {
143 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(%s) $(LDFLAGS)\n", objs, shlib_list
145 function sharedlinks(directory) {
146 if ( ShlibVer != "auto" && ShlibVer != "cygdll" ) {
147 printf "\tcd %s && (", directory
148 if ( DoLinks == "reverse" ) {
149 if ( ShlibVer == "rel" ) {
150 symlink(lib_name, abi_name);
151 symlink(abi_name, rel_name);
152 } else if ( ShlibVer == "abi" ) {
153 symlink(lib_name, abi_name);
156 if ( ShlibVer == "rel" ) {
157 symlink(rel_name, abi_name);
158 symlink(abi_name, lib_name);
159 } else if ( ShlibVer == "abi" ) {
160 symlink(abi_name, lib_name);
166 function shlib_build(directory) {
167 dst_libs = sprintf("%s/%s", directory, end_name);
168 printf "%s : \\\n", dst_libs
169 printf "\t\t%s \\\n", directory
170 if (subset ~ /^base/ || subset == "ticlib" ) {
172 sub(/^[^.]\./,".",suffix)
173 if (directory != "../lib") {
174 printf "\t\t%s/%s \\\n", "../lib", end_name_of(TermlibRoot);
176 printf "\t\t%s/%s \\\n", directory, end_name_of(TermlibRoot);
179 printf "\t\t$(%s_OBJS)\n", OBJS
180 printf "\t@echo linking $@\n"
181 print "\t-@rm -f %s", dst_libs;
183 make_shlib(OBJS, "TICS_LIST")
184 } else if ( is_termlib() ) {
185 make_shlib(OBJS, "TINFO_LIST")
187 make_shlib(OBJS, "SHLIB_LIST")
189 sharedlinks(directory)
191 function shlib_install(directory) {
192 src_lib1 = sprintf("../lib/%s", end_name);
193 dst_lib1 = sprintf("%s/%s", directory, end_name);
194 printf "%s : \\\n", dst_libs
195 printf "\t\t%s \\\n", directory
196 printf "\t\t%s\n", src_libs
197 printf "\t@echo installing $@\n"
198 print "\t-@rm -f %s", dst_libs;
199 printf "\t$(INSTALL_LIB) %s %s\n", src_lib1, dst_lib1;
200 if ( src_lib2 != "" ) {
201 printf "\t$(INSTALL_LIB) %s %s\n", src_lib2, dst_lib2;
203 sharedlinks(directory)
205 function install_dll(directory,filename) {
206 src_name = sprintf("../lib/%s", filename);
207 dst_name = sprintf("$(DESTDIR)%s/%s", directory, filename);
208 printf "\t@echo installing %s as %s\n", src_name, dst_name
209 printf "\t-@rm -f %s\n", dst_name
210 if ( directory == "$(bindir)" ) {
211 program = "$(INSTALL) -m 755";
213 program = "$(INSTALL_LIB)";
215 printf "\t%s %s %s\n", program, src_name, dst_name
223 if (subset == "none") {
225 } else if (index(subset,$2) > 0) {
229 printf "# generated by mk-1st.awk (subset=%s)\n", subset
230 printf "# name: %s\n", name
231 printf "# traces: %s\n", traces
232 printf "# MODEL: %s\n", MODEL
233 printf "# model: %s\n", model
234 printf "# prefix: %s\n", prefix
235 printf "# suffix: %s\n", suffix
236 printf "# subset: %s\n", subset
237 printf "# ShlibVer: %s\n", ShlibVer
238 printf "# ShlibVerInfix: %s\n", ShlibVerInfix
239 printf "# TermlibRoot: %s\n", TermlibRoot
240 printf "# ReLink: %s\n", ReLink
241 printf "# DoLinks: %s\n", DoLinks
242 printf "# rmSoLocs: %s\n", rmSoLocs
243 printf "# ldconfig: %s\n", ldconfig
244 printf "# overwrite: %s\n", overwrite
245 printf "# depend: %s\n", depend
246 printf "# host: %s\n", host
253 } else if ( is_termlib() ) {
264 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
269 && ( $1 != "link_test" ) \
277 printf "%s_OBJS =", OBJS
283 printf " \\\n\t../%s/%s$o", model, $1
290 printf "\n$(%s_OBJS) : %s\n", OBJS, depend
295 lib_name = lib_name_of(name);
296 if ( MODEL == "SHARED" )
298 abi_name = abi_name_of(name);
299 rel_name = rel_name_of(name);
300 imp_name = imp_name_of(name);
301 end_name = end_name_of(name);
303 shlib_build("../lib")
307 print "install.libs \\"
309 if ( ShlibVer == "cygdll" ) {
311 dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
312 printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs
313 install_dll("$(bindir)",end_name);
314 install_dll("$(libdir)",imp_name);
318 lib_dir = "$(DESTDIR)$(libdir)";
319 printf "install.%s :: %s/%s\n", name, lib_dir, end_name
321 if ( ReLink == "yes" ) {
324 shlib_install(lib_dir)
328 if ( overwrite == "yes" && name == "ncurses" )
330 if ( ShlibVer == "cygdll" ) {
331 ovr_name = sprintf("libcurses%s.a", suffix)
332 printf "\t@echo linking %s to %s\n", imp_name, ovr_name
333 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, imp_name, ovr_name
335 ovr_name = sprintf("libcurses%s", suffix)
336 printf "\t@echo linking %s to %s\n", end_name, ovr_name
337 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, end_name, ovr_name
340 if ( ldconfig != "" && ldconfig != ":" ) {
341 printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
345 print "uninstall.libs \\"
346 printf "uninstall.%s ::\n", name
347 if ( ShlibVer == "cygdll" ) {
349 printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
350 printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
352 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
353 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
356 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
357 removelinks("$(DESTDIR)$(libdir)")
358 if ( overwrite == "yes" && name == "ncurses" )
360 if ( ShlibVer == "cygdll" ) {
361 ovr_name = sprintf("libcurses%s.a", suffix)
363 ovr_name = sprintf("libcurses%s", suffix)
365 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
368 if ( rmSoLocs == "yes" ) {
370 print "mostlyclean \\"
372 printf "\t-@rm -f so_locations\n"
375 else if ( MODEL == "LIBTOOL" )
383 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
384 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
387 print "install.libs \\"
388 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
389 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
390 printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
393 print "uninstall.libs \\"
394 printf "uninstall.%s ::\n", name
395 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
396 printf "\t-@$(LIBTOOL_UNINSTALL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
401 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
402 printf "\t$(AR) $(AR_OPTS) $@ $?\n"
403 printf "\t$(RANLIB) $@\n"
404 if ( host == "vxworks" )
406 printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
410 print "install.libs \\"
411 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
412 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
413 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
414 if ( overwrite == "yes" && lib_name == "libncurses.a" )
416 printf "\t@echo linking libcurses.a to libncurses.a\n"
417 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
418 printf "\t(cd $(DESTDIR)$(libdir) && $(LN_S) libncurses.a libcurses.a)\n"
420 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
421 if ( host == "vxworks" )
423 printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name, name
424 printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name, name
428 print "uninstall.libs \\"
429 printf "uninstall.%s ::\n", name
430 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
431 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
432 if ( overwrite == "yes" && lib_name == "libncurses.a" )
434 printf "\t@echo linking libcurses.a to libncurses.a\n"
435 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
437 if ( host == "vxworks" )
439 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
440 printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
445 removelinks("../lib");
447 print "mostlyclean::"
448 printf "\t-rm -f $(%s_OBJS)\n", OBJS
449 if ( MODEL == "LIBTOOL" ) {
450 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
453 else if ( found == 2 )
456 print "mostlyclean::"
457 printf "\t-rm -f $(%s_OBJS)\n", OBJS
458 if ( MODEL == "LIBTOOL" ) {
459 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
463 printf "\t-rm -f $(%s_OBJS)\n", OBJS
464 if ( MODEL == "LIBTOOL" ) {
465 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS