1# $Id: mk-1st.awk,v 1.45 2000/08/19 19:13:19 tom Exp $ 2############################################################################## 3# Copyright (c) 1998,2000 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,2000 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# ShlibVer ("rel", "abi" or "auto", to augment DoLinks variable) 43# DoLinks ("yes", "reverse" or "no", flag to add symbolic links) 44# rmSoLocs ("yes" or "no", flag to add extra clean target) 45# overwrite ("yes" or "no", flag to add link to libcurses.a 46# 47# Notes: 48# CLIXs nawk does not like underscores in command-line variable names. 49# Mixed-case is ok. 50# HP/UX requires shared libraries to have executable permissions. 51# 52function symlink(src,dst) { 53 if ( src != dst ) { 54 printf "rm -f %s; ", dst 55 printf "$(LN_S) %s %s; ", src, dst 56 } 57 } 58function rmlink(directory, dst) { 59 printf "\t-rm -f %s/%s\n", directory, dst 60} 61function removelinks(directory) { 62 rmlink(directory, end_name); 63 if ( DoLinks == "reverse" ) { 64 if ( ShlibVer == "rel" ) { 65 rmlink(directory, abi_name); 66 rmlink(directory, rel_name); 67 } else if ( ShlibVer == "abi" ) { 68 rmlink(directory, abi_name); 69 } 70 } else { 71 if ( ShlibVer == "rel" ) { 72 rmlink(directory, abi_name); 73 rmlink(directory, lib_name); 74 } else if ( ShlibVer == "abi" ) { 75 rmlink(directory, lib_name); 76 } 77 } 78 } 79function sharedlinks(directory) { 80 if ( ShlibVer != "auto" ) { 81 printf "\tcd %s && (", directory 82 if ( DoLinks == "reverse" ) { 83 if ( ShlibVer == "rel" ) { 84 symlink(lib_name, abi_name); 85 symlink(abi_name, rel_name); 86 } else if ( ShlibVer == "abi" ) { 87 symlink(lib_name, abi_name); 88 } 89 } else { 90 if ( ShlibVer == "rel" ) { 91 symlink(rel_name, abi_name); 92 symlink(abi_name, lib_name); 93 } else if ( ShlibVer == "abi" ) { 94 symlink(abi_name, lib_name); 95 } 96 } 97 printf ")\n" 98 } 99 } 100BEGIN { 101 found = 0 102 using = 0 103 } 104 /^@/ { 105 using = 0 106 if (subset == "none") { 107 using = 1 108 } else if (index(subset,$2) > 0) { 109 if (using == 0) { 110 if (found == 0) { 111 print "" 112 print "# generated by mk-1st.awk" 113 print "" 114 } 115 using = 1 116 } 117 if ( subset == "termlib") { 118 name = "tinfo" 119 OBJS = MODEL "_T" 120 } else { 121 OBJS = MODEL 122 } 123 } 124 } 125 /^[@#]/ { 126 next 127 } 128 $1 ~ /trace/ { 129 if (traces != "all" && traces != MODEL && $1 != "lib_trace") 130 next 131 } 132 { 133 if (using \ 134 && ( $2 == "lib" \ 135 || $2 == "progs" \ 136 || $2 == "c++" \ 137 || $2 == "tack" )) 138 { 139 if ( found == 0 ) 140 { 141 printf "%s_OBJS =", OBJS 142 if ( $2 == "lib" ) 143 found = 1 144 else 145 found = 2 146 } 147 printf " \\\n\t../%s/%s.o", model, $1 148 } 149 } 150END { 151 print "" 152 if ( found != 0 ) 153 { 154 printf "\n$(%s_OBJS) : %s\n", OBJS, depend 155 } 156 if ( found == 1 ) 157 { 158 print "" 159 lib_name = sprintf("%s%s%s", prefix, name, suffix) 160 if ( MODEL == "SHARED" ) 161 { 162 abi_name = sprintf("%s.$(ABI_VERSION)", lib_name); 163 rel_name = sprintf("%s.$(REL_VERSION)", lib_name); 164 if ( DoLinks == "reverse") { 165 end_name = lib_name; 166 } else { 167 if ( ShlibVer == "rel" ) { 168 end_name = rel_name; 169 } else if ( ShlibVer == "abi" ) { 170 end_name = abi_name; 171 } else { 172 end_name = lib_name; 173 } 174 } 175 printf "../lib/%s : $(%s_OBJS)\n", end_name, OBJS 176 print "\t-@rm -f $@" 177 if ( subset == "termlib") { 178 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(TINFO_LIST)\n", OBJS 179 } else { 180 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(SHLIB_LIST)\n", OBJS 181 } 182 sharedlinks("../lib") 183 print "" 184 print "install \\" 185 print "install.libs \\" 186 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, end_name 187 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", end_name, end_name 188 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", end_name 189 printf "\t$(INSTALL_LIB) ../lib/%s $(DESTDIR)$(libdir)/%s\n", end_name, end_name 190 sharedlinks("$(DESTDIR)$(libdir)") 191 if ( overwrite == "yes" && name == "ncurses" ) 192 { 193 ovr_name = sprintf("libcurses%s", suffix) 194 printf "\t@echo linking %s to %s\n", end_name, ovr_name 195 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, end_name, ovr_name 196 } 197 if ( ldconfig != "" ) { 198 printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig 199 } 200 print "" 201 print "uninstall \\" 202 print "uninstall.libs \\" 203 printf "uninstall.%s ::\n", name 204 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name 205 removelinks("$(DESTDIR)$(libdir)") 206 if ( overwrite == "yes" && name == "ncurses" ) 207 { 208 ovr_name = sprintf("libcurses%s", suffix) 209 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name 210 } 211 if ( rmSoLocs == "yes" ) { 212 print "" 213 print "mostlyclean \\" 214 print "clean ::" 215 printf "\t-@rm -f so_locations\n" 216 } 217 } 218 else 219 { 220 end_name = lib_name; 221 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS 222 printf "\t$(AR) $(AR_OPTS) $@ $?\n" 223 printf "\t$(RANLIB) $@\n" 224 if ( target == "vxworks" ) 225 { 226 printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=.o)\n" 227 } 228 print "" 229 print "install \\" 230 print "install.libs \\" 231 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name 232 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name 233 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name 234 if ( overwrite == "yes" && lib_name == "libncurses.a" ) 235 { 236 printf "\t@echo linking libcurses.a to libncurses.a\n" 237 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n" 238 printf "\t(cd $(DESTDIR)$(libdir) && $(LN_S) libncurses.a libcurses.a)\n" 239 } 240 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name 241 if ( target == "vxworks" ) 242 { 243 printf "\t@echo installing ../lib/lib%s.o as $(DESTDIR)$(libdir)/lib%s.o\n", name, name 244 printf "\t$(INSTALL_DATA) ../lib/lib%s.o $(DESTDIR)$(libdir)/lib%s.o\n", name, name 245 } 246 print "" 247 print "uninstall \\" 248 print "uninstall.libs \\" 249 printf "uninstall.%s ::\n", name 250 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name 251 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name 252 if ( overwrite == "yes" && lib_name == "libncurses.a" ) 253 { 254 printf "\t@echo linking libcurses.a to libncurses.a\n" 255 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n" 256 } 257 if ( target == "vxworks" ) 258 { 259 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s.o\n", name 260 printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s.o\n", name 261 } 262 } 263 print "" 264 print "clean ::" 265 removelinks("../lib"); 266 print "" 267 print "mostlyclean::" 268 printf "\t-rm -f $(%s_OBJS)\n", OBJS 269 } 270 else if ( found == 2 ) 271 { 272 print "" 273 print "mostlyclean::" 274 printf "\t-rm -f $(%s_OBJS)\n", OBJS 275 print "" 276 print "clean ::" 277 printf "\t-rm -f $(%s_OBJS)\n", OBJS 278 } 279 } 280