proj-shared.el 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. ;;; ede-proj-shared.el --- EDE Generic Project shared library support
  2. ;;; Copyright (C) 1998-2000, 2009-2012 Free Software Foundation, Inc.
  3. ;; Author: Eric M. Ludlam <zappo@gnu.org>
  4. ;; Keywords: project, make
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;;
  18. ;; Handle shared object libraries in and EDE Project file.
  19. ;; Tries to deal with libtool and non-libtool situations.
  20. (require 'ede/pmake)
  21. (require 'ede/proj-obj)
  22. (require 'ede/proj-prog)
  23. ;;; THIS NEEDS WORK. SEE ede-proj-obj.
  24. ;;; Code:
  25. (defclass ede-proj-target-makefile-shared-object
  26. (ede-proj-target-makefile-program)
  27. ((availablecompilers :initform '(ede-gcc-libtool-shared-compiler
  28. ;;ede-gcc-shared-compiler
  29. ede-g++-libtool-shared-compiler
  30. ;;ede-g++-shared-compiler
  31. ))
  32. (availablelinkers :initform '(ede-cc-linker-libtool
  33. ede-g++-linker-libtool
  34. ;; Add more linker thingies here.
  35. ))
  36. (ldflags :custom (repeat (string :tag "Libtool flag"))
  37. :documentation
  38. "Additional flags to add when linking this shared library.
  39. Use ldlibs to add addition libraries.")
  40. )
  41. "This target generates a shared library.")
  42. (defvar ede-gcc-shared-compiler
  43. (clone ede-gcc-compiler
  44. "ede-c-shared-compiler"
  45. :name "gcc -shared"
  46. :variables '(("CC_SHARED" . "gcc")
  47. ("C_SHARED_COMPILE" .
  48. "$(CC_SHARED) -shared $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)"))
  49. ; :linkvariables '(("C_SHARED_LINK" .
  50. ; "$(CC_SHARED) -shared $(CFLAGS) $(LDFLAGS) -L. -o $@ $^")
  51. ; )
  52. ; :commands '("$(C_SHARED_LINK) %s")
  53. ;; @TODO - additive modification of autoconf.
  54. :autoconf '("AC_PROG_LIBTOOL")
  55. )
  56. "Compiler for C sourcecode.")
  57. (defvar ede-gcc-libtool-shared-compiler
  58. (clone ede-gcc-shared-compiler
  59. "ede-c-shared-compiler-libtool"
  60. :name "libtool"
  61. :variables '(("LIBTOOL" . "libtool")
  62. ("LTCOMPILE" . "$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)")
  63. ("LTLINK" . "$(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -L. -o $@")
  64. )
  65. :rules (list (ede-makefile-rule
  66. "cc-inference-rule-libtool"
  67. :target "%.o"
  68. :dependencies "%.c"
  69. :rules '("@echo '$(LTCOMPILE) -o $@ $<'; \\"
  70. "$(LTCOMPILE) -o $@ $<"
  71. )
  72. ))
  73. :autoconf '("AC_PROG_LIBTOOL")
  74. )
  75. "Compiler for C sourcecode.")
  76. (defvar ede-cc-linker-libtool
  77. (clone ede-cc-linker
  78. "ede-cc-linker-libtool"
  79. :name "cc shared"
  80. ;; Only use this linker when c++ exists.
  81. :sourcetype '(ede-source-c++)
  82. :variables '(
  83. ("LIBTOOL" . "libtool")
  84. ("LTLINK" . "$(LIBTOOL) --tag=CPP --mode=link $(CPP) $(CFLAGS) $(LDFLAGS) -L. -o $@")
  85. )
  86. :commands '("$(LTLINK) -o $@ $^")
  87. :autoconf '("AC_PROG_LIBTOOL")
  88. :objectextention ".la")
  89. "Linker needed for c++ programs.")
  90. (defvar ede-g++-shared-compiler
  91. (clone ede-g++-compiler
  92. "ede-c++-shared-compiler"
  93. :name "gcc -shared"
  94. :variables '(("CXX_SHARED" . "g++")
  95. ("CXX_SHARED_COMPILE" .
  96. "$(CXX_SHARED) -shared $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)"))
  97. ;; @TODO - additive modification of autoconf.
  98. :autoconf '("AC_PROG_LIBTOOL")
  99. )
  100. "Compiler for C sourcecode.")
  101. (defvar ede-g++-libtool-shared-compiler
  102. (clone ede-g++-shared-compiler
  103. "ede-c++-shared-compiler-libtool"
  104. :name "libtool"
  105. :variables '(("CXX" "g++")
  106. ("LIBTOOL" . "libtool")
  107. ("LTCOMPILE" . "$(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)")
  108. )
  109. :rules (list (ede-makefile-rule
  110. "c++-inference-rule-libtool"
  111. :target "%.o"
  112. :dependencies "%.cpp"
  113. :rules '("@echo '$(LTCOMPILE) -o $@ $<'; \\"
  114. "$(LTCOMPILE) -o $@ $<"
  115. )
  116. ))
  117. :autoconf '("AC_PROG_LIBTOOL")
  118. )
  119. "Compiler for C sourcecode.")
  120. (defvar ede-g++-linker-libtool
  121. (clone ede-g++-linker
  122. "ede-g++-linker-libtool"
  123. :name "g++"
  124. ;; Only use this linker when c++ exists.
  125. :sourcetype '(ede-source-c++)
  126. :variables '(
  127. ("LIBTOOL" . "libtool")
  128. ("LTLINK" . "$(LIBTOOL) --tag=CXX --mode=link $(CXX) $(CFLAGS) $(LDFLAGS) -L. -o $@")
  129. )
  130. :commands '("$(LTLINK) -o $@ $^")
  131. :autoconf '("AC_PROG_LIBTOOL")
  132. :objectextention ".la")
  133. "Linker needed for c++ programs.")
  134. ;;; @TODO - C++ versions of the above.
  135. (when nil
  136. (insert;; These C to O rules create dependencies
  137. "%.o: %.c\n"
  138. "\t@echo '$(COMPILE) -c $<'; \\\n"
  139. "\t$(COMPILE)"
  140. (if (oref this automatic-dependencies)
  141. " -Wp,-MD,.deps/$(*F).P"
  142. "")
  143. " -c $<\n\n")
  144. (if have-libtool
  145. (insert;; These C to shared o rules create pic code.
  146. "%.lo: %.c\n"
  147. "\t@echo '$(LTCOMPILE) -c $<'; \\\n"
  148. "\t$(LTCOMPILE) -Wp,-MD,.deps/$(*F).p -c $<\n"
  149. "\t@-sed -e 's/^\([^:]*\)\.o:/\1.lo \1.o:/' \\\n"
  150. "\t < .deps/$(*F).p > .deps/$(*F).P\n"
  151. "\t@-rm -f .deps/$(*F).p\n\n"))
  152. )
  153. (defmethod ede-proj-configure-add-missing
  154. ((this ede-proj-target-makefile-shared-object))
  155. "Query if any files needed by THIS provided by automake are missing.
  156. Results in --add-missing being passed to automake."
  157. (not (and (ede-expand-filename (ede-toplevel) "ltconfig")
  158. (ede-expand-filename (ede-toplevel) "ltmain.sh"))))
  159. (defmethod ede-proj-makefile-insert-automake-pre-variables
  160. ((this ede-proj-target-makefile-shared-object))
  161. "Insert bin_PROGRAMS variables needed by target THIS.
  162. We aren't actually inserting SOURCE details, but this is used by the
  163. Makefile.am generator, so use it to add this important bin program."
  164. (ede-pmake-insert-variable-shared "lib_LTLIBRARIES"
  165. (insert (concat "lib" (ede-name this) ".la"))))
  166. (defmethod ede-proj-makefile-insert-automake-post-variables
  167. ((this ede-proj-target-makefile-shared-object))
  168. "Insert bin_PROGRAMS variables needed by target THIS.
  169. We need to override -program which has an LDADD element."
  170. nil)
  171. (defmethod ede-proj-makefile-target-name ((this ede-proj-target-makefile-shared-object))
  172. "Return the name of the main target for THIS target."
  173. ;; We need some platform gunk to make the .so change to .sl, or .a,
  174. ;; depending on the platform we are going to compile against.
  175. (concat "lib" (ede-name this) ".la"))
  176. (defmethod ede-proj-makefile-sourcevar ((this ede-proj-target-makefile-shared-object))
  177. "Return the variable name for THIS's sources."
  178. (if (eq (oref (ede-target-parent this) makefile-type) 'Makefile.am)
  179. (concat "lib" (oref this name) "_la_SOURCES")
  180. (call-next-method)))
  181. (provide 'ede/proj-shared)
  182. ;;; ede/proj-shared.el ends here