1 # $Id: mk-1st.awk,v 1.85 2010/08/07 20:42:30 Gabriele.Balducci Exp $
2 ##############################################################################
3 # Copyright (c) 1998-2009,2010 Free Software Foundation, Inc. #
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: #
13 # The above copyright notice and this permission notice shall be included in #
14 # all copies or substantial portions of the Software. #
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. #
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 #
28 ##############################################################################
30 # Author: Thomas E. Dickey
32 # Generate list of objects for a given model library
34 # name (library name, e.g., "ncurses", "panel", "forms", "menus")
35 # traces ("all" or "DEBUG", to control whether tracing is compiled in)
36 # MODEL (e.g., "DEBUG", uppercase; toupper is not portable)
37 # model (directory into which we compile, e.g., "obj")
38 # prefix (e.g., "lib", for Unix-style libraries)
39 # suffix (e.g., "_g.a", for debug libraries)
40 # subset ("none", "base", "base+ext_funcs" or "termlib", etc.)
41 # ShlibVer ("rel", "abi" or "auto", to augment DoLinks variable)
42 # ShlibVerInfix ("yes" or "no", determines location of version #)
43 # SymLink ("ln -s", etc)
44 # TermlibRoot ("tinfo" or other root for libterm.so)
45 # TermlibSuffix (".so" or other suffix for libterm.so)
46 # ReLink ("yes", or "no", flag to rebuild shared libs on install)
47 # DoLinks ("yes", "reverse" or "no", flag to add symbolic links)
48 # rmSoLocs ("yes" or "no", flag to add extra clean target)
49 # ldconfig (path for this tool, if used)
50 # overwrite ("yes" or "no", flag to add link to libcurses.a
51 # depend (optional dependencies for all objects, e.g, ncurses_cfg.h)
52 # host (cross-compile host, if any)
53 # libtool_version (libtool "-version-info" or "-version-number")
56 # CLIXs nawk does not like underscores in command-line variable names.
57 # Mixed-case variable names are ok.
58 # HP/UX requires shared libraries to have executable permissions.
60 function is_ticlib
() {
61 return ( subset ~
/^ticlib$
/ );
63 function is_termlib
() {
64 return ( subset ~
/^
(ticlib\
+)?termlib
((\
+[^
+ ]+)*\
+[a
-z_
]+_tinfo
)?$
/ );
67 function lib_name_of
(a_name
) {
68 return sprintf("%s%s%s", prefix
, a_name
, suffix
)
71 function imp_name_of
(a_name
) {
72 if (ShlibVerInfix ==
"cygdll") {
73 result =
sprintf("%s%s%s.a", prefix
, a_name
, suffix
);
80 function abi_name_of
(a_name
) {
81 if (ShlibVerInfix ==
"cygdll") {
82 result =
sprintf("%s%s$(ABI_VERSION)%s", "cyg", a_name
, suffix
);
83 } else if (ShlibVerInfix ==
"yes") {
84 result =
sprintf("%s%s.$(ABI_VERSION)%s", prefix
, a_name
, suffix
);
86 result =
sprintf("%s.$(ABI_VERSION)", lib_name_of
(a_name
));
91 function rel_name_of
(a_name
) {
92 if (ShlibVerInfix ==
"cygdll") {
93 result =
sprintf("%s%s$(REL_VERSION)%s", "cyg", a_name
, suffix
);
94 } else if (ShlibVerInfix ==
"yes") {
95 result =
sprintf("%s%s.$(REL_VERSION)%s", prefix
, a_name
, suffix
);
97 result =
sprintf("%s.$(REL_VERSION)", lib_name_of
(a_name
));
102 function end_name_of
(a_name
) {
103 if ( MODEL
!= "SHARED" ) {
104 result = lib_name_of
(a_name
);
105 } else if ( DoLinks ==
"reverse") {
106 result = lib_name_of
(a_name
);
108 if ( ShlibVer ==
"rel" ) {
109 result = rel_name_of
(a_name
);
110 } else if ( ShlibVer ==
"abi" || ShlibVer ==
"cygdll" ) {
111 result = abi_name_of
(a_name
);
113 result = lib_name_of
(a_name
);
118 function symlink
(src
,dst
) {
120 if ( SymLink !~
/.
*-f.
*/ ) {
121 printf "rm -f %s; ", dst
123 printf "$(LN_S) %s %s; ", src
, dst
126 function rmlink
(directory
, dst
) {
127 printf "\t-rm -f %s/%s\n", directory
, dst
129 function removelinks
(directory
) {
130 rmlink
(directory
, end_name
);
131 if ( DoLinks ==
"reverse" ) {
132 if ( ShlibVer ==
"rel" ) {
133 rmlink
(directory
, abi_name
);
134 rmlink
(directory
, rel_name
);
135 } else if ( ShlibVer ==
"abi" ) {
136 rmlink
(directory
, abi_name
);
139 if ( ShlibVer ==
"rel" ) {
140 rmlink
(directory
, abi_name
);
141 rmlink
(directory
, lib_name
);
142 } else if ( ShlibVer ==
"abi" ) {
143 rmlink
(directory
, lib_name
);
147 function make_shlib
(objs
, shlib_list
) {
148 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(%s) $(LDFLAGS)\n", objs
, shlib_list
150 function sharedlinks
(directory
) {
151 if ( ShlibVer
!= "auto" && ShlibVer
!= "cygdll" ) {
152 printf "\tcd %s && (", directory
153 if ( DoLinks ==
"reverse" ) {
154 if ( ShlibVer ==
"rel" ) {
155 symlink
(lib_name
, abi_name
);
156 symlink
(abi_name
, rel_name
);
157 } else if ( ShlibVer ==
"abi" ) {
158 symlink
(lib_name
, abi_name
);
161 if ( ShlibVer ==
"rel" ) {
162 symlink
(rel_name
, abi_name
);
163 symlink
(abi_name
, lib_name
);
164 } else if ( ShlibVer ==
"abi" ) {
165 symlink
(abi_name
, lib_name
);
171 # termlib may be named explicitly via "--with-termlib=XXX", which overrides
172 # any suffix. Temporarily override "suffix" to account for this.
173 function termlib_end_of
() {
174 termlib_save_suffix = suffix
;
175 suffix = TermlibSuffix
;
176 termlib_temp_result = end_name_of
(TermlibRoot
);
177 suffix = termlib_save_suffix
;
178 return termlib_temp_result
;
180 function shlib_build
(directory
) {
181 dst_libs =
sprintf("%s/%s", directory
, end_name
);
182 printf "%s : \\\n", dst_libs
183 printf "\t\t%s \\\n", directory
184 if (subset ~
/^base
/ || subset ==
"ticlib" ) {
186 sub(/^
[^.
]\.
/,".",suffix
)
187 if (directory
!= "../lib") {
188 printf "\t\t%s/%s \\\n", "../lib", termlib_end_of
();
190 printf "\t\t%s/%s \\\n", directory
, termlib_end_of
();
193 printf "\t\t$(%s_OBJS)\n", OBJS
194 printf "\t@echo linking $@\n"
196 make_shlib
(OBJS
, "TICS_LIST")
197 } else if ( is_termlib
() ) {
198 make_shlib
(OBJS
, "TINFO_LIST")
200 make_shlib
(OBJS
, "SHLIB_LIST")
202 sharedlinks
(directory
)
204 function shlib_install
(directory
) {
205 src_lib1 =
sprintf("../lib/%s", end_name
);
206 dst_lib1 =
sprintf("%s/%s", directory
, end_name
);
207 printf "%s : \\\n", dst_lib1
208 printf "\t\t%s \\\n", directory
209 printf "\t\t%s\n", src_lib1
210 printf "\t@echo installing $@\n"
211 printf "\t$(INSTALL_LIB) %s %s\n", src_lib1
, dst_lib1
;
212 sharedlinks
(directory
)
214 function install_dll
(directory
,filename) {
215 src_name =
sprintf("../lib/%s", filename);
216 dst_name =
sprintf("$(DESTDIR)%s/%s", directory
, filename);
217 printf "\t@echo installing %s as %s\n", src_name
, dst_name
218 if ( directory ==
"$(bindir)" ) {
219 program =
"$(INSTALL) -m 755";
221 program =
"$(INSTALL_LIB)";
223 printf "\t%s %s %s\n", program
, src_name
, dst_name
231 if (subset ==
"none") {
233 } else if (index(subset,$
2) > 0) {
237 printf "# generated by mk-1st.awk (subset=%s)\n", subset
238 printf "# name: %s\n", name
239 printf "# traces: %s\n", traces
240 printf "# MODEL: %s\n", MODEL
241 printf "# model: %s\n", model
242 printf "# prefix: %s\n", prefix
243 printf "# suffix: %s\n", suffix
244 printf "# subset: %s\n", subset
245 printf "# ShlibVer: %s\n", ShlibVer
246 printf "# ShlibVerInfix: %s\n", ShlibVerInfix
247 printf "# SymLink: %s\n", SymLink
248 printf "# TermlibRoot: %s\n", TermlibRoot
249 printf "# TermlibSuffix: %s\n", TermlibSuffix
250 printf "# ReLink: %s\n", ReLink
251 printf "# DoLinks: %s\n", DoLinks
252 printf "# rmSoLocs: %s\n", rmSoLocs
253 printf "# ldconfig: %s\n", ldconfig
254 printf "# overwrite: %s\n", overwrite
255 printf "# depend: %s\n", depend
256 printf "# host: %s\n", host
263 } else if ( is_termlib
() ) {
274 if (traces
!= "all" && traces
!= MODEL
&& $
1 != "lib_trace")
279 && ( $
1 != "link_test" ) \
287 printf "%s_OBJS =", OBJS
293 printf " \\\n\t../%s/%s$o", model
, $
1
300 printf "\n$(%s_OBJS) : %s\n", OBJS
, depend
305 lib_name = lib_name_of
(name
);
306 if ( MODEL ==
"SHARED" )
308 abi_name = abi_name_of
(name
);
309 rel_name = rel_name_of
(name
);
310 imp_name = imp_name_of
(name
);
311 end_name = end_name_of
(name
);
313 shlib_build
("../lib")
317 print "install.libs \\"
319 if ( ShlibVer ==
"cygdll" ) {
321 dst_dirs =
"$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
322 printf "install.%s :: %s $(LIBRARIES)\n", name
, dst_dirs
323 install_dll
("$(bindir)",end_name
);
324 install_dll
("$(libdir)",imp_name
);
328 lib_dir =
"$(DESTDIR)$(libdir)";
329 printf "install.%s :: %s/%s\n", name
, lib_dir
, end_name
331 if ( ReLink ==
"yes" ) {
334 shlib_install
(lib_dir
)
338 if ( overwrite ==
"yes" && name ==
"ncurses" )
340 if ( ShlibVer ==
"cygdll" ) {
341 ovr_name =
sprintf("libcurses%s.a", suffix
)
342 printf "\t@echo linking %s to %s\n", imp_name
, ovr_name
343 printf "\tcd $(DESTDIR)$(libdir) && ("
344 symlink
(imp_name
, ovr_name
)
347 ovr_name =
sprintf("libcurses%s", suffix
)
348 printf "\t@echo linking %s to %s\n", end_name
, ovr_name
349 printf "\tcd $(DESTDIR)$(libdir) && ("
350 symlink
(end_name
, ovr_name
)
354 if ( ldconfig
!= "" && ldconfig
!= ":" ) {
355 printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
359 print "uninstall.libs \\"
360 printf "uninstall.%s ::\n", name
361 if ( ShlibVer ==
"cygdll" ) {
363 printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
364 printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
366 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
367 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
370 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
371 removelinks
("$(DESTDIR)$(libdir)")
372 if ( overwrite ==
"yes" && name ==
"ncurses" )
374 if ( ShlibVer ==
"cygdll" ) {
375 ovr_name =
sprintf("libcurses%s.a", suffix
)
377 ovr_name =
sprintf("libcurses%s", suffix
)
379 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
382 if ( rmSoLocs ==
"yes" ) {
384 print "mostlyclean \\"
386 printf "\t-@rm -f so_locations\n"
389 else if ( MODEL ==
"LIBTOOL" )
397 printf "../lib/%s : $(%s_OBJS)\n", lib_name
, OBJS
399 printf "\tcd ../lib && $(LIBTOOL_LINK) $(%s) -o %s $(%s_OBJS:$o=.lo) -rpath $(DESTDIR)$(libdir) %s $(NCURSES_MAJOR):$(NCURSES_MINOR) $(LT_UNDEF) $(TICS_LIST)\n", compile
, lib_name
, OBJS
, libtool_version
400 } else if ( is_termlib
() ) {
401 printf "\tcd ../lib && $(LIBTOOL_LINK) $(%s) -o %s $(%s_OBJS:$o=.lo) -rpath $(DESTDIR)$(libdir) %s $(NCURSES_MAJOR):$(NCURSES_MINOR) $(LT_UNDEF) $(TINFO_LIST)\n", compile
, lib_name
, OBJS
, libtool_version
403 printf "\tcd ../lib && $(LIBTOOL_LINK) $(%s) -o %s $(%s_OBJS:$o=.lo) -rpath $(DESTDIR)$(libdir) %s $(NCURSES_MAJOR):$(NCURSES_MINOR) $(LT_UNDEF) $(SHLIB_LIST)\n", compile
, lib_name
, OBJS
, libtool_version
407 print "install.libs \\"
408 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name
, lib_name
409 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name
, lib_name
410 printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
413 print "uninstall.libs \\"
414 printf "uninstall.%s ::\n", name
415 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
416 printf "\t-@$(LIBTOOL_UNINSTALL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
421 printf "../lib/%s : $(%s_OBJS)\n", lib_name
, OBJS
422 printf "\t$(AR) $(ARFLAGS) $@ $?\n"
423 printf "\t$(RANLIB) $@\n"
424 if ( host ==
"vxworks" )
426 printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
430 print "install.libs \\"
431 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name
, lib_name
432 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name
, lib_name
433 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name
, lib_name
434 if ( overwrite ==
"yes" && lib_name ==
"libncurses.a" )
436 printf "\t@echo linking libcurses.a to libncurses.a\n"
437 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
438 printf "\t(cd $(DESTDIR)$(libdir) && "
439 symlink
("libncurses.a", "libcurses.a")
442 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
443 if ( host ==
"vxworks" )
445 printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name
, name
446 printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name
, name
450 print "uninstall.libs \\"
451 printf "uninstall.%s ::\n", name
452 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
453 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
454 if ( overwrite ==
"yes" && lib_name ==
"libncurses.a" )
456 printf "\t@echo linking libcurses.a to libncurses.a\n"
457 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
459 if ( host ==
"vxworks" )
461 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
462 printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
467 removelinks
("../lib");
469 print "mostlyclean::"
470 printf "\t-rm -f $(%s_OBJS)\n", OBJS
471 if ( MODEL ==
"LIBTOOL" ) {
472 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
475 else if ( found ==
2 )
478 print "mostlyclean::"
479 printf "\t-rm -f $(%s_OBJS)\n", OBJS
480 if ( MODEL ==
"LIBTOOL" ) {
481 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
485 printf "\t-rm -f $(%s_OBJS)\n", OBJS
486 if ( MODEL ==
"LIBTOOL" ) {
487 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS