235ceab03fd97d1ea58f7cd98d4186ebdf3dd610
[ncurses.git] / mk-1st.awk
1 # $Id: mk-1st.awk,v 1.20 1997/05/05 21:28:17 tom Exp $
2 ################################################################################
3 # Copyright 1996,1997 by Thomas E. Dickey <dickey@clark.net>                   #
4 # All Rights Reserved.                                                         #
5 #                                                                              #
6 # Permission to use, copy, modify, and distribute this software and its        #
7 # documentation for any purpose and without fee is hereby granted, provided    #
8 # that the above copyright notice appear in all copies and that both that      #
9 # copyright notice and this permission notice appear in supporting             #
10 # documentation, and that the name of the above listed copyright holder(s) not #
11 # be used in advertising or publicity pertaining to distribution of the        #
12 # software without specific, written prior permission. THE ABOVE LISTED        #
13 # COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,    #
14 # INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT #
15 # SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY SPECIAL,        #
16 # INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM   #
17 # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE   #
18 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR    #
19 # PERFORMANCE OF THIS SOFTWARE.                                                #
20 ################################################################################
21 # Generate list of objects for a given model library
22 # Variables:
23 #       name (library name, e.g., "ncurses", "panel", "forms", "menus")
24 #       model (directory into which we compile, e.g., "obj")
25 #       suffix (e.g., "_g.a", for debug libraries)
26 #       MODEL (e.g., "DEBUG", uppercase; toupper is not portable)
27 #       DoLinks ("yes" or "no", flag to add symbolic links)
28 #       rmSoLocs ("yes" or "no", flag to add extra clean target)
29 #       overwrite ("yes" or "no", flag to add link to libcurses.a
30 #
31 # Notes:
32 #       CLIXs nawk does not like underscores in command-line variable names.
33 #       Mixed-case is ok.
34 #       HP/UX requires shared libraries to have executable permissions.
35 #
36 function symlink(src,dst) {
37                 if ( src != dst ) {
38                         printf "rm -f %s; ", dst
39                         printf "$(LN_S) %s %s; ", src, dst
40                 }
41         }
42 function sharedlinks(directory) {
43                 if ( end_name != lib_name ) {
44                         printf "\tcd %s && (", directory
45                         abi_name = sprintf("%s.$(ABI_VERSION)", lib_name);
46                         symlink(end_name, abi_name);
47                         symlink(abi_name, lib_name);
48                         printf ")\n"
49                 }
50         }
51 function removelinks() {
52                 if ( end_name != lib_name ) {
53                         printf "\trm -f ../lib/%s ../lib/%s\n", abi_name, end_name
54                 }
55         }
56 function installed_name() {
57                 if ( DO_LINKS == "yes" ) {
58                         return sprintf("%s.$(REL_VERSION)", lib_name);
59                 } else {
60                         return lib_name;
61                 }
62         }
63 BEGIN   {
64                 print  ""
65                 print  "# generated by mk-1st.awk"
66                 print  ""
67                 found = 0;
68         }
69         !/^#/ {
70                 if ( $2 == "lib" || $2 == "progs" )
71                 {
72                         if ( found == 0 )
73                         {
74                                 printf "%s_OBJS =", MODEL
75                                 if ( $2 == "lib" )
76                                         found = 1
77                                 else
78                                         found = 2
79                         }
80                         printf " \\\n\t../%s/%s.o", model, $1
81                 }
82         }
83 END     {
84                 print  ""
85                 if ( found != 0 )
86                 {
87                         printf "\n$(%s_OBJS) : %s\n", MODEL, depend
88                 }
89                 if ( found == 1 )
90                 {
91                         print  ""
92                         lib_name = sprintf("lib%s%s", name, suffix)
93                         if ( MODEL == "SHARED" )
94                         {
95                                 if ( DoLinks == "yes" ) {
96                                         end_name = sprintf("%s.$(REL_VERSION)", lib_name);
97                                 } else {
98                                         end_name = lib_name;
99                                 }
100                                 printf "../lib/%s : $(%s_OBJS)\n", lib_name, MODEL
101                                 print  "\t@-rm -f $@"
102                                 printf "\t$(MK_SHARED_LIB) $(%s_OBJS)\n", MODEL
103                                 sharedlinks("../lib")
104                                 print  ""
105                                 if ( end_name != lib_name ) {
106                                         printf "../lib/%s : ../lib/%s\n", end_name, lib_name
107                                 }
108                                 print  ""
109                                 print  "install \\"
110                                 print  "install.libs \\"
111                                 printf "install.%s :: $(INSTALL_PREFIX)$(libdir) ../lib/%s\n", name, end_name
112                                 printf "\t@echo installing ../lib/%s as $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name, end_name
113                                 printf "\t-rm -f $(INSTALL_PREFIX)$(libdir)/%s \n", end_name
114                                 printf "\t$(INSTALL) ../lib/%s $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name, end_name
115                                 sharedlinks("$(INSTALL_PREFIX)$(libdir)")
116                                 if ( overwrite == "yes" && name == "ncurses" )
117                                 {
118                                         ovr_name = sprintf("libcurses%s", suffix)
119                                         printf "\t@echo linking %s to %s\n", ovr_name, lib_name
120                                         printf "\t-rm -f $(INSTALL_PREFIX)$(libdir)/%s \n", ovr_name
121                                         printf "\t(cd $(INSTALL_PREFIX)$(libdir) && $(LN_S) %s %s)\n", lib_name, ovr_name
122                                 }
123                                 printf "\t- ldconfig\n"
124                                 if ( rmSoLocs == "yes" ) {
125                                         print  ""
126                                         print  "mostlyclean \\"
127                                         print  "clean ::"
128                                         printf "\t@-rm -f so_locations\n"
129                                 }
130                         }
131                         else
132                         {
133                                 end_name = lib_name;
134                                 printf "../lib/%s : $(%s_OBJS)\n", lib_name, MODEL
135                                 printf "\t$(AR) $(AR_OPTS) $@ $?\n"
136                                 printf "\t$(RANLIB) $@\n"
137                                 print  ""
138                                 print  "install \\"
139                                 print  "install.libs \\"
140                                 printf "install.%s :: $(INSTALL_PREFIX)$(libdir) ../lib/%s\n", name, lib_name
141                                 printf "\t@echo installing ../lib/%s as $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name, lib_name
142                                 printf "\t$(INSTALL_DATA) ../lib/%s $(INSTALL_PREFIX)$(libdir)/%s \n", lib_name, lib_name
143                                 if ( overwrite == "yes" && lib_name == "libncurses.a" )
144                                 {
145                                         printf "\t@echo linking libcurses.a to libncurses.a \n"
146                                         printf "\t-rm -f $(INSTALL_PREFIX)$(libdir)/libcurses.a \n"
147                                         printf "\t(cd $(INSTALL_PREFIX)$(libdir) && $(LN_S) libncurses.a libcurses.a)\n"
148                                 }
149                                 printf "\t$(RANLIB) $(INSTALL_PREFIX)$(libdir)/%s\n", lib_name
150                         }
151                         print ""
152                         print "mostlyclean \\"
153                         print "clean ::"
154                         printf "\trm -f ../lib/%s\n", lib_name
155                         printf "\trm -f $(%s_OBJS)\n", MODEL
156                         removelinks();
157                 }
158                 else if ( found == 2 )
159                 {
160                         print ""
161                         print "mostlyclean \\"
162                         print "clean ::"
163                         printf "\trm -f $(%s_OBJS)\n", MODEL
164                 }
165         }