xref: /freebsd/contrib/ncurses/mk-hdr.awk (revision 43a5ec4eb41567cc92586503212743d89686d78f)
1# $Id: mk-hdr.awk,v 1.7 2020/08/31 23:48:44 tom Exp $
2##############################################################################
3# Copyright 2020 Thomas E. Dickey                                            #
4# Copyright 2007-2010,2013 Free Software Foundation, Inc.                    #
5#                                                                            #
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#
31# Author: Thomas E. Dickey	2007
32#
33# Generate install/uninstall rules for header files
34# Variables:
35#	subset	  ("none", "base", "base+ext_funcs" or "termlib", etc.)
36#	compat	  ("yes" or "no", flag to add link to curses.h
37#
38function basename(path) {
39	sub(/^.*\//,"",path)
40	return path;
41}
42function in_subset(value) {
43	value = " " value " ";
44	check = subset;
45	gsub("[+]", " ", check);
46	check = " " check " ";
47	return index(check,value);
48}
49BEGIN	{
50		found = 0
51		using = 1
52		count = 0
53	}
54	/^@/ {
55		using = 0
56		if (subset == "none") {
57			using = 1
58		} else if (in_subset($2) > 0) {
59			using = 1
60		} else {
61			using = 0
62		}
63	}
64	/^[@#]/ {
65		next
66	}
67	{
68		if (using && NF != 0) {
69			if (found == 0) {
70				print  ""
71				print  "# generated by mk-hdr.awk"
72				printf "#  subset:     %s\n", subset
73				printf "#  compat:     %s\n", compat
74				print  ""
75				found = 1
76			}
77			data[count] = $1
78			count = count + 1
79		}
80	}
81END	{
82		if ( count > 0 )
83		{
84			print "${INCLUDEDIR} :"
85			print "	mkdir -p $@"
86			print ""
87			print "install \\"
88			print "install.libs \\"
89			print "install.includes :: ${AUTO_SRC} ${INCLUDEDIR} \\"
90
91			for (i = 0; i < count - 1; ++i) {
92				printf "		%s \\\n", data[i]
93			}
94			printf "		%s\n", data[count - 1]
95
96			for (i = 0; i < count; ++i) {
97				printf "	@ (cd ${INCLUDEDIR} && rm -f %s) ; ../headers.sh ${INSTALL_DATA} ${INCLUDEDIR} ${srcdir} %s\n", basename(data[i]), data[i]
98				if (data[i] == "curses.h" && compat == "yes") {
99					printf "	@ (cd ${INCLUDEDIR} && rm -f ncurses.h && ${LN_S} %s ncurses.h)\n", data[i]
100				}
101			}
102			print ""
103			print "uninstall \\"
104			print "uninstall.libs \\"
105			print "uninstall.includes ::"
106
107			for (i = 0; i < count; ++i) {
108				printf "	-@ (cd ${INCLUDEDIR} && rm -f %s)\n", basename(data[i])
109				if (data[i] == "curses.h" && compat == "yes") {
110					printf "	-@ (cd ${INCLUDEDIR} && rm -f ncurses.h)\n"
111				}
112			}
113		}
114	}
115# vile:ts=4 sw=4
116