ncurses 6.2 - patch 20200829
[ncurses.git] / mk-hdr.awk
1 # $Id: mk-hdr.awk,v 1.6 2020/08/29 22:07:18 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 #
38 function basename(path) {
39         sub(/^.*\//,"",path)
40         return path;
41 }
42 function in_subset(value) {
43         value = " " value " ";
44         check = subset;
45         sub(" .*$", "", check);
46         gsub("[+]", " ", check);
47         check = " " check " ";
48         return index(check,value);
49 }
50 BEGIN   {
51                 found = 0
52                 using = 1
53                 count = 0
54         }
55         /^@/ {
56                 using = 0
57                 if (subset == "none") {
58                         using = 1
59                 } else if (in_subset($2) > 0) {
60                         using = 1
61                 } else {
62                         using = 0
63                 }
64         }
65         /^[@#]/ {
66                 next
67         }
68         {
69                 if (using && NF != 0) {
70                         if (found == 0) {
71                                 print  ""
72                                 print  "# generated by mk-hdr.awk"
73                                 printf "#  subset:     %s\n", subset 
74                                 printf "#  compat:     %s\n", compat 
75                                 print  ""
76                                 found = 1
77                         }
78                         data[count] = $1
79                         count = count + 1
80                 }
81         }
82 END     {
83                 if ( count > 0 )
84                 {
85                         print "${INCLUDEDIR} :"
86                         print " mkdir -p $@"
87                         print ""
88                         print "install \\"
89                         print "install.libs \\"
90                         print "install.includes :: ${AUTO_SRC} ${INCLUDEDIR} \\"
91
92                         for (i = 0; i < count - 1; ++i) {
93                                 printf "                %s \\\n", data[i]
94                         }
95                         printf "                %s\n", data[count - 1]
96
97                         for (i = 0; i < count; ++i) {
98                                 printf "        @ (cd ${INCLUDEDIR} && rm -f %s) ; ../headers.sh ${INSTALL_DATA} ${INCLUDEDIR} ${srcdir} %s\n", basename(data[i]), data[i]
99                                 if (data[i] == "curses.h" && compat == "yes") {
100                                         printf "        @ (cd ${INCLUDEDIR} && rm -f ncurses.h && ${LN_S} %s ncurses.h)\n", data[i]
101                                 }
102                         }
103                         print ""
104                         print "uninstall \\"
105                         print "uninstall.libs \\"
106                         print "uninstall.includes ::"
107
108                         for (i = 0; i < count; ++i) {
109                                 printf "        -@ (cd ${INCLUDEDIR} && rm -f %s)\n", basename(data[i])
110                                 if (data[i] == "curses.h" && compat == "yes") {
111                                         printf "        -@ (cd ${INCLUDEDIR} && rm -f ncurses.h)\n"
112                                 }
113                         }
114                 }
115         }
116 # vile:ts=4 sw=4