blob: 7608afedb01e877e078e183a2cb3c9447a058edf [file] [log] [blame]
micky3879b9f5e72025-07-08 18:04:53 -04001# $Id: mk-hdr.awk,v 1.8 2021/06/17 21:20:30 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 2007-2010,2013 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#
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}
micky3879b9f5e72025-07-08 18:04:53 -040042function in_subset(value) {
43 value = " " value " ";
44 check = subset;
45 gsub("[+]", " ", check);
46 check = " " check " ";
47 return index(check,value);
48}
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053049BEGIN {
50 found = 0
51 using = 1
52 count = 0
53 }
54 /^@/ {
55 using = 0
56 if (subset == "none") {
57 using = 1
micky3879b9f5e72025-07-08 18:04:53 -040058 } else if (in_subset($2) > 0) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053059 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"
micky3879b9f5e72025-07-08 18:04:53 -040072 printf "# subset: %s\n", subset
73 printf "# compat: %s\n", compat
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053074 print ""
75 found = 1
76 }
77 data[count] = $1
78 count = count + 1
79 }
80 }
81END {
82 if ( count > 0 )
83 {
Steve Kondikae271bc2015-11-15 02:50:53 +010084 print "${INCLUDEDIR} :"
85 print " mkdir -p $@"
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053086 print ""
87 print "install \\"
88 print "install.libs \\"
Steve Kondikae271bc2015-11-15 02:50:53 +010089 print "install.includes :: ${AUTO_SRC} ${INCLUDEDIR} \\"
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053090
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) {
Steve Kondikae271bc2015-11-15 02:50:53 +010097 printf " @ (cd ${INCLUDEDIR} && rm -f %s) ; ../headers.sh ${INSTALL_DATA} ${INCLUDEDIR} ${srcdir} %s\n", basename(data[i]), data[i]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053098 if (data[i] == "curses.h" && compat == "yes") {
Steve Kondikae271bc2015-11-15 02:50:53 +010099 printf " @ (cd ${INCLUDEDIR} && rm -f ncurses.h && ${LN_S} %s ncurses.h)\n", data[i]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530100 }
101 }
102 print ""
103 print "uninstall \\"
104 print "uninstall.libs \\"
105 print "uninstall.includes ::"
106
107 for (i = 0; i < count; ++i) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100108 printf " -@ (cd ${INCLUDEDIR} && rm -f %s)\n", basename(data[i])
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530109 if (data[i] == "curses.h" && compat == "yes") {
Steve Kondikae271bc2015-11-15 02:50:53 +0100110 printf " -@ (cd ${INCLUDEDIR} && rm -f ncurses.h)\n"
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530111 }
112 }
113 }
114 }
115# vile:ts=4 sw=4