mk-1st.awk revision 62449
1# $Id: mk-1st.awk,v 1.40 2000/04/01 20:50:29 tom Exp $ 2############################################################################## 3# Copyright (c) 1998 Free Software Foundation, Inc. # 4# # 5# Permission is hereby granted, free of charge, to any person obtaining a # 6# copy of this software and associated documentation files (the "Software"), # 7# to deal in the Software without restriction, including without limitation # 8# the rights to use, copy, modify, merge, publish, distribute, distribute # 9# with modifications, sublicense, and/or sell copies of the Software, and to # 10# permit persons to whom the Software is furnished to do so, subject to the # 11# following conditions: # 12# # 13# The above copyright notice and this permission notice shall be included in # 14# all copies or substantial portions of the Software. # 15# # 16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # 17# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # 18# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # 19# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # 20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # 21# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # 22# DEALINGS IN THE SOFTWARE. # 23# # 24# Except as contained in this notice, the name(s) of the above copyright # 25# holders shall not be used in advertising or otherwise to promote the sale, # 26# use or other dealings in this Software without prior written # 27# authorization. # 28############################################################################## 29# 30# Author: Thomas E. Dickey <dickey@clark.net> 1996,1997 31# 32# Generate list of objects for a given model library 33# Variables: 34# name (library name, e.g., "ncurses", "panel", "forms", "menus") 35# model (directory into which we compile, e.g., "obj") 36# prefix (e.g., "lib", for Unix-style libraries) 37# suffix (e.g., "_g.a", for debug libraries) 38# MODEL (e.g., "DEBUG", uppercase; toupper is not portable) 39# depend (optional dependencies for all objects, e.g, ncurses_cfg.h) 40# subset ("none", "base", "base+ext_funcs" or "termlib") 41# target (cross-compile target, if any) 42# DoLinks ("yes", "reverse" or "no", flag to add symbolic links) 43# rmSoLocs ("yes" or "no", flag to add extra clean target) 44# overwrite ("yes" or "no", flag to add link to libcurses.a 45# 46# Notes: 47# CLIXs nawk does not like underscores in command-line variable names. 48# Mixed-case is ok. 49# HP/UX requires shared libraries to have executable permissions. 50# 51function symlink(src,dst) { 52 if ( src != dst ) { 53 if ( DoLinks == "reverse" ) { 54 printf "rm -f %s; ", src 55 printf "$(LN_S) %s %s; ", dst, src 56 } else { 57 printf "rm -f %s; ", dst 58 printf "$(LN_S) %s %s; ", src, dst 59 } 60 } 61 } 62function sharedlinks(directory, add) { 63 if ( end_name != lib_name ) { 64 if ( DoLinks == "yes" ) { 65 abi_name = sprintf("%s.$(ABI_VERSION)", lib_name); 66 } else { 67 abi_name = end_name; 68 } 69 if (add) { 70 printf "\tcd %s && (", directory 71 if ( abi_name != end_name ) { 72 symlink(end_name, abi_name); 73 } 74 symlink(abi_name, lib_name); 75 printf ")\n" 76 } else { 77 if ( abi_name != end_name ) { 78 printf "\t-@rm -f %s/%s\n", directory, abi_name 79 } 80 printf "\t-@rm -f %s/%s\n", directory, lib_name 81 } 82 } 83 } 84function removelinks() { 85 if ( end_name != lib_name ) { 86 if ( abi_name != end_name ) { 87 printf "\t-rm -f ../lib/%s\n", abi_name 88 } 89 printf "\t-rm -f ../lib/%s\n", end_name 90 } 91 } 92BEGIN { 93 found = 0 94 using = 0 95 } 96 /^@/ { 97 using = 0 98 if (subset == "none") { 99 using = 1 100 } else if (index(subset,$2) > 0) { 101 if (using == 0) { 102 if (found == 0) { 103 print "" 104 print "# generated by mk-1st.awk" 105 print "" 106 } 107 using = 1 108 } 109 if ( subset == "termlib") { 110 name = "tinfo" 111 OBJS = MODEL "_T" 112 } else { 113 OBJS = MODEL 114 } 115 } 116 } 117 /^[@#]/ { 118 next 119 } 120 $1 ~ /trace/ { 121 if (traces != "all" && traces != MODEL && $1 != "lib_trace") 122 next 123 } 124 { 125 if (using \ 126 && ( $2 == "lib" \ 127 || $2 == "progs" \ 128 || $2 == "c++" \ 129 || $2 == "tack" )) 130 { 131 if ( found == 0 ) 132 { 133 printf "%s_OBJS =", OBJS 134 if ( $2 == "lib" ) 135 found = 1 136 else 137 found = 2 138 } 139 printf " \\\n\t../%s/%s.o", model, $1 140 } 141 } 142END { 143 print "" 144 if ( found != 0 ) 145 { 146 printf "\n$(%s_OBJS) : %s\n", OBJS, depend 147 } 148 if ( found == 1 ) 149 { 150 print "" 151 lib_name = sprintf("%s%s%s", prefix, name, suffix) 152 if ( MODEL == "SHARED" ) 153 { 154 if ( DoLinks == "yes" ) { 155 end_name = sprintf("%s.$(REL_VERSION)", lib_name); 156 } else if ( DoLinks == "reverse") { 157 tmp_name = sprintf("%s.$(ABI_VERSION)", lib_name); 158 end_name = lib_name; 159 lib_name = tmp_name; 160 } else { 161 end_name = lib_name; 162 } 163 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS 164 print "\t-@rm -f $@" 165 if ( subset == "termlib") { 166 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(TINFO_LIST)\n", OBJS 167 } else { 168 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(SHLIB_LIST)\n", OBJS 169 } 170 sharedlinks("../lib", 1) 171 print "" 172 if ( end_name != lib_name ) { 173 printf "../lib/%s : ../lib/%s\n", end_name, lib_name 174 } 175 print "" 176 print "install \\" 177 print "install.libs \\" 178 printf "install.%s :: $(INSTALL_PREFIX)$(libdir) ../lib/%s\n", name, end_name 179 printf "\t@echo installing ../lib/%s as $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name, end_name 180 if ( DoLinks == "reverse") { 181 printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name 182 printf "\t$(INSTALL_LIB) ../lib/%s $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name, lib_name 183 } else { 184 printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/%s \n", end_name 185 printf "\t$(INSTALL_LIB) ../lib/%s $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name, end_name 186 } 187 sharedlinks("$(INSTALL_PREFIX)$(libdir)", 1) 188 if ( overwrite == "yes" && name == "ncurses" ) 189 { 190 ovr_name = sprintf("libcurses%s", suffix) 191 printf "\t@echo linking %s to %s\n", lib_name, ovr_name 192 printf "\tcd $(INSTALL_PREFIX)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, lib_name, ovr_name 193 } 194 if ( ldconfig != "" ) { 195 printf "\t- test -z \"$(INSTALL_PREFIX)\" && %s\n", ldconfig 196 } 197 print "" 198 print "uninstall \\" 199 print "uninstall.libs \\" 200 printf "uninstall.%s ::\n", name 201 printf "\t@echo uninstalling $(INSTALL_PREFIX)$(libdir)/%s \n", end_name 202 printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/%s\n", end_name 203 sharedlinks("$(INSTALL_PREFIX)$(libdir)", 0) 204 if ( overwrite == "yes" && name == "ncurses" ) 205 { 206 ovr_name = sprintf("libcurses%s", suffix) 207 printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/%s \n", ovr_name 208 } 209 if ( rmSoLocs == "yes" ) { 210 print "" 211 print "mostlyclean \\" 212 print "clean ::" 213 printf "\t-@rm -f so_locations\n" 214 } 215 } 216 else 217 { 218 end_name = lib_name; 219 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS 220 printf "\t$(AR) $(AR_OPTS) $@ $?\n" 221 printf "\t$(RANLIB) $@\n" 222 if ( target == "vxworks" ) 223 { 224 printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=.o)\n" 225 } 226 print "" 227 print "install \\" 228 print "install.libs \\" 229 printf "install.%s :: $(INSTALL_PREFIX)$(libdir) ../lib/%s\n", name, lib_name 230 printf "\t@echo installing ../lib/%s as $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name, lib_name 231 printf "\t$(INSTALL_DATA) ../lib/%s $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name, lib_name 232 if ( overwrite == "yes" && lib_name == "libncurses.a" ) 233 { 234 printf "\t@echo linking libcurses.a to libncurses.a \n" 235 printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/libcurses.a \n" 236 printf "\t(cd $(INSTALL_PREFIX)$(libdir) && $(LN_S) libncurses.a libcurses.a)\n" 237 } 238 printf "\t$(RANLIB) $(INSTALL_PREFIX)$(libdir)/%s\n", lib_name 239 if ( target == "vxworks" ) 240 { 241 printf "\t@echo installing ../lib/lib%s.o as $(INSTALL_PREFIX)$(libdir)/lib%s.o\n", name, name 242 printf "\t$(INSTALL_DATA) ../lib/lib%s.o $(INSTALL_PREFIX)$(libdir)/lib%s.o\n", name, name 243 } 244 print "" 245 print "uninstall \\" 246 print "uninstall.libs \\" 247 printf "uninstall.%s ::\n", name 248 printf "\t@echo uninstalling $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name 249 printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/%s\n", lib_name 250 if ( overwrite == "yes" && lib_name == "libncurses.a" ) 251 { 252 printf "\t@echo linking libcurses.a to libncurses.a \n" 253 printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/libcurses.a \n" 254 } 255 if ( target == "vxworks" ) 256 { 257 printf "\t@echo uninstalling $(INSTALL_PREFIX)$(libdir)/lib%s.o\n", name 258 printf "\t-@rm -f $(INSTALL_PREFIX)$(libdir)/lib%s.o\n", name 259 } 260 } 261 print "" 262 print "clean ::" 263 printf "\t-rm -f ../lib/%s\n", lib_name 264 print "" 265 print "mostlyclean::" 266 printf "\t-rm -f $(%s_OBJS)\n", OBJS 267 print "" 268 print "clean ::" 269 removelinks(); 270 } 271 else if ( found == 2 ) 272 { 273 print "" 274 print "mostlyclean::" 275 printf "\t-rm -f $(%s_OBJS)\n", OBJS 276 print "" 277 print "clean ::" 278 printf "\t-rm -f $(%s_OBJS)\n", OBJS 279 } 280 } 281