xref: /freebsd/contrib/ncurses/mk-0th.awk (revision 6574b8ed19b093f0af09501d2c9676c28993cb97)
1# $Id: mk-0th.awk,v 1.22 2012/06/30 20:56:11 tom Exp $
2##############################################################################
3# Copyright (c) 1998-2010,2012 Free Software Foundation, Inc.                #
4#                                                                            #
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:                                                      #
12#                                                                            #
13# The above copyright notice and this permission notice shall be included in #
14# all copies or substantial portions of the Software.                        #
15#                                                                            #
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.                                                  #
23#                                                                            #
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               #
27# authorization.                                                             #
28##############################################################################
29#
30# Author: Thomas E. Dickey 1996-on
31#
32# Generate list of sources for a library, together with lint/lintlib rules
33#
34# Variables:
35#	libname (library name, e.g., "ncurses", "panel", "forms", "menus")
36#	subsets (is used here to decide if wide-character code is used)
37#	ticlib (library name for libtic, e.g., "tic")
38#	termlib (library name for libtinfo, e.g., "tinfo")
39#
40function make_lintlib(name,sources) {
41	print  ""
42	print  "clean ::"
43	printf "\trm -f llib-l%s.*\n", name
44	print  ""
45	print  "realclean ::"
46	printf "\trm -f llib-l%s\n", name
47	print  ""
48	printf "llib-l%s : %s\n", name, sources
49	printf "\tcproto -a -l -DNCURSES_ENABLE_STDBOOL_H=0 -DLINT $(CPPFLAGS) %s >$@\n", sources
50	print  ""
51	print  "lintlib ::"
52	printf "\tsh $(srcdir)/../misc/makellib %s $(CPPFLAGS)\n", name
53	print ""
54	print "lint ::"
55	printf "\t$(LINT) $(LINT_OPTS) $(CPPFLAGS) %s $(LINT_LIBS)\n", sources
56}
57
58# A blank in "subsets" indicates a split-off of the library into a separate
59# file, e.g., for libtic or libtinfo.  They are all logical parts of the same
60# library.
61function which_library() {
62	if ( ( which == "ticlib" ) && ( subsets ~ /ticlib / ) ) {
63		return ticlib;
64	} else if ( ( which == "termlib" || which == "ext_tinfo" ) && ( subsets ~ /[[:space:]]base/ ) ) {
65		return termlib;
66	} else {
67		return libname;
68	}
69}
70
71function show_list(name, len, list) {
72	if ( len > 0 ) {
73		printf "\n%s_SRC =", toupper(name);
74		for (n = 0; n < len; ++n)
75			printf " \\\n\t%s", list[n];
76		print "";
77		make_lintlib(name, sprintf("$(%s_SRC)", toupper(name)));
78	}
79}
80
81BEGIN	{
82		which = libname;
83		using = 0;
84		found = 0;
85		count_ticlib = 0;
86		count_termlib = 0;
87		count_library = 0;
88	}
89	/^@/ {
90		which = $0;
91		sub(/^@[[:blank:]]+/, "", which);
92		sub(/[[:blank:]]+$/, "", which);
93	}
94	!/^[@#]/ {
95		if (using == 0)
96		{
97			print  ""
98			print  "# generated by mk-0th.awk"
99			printf "#   libname:    %s\n", libname
100			printf "#   subsets:    %s\n", subsets
101			if ( libname ~ /ncurses/ ) {
102				printf "#   ticlib:     %s\n", ticlib
103				printf "#   termlib:    %s\n", termlib
104			}
105			print  ""
106			print  ".SUFFIXES: .c .cc .h .i .ii"
107			print  ".c.i :"
108			printf "\t$(CPP) $(CPPFLAGS) $< >$@\n"
109			print  ".cc.ii :"
110			printf "\t$(CPP) $(CPPFLAGS) $< >$@\n"
111			print  ".h.i :"
112			printf "\t$(CPP) $(CPPFLAGS) $< >$@\n"
113			print  ""
114			using = 1;
115		}
116		if (which ~ /port_/ )
117		{
118			# skip win32 source
119		}
120		else if ( $0 != "" && $1 != "link_test" )
121		{
122			if ( found == 0 )
123			{
124				if ( subsets ~ /widechar/ )
125					widechar = 1;
126				else
127					widechar = 0;
128				printf "C_SRC ="
129				if ( $2 == "lib" )
130					found = 1
131				else
132					found = 2
133			}
134			if ( libname == "c++" || libname == "c++w" ) {
135				srcname = sprintf("%s/%s.cc", $3, $1);
136				printf " \\\n\t%s", srcname;
137			} else if ( widechar == 1 || $3 != "$(wide)" ) {
138				srcname = sprintf("%s/%s.c", $3, $1);
139				printf " \\\n\t%s", srcname;
140				if ( which_library() == libname ) {
141					list_library[count_library++] = srcname;
142				} else if ( which_library() == ticlib ) {
143					list_ticlib[count_ticlib++] = srcname;
144				} else {
145					list_termlib[count_termlib++] = srcname;
146				}
147			}
148		}
149	}
150END	{
151		print  ""
152		if ( found == 1 )
153		{
154			print  ""
155			printf "# Producing llib-l%s is time-consuming, so there's no direct-dependency for\n", libname;
156			print  "# it in the lintlib rule.  We'll only remove in the cleanest setup.";
157			show_list(libname, count_library, list_library);
158			show_list(ticlib, count_ticlib, list_ticlib);
159			show_list(termlib, count_termlib, list_termlib);
160		}
161		else
162		{
163			print  ""
164			print  "lintlib :"
165			print  "\t@echo no action needed"
166		}
167	}
168# vile:ts=4 sw=4
169