mk-1st.awk revision 97049
1166124Srafan# $Id: mk-1st.awk,v 1.55 2002/04/20 17:32:47 tom Exp $ 2262685Sdelphij############################################################################## 3166124Srafan# Copyright (c) 1998,2000,2002 Free Software Foundation, Inc. # 4166124Srafan# # 5166124Srafan# Permission is hereby granted, free of charge, to any person obtaining a # 6166124Srafan# copy of this software and associated documentation files (the "Software"), # 7166124Srafan# to deal in the Software without restriction, including without limitation # 8166124Srafan# the rights to use, copy, modify, merge, publish, distribute, distribute # 9166124Srafan# with modifications, sublicense, and/or sell copies of the Software, and to # 10166124Srafan# permit persons to whom the Software is furnished to do so, subject to the # 11166124Srafan# following conditions: # 12166124Srafan# # 13166124Srafan# The above copyright notice and this permission notice shall be included in # 14166124Srafan# all copies or substantial portions of the Software. # 15166124Srafan# # 16166124Srafan# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # 17166124Srafan# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # 18166124Srafan# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # 19166124Srafan# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # 20166124Srafan# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # 21166124Srafan# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # 22166124Srafan# DEALINGS IN THE SOFTWARE. # 23166124Srafan# # 24166124Srafan# Except as contained in this notice, the name(s) of the above copyright # 25166124Srafan# holders shall not be used in advertising or otherwise to promote the sale, # 26166124Srafan# use or other dealings in this Software without prior written # 27166124Srafan# authorization. # 28262685Sdelphij############################################################################## 29166124Srafan# 3050276Speter# Author: Thomas E. Dickey <dickey@clark.net> 1996,1997,2000 3150276Speter# 3250276Speter# Generate list of objects for a given model library 3350276Speter# Variables: 34166124Srafan# name (library name, e.g., "ncurses", "panel", "forms", "menus") 35166124Srafan# model (directory into which we compile, e.g., "obj") 3650276Speter# prefix (e.g., "lib", for Unix-style libraries) 37166124Srafan# suffix (e.g., "_g.a", for debug libraries) 38166124Srafan# MODEL (e.g., "DEBUG", uppercase; toupper is not portable) 39166124Srafan# depend (optional dependencies for all objects, e.g, ncurses_cfg.h) 40166124Srafan# subset ("none", "base", "base+ext_funcs" or "termlib") 41166124Srafan# target (cross-compile target, if any) 42166124Srafan# ShlibVer ("rel", "abi" or "auto", to augment DoLinks variable) 43166124Srafan# ShlibVerInfix ("yes" or "no", determines location of version #) 44166124Srafan# DoLinks ("yes", "reverse" or "no", flag to add symbolic links) 45166124Srafan# rmSoLocs ("yes" or "no", flag to add extra clean target) 46166124Srafan# overwrite ("yes" or "no", flag to add link to libcurses.a 47166124Srafan# 48262685Sdelphij# Notes: 49262685Sdelphij# CLIXs nawk does not like underscores in command-line variable names. 50262685Sdelphij# Mixed-case is ok. 51262685Sdelphij# HP/UX requires shared libraries to have executable permissions. 52262685Sdelphij# 53262685Sdelphijfunction symlink(src,dst) { 54262685Sdelphij if ( src != dst ) { 55262685Sdelphij printf "rm -f %s; ", dst 56262685Sdelphij printf "$(LN_S) %s %s; ", src, dst 57262685Sdelphij } 58262685Sdelphij } 59262685Sdelphijfunction rmlink(directory, dst) { 60262685Sdelphij printf "\t-rm -f %s/%s\n", directory, dst 61262685Sdelphij} 62262685Sdelphijfunction removelinks(directory) { 63262685Sdelphij rmlink(directory, end_name); 64262685Sdelphij if ( DoLinks == "reverse" ) { 65262685Sdelphij if ( ShlibVer == "rel" ) { 66262685Sdelphij rmlink(directory, abi_name); 67262685Sdelphij rmlink(directory, rel_name); 68262685Sdelphij } else if ( ShlibVer == "abi" ) { 69262685Sdelphij rmlink(directory, abi_name); 70262685Sdelphij } 71262685Sdelphij } else { 72262685Sdelphij if ( ShlibVer == "rel" ) { 73262685Sdelphij rmlink(directory, abi_name); 74262685Sdelphij rmlink(directory, lib_name); 75262685Sdelphij } else if ( ShlibVer == "abi" ) { 76262685Sdelphij rmlink(directory, lib_name); 77262685Sdelphij } 78262685Sdelphij } 79262685Sdelphij } 80262685Sdelphijfunction sharedlinks(directory) { 81262685Sdelphij if ( ShlibVer != "auto" && ShlibVer != "cygdll" ) { 82262685Sdelphij printf "\tcd %s && (", directory 83262685Sdelphij if ( DoLinks == "reverse" ) { 84262685Sdelphij if ( ShlibVer == "rel" ) { 85262685Sdelphij symlink(lib_name, abi_name); 86262685Sdelphij symlink(abi_name, rel_name); 87262685Sdelphij } else if ( ShlibVer == "abi" ) { 88262685Sdelphij symlink(lib_name, abi_name); 89262685Sdelphij } 90262685Sdelphij } else { 91262685Sdelphij if ( ShlibVer == "rel" ) { 92262685Sdelphij symlink(rel_name, abi_name); 93262685Sdelphij symlink(abi_name, lib_name); 94262685Sdelphij } else if ( ShlibVer == "abi" ) { 95262685Sdelphij symlink(abi_name, lib_name); 96262685Sdelphij } 97262685Sdelphij } 98262685Sdelphij printf ")\n" 99262685Sdelphij } 100262685Sdelphij } 101262685SdelphijBEGIN { 102262685Sdelphij found = 0 103262685Sdelphij using = 0 104262685Sdelphij } 105262685Sdelphij /^@/ { 106262685Sdelphij using = 0 107262685Sdelphij if (subset == "none") { 108262685Sdelphij using = 1 109262685Sdelphij } else if (index(subset,$2) > 0) { 110262685Sdelphij if (using == 0) { 111262685Sdelphij if (found == 0) { 112262685Sdelphij print "" 113262685Sdelphij print "# generated by mk-1st.awk" 114262685Sdelphij print "" 115262685Sdelphij } 116262685Sdelphij using = 1 117262685Sdelphij } 118262685Sdelphij if ( subset == "termlib") { 119262685Sdelphij name = "tinfo" 120262685Sdelphij OBJS = MODEL "_T" 121262685Sdelphij } else { 122262685Sdelphij OBJS = MODEL 123262685Sdelphij } 124262685Sdelphij } 125262685Sdelphij } 126262685Sdelphij /^[@#]/ { 127262685Sdelphij next 128262685Sdelphij } 129262685Sdelphij $1 ~ /trace/ { 130262685Sdelphij if (traces != "all" && traces != MODEL && $1 != "lib_trace") 131262685Sdelphij next 132262685Sdelphij } 133262685Sdelphij { 134262685Sdelphij if (using \ 135262685Sdelphij && ( $1 != "link_test" ) \ 136262685Sdelphij && ( $2 == "lib" \ 137262685Sdelphij || $2 == "progs" \ 138262685Sdelphij || $2 == "c++" \ 139262685Sdelphij || $2 == "tack" )) 140262685Sdelphij { 141262685Sdelphij if ( found == 0 ) 142262685Sdelphij { 143262685Sdelphij printf "%s_OBJS =", OBJS 144262685Sdelphij if ( $2 == "lib" ) 145262685Sdelphij found = 1 146262685Sdelphij else 147262685Sdelphij found = 2 148262685Sdelphij } 149262685Sdelphij printf " \\\n\t../%s/%s.o", model, $1 150262685Sdelphij } 151262685Sdelphij } 152262685SdelphijEND { 153262685Sdelphij print "" 154262685Sdelphij if ( found != 0 ) 155262685Sdelphij { 156262685Sdelphij printf "\n$(%s_OBJS) : %s\n", OBJS, depend 157262685Sdelphij } 158262685Sdelphij if ( found == 1 ) 159262685Sdelphij { 160262685Sdelphij print "" 161262685Sdelphij lib_name = sprintf("%s%s%s", prefix, name, suffix) 162262685Sdelphij if ( MODEL == "SHARED" ) 163262685Sdelphij { 164262685Sdelphij if (ShlibVerInfix == "cygdll") { 165262685Sdelphij abi_name = sprintf("%s%s$(ABI_VERSION)%s", prefix, name, suffix); 166262685Sdelphij rel_name = sprintf("%s%s$(REL_VERSION)%s", prefix, name, suffix); 167262685Sdelphij imp_name = sprintf("%s%s%s.a", prefix, name, suffix); 168262685Sdelphij } else if (ShlibVerInfix == "yes") { 169262685Sdelphij abi_name = sprintf("%s%s.$(ABI_VERSION)%s", prefix, name, suffix); 170262685Sdelphij rel_name = sprintf("%s%s.$(REL_VERSION)%s", prefix, name, suffix); 171262685Sdelphij } else { 172262685Sdelphij abi_name = sprintf("%s.$(ABI_VERSION)", lib_name); 173262685Sdelphij rel_name = sprintf("%s.$(REL_VERSION)", lib_name); 174262685Sdelphij } 175262685Sdelphij if ( DoLinks == "reverse") { 176262685Sdelphij end_name = lib_name; 177262685Sdelphij } else { 178262685Sdelphij if ( ShlibVer == "rel" ) { 179262685Sdelphij end_name = rel_name; 180262685Sdelphij } else if ( ShlibVer == "abi" || ShlibVer == "cygdll" ) { 181262685Sdelphij end_name = abi_name; 182262685Sdelphij } else { 183262685Sdelphij end_name = lib_name; 184262685Sdelphij } 185262685Sdelphij } 186262685Sdelphij 187262685Sdelphij if ( ShlibVer == "cygdll" ) { 188262685Sdelphij dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)"; 189262685Sdelphij printf "$(SHARED_LIB) $(IMPORT_LIB) : $(%s_OBJS)\n", OBJS; 190262685Sdelphij print "\t-@rm -f $(SHARED_LIB) $(IMPORT_LIB)"; 191262685Sdelphij } else { 192262685Sdelphij dst_dirs = "$(DESTDIR)$(libdir)"; 193262685Sdelphij printf "../lib/%s : $(%s_OBJS)\n", end_name, OBJS 194262685Sdelphij print "\t-@rm -f $@"; 195262685Sdelphij } 196262685Sdelphij if ( subset == "termlib") { 197262685Sdelphij printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(TINFO_LIST)\n", OBJS 198262685Sdelphij } else { 199262685Sdelphij printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(SHLIB_LIST) $(LDFLAGS)\n", OBJS 200262685Sdelphij } 201262685Sdelphij sharedlinks("../lib") 202262685Sdelphij 203262685Sdelphij print "" 204262685Sdelphij print "install \\" 205262685Sdelphij print "install.libs \\" 206262685Sdelphij printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs 207262685Sdelphij 208262685Sdelphij if ( ShlibVer == "cygdll" ) { 209262685Sdelphij 210262685Sdelphij src_name = sprintf("../lib/%s", end_name); 211262685Sdelphij dst_name = sprintf("$(DESTDIR)$(bindir)/%s", end_name); 212262685Sdelphij printf "\t@echo installing %s as %s\n", src_name, dst_name 213262685Sdelphij printf "\t-@rm -f %s\n", dst_name 214262685Sdelphij printf "\t$(INSTALL_LIB) %s %s\n", src_name, dst_name 215262685Sdelphij 216262685Sdelphij src_name = sprintf("../lib/%s", imp_name); 217262685Sdelphij dst_name = sprintf("$(DESTDIR)$(libdir)/%s", imp_name); 218262685Sdelphij printf "\t@echo installing %s as %s\n", src_name, dst_name 219262685Sdelphij printf "\t-@rm -f %s\n", dst_name 220262685Sdelphij printf "\t$(INSTALL_LIB) %s %s\n", src_name, dst_name 221262685Sdelphij 222262685Sdelphij } else { 223262685Sdelphij 224262685Sdelphij src_name = sprintf("../lib/%s", end_name); 225262685Sdelphij dst_name = sprintf("$(DESTDIR)$(libdir)/%s", end_name); 226262685Sdelphij printf "\t@echo installing %s as %s\n", src_name, dst_name 227262685Sdelphij printf "\t-@rm -f %s\n", dst_name 228262685Sdelphij printf "\t$(INSTALL_LIB) %s %s\n", src_name, dst_name 229262685Sdelphij 230262685Sdelphij sharedlinks("$(DESTDIR)$(libdir)") 231262685Sdelphij 232262685Sdelphij } 233262685Sdelphij 234262685Sdelphij if ( overwrite == "yes" && name == "ncurses" ) 235262685Sdelphij { 236262685Sdelphij ovr_name = sprintf("libcurses%s", suffix) 237262685Sdelphij printf "\t@echo linking %s to %s\n", end_name, ovr_name 238262685Sdelphij printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, end_name, ovr_name 239262685Sdelphij } 240262685Sdelphij if ( ldconfig != "" ) { 241262685Sdelphij printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig 242262685Sdelphij } 243262685Sdelphij print "" 244262685Sdelphij print "uninstall \\" 245262685Sdelphij print "uninstall.libs \\" 246262685Sdelphij printf "uninstall.%s ::\n", name 247262685Sdelphij if ( ShlibVer == "cygdll" ) { 248262685Sdelphij 249262685Sdelphij printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name 250262685Sdelphij printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name 251262685Sdelphij 252262685Sdelphij printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name 253262685Sdelphij printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name 254262685Sdelphij 255262685Sdelphij } else { 256262685Sdelphij printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name 257262685Sdelphij removelinks("$(DESTDIR)$(libdir)") 258262685Sdelphij if ( overwrite == "yes" && name == "ncurses" ) 259262685Sdelphij { 260262685Sdelphij ovr_name = sprintf("libcurses%s", suffix) 261262685Sdelphij printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name 262262685Sdelphij } 263262685Sdelphij } 264262685Sdelphij if ( rmSoLocs == "yes" ) { 265262685Sdelphij print "" 266262685Sdelphij print "mostlyclean \\" 267262685Sdelphij print "clean ::" 268262685Sdelphij printf "\t-@rm -f so_locations\n" 269262685Sdelphij } 270262685Sdelphij } 271262685Sdelphij else if ( MODEL == "LIBTOOL" ) 272262685Sdelphij { 273262685Sdelphij if ( $2 == "c++" ) { 274262685Sdelphij compile="CXX" 275262685Sdelphij } else { 276262685Sdelphij compile="CC" 277262685Sdelphij } 278262685Sdelphij end_name = lib_name; 279262685Sdelphij printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS 280262685Sdelphij 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 281262685Sdelphij print "" 282262685Sdelphij print "install \\" 283262685Sdelphij print "install.libs \\" 284262685Sdelphij printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name 285262685Sdelphij printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name 286262685Sdelphij printf "\tcd ../lib; $(LIBTOOL) $(INSTALL_DATA) %s $(DESTDIR)$(libdir)\n", lib_name 287262685Sdelphij print "" 288262685Sdelphij print "uninstall \\" 289262685Sdelphij print "uninstall.libs \\" 290262685Sdelphij printf "uninstall.%s ::\n", name 291262685Sdelphij printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name 292262685Sdelphij printf "\t-@$(LIBTOOL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name 293262685Sdelphij } 294262685Sdelphij else 295262685Sdelphij { 296262685Sdelphij end_name = lib_name; 297262685Sdelphij printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS 298262685Sdelphij printf "\t$(AR) $(AR_OPTS) $@ $?\n" 299262685Sdelphij printf "\t$(RANLIB) $@\n" 300262685Sdelphij if ( target == "vxworks" ) 301262685Sdelphij { 302262685Sdelphij printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=.o)\n" 303262685Sdelphij } 304262685Sdelphij print "" 305262685Sdelphij print "install \\" 306262685Sdelphij print "install.libs \\" 307262685Sdelphij printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name 308262685Sdelphij printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name 309262685Sdelphij printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name 310262685Sdelphij if ( overwrite == "yes" && lib_name == "libncurses.a" ) 311262685Sdelphij { 312262685Sdelphij printf "\t@echo linking libcurses.a to libncurses.a\n" 313262685Sdelphij printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n" 314262685Sdelphij printf "\t(cd $(DESTDIR)$(libdir) && $(LN_S) libncurses.a libcurses.a)\n" 315262685Sdelphij } 316262685Sdelphij printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name 317262685Sdelphij if ( target == "vxworks" ) 318262685Sdelphij { 319262685Sdelphij printf "\t@echo installing ../lib/lib%s.o as $(DESTDIR)$(libdir)/lib%s.o\n", name, name 320262685Sdelphij printf "\t$(INSTALL_DATA) ../lib/lib%s.o $(DESTDIR)$(libdir)/lib%s.o\n", name, name 321262685Sdelphij } 322262685Sdelphij print "" 323262685Sdelphij print "uninstall \\" 324262685Sdelphij print "uninstall.libs \\" 325262685Sdelphij printf "uninstall.%s ::\n", name 326262685Sdelphij printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name 327262685Sdelphij printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name 328262685Sdelphij if ( overwrite == "yes" && lib_name == "libncurses.a" ) 329262685Sdelphij { 330262685Sdelphij printf "\t@echo linking libcurses.a to libncurses.a\n" 331262685Sdelphij printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n" 332262685Sdelphij } 333262685Sdelphij if ( target == "vxworks" ) 334262685Sdelphij { 335262685Sdelphij printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s.o\n", name 336262685Sdelphij printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s.o\n", name 337262685Sdelphij } 338262685Sdelphij } 339262685Sdelphij print "" 340262685Sdelphij print "clean ::" 341262685Sdelphij removelinks("../lib"); 342262685Sdelphij print "" 343262685Sdelphij print "mostlyclean::" 344262685Sdelphij printf "\t-rm -f $(%s_OBJS)\n", OBJS 345262685Sdelphij if ( MODEL == "LIBTOOL" ) { 346262685Sdelphij printf "\t-rm -f $(%s_OBJS:.o=.lo)\n", OBJS 347262685Sdelphij } 348262685Sdelphij } 349262685Sdelphij else if ( found == 2 ) 350262685Sdelphij { 351262685Sdelphij print "" 352262685Sdelphij print "mostlyclean::" 353262685Sdelphij printf "\t-rm -f $(%s_OBJS)\n", OBJS 354262685Sdelphij if ( MODEL == "LIBTOOL" ) { 355262685Sdelphij printf "\t-rm -f $(%s_OBJS:.o=.lo)\n", OBJS 356262685Sdelphij } 357262685Sdelphij print "" 358262685Sdelphij print "clean ::" 359262685Sdelphij printf "\t-rm -f $(%s_OBJS)\n", OBJS 360262685Sdelphij if ( MODEL == "LIBTOOL" ) { 361262685Sdelphij printf "\t-rm -f $(%s_OBJS:.o=.lo)\n", OBJS 362262685Sdelphij } 363262685Sdelphij } 364262685Sdelphij } 365262685Sdelphij