1 # $Id: mk-1st.awk,v 1.96 2013/09/07 17:54:05 Alexey.Pavlov Exp $
2 ##############################################################################
3 # Copyright (c) 1998-2012,2013 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 # CXX_MODEL (e.g., "DEBUG", uppercase)
38 # model (directory into which we compile, e.g., "obj")
39 # prefix (e.g., "lib", for Unix-style libraries)
40 # suffix (e.g., "_g.a", for debug libraries)
41 # subset ("none", "base", "base+ext_funcs" or "termlib", etc.)
42 # driver ("yes" or "no", depends on --enable-term-driver)
43 # ShlibVer ("rel", "abi" or "auto", to augment DoLinks variable)
44 # ShlibVerInfix ("yes" or "no", determines location of version #)
45 # SymLink ("ln -s", etc)
46 # TermlibRoot ("tinfo" or other root for libterm.so)
47 # TermlibSuffix (".so" or other suffix for libterm.so)
48 # ReLink ("yes", or "no", flag to rebuild shared libs on install)
49 # DoLinks ("yes", "reverse" or "no", flag to add symbolic links)
50 # rmSoLocs ("yes" or "no", flag to add extra clean target)
51 # ldconfig (path for this tool, if used)
52 # overwrite ("yes" or "no", flag to add link to libcurses.a
53 # depend (optional dependencies for all objects, e.g, ncurses_cfg.h)
54 # host (cross-compile host, if any)
55 # libtool_version (libtool "-version-info" or "-version-number")
58 # CLIXs nawk does not like underscores in command-line variable names.
59 # Mixed-case variable names are ok.
60 # HP/UX requires shared libraries to have executable permissions.
62 function is_ticlib
() {
63 return ( subset ~
/^ticlib$
/ );
65 function is_termlib
() {
66 return ( subset ~
/^
(ticlib\
+)?termlib
((\
+[^
+ ]+)*\
+[a
-z_
]+_tinfo
)?$
/ );
69 function lib_name_of
(a_name
) {
70 return sprintf("%s%s%s", prefix
, a_name
, suffix
)
73 function imp_name_of
(a_name
) {
74 if (ShlibVerInfix ==
"cygdll" || ShlibVerInfix ==
"msysdll" || ShlibVerInfix ==
"mingw") {
75 result =
sprintf("%s%s%s.a", prefix
, a_name
, suffix
);
82 function abi_name_of
(a_name
) {
83 if (ShlibVerInfix ==
"cygdll") {
84 result =
sprintf("%s%s$(ABI_VERSION)%s", "cyg", a_name
, suffix
);
85 } else if (ShlibVerInfix ==
"msysdll") {
86 result =
sprintf("%s%s$(ABI_VERSION)%s", "msys-", a_name
, suffix
);
87 } else if (ShlibVerInfix ==
"mingw") {
88 result =
sprintf("%s%s$(ABI_VERSION)%s", prefix
, a_name
, suffix
);
89 } else if (ShlibVerInfix ==
"yes") {
90 result =
sprintf("%s%s.$(ABI_VERSION)%s", prefix
, a_name
, suffix
);
92 result =
sprintf("%s.$(ABI_VERSION)", lib_name_of
(a_name
));
97 function rel_name_of
(a_name
) {
98 if (ShlibVerInfix ==
"cygdll") {
99 result =
sprintf("%s%s$(REL_VERSION)%s", "cyg", a_name
, suffix
);
100 } else if (ShlibVerInfix ==
"msysdll") {
101 result =
sprintf("%s%s$(ABI_VERSION)%s", "msys-", a_name
, suffix
);
102 } else if (ShlibVerInfix ==
"mingw") {
103 result =
sprintf("%s%s$(REL_VERSION)%s", prefix
, a_name
, suffix
);
104 } else if (ShlibVerInfix ==
"yes") {
105 result =
sprintf("%s%s.$(REL_VERSION)%s", prefix
, a_name
, suffix
);
107 result =
sprintf("%s.$(REL_VERSION)", lib_name_of
(a_name
));
112 function end_name_of
(a_name
) {
113 if ( MODEL
!= "SHARED" ) {
114 result = lib_name_of
(a_name
);
115 } else if ( DoLinks ==
"reverse") {
116 result = lib_name_of
(a_name
);
118 if ( ShlibVer ==
"rel" ) {
119 result = rel_name_of
(a_name
);
120 } else if ( ShlibVer ==
"abi" || ShlibVer ==
"cygdll" || ShlibVer ==
"msysdll" || ShlibVer ==
"mingw" ) {
121 result = abi_name_of
(a_name
);
123 result = lib_name_of
(a_name
);
128 function symlink
(src
,dst
) {
130 if ( SymLink !~
/.
*-f.
*/ ) {
131 printf "rm -f %s; ", dst
133 printf "$(LN_S) %s %s; ", src
, dst
136 function rmlink
(directory
, dst
) {
138 printf "\t-rm -f %s/%s\n", directory
, dst
141 function removelinks
(directory
) {
143 links
[nlinks
++] = end_name
;
144 if ( DoLinks ==
"reverse" ) {
145 if ( ShlibVer ==
"rel" ) {
146 links
[nlinks
++] = abi_name
;
147 links
[nlinks
++] = rel_name
;
148 } else if ( ShlibVer ==
"abi" ) {
149 links
[nlinks
++] = abi_name
;
152 if ( ShlibVer ==
"rel" ) {
153 links
[nlinks
++] = abi_name
;
154 links
[nlinks
++] = lib_name
;
155 } else if ( ShlibVer ==
"abi" ) {
156 links
[nlinks
++] = lib_name
;
159 for (j =
0; j
< nlinks
; ++j
) {
161 for (k =
0; k
< j
; ++k
) {
162 if ( links
[j
] == links
[k
] ) {
168 rmlink
(directory
, links
[j
]);
172 function make_shlib
(objs
, shlib_list
) {
173 printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(%s) $(LDFLAGS)\n", objs
, shlib_list
175 function sharedlinks
(directory
) {
176 if ( ShlibVer
!= "auto" && ShlibVer
!= "cygdll" && ShlibVer
!= "msysdll" && ShlibVer
!= "mingw" ) {
177 printf "\tcd %s && (", directory
178 if ( DoLinks ==
"reverse" ) {
179 if ( ShlibVer ==
"rel" ) {
180 symlink
(lib_name
, abi_name
);
181 symlink
(abi_name
, rel_name
);
182 } else if ( ShlibVer ==
"abi" ) {
183 symlink
(lib_name
, abi_name
);
186 if ( ShlibVer ==
"rel" ) {
187 symlink
(rel_name
, abi_name
);
188 symlink
(abi_name
, lib_name
);
189 } else if ( ShlibVer ==
"abi" ) {
190 symlink
(abi_name
, lib_name
);
196 # termlib may be named explicitly via "--with-termlib=XXX", which overrides
197 # any suffix. Temporarily override "suffix" to account for this.
198 function termlib_end_of
() {
199 termlib_save_suffix = suffix
;
200 suffix = TermlibSuffix
;
201 termlib_temp_result = end_name_of
(TermlibRoot
);
202 suffix = termlib_save_suffix
;
203 return termlib_temp_result
;
205 function shlib_build
(directory
) {
206 dst_libs =
sprintf("%s/%s", directory
, end_name
);
207 printf "%s : \\\n", dst_libs
208 printf "\t\t%s \\\n", directory
209 if (subset ==
"ticlib" && driver ==
"yes" ) {
211 sub(/^tic
/, "ncurses", base
); # workaround for "w"
212 printf "\t\t%s/%s \\\n", directory
, end_name_of
(base
);
214 if (subset ~
/^base
/ || subset ==
"ticlib" ) {
216 sub(/^
[^.
]\.
/,".",suffix
)
217 if (directory
!= "../lib") {
218 printf "\t\t%s/%s \\\n", "../lib", termlib_end_of
();
220 printf "\t\t%s/%s \\\n", directory
, termlib_end_of
();
223 printf "\t\t$(%s_OBJS)\n", OBJS
224 printf "\t@echo linking $@\n"
226 make_shlib
(OBJS
, "TICS_LIST")
227 } else if ( is_termlib
() ) {
228 make_shlib
(OBJS
, "TINFO_LIST")
230 make_shlib
(OBJS
, "SHLIB_LIST")
232 sharedlinks
(directory
)
234 function shlib_install
(directory
) {
235 src_lib1 =
sprintf("../lib/%s", end_name
);
236 dst_lib1 =
sprintf("%s/%s", directory
, end_name
);
237 printf "%s : \\\n", dst_lib1
238 printf "\t\t%s \\\n", directory
239 printf "\t\t%s\n", src_lib1
240 printf "\t@echo installing $@\n"
241 printf "\t$(INSTALL_LIB) %s %s\n", src_lib1
, dst_lib1
;
242 sharedlinks
(directory
)
244 function install_dll
(directory
,filename) {
245 src_name =
sprintf("../lib/%s", filename);
246 dst_name =
sprintf("$(DESTDIR)%s/%s", directory
, filename);
247 printf "\t@echo installing %s as %s\n", src_name
, dst_name
248 if ( directory ==
"$(bindir)" ) {
249 program =
"$(INSTALL) -m 755";
251 program =
"$(INSTALL_LIB)";
253 printf "\t%s %s %s\n", program
, src_name
, dst_name
262 if (subset ==
"none") {
264 } else if (index(subset,$
2) > 0) {
267 if ( name ~
/^.
*\
+\
+.
*/ ) {
268 if ( CXX_MODEL ==
"NORMAL" && MODEL ==
"SHARED" ) {
270 printf "# overriding model from %s to match CXX_MODEL\n", MODEL
;
277 printf "# generated by mk-1st.awk (subset=%s)\n", subset
278 printf "# name: %s\n", name
279 printf "# traces: %s\n", traces
280 printf "# MODEL: %s\n", MODEL
281 printf "# CXX_MODEL: %s\n", CXX_MODEL
282 printf "# model: %s\n", model
283 printf "# prefix: %s\n", prefix
284 printf "# suffix: %s\n", suffix
285 printf "# subset: %s\n", subset
286 printf "# driver: %s\n", driver
287 printf "# ShlibVer: %s\n", ShlibVer
288 printf "# ShlibVerInfix: %s\n", ShlibVerInfix
289 printf "# SymLink: %s\n", SymLink
290 printf "# TermlibRoot: %s\n", TermlibRoot
291 printf "# TermlibSuffix: %s\n", TermlibSuffix
292 printf "# ReLink: %s\n", ReLink
293 printf "# DoLinks: %s\n", DoLinks
294 printf "# rmSoLocs: %s\n", rmSoLocs
295 printf "# ldconfig: %s\n", ldconfig
296 printf "# overwrite: %s\n", overwrite
297 printf "# depend: %s\n", depend
298 printf "# host: %s\n", host
305 } else if ( is_termlib
() ) {
316 if (traces
!= "all" && traces
!= MODEL
&& $
1 != "lib_trace")
321 && ( $
1 != "link_test" ) \
329 printf "%s_OBJS =", OBJS
332 } else if ( $
2 ==
"c++" ) {
333 TOOL_PREFIX =
"CXX_";
346 printf " \\\n\t../%s/%s$o", model
, $
1;
353 printf "\n$(%s_OBJS) : %s\n", OBJS
, depend
358 lib_name = lib_name_of
(name
);
359 if ( MODEL ==
"SHARED" )
361 abi_name = abi_name_of
(name
);
362 rel_name = rel_name_of
(name
);
363 imp_name = imp_name_of
(name
);
364 end_name = end_name_of
(name
);
366 shlib_build
("../lib")
370 print "install.libs \\"
372 if ( ShlibVer ==
"cygdll" || ShlibVer ==
"msysdll" || ShlibVer ==
"mingw") {
374 dst_dirs =
"$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
375 printf "install.%s :: %s $(LIBRARIES)\n", name
, dst_dirs
376 install_dll
("$(bindir)",end_name
);
377 install_dll
("$(libdir)",imp_name
);
381 lib_dir =
"$(DESTDIR)$(libdir)";
382 printf "install.%s :: %s/%s\n", name
, lib_dir
, end_name
384 if ( ReLink ==
"yes" ) {
387 shlib_install
(lib_dir
)
391 if ( overwrite ==
"yes" && name ==
"ncurses" )
393 if ( ShlibVer ==
"cygdll" || ShlibVer ==
"msysdll" || ShlibVer ==
"mingw") {
394 ovr_name =
sprintf("libcurses%s.a", suffix
)
395 printf "\t@echo linking %s to %s\n", imp_name
, ovr_name
396 printf "\tcd $(DESTDIR)$(libdir) && ("
397 symlink
(imp_name
, ovr_name
)
400 ovr_name =
sprintf("libcurses%s", suffix
)
401 printf "\t@echo linking %s to %s\n", end_name
, ovr_name
402 printf "\tcd $(DESTDIR)$(libdir) && ("
403 symlink
(end_name
, ovr_name
)
407 if ( ldconfig
!= "" && ldconfig
!= ":" ) {
408 printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
412 print "uninstall.libs \\"
413 printf "uninstall.%s ::\n", name
414 if ( ShlibVer ==
"cygdll" || ShlibVer ==
"msysdll" || ShlibVer ==
"mingw") {
416 printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
417 printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
419 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
420 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
423 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
424 removelinks
("$(DESTDIR)$(libdir)")
425 if ( overwrite ==
"yes" && name ==
"ncurses" )
427 ovr_name =
sprintf("libcurses%s", suffix
)
428 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
431 if ( rmSoLocs ==
"yes" ) {
433 print "mostlyclean \\"
435 printf "\t-@rm -f so_locations\n"
438 else if ( MODEL ==
"LIBTOOL" )
441 printf "../lib/%s : $(%s_OBJS)\n", lib_name
, OBJS
443 which_list =
"TICS_LIST";
444 } else if ( is_termlib
() ) {
445 which_list =
"TINFO_LIST";
447 which_list =
"SHLIB_LIST";
449 printf "\tcd ../lib && $(LIBTOOL_LINK) $(%s) $(%s) \\\n", CC_NAME
, CC_FLAG
;
450 printf "\t\t-o %s $(%s_OBJS:$o=.lo) \\\n", lib_name
, OBJS
;
451 printf "\t\t-rpath $(DESTDIR)$(libdir) \\\n";
452 printf "\t\t%s $(NCURSES_MAJOR):$(NCURSES_MINOR) $(LT_UNDEF) $(%s) $(LDFLAGS)\n", libtool_version
, which_list
;
455 print "install.libs \\"
456 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name
, lib_name
457 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name
, lib_name
458 printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
461 print "uninstall.libs \\"
462 printf "uninstall.%s ::\n", name
463 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
464 printf "\t-@$(LIBTOOL_UNINSTALL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
469 printf "../lib/%s : $(%s_OBJS)\n", lib_name
, OBJS
470 printf "\t$(%sAR) $(%sARFLAGS) $@ $?\n", TOOL_PREFIX
, TOOL_PREFIX
;
471 printf "\t$(RANLIB) $@\n"
472 if ( host ==
"vxworks" )
474 printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
478 print "install.libs \\"
479 printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name
, lib_name
480 printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name
, lib_name
481 printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name
, lib_name
482 if ( overwrite ==
"yes" && lib_name ==
"libncurses.a" )
484 printf "\t@echo linking libcurses.a to libncurses.a\n"
485 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
486 printf "\t(cd $(DESTDIR)$(libdir) && "
487 symlink
("libncurses.a", "libcurses.a")
490 printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
491 if ( host ==
"vxworks" )
493 printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name
, name
494 printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name
, name
498 print "uninstall.libs \\"
499 printf "uninstall.%s ::\n", name
500 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
501 printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
502 if ( overwrite ==
"yes" && lib_name ==
"libncurses.a" )
504 printf "\t@echo linking libcurses.a to libncurses.a\n"
505 printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
507 if ( host ==
"vxworks" )
509 printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
510 printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
515 removelinks
("../lib");
517 print "mostlyclean::"
518 printf "\t-rm -f $(%s_OBJS)\n", OBJS
519 if ( MODEL ==
"LIBTOOL" ) {
520 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
523 else if ( found ==
2 )
526 print "mostlyclean::"
527 printf "\t-rm -f $(%s_OBJS)\n", OBJS
528 if ( MODEL ==
"LIBTOOL" ) {
529 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
533 printf "\t-rm -f $(%s_OBJS)\n", OBJS
534 if ( MODEL ==
"LIBTOOL" ) {
535 printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS