blob: 366224309112ac0316e06fb1d099855417870f62 [file] [log] [blame]
micky3879b9f5e72025-07-08 18:04:53 -04001# $Id: mk-0th.awk,v 1.24 2021/03/20 11:44:48 tom Exp $
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302##############################################################################
micky3879b9f5e72025-07-08 18:04:53 -04003# Copyright 2020,2021 Thomas E. Dickey #
4# Copyright 1998-2010,2012 Free Software Foundation, Inc. #
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05305# #
6# Permission is hereby granted, free of charge, to any person obtaining a #
7# copy of this software and associated documentation files (the "Software"), #
8# to deal in the Software without restriction, including without limitation #
9# the rights to use, copy, modify, merge, publish, distribute, distribute #
10# with modifications, sublicense, and/or sell copies of the Software, and to #
11# permit persons to whom the Software is furnished to do so, subject to the #
12# following conditions: #
13# #
14# The above copyright notice and this permission notice shall be included in #
15# all copies or substantial portions of the Software. #
16# #
17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
20# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
22# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
23# DEALINGS IN THE SOFTWARE. #
24# #
25# Except as contained in this notice, the name(s) of the above copyright #
26# holders shall not be used in advertising or otherwise to promote the sale, #
27# use or other dealings in this Software without prior written #
28# authorization. #
29##############################################################################
30#
Steve Kondikae271bc2015-11-15 02:50:53 +010031# Author: Thomas E. Dickey 1996-on
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053032#
33# Generate list of sources for a library, together with lint/lintlib rules
34#
35# Variables:
36# libname (library name, e.g., "ncurses", "panel", "forms", "menus")
37# subsets (is used here to decide if wide-character code is used)
Steve Kondikae271bc2015-11-15 02:50:53 +010038# ticlib (library name for libtic, e.g., "tic")
39# termlib (library name for libtinfo, e.g., "tinfo")
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053040#
Steve Kondikae271bc2015-11-15 02:50:53 +010041function make_lintlib(name,sources) {
42 print ""
43 print "clean ::"
44 printf "\trm -f llib-l%s.*\n", name
45 print ""
46 print "realclean ::"
47 printf "\trm -f llib-l%s\n", name
48 print ""
49 printf "llib-l%s : %s\n", name, sources
50 printf "\tcproto -a -l -DNCURSES_ENABLE_STDBOOL_H=0 -DLINT $(CPPFLAGS) %s >$@\n", sources
51 print ""
52 print "lintlib ::"
53 printf "\tsh $(srcdir)/../misc/makellib %s $(CPPFLAGS)\n", name
54 print ""
55 print "lint ::"
56 printf "\t$(LINT) $(LINT_OPTS) $(CPPFLAGS) %s $(LINT_LIBS)\n", sources
57}
58
59# A blank in "subsets" indicates a split-off of the library into a separate
60# file, e.g., for libtic or libtinfo. They are all logical parts of the same
61# library.
62function which_library() {
63 if ( ( which == "ticlib" ) && ( subsets ~ /ticlib / ) ) {
64 return ticlib;
65 } else if ( ( which == "termlib" || which == "ext_tinfo" ) && ( subsets ~ /[[:space:]]base/ ) ) {
66 return termlib;
67 } else {
68 return libname;
69 }
70}
71
72function show_list(name, len, list) {
73 if ( len > 0 ) {
74 printf "\n%s_SRC =", toupper(name);
75 for (n = 0; n < len; ++n)
76 printf " \\\n\t%s", list[n];
77 print "";
78 make_lintlib(name, sprintf("$(%s_SRC)", toupper(name)));
79 }
80}
81
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053082BEGIN {
Steve Kondikae271bc2015-11-15 02:50:53 +010083 which = libname;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053084 using = 0;
85 found = 0;
Steve Kondikae271bc2015-11-15 02:50:53 +010086 count_ticlib = 0;
87 count_termlib = 0;
88 count_library = 0;
89 }
90 /^@/ {
91 which = $0;
92 sub(/^@[[:blank:]]+/, "", which);
93 sub(/[[:blank:]]+$/, "", which);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053094 }
95 !/^[@#]/ {
96 if (using == 0)
97 {
98 print ""
99 print "# generated by mk-0th.awk"
100 printf "# libname: %s\n", libname
101 printf "# subsets: %s\n", subsets
Steve Kondikae271bc2015-11-15 02:50:53 +0100102 if ( libname ~ /ncurses/ ) {
103 printf "# ticlib: %s\n", ticlib
104 printf "# termlib: %s\n", termlib
105 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530106 print ""
107 print ".SUFFIXES: .c .cc .h .i .ii"
108 print ".c.i :"
109 printf "\t$(CPP) $(CPPFLAGS) $< >$@\n"
110 print ".cc.ii :"
111 printf "\t$(CPP) $(CPPFLAGS) $< >$@\n"
112 print ".h.i :"
113 printf "\t$(CPP) $(CPPFLAGS) $< >$@\n"
114 print ""
115 using = 1;
116 }
Steve Kondikae271bc2015-11-15 02:50:53 +0100117 if (which ~ /port_/ )
118 {
119 # skip win32 source
120 }
121 else if ( $0 != "" && $1 != "link_test" )
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530122 {
123 if ( found == 0 )
124 {
125 if ( subsets ~ /widechar/ )
126 widechar = 1;
127 else
128 widechar = 0;
129 printf "C_SRC ="
130 if ( $2 == "lib" )
131 found = 1
micky3879b9f5e72025-07-08 18:04:53 -0400132 else if ( $2 == "c++" )
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530133 found = 2
micky3879b9f5e72025-07-08 18:04:53 -0400134 else
135 found = 3
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530136 }
137 if ( libname == "c++" || libname == "c++w" ) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100138 srcname = sprintf("%s/%s.cc", $3, $1);
139 printf " \\\n\t%s", srcname;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530140 } else if ( widechar == 1 || $3 != "$(wide)" ) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100141 srcname = sprintf("%s/%s.c", $3, $1);
142 printf " \\\n\t%s", srcname;
143 if ( which_library() == libname ) {
144 list_library[count_library++] = srcname;
145 } else if ( which_library() == ticlib ) {
146 list_ticlib[count_ticlib++] = srcname;
147 } else {
148 list_termlib[count_termlib++] = srcname;
149 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530150 }
151 }
152 }
153END {
154 print ""
155 if ( found == 1 )
156 {
157 print ""
Steve Kondikae271bc2015-11-15 02:50:53 +0100158 printf "# Producing llib-l%s is time-consuming, so there's no direct-dependency for\n", libname;
159 print "# it in the lintlib rule. We'll only remove in the cleanest setup.";
160 show_list(libname, count_library, list_library);
161 show_list(ticlib, count_ticlib, list_ticlib);
162 show_list(termlib, count_termlib, list_termlib);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530163 }
micky3879b9f5e72025-07-08 18:04:53 -0400164 else if ( found == 2 )
165 {
166 make_lintlib(libname, "$(C_SRC)");
167 }
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530168 else
169 {
170 print ""
171 print "lintlib :"
172 print "\t@echo no action needed"
173 }
174 }
Steve Kondikae271bc2015-11-15 02:50:53 +0100175# vile:ts=4 sw=4