1# $Id: mk-1st.awk,v 1.55 2002/04/20 17:32:47 tom Exp $ 2############################################################################## 3# Copyright (c) 1998,2000,2002 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# ShlibVerInfix ("yes" or "no", determines location of version #) 44# DoLinks ("yes", "reverse" or "no", flag to add symbolic links) 45# rmSoLocs ("yes" or "no", flag to add extra clean target) 46# overwrite ("yes" or "no", flag to add link to libcurses.a 47# 48# Notes: 49# CLIXs nawk does not like underscores in command-line variable names. 50# Mixed-case is ok. 51# HP/UX requires shared libraries to have executable permissions. 52# 53function symlink(src,dst) { 54 if ( src != dst ) { 55 printf "rm -f %s; ", dst 56 printf "$(LN_S) %s %s; ", src, dst 57 } 58 } 59function rmlink(directory, dst) { 60 printf "\t-rm -f %s/%s\n", directory, dst 61} 62function removelinks(directory) { 63 rmlink(directory, end_name); 64 if ( DoLinks == "reverse" ) { 65 if ( ShlibVer == "rel" ) { 66 rmlink(directory, abi_name); 67 rmlink(directory, rel_name); 68 } else if ( ShlibVer == "abi" ) { 69 rmlink(directory, abi_name); 70 } 71 } else { 72 if ( ShlibVer == "rel" ) { 73 rmlink(directory, abi_name); 74 rmlink(directory, lib_name); 75 } else if ( ShlibVer == "abi" ) { 76 rmlink(directory, lib_name); 77 } 78 } 79 } 80function sharedlinks(directory) { 81 if ( ShlibVer != "auto" && ShlibVer != "cygdll" ) { 82 printf "\tcd %s && (", directory 83 if ( DoLinks == "reverse" ) { 84 if ( ShlibVer == "rel" ) { 85 symlink(lib_name, abi_name); 86 symlink(abi_name, rel_name); 87 } else if ( ShlibVer == "abi" ) { 88 symlink(lib_name, abi_name); 89 } 90 } else { 91 if ( ShlibVer == "rel" ) { 92 symlink(rel_name, abi_name); 93 symlink(abi_name, lib_name); 94 } else if ( ShlibVer == "abi" ) { 95 symlink(abi_name, lib_name); 96 } 97 } 98 printf ")\n" 99 } 100 } 101BEGIN { 102 found = 0 103 using = 0 104 } 105 /^@/ { 106 using = 0 107 if (subset == "none") { 108 using = 1 109 } else if (index(subset,$2) > 0) { 110 if (using == 0) { 111 if (found == 0) { 112 print "" 113 print "# generated by mk-1st.awk" 114 print "" 115 } 116 using = 1 117 } 118 if ( subset == "termlib") { 119 name = "tinfo" 120 OBJS = MODEL "_T" 121 } else { 122 OBJS = MODEL 123 } 124 } 125 } 126 /^[@#]/ { 127 next 128 } 129 $1 ~ /trace/ { 130 if (traces != "all" && traces != MODEL && $1 != "lib_trace") 131 next 132 } 133 { 134 if (using \ 135 && ( $1 != "link_test" ) \ 136 && ( $2 == "lib" \ 137 || $2 == "progs" \ 138 || $2 == "c++" \ 139 || $2 == "tack" )) 140 { 141 if ( found == 0 ) 142 { 143 printf "%s_OBJS =", OBJS 144 if ( $2 == "lib" ) 145 found = 1 146 else 147 found = 2 148 } 149 printf " \\\n\t../%s/%s.o", model, $1 150 } 151 } 152END { 153 print "" 154 if ( found != 0 ) 155 { 156 printf "\n$(%s_OBJS) : %s\n", OBJS, depend 157 } 158 if ( found == 1 ) 159 { 160 print "" 161 lib_name = sprintf("%s%s%s", prefix, name, suffix) 162 if ( MODEL == "SHARED" ) 163 { 164 if (ShlibVerInfix == "cygdll") { 165 abi_name = sprintf("%s%s$(ABI_VERSION)%s", prefix, name, suffix); 166 rel_name = sprintf("%s%s$(REL_VERSION)%s", prefix, name, suffix); 167 imp_name = sprintf("%s%s%s.a", prefix, name, suffix); 168 } else if (ShlibVerInfix == "yes") { 169 abi_name = sprintf("%s%s.$(ABI_VERSION)%s", prefix, name, suffix); 170 rel_name = sprintf("%s%s.$(REL_VERSION)%s", prefix, name, suffix); 171 } else { 172 abi_name = sprintf("%s.$(ABI_VERSION)", lib_name); 173 rel_name = sprintf("%s.$(REL_VERSION)", lib_name); 174 } 175 if ( DoLinks == "reverse") { 176 end_name = lib_name; 177 } else { 178 if ( ShlibVer == "rel" ) { 179 end_name = rel_name; 180 } else if ( ShlibVer == "abi" || ShlibVer == "cygdll" ) { 181 end_name = abi_name; 182 } else { 183 end_name = lib_name; 184 } 185 } 186 187 if ( ShlibVer == "cygdll" ) { 188 dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)"; 189 printf "$(SHARED_LIB) $(IMPORT_LIB) : $(%s_OBJS)\n", OBJS; 190 print "\t-@rm -f $(SHARED_LIB) $(IMPORT_LIB)"; 191 } else { 192 dst_dirs = "$(DESTDIR)$(libdir)"; 193 printf "../lib/%s : $(%s_OBJS)\n", end_name, OBJS 194 print "\t-@rm -f $@"; 195 } 196 if ( subset == "termlib") { 197 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(TINFO_LIST)\n", OBJS 198 } else { 199 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(SHLIB_LIST) $(LDFLAGS)\n", OBJS 200 } 201 sharedlinks("../lib") 202 203 print "" 204 print "install \\" 205 print "install.libs \\" 206 printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs 207 208 if ( ShlibVer == "cygdll" ) { 209 210 src_name = sprintf("../lib/%s", end_name); 211 dst_name = sprintf("$(DESTDIR)$(bindir)/%s", end_name); 212 printf "\t@echo installing %s as %s\n", src_name, dst_name 213 printf "\t-@rm -f %s\n", dst_name 214 printf "\t$(INSTALL_LIB) %s %s\n", src_name, dst_name 215 216 src_name = sprintf("../lib/%s", imp_name); 217 dst_name = sprintf("$(DESTDIR)$(libdir)/%s", imp_name); 218 printf "\t@echo installing %s as %s\n", src_name, dst_name 219 printf "\t-@rm -f %s\n", dst_name 220 printf "\t$(INSTALL_LIB) %s %s\n", src_name, dst_name 221 222 } else { 223 224 src_name = sprintf("../lib/%s", end_name); 225 dst_name = sprintf("$(DESTDIR)$(libdir)/%s", end_name); 226 printf "\t@echo installing %s as %s\n", src_name, dst_name 227 printf "\t-@rm -f %s\n", dst_name 228 printf "\t$(INSTALL_LIB) %s %s\n", src_name, dst_name 229 230 sharedlinks("$(DESTDIR)$(libdir)") 231 232 } 233 234 if ( overwrite == "yes" && name == "ncurses" ) 235 { 236 ovr_name = sprintf("libcurses%s", suffix) 237 printf "\t@echo linking %s to %s\n", end_name, ovr_name 238 printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, end_name, ovr_name 239 } 240 if ( ldconfig != "" ) { 241 printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig 242 } 243 print "" 244 print "uninstall \\" 245 print "uninstall.libs \\" 246 printf "uninstall.%s ::\n", name 247 if ( ShlibVer == "cygdll" ) { 248 249 printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name 250 printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name 251 252 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name 253 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name 254 255 } else { 256 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name 257 removelinks("$(DESTDIR)$(libdir)") 258 if ( overwrite == "yes" && name == "ncurses" ) 259 { 260 ovr_name = sprintf("libcurses%s", suffix) 261 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name 262 } 263 } 264 if ( rmSoLocs == "yes" ) { 265 print "" 266 print "mostlyclean \\" 267 print "clean ::" 268 printf "\t-@rm -f so_locations\n" 269 } 270 } 271 else if ( MODEL == "LIBTOOL" ) 272 { 273 if ( $2 == "c++" ) { 274 compile="CXX" 275 } else { 276 compile="CC" 277 } 278 end_name = lib_name; 279 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS 280 printf "\tcd ../lib && $(LIBTOOL) $(%s) -o %s $(%s_OBJS:.o=.lo) -rpath $(DESTDIR)$(libdir) -version-info $(NCURSES_MAJOR):$(NCURSES_MINOR)\n", compile, lib_name, OBJS 281 print "" 282 print "install \\" 283 print "install.libs \\" 284 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name 285 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name 286 printf "\tcd ../lib; $(LIBTOOL) $(INSTALL_DATA) %s $(DESTDIR)$(libdir)\n", lib_name 287 print "" 288 print "uninstall \\" 289 print "uninstall.libs \\" 290 printf "uninstall.%s ::\n", name 291 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name 292 printf "\t-@$(LIBTOOL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name 293 } 294 else 295 { 296 end_name = lib_name; 297 printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS 298 printf "\t$(AR) $(AR_OPTS) $@ $?\n" 299 printf "\t$(RANLIB) $@\n" 300 if ( target == "vxworks" ) 301 { 302 printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=.o)\n" 303 } 304 print "" 305 print "install \\" 306 print "install.libs \\" 307 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name 308 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name 309 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name 310 if ( overwrite == "yes" && lib_name == "libncurses.a" ) 311 { 312 printf "\t@echo linking libcurses.a to libncurses.a\n" 313 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n" 314 printf "\t(cd $(DESTDIR)$(libdir) && $(LN_S) libncurses.a libcurses.a)\n" 315 } 316 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name 317 if ( target == "vxworks" ) 318 { 319 printf "\t@echo installing ../lib/lib%s.o as $(DESTDIR)$(libdir)/lib%s.o\n", name, name 320 printf "\t$(INSTALL_DATA) ../lib/lib%s.o $(DESTDIR)$(libdir)/lib%s.o\n", name, name 321 } 322 print "" 323 print "uninstall \\" 324 print "uninstall.libs \\" 325 printf "uninstall.%s ::\n", name 326 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name 327 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name 328 if ( overwrite == "yes" && lib_name == "libncurses.a" ) 329 { 330 printf "\t@echo linking libcurses.a to libncurses.a\n" 331 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n" 332 } 333 if ( target == "vxworks" ) 334 { 335 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s.o\n", name 336 printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s.o\n", name 337 } 338 } 339 print "" 340 print "clean ::" 341 removelinks("../lib"); 342 print "" 343 print "mostlyclean::" 344 printf "\t-rm -f $(%s_OBJS)\n", OBJS 345 if ( MODEL == "LIBTOOL" ) { 346 printf "\t-rm -f $(%s_OBJS:.o=.lo)\n", OBJS 347 } 348 } 349 else if ( found == 2 ) 350 { 351 print "" 352 print "mostlyclean::" 353 printf "\t-rm -f $(%s_OBJS)\n", OBJS 354 if ( MODEL == "LIBTOOL" ) { 355 printf "\t-rm -f $(%s_OBJS:.o=.lo)\n", OBJS 356 } 357 print "" 358 print "clean ::" 359 printf "\t-rm -f $(%s_OBJS)\n", OBJS 360 if ( MODEL == "LIBTOOL" ) { 361 printf "\t-rm -f $(%s_OBJS:.o=.lo)\n", OBJS 362 } 363 } 364 } 365