1 # $Id: mk-1st.awk,v 1.71 2007/01/13 21:33:25 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 # DoLinks ("yes", "reverse" or "no", flag to add symbolic links)
44 # rmSoLocs ("yes" or "no", flag to add extra clean target)
45 # ldconfig (path for this tool, if used)
46 # overwrite ("yes" or "no", flag to add link to libcurses.a
47 # depend (optional dependencies for all objects, e.g, ncurses_cfg.h)
48 # host (cross-compile host, if any)
51 # CLIXs nawk does not like underscores in command-line variable names.
52 # Mixed-case variable names are ok.
53 # HP/UX requires shared libraries to have executable permissions.
55 function is_ticlib() {
56 return ( subset ~ /^ticlib$/ );
58 function is_termlib() {
59 return ( subset ~ /^(ticlib\+)?termlib(\+ext_tinfo)?$/ );
62 function lib_name_of(a_name) {
63 return sprintf("%s%s%s", prefix, a_name, suffix)
66 function imp_name_of(a_name) {
67 if (ShlibVerInfix == "cygdll") {
68 result = sprintf("%s%s%s.a", prefix, a_name, suffix);
75 function abi_name_of(a_name) {
76 if (ShlibVerInfix == "cygdll") {
77 result = sprintf("%s%s$(ABI_VERSION)%s", "cyg", a_name, suffix);
78 } else if (ShlibVerInfix == "yes") {
79 result = sprintf("%s%s.$(ABI_VERSION)%s", prefix, a_name, suffix);
81 result = sprintf("%s.$(ABI_VERSION)", lib_name_of(a_name));
86 function rel_name_of(a_name) {
87 if (ShlibVerInfix == "cygdll") {
88 result = sprintf("%s%s$(REL_VERSION)%s", "cyg", a_name, suffix);
89 } else if (ShlibVerInfix == "yes") {
90 result = sprintf("%s%s.$(REL_VERSION)%s", prefix, a_name, suffix);
92 result = sprintf("%s.$(REL_VERSION)", lib_name_of(a_name));
97 function end_name_of(a_name) {
98 if ( MODEL != "SHARED" ) {
99 result = lib_name_of(a_name);
100 } else if ( DoLinks == "reverse") {
101 result = lib_name_of(a_name);
103 if ( ShlibVer == "rel" ) {
104 result = rel_name_of(a_name);
105 } else if ( ShlibVer == "abi" || ShlibVer == "cygdll" ) {
106 result = abi_name_of(a_name);
108 result = lib_name_of(a_name);
113 function symlink(src,dst) {
115 printf "rm -f %s; ", dst
116 printf "$(LN_S) %s %s; ", src, dst
119 function rmlink(directory, dst) {
120 printf "\t-rm -f %s/%s\n", directory, dst
122 function removelinks(directory) {
123 rmlink(directory, end_name);
124 if ( DoLinks == "reverse" ) {
125 if ( ShlibVer == "rel" ) {
126 rmlink(directory, abi_name);
127 rmlink(directory, rel_name);
128 } else if ( ShlibVer == "abi" ) {
129 rmlink(directory, abi_name);
132 if ( ShlibVer == "rel" ) {
133 rmlink(directory, abi_name);
134 rmlink(directory, lib_name);
135 } else if ( ShlibVer == "abi" ) {
136 rmlink(directory, lib_name);
140 function make_shlib(objs, shlib_list) {
141 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(%s) $(LDFLAGS)\n", objs, shlib_list
143 function sharedlinks(directory) {
144 if ( ShlibVer != "auto" && ShlibVer != "cygdll" ) {
145 printf "\tcd %s && (", directory
146 if ( DoLinks == "reverse" ) {
147 if ( ShlibVer == "rel" ) {
148 symlink(lib_name, abi_name);
149 symlink(abi_name, rel_name);
150 } else if ( ShlibVer == "abi" ) {
151 symlink(lib_name, abi_name);
154 if ( ShlibVer == "rel" ) {
155 symlink(rel_name, abi_name);
156 symlink(abi_name, lib_name);
157 } else if ( ShlibVer == "abi" ) {
158 symlink(abi_name, lib_name);
164 function shlib_rule(directory) {
165 if ( ShlibVer == "cygdll" ) {
166 dst_libs = sprintf("%s/$(SHARED_LIB) %s/$(IMPORT_LIB)", directory, directory);
168 dst_libs = sprintf("%s/%s", directory, end_name);
170 printf "%s : \\\n", dst_libs
171 printf "\t\t%s \\\n", directory
172 if (subset ~ /^base/ ) {
173 if (directory != "../lib") {
174 printf "\t\t%s/%s \\\n", "../lib", end_name_of("tinfo");
176 printf "\t\t%s/%s \\\n", directory, end_name_of("tinfo");
178 printf "\t\t$(%s_OBJS)\n", OBJS
179 printf "\t@echo linking $@\n"
180 print "\t-@rm -f %s", dst_libs;
182 make_shlib(OBJS, "TICS_LIST")
183 } else if ( is_termlib() ) {
184 make_shlib(OBJS, "TINFO_LIST")
186 make_shlib(OBJS, "SHLIB_LIST")
188 sharedlinks(directory)
190 function install_dll(directory,filename) {
191 src_name = sprintf("../lib/%s", filename);
192 dst_name = sprintf("$(DESTDIR)%s/%s", directory, filename);
193 printf "\t@echo installing %s as %s\n", src_name, dst_name
194 printf "\t-@rm -f %s\n", dst_name
195 if ( directory == "$(bindir)" ) {
196 program = "$(INSTALL) -m 755";
198 program = "$(INSTALL_LIB)";
200 printf "\t%s %s %s\n", program, src_name, dst_name
208 if (subset == "none") {
210 } else if (index(subset,$2) > 0) {
214 printf "# generated by mk-1st.awk (subset=%s)\n", subset
215 printf "# name: %s\n", name
216 printf "# traces: %s\n", traces
217 printf "# MODEL: %s\n", MODEL
218 printf "# model: %s\n", model
219 printf "# prefix: %s\n", prefix
220 printf "# suffix: %s\n", suffix
221 printf "# subset: %s\n", subset
222 printf "# ShlibVer: %s\n", ShlibVer
223 printf "# ShlibVerInfix: %s\n", ShlibVerInfix
224 printf "# DoLinks: %s\n", DoLinks
225 printf "# rmSoLocs: %s\n", rmSoLocs
226 printf "# ldconfig: %s\n", ldconfig
227 printf "# overwrite: %s\n", overwrite
228 printf "# depend: %s\n", depend
229 printf "# host: %s\n", host
236 } else if ( is_termlib() ) {
247 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
252 && ( $1 != "link_test" ) \
260 printf "%s_OBJS =", OBJS
266 printf " \\\n\t../%s/%s$o", model, $1
273 printf "\n$(%s_OBJS) : %s\n", OBJS, depend
278 lib_name = lib_name_of(name);
279 if ( MODEL == "SHARED" )
281 abi_name = abi_name_of(name);
282 rel_name = rel_name_of(name);
283 imp_name = imp_name_of(name);
284 end_name = end_name_of(name);
290 print "install.libs \\"
292 if ( ShlibVer == "cygdll" ) {
294 dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
295 printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs
296 install_dll("$(bindir)",end_name);
297 install_dll("$(libdir)",imp_name);
301 lib_dir = "$(DESTDIR)$(libdir)";
302 printf "install.%s :: %s/%s\n", name, lib_dir, end_name
307 if ( overwrite == "yes" && name == "ncurses" )
309 if ( ShlibVer == "cygdll" ) {
310 ovr_name = sprintf("libcurses%s.a", suffix)
311 printf "\t@echo linking %s to %s\n", imp_name, ovr_name
312 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, imp_name, ovr_name
314 ovr_name = sprintf("libcurses%s", suffix)
315 printf "\t@echo linking %s to %s\n", end_name, ovr_name
316 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, end_name, ovr_name
319 if ( ldconfig != "" && ldconfig != ":" ) {
320 printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
324 print "uninstall.libs \\"
325 printf "uninstall.%s ::\n", name
326 if ( ShlibVer == "cygdll" ) {
328 printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
329 printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
331 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
332 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
335 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
336 removelinks("$(DESTDIR)$(libdir)")
337 if ( overwrite == "yes" && name == "ncurses" )
339 if ( ShlibVer == "cygdll" ) {
340 ovr_name = sprintf("libcurses%s.a", suffix)
342 ovr_name = sprintf("libcurses%s", suffix)
344 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
347 if ( rmSoLocs == "yes" ) {
349 print "mostlyclean \\"
351 printf "\t-@rm -f so_locations\n"
354 else if ( MODEL == "LIBTOOL" )
362 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
363 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
366 print "install.libs \\"
367 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
368 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
369 printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
372 print "uninstall.libs \\"
373 printf "uninstall.%s ::\n", name
374 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
375 printf "\t-@$(LIBTOOL_UNINSTALL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
380 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
381 printf "\t$(AR) $(AR_OPTS) $@ $?\n"
382 printf "\t$(RANLIB) $@\n"
383 if ( host == "vxworks" )
385 printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
389 print "install.libs \\"
390 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
391 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
392 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
393 if ( overwrite == "yes" && lib_name == "libncurses.a" )
395 printf "\t@echo linking libcurses.a to libncurses.a\n"
396 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
397 printf "\t(cd $(DESTDIR)$(libdir) && $(LN_S) libncurses.a libcurses.a)\n"
399 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
400 if ( host == "vxworks" )
402 printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name, name
403 printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name, name
407 print "uninstall.libs \\"
408 printf "uninstall.%s ::\n", name
409 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
410 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
411 if ( overwrite == "yes" && lib_name == "libncurses.a" )
413 printf "\t@echo linking libcurses.a to libncurses.a\n"
414 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
416 if ( host == "vxworks" )
418 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
419 printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
424 removelinks("../lib");
426 print "mostlyclean::"
427 printf "\t-rm -f $(%s_OBJS)\n", OBJS
428 if ( MODEL == "LIBTOOL" ) {
429 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
432 else if ( found == 2 )
435 print "mostlyclean::"
436 printf "\t-rm -f $(%s_OBJS)\n", OBJS
437 if ( MODEL == "LIBTOOL" ) {
438 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
442 printf "\t-rm -f $(%s_OBJS)\n", OBJS
443 if ( MODEL == "LIBTOOL" ) {
444 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS