ncurses 6.2 - patch 20200215
[ncurses.git] / mk-2nd.awk
1 # $Id: mk-2nd.awk,v 1.20 2020/02/02 23:34:34 tom Exp $
2 ##############################################################################
3 # Copyright 2020 Thomas E. Dickey                                            #
4 # Copyright 1998-2004,2005 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
32 #
33 # Generate compile-rules for the modules that we are using in libraries or
34 # programs.  We are listing them explicitly because we have turned off the
35 # suffix rules (to force compilation with the appropriate flags).  We could use
36 # make-recursion but that would result in makefiles that are useless for
37 # development.
38 #
39 # Variables:
40 #       model directory into which objects are compiled.
41 #       MODEL (uppercase version of "model"; toupper is not portable)
42 #       echo (yes iff we will show the $(CC) lines)
43 #       subset ("none", "base", "base+ext_funcs" or "termlib")
44 #       crenames ("yes" or "no", flag to control whether -c & -o options are used)
45 #       cxxrenames ("yes" or "no", flag to control whether -c & -o options are used)
46 #       traces ("all" or "DEBUG", to control whether tracing is compiled in)
47 #       srcdir is expanded when "configure --srcdir" was used
48 #
49 # Fields in src/modules:
50 #       $1 = module name
51 #       $2 = progs|lib|c++
52 #       $3 = source-directory
53 #
54 # Fields in src/modules past $3 are dependencies
55 #
56 BEGIN   {
57                 found = 0
58                 using = 0
59         }
60         /^@/ {
61                 using = 0
62                 if (subset == "none") {
63                         using = 1
64                 } else if (index(subset,$2) > 0) {
65                         if (using == 0) {
66                                 if (found == 0) {
67                                         print  ""
68                                         print  "# generated by mk-2nd.awk"
69                                         printf "#   model:      %s\n", model
70                                         printf "#   MODEL:      %s\n", MODEL
71                                         printf "#   echo:       %s\n", echo 
72                                         printf "#   subset:     %s\n", subset
73                                         printf "#   crenames:   %s\n", crenames
74                                         printf "#   cxxrenames: %s\n", cxxrenames
75                                         printf "#   traces:     %s\n", traces
76                                         printf "#   srcdir:     %s\n", srcdir
77                                 }
78                                 using = 1
79                         }
80                 }
81         }
82         /^[@#]/ {
83                 next
84         }
85         $1 ~ /trace/ {
86                 if (traces != "all" && traces != MODEL && $1 != "lib_trace")
87                         next
88         }
89         {
90                 if ($0 != "" \
91                  && using != 0) {
92                         found = 1
93                         if ( $1 != "" ) {
94                                 print  ""
95                                 if ( $2 == "c++" ) {
96                                         compile="CXX"
97                                         suffix=".cc"
98                                         use_c_o=cxxrenames
99                                 } else {
100                                         compile="CC"
101                                         suffix=".c"
102                                         use_c_o=crenames
103                                 }
104                                 printf "../%s/%s$o :\t%s/%s%s", model, $1, $3, $1, suffix
105                                 for (n = 4; n <= NF; n++) printf " \\\n\t\t\t%s", $n
106                                 print  ""
107                                 if ( echo == "yes" )
108                                         atsign=""
109                                 else {
110                                         atsign="@"
111                                         printf "\t@echo 'compiling %s (%s)'\n", $1, model
112                                 }
113                                 printf "\t%s", atsign;
114                                 if ( use_c_o != "yes" ) {
115                                         printf "cd ../%s; ", model;
116                                 }
117                                 # The choice here is between
118                                 #       base+ext_funcs and
119                                 #       termlib+ext_tinfo
120                                 # but they may appear in the same value.
121                                 if ( subset ~ /base/ ) {
122                                         mycflags=""
123                                 } else if ( subset ~ /termlib/ ) {
124                                         mycflags=" -DUSE_TERMLIB"
125                                 }
126                                 printf "$(LIBTOOL_COMPILE) $(%s) $(CFLAGS_%s)%s -c ", compile, MODEL, mycflags
127                                 if ( $3 == "." || srcdir == "." ) {
128                                         dir = $3 "/"
129                                         sub("^\\$\\(srcdir\\)/","",dir);
130                                         sub("^\\./","",dir);
131                                         printf "../%s/%s%s%s", name, dir, $1, suffix
132                                 } else {
133                                         printf "%s/%s%s", $3, $1, suffix
134                                 }
135                                 if ( use_c_o == "yes" ) {
136                                         printf " -o ../%s/%s$o", model, $1
137                                 }
138                         } else {
139                                 printf "%s", $1
140                                 for (n = 2; n <= NF; n++) printf " %s", $n
141                         }
142                         print  ""
143                 }
144         }
145 END     {
146                 print  ""
147         }