mk-1st.awk 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. # $Id: mk-1st.awk,v 1.78 2007/03/24 22:10:55 tom Exp $
  2. ##############################################################################
  3. # Copyright (c) 1998-2006,2007 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
  31. #
  32. # Generate list of objects for a given model library
  33. # Variables:
  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. # TermlibRoot ("tinfo" or other root for libterm.so)
  44. # TermlibSuffix (".so" or other suffix for libterm.so)
  45. # ReLink ("yes", or "no", flag to rebuild shared libs on install)
  46. # DoLinks ("yes", "reverse" or "no", flag to add symbolic links)
  47. # rmSoLocs ("yes" or "no", flag to add extra clean target)
  48. # ldconfig (path for this tool, if used)
  49. # overwrite ("yes" or "no", flag to add link to libcurses.a
  50. # depend (optional dependencies for all objects, e.g, ncurses_cfg.h)
  51. # host (cross-compile host, if any)
  52. #
  53. # Notes:
  54. # CLIXs nawk does not like underscores in command-line variable names.
  55. # Mixed-case variable names are ok.
  56. # HP/UX requires shared libraries to have executable permissions.
  57. #
  58. function is_ticlib() {
  59. return ( subset ~ /^ticlib$/ );
  60. }
  61. function is_termlib() {
  62. return ( subset ~ /^(ticlib\+)?termlib(\+ext_tinfo)?$/ );
  63. }
  64. # see lib_name
  65. function lib_name_of(a_name) {
  66. return sprintf("%s%s%s", prefix, a_name, suffix)
  67. }
  68. # see imp_name
  69. function imp_name_of(a_name) {
  70. if (ShlibVerInfix == "cygdll") {
  71. result = sprintf("%s%s%s.a", prefix, a_name, suffix);
  72. } else {
  73. result = "";
  74. }
  75. return result;
  76. }
  77. # see abi_name
  78. function abi_name_of(a_name) {
  79. if (ShlibVerInfix == "cygdll") {
  80. result = sprintf("%s%s$(ABI_VERSION)%s", "cyg", a_name, suffix);
  81. } else if (ShlibVerInfix == "yes") {
  82. result = sprintf("%s%s.$(ABI_VERSION)%s", prefix, a_name, suffix);
  83. } else {
  84. result = sprintf("%s.$(ABI_VERSION)", lib_name_of(a_name));
  85. }
  86. return result;
  87. }
  88. # see rel_name
  89. function rel_name_of(a_name) {
  90. if (ShlibVerInfix == "cygdll") {
  91. result = sprintf("%s%s$(REL_VERSION)%s", "cyg", a_name, suffix);
  92. } else if (ShlibVerInfix == "yes") {
  93. result = sprintf("%s%s.$(REL_VERSION)%s", prefix, a_name, suffix);
  94. } else {
  95. result = sprintf("%s.$(REL_VERSION)", lib_name_of(a_name));
  96. }
  97. return result;
  98. }
  99. # see end_name
  100. function end_name_of(a_name) {
  101. if ( MODEL != "SHARED" ) {
  102. result = lib_name_of(a_name);
  103. } else if ( DoLinks == "reverse") {
  104. result = lib_name_of(a_name);
  105. } else {
  106. if ( ShlibVer == "rel" ) {
  107. result = rel_name_of(a_name);
  108. } else if ( ShlibVer == "abi" || ShlibVer == "cygdll" ) {
  109. result = abi_name_of(a_name);
  110. } else {
  111. result = lib_name_of(a_name);
  112. }
  113. }
  114. return result
  115. }
  116. function symlink(src,dst) {
  117. if ( src != dst ) {
  118. printf "rm -f %s; ", dst
  119. printf "$(LN_S) %s %s; ", src, dst
  120. }
  121. }
  122. function rmlink(directory, dst) {
  123. printf "\t-rm -f %s/%s\n", directory, dst
  124. }
  125. function removelinks(directory) {
  126. rmlink(directory, end_name);
  127. if ( DoLinks == "reverse" ) {
  128. if ( ShlibVer == "rel" ) {
  129. rmlink(directory, abi_name);
  130. rmlink(directory, rel_name);
  131. } else if ( ShlibVer == "abi" ) {
  132. rmlink(directory, abi_name);
  133. }
  134. } else {
  135. if ( ShlibVer == "rel" ) {
  136. rmlink(directory, abi_name);
  137. rmlink(directory, lib_name);
  138. } else if ( ShlibVer == "abi" ) {
  139. rmlink(directory, lib_name);
  140. }
  141. }
  142. }
  143. function make_shlib(objs, shlib_list) {
  144. printf "\t$(MK_SHARED_LIB) $(%s_OBJS) $(%s) $(LDFLAGS)\n", objs, shlib_list
  145. }
  146. function sharedlinks(directory) {
  147. if ( ShlibVer != "auto" && ShlibVer != "cygdll" ) {
  148. printf "\tcd %s && (", directory
  149. if ( DoLinks == "reverse" ) {
  150. if ( ShlibVer == "rel" ) {
  151. symlink(lib_name, abi_name);
  152. symlink(abi_name, rel_name);
  153. } else if ( ShlibVer == "abi" ) {
  154. symlink(lib_name, abi_name);
  155. }
  156. } else {
  157. if ( ShlibVer == "rel" ) {
  158. symlink(rel_name, abi_name);
  159. symlink(abi_name, lib_name);
  160. } else if ( ShlibVer == "abi" ) {
  161. symlink(abi_name, lib_name);
  162. }
  163. }
  164. printf ")\n"
  165. }
  166. }
  167. # termlib may be named explicitly via "--with-termlib=XXX", which overrides
  168. # any suffix. Temporarily override "suffix" to account for this.
  169. function termlib_end_of() {
  170. termlib_save_suffix = suffix;
  171. suffix = TermlibSuffix;
  172. termlib_temp_result = end_name_of(TermlibRoot);
  173. suffix = termlib_save_suffix;
  174. return termlib_temp_result;
  175. }
  176. function shlib_build(directory) {
  177. dst_libs = sprintf("%s/%s", directory, end_name);
  178. printf "%s : \\\n", dst_libs
  179. printf "\t\t%s \\\n", directory
  180. if (subset ~ /^base/ || subset == "ticlib" ) {
  181. save_suffix = suffix
  182. sub(/^[^.]\./,".",suffix)
  183. if (directory != "../lib") {
  184. printf "\t\t%s/%s \\\n", "../lib", termlib_end_of();
  185. }
  186. printf "\t\t%s/%s \\\n", directory, termlib_end_of();
  187. suffix = save_suffix
  188. }
  189. printf "\t\t$(%s_OBJS)\n", OBJS
  190. printf "\t@echo linking $@\n"
  191. if ( is_ticlib() ) {
  192. make_shlib(OBJS, "TICS_LIST")
  193. } else if ( is_termlib() ) {
  194. make_shlib(OBJS, "TINFO_LIST")
  195. } else {
  196. make_shlib(OBJS, "SHLIB_LIST")
  197. }
  198. sharedlinks(directory)
  199. }
  200. function shlib_install(directory) {
  201. src_lib1 = sprintf("../lib/%s", end_name);
  202. dst_lib1 = sprintf("%s/%s", directory, end_name);
  203. printf "%s : \\\n", dst_lib1
  204. printf "\t\t%s \\\n", directory
  205. printf "\t\t%s\n", src_lib1
  206. printf "\t@echo installing $@\n"
  207. printf "\t$(INSTALL_LIB) %s %s\n", src_lib1, dst_lib1;
  208. sharedlinks(directory)
  209. }
  210. function install_dll(directory,filename) {
  211. src_name = sprintf("../lib/%s", filename);
  212. dst_name = sprintf("$(DESTDIR)%s/%s", directory, filename);
  213. printf "\t@echo installing %s as %s\n", src_name, dst_name
  214. if ( directory == "$(bindir)" ) {
  215. program = "$(INSTALL) -m 755";
  216. } else {
  217. program = "$(INSTALL_LIB)";
  218. }
  219. printf "\t%s %s %s\n", program, src_name, dst_name
  220. }
  221. BEGIN {
  222. found = 0
  223. using = 0
  224. }
  225. /^@/ {
  226. using = 0
  227. if (subset == "none") {
  228. using = 1
  229. } else if (index(subset,$2) > 0) {
  230. if (using == 0) {
  231. if (found == 0) {
  232. print ""
  233. printf "# generated by mk-1st.awk (subset=%s)\n", subset
  234. printf "# name: %s\n", name
  235. printf "# traces: %s\n", traces
  236. printf "# MODEL: %s\n", MODEL
  237. printf "# model: %s\n", model
  238. printf "# prefix: %s\n", prefix
  239. printf "# suffix: %s\n", suffix
  240. printf "# subset: %s\n", subset
  241. printf "# ShlibVer: %s\n", ShlibVer
  242. printf "# ShlibVerInfix: %s\n", ShlibVerInfix
  243. printf "# TermlibRoot: %s\n", TermlibRoot
  244. printf "# TermlibSuffix: %s\n", TermlibSuffix
  245. printf "# ReLink: %s\n", ReLink
  246. printf "# DoLinks: %s\n", DoLinks
  247. printf "# rmSoLocs: %s\n", rmSoLocs
  248. printf "# ldconfig: %s\n", ldconfig
  249. printf "# overwrite: %s\n", overwrite
  250. printf "# depend: %s\n", depend
  251. printf "# host: %s\n", host
  252. print ""
  253. }
  254. using = 1
  255. }
  256. if ( is_ticlib() ) {
  257. OBJS = MODEL "_P"
  258. } else if ( is_termlib() ) {
  259. OBJS = MODEL "_T"
  260. } else {
  261. OBJS = MODEL
  262. }
  263. }
  264. }
  265. /^[@#]/ {
  266. next
  267. }
  268. $1 ~ /trace/ {
  269. if (traces != "all" && traces != MODEL && $1 != "lib_trace")
  270. next
  271. }
  272. {
  273. if (using \
  274. && ( $1 != "link_test" ) \
  275. && ( $2 == "lib" \
  276. || $2 == "progs" \
  277. || $2 == "c++" \
  278. || $2 == "tack" ))
  279. {
  280. if ( found == 0 )
  281. {
  282. printf "%s_OBJS =", OBJS
  283. if ( $2 == "lib" )
  284. found = 1
  285. else
  286. found = 2
  287. }
  288. printf " \\\n\t../%s/%s$o", model, $1
  289. }
  290. }
  291. END {
  292. print ""
  293. if ( found != 0 )
  294. {
  295. printf "\n$(%s_OBJS) : %s\n", OBJS, depend
  296. }
  297. if ( found == 1 )
  298. {
  299. print ""
  300. lib_name = lib_name_of(name);
  301. if ( MODEL == "SHARED" )
  302. {
  303. abi_name = abi_name_of(name);
  304. rel_name = rel_name_of(name);
  305. imp_name = imp_name_of(name);
  306. end_name = end_name_of(name);
  307. shlib_build("../lib")
  308. print ""
  309. print "install \\"
  310. print "install.libs \\"
  311. if ( ShlibVer == "cygdll" ) {
  312. dst_dirs = "$(DESTDIR)$(bindir) $(DESTDIR)$(libdir)";
  313. printf "install.%s :: %s $(LIBRARIES)\n", name, dst_dirs
  314. install_dll("$(bindir)",end_name);
  315. install_dll("$(libdir)",imp_name);
  316. } else {
  317. lib_dir = "$(DESTDIR)$(libdir)";
  318. printf "install.%s :: %s/%s\n", name, lib_dir, end_name
  319. print ""
  320. if ( ReLink == "yes" ) {
  321. shlib_build(lib_dir)
  322. } else {
  323. shlib_install(lib_dir)
  324. }
  325. }
  326. if ( overwrite == "yes" && name == "ncurses" )
  327. {
  328. if ( ShlibVer == "cygdll" ) {
  329. ovr_name = sprintf("libcurses%s.a", suffix)
  330. printf "\t@echo linking %s to %s\n", imp_name, ovr_name
  331. printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, imp_name, ovr_name
  332. } else {
  333. ovr_name = sprintf("libcurses%s", suffix)
  334. printf "\t@echo linking %s to %s\n", end_name, ovr_name
  335. printf "\tcd $(DESTDIR)$(libdir) && (rm -f %s; $(LN_S) %s %s; )\n", ovr_name, end_name, ovr_name
  336. }
  337. }
  338. if ( ldconfig != "" && ldconfig != ":" ) {
  339. printf "\t- test -z \"$(DESTDIR)\" && %s\n", ldconfig
  340. }
  341. print ""
  342. print "uninstall \\"
  343. print "uninstall.libs \\"
  344. printf "uninstall.%s ::\n", name
  345. if ( ShlibVer == "cygdll" ) {
  346. printf "\t@echo uninstalling $(DESTDIR)$(bindir)/%s\n", end_name
  347. printf "\t-@rm -f $(DESTDIR)$(bindir)/%s\n", end_name
  348. printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", imp_name
  349. printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", imp_name
  350. } else {
  351. printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", end_name
  352. removelinks("$(DESTDIR)$(libdir)")
  353. if ( overwrite == "yes" && name == "ncurses" )
  354. {
  355. if ( ShlibVer == "cygdll" ) {
  356. ovr_name = sprintf("libcurses%s.a", suffix)
  357. } else {
  358. ovr_name = sprintf("libcurses%s", suffix)
  359. }
  360. printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", ovr_name
  361. }
  362. }
  363. if ( rmSoLocs == "yes" ) {
  364. print ""
  365. print "mostlyclean \\"
  366. print "clean ::"
  367. printf "\t-@rm -f so_locations\n"
  368. }
  369. }
  370. else if ( MODEL == "LIBTOOL" )
  371. {
  372. if ( $2 == "c++" ) {
  373. compile="CXX"
  374. } else {
  375. compile="CC"
  376. }
  377. end_name = lib_name;
  378. printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
  379. printf "\tcd ../lib && $(LIBTOOL_LINK) $(%s) -o %s $(%s_OBJS:$o=.lo) -rpath $(DESTDIR)$(libdir) -version-info $(NCURSES_MAJOR):$(NCURSES_MINOR) $(SHLIB_LIST)\n", compile, lib_name, OBJS
  380. print ""
  381. print "install \\"
  382. print "install.libs \\"
  383. printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
  384. printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
  385. printf "\tcd ../lib; $(LIBTOOL_INSTALL) $(INSTALL) %s $(DESTDIR)$(libdir)\n", lib_name
  386. print ""
  387. print "uninstall \\"
  388. print "uninstall.libs \\"
  389. printf "uninstall.%s ::\n", name
  390. printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
  391. printf "\t-@$(LIBTOOL_UNINSTALL) rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
  392. }
  393. else
  394. {
  395. end_name = lib_name;
  396. printf "../lib/%s : $(%s_OBJS)\n", lib_name, OBJS
  397. printf "\t$(AR) $(AR_OPTS) $@ $?\n"
  398. printf "\t$(RANLIB) $@\n"
  399. if ( host == "vxworks" )
  400. {
  401. printf "\t$(LD) $(LD_OPTS) $? -o $(@:.a=$o)\n"
  402. }
  403. print ""
  404. print "install \\"
  405. print "install.libs \\"
  406. printf "install.%s :: $(DESTDIR)$(libdir) ../lib/%s\n", name, lib_name
  407. printf "\t@echo installing ../lib/%s as $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
  408. printf "\t$(INSTALL_DATA) ../lib/%s $(DESTDIR)$(libdir)/%s\n", lib_name, lib_name
  409. if ( overwrite == "yes" && lib_name == "libncurses.a" )
  410. {
  411. printf "\t@echo linking libcurses.a to libncurses.a\n"
  412. printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
  413. printf "\t(cd $(DESTDIR)$(libdir) && $(LN_S) libncurses.a libcurses.a)\n"
  414. }
  415. printf "\t$(RANLIB) $(DESTDIR)$(libdir)/%s\n", lib_name
  416. if ( host == "vxworks" )
  417. {
  418. printf "\t@echo installing ../lib/lib%s$o as $(DESTDIR)$(libdir)/lib%s$o\n", name, name
  419. printf "\t$(INSTALL_DATA) ../lib/lib%s$o $(DESTDIR)$(libdir)/lib%s$o\n", name, name
  420. }
  421. print ""
  422. print "uninstall \\"
  423. print "uninstall.libs \\"
  424. printf "uninstall.%s ::\n", name
  425. printf "\t@echo uninstalling $(DESTDIR)$(libdir)/%s\n", lib_name
  426. printf "\t-@rm -f $(DESTDIR)$(libdir)/%s\n", lib_name
  427. if ( overwrite == "yes" && lib_name == "libncurses.a" )
  428. {
  429. printf "\t@echo linking libcurses.a to libncurses.a\n"
  430. printf "\t-@rm -f $(DESTDIR)$(libdir)/libcurses.a\n"
  431. }
  432. if ( host == "vxworks" )
  433. {
  434. printf "\t@echo uninstalling $(DESTDIR)$(libdir)/lib%s$o\n", name
  435. printf "\t-@rm -f $(DESTDIR)$(libdir)/lib%s$o\n", name
  436. }
  437. }
  438. print ""
  439. print "clean ::"
  440. removelinks("../lib");
  441. print ""
  442. print "mostlyclean::"
  443. printf "\t-rm -f $(%s_OBJS)\n", OBJS
  444. if ( MODEL == "LIBTOOL" ) {
  445. printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
  446. }
  447. }
  448. else if ( found == 2 )
  449. {
  450. print ""
  451. print "mostlyclean::"
  452. printf "\t-rm -f $(%s_OBJS)\n", OBJS
  453. if ( MODEL == "LIBTOOL" ) {
  454. printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
  455. }
  456. print ""
  457. print "clean ::"
  458. printf "\t-rm -f $(%s_OBJS)\n", OBJS
  459. if ( MODEL == "LIBTOOL" ) {
  460. printf "\t-$(LIBTOOL_CLEAN) rm -f $(%s_OBJS:$o=.lo)\n", OBJS
  461. }
  462. }
  463. }
  464. # vile:ts=4 sw=4