Makefile.inc 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # LIBRARY-DIRECTORY-MAKEFILE
  2. # conventions:
  3. # - all subdirectories containing a "Makefile.inc" are considered sublibraries
  4. # exception: "progs/" and "tests/" subdirectories!
  5. # - all ".C", ".cpp" and ".c" files in the current directory are linked to a
  6. # library
  7. # - the library depends on all sublibraries
  8. # - the library name is created with $(LIBNAME), i.e. it will be somehow
  9. # related to the directory name and with the extension .a
  10. # (e.g. lib1/sublib -> lib1_sublib.a)
  11. # - the library will be added to the default build list ALL_LIBRARIES
  12. # --------------------------------
  13. # - remember the last subdirectory
  14. #
  15. # set the variable $(SUBDIR) correctly to the current subdirectory. this
  16. # variable can be used throughout the current makefile.inc. The many
  17. # SUBDIR_before, _add, and everything are only required so that we can recover
  18. # the previous content of SUBDIR before exitting the makefile.inc
  19. SUBDIR_add:=$(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
  20. SUBDIR_before:=$(SUBDIR)
  21. SUBDIR:=$(strip $(SUBDIR_add))
  22. SUBDIR_before_$(SUBDIR):=$(SUBDIR_before)
  23. ifeq "$(SUBDIR)" "./"
  24. SUBDIR:=
  25. endif
  26. # ------------------------
  27. # - include subdirectories
  28. #
  29. # note the variables $(SUBDIRS_OF_$(SUBDIR)) are required later on to recover
  30. # the dependencies automatically. if you handle dependencies on your own, you
  31. # can also dump the $(SUBDIRS_OF_$(SUBDIR)) variable, and include the
  32. # makefile.inc of the subdirectories on your own...
  33. SUBDIRS_OF_$(SUBDIR):=$(patsubst %/Makefile.inc,%,$(wildcard $(SUBDIR)*/Makefile.inc))
  34. include $(SUBDIRS_OF_$(SUBDIR):%=%/Makefile.inc)
  35. # ----------------------------
  36. # - include local dependencies
  37. #
  38. # you can specify libraries needed by the individual objects or by the whole
  39. # directory. the object specific additional libraries are only considered
  40. # when compiling the specific object files
  41. # TODO: update documentation...
  42. -include $(SUBDIR)libdepend.inc
  43. $(foreach d,$(filter-out %progs %tests,$(SUBDIRS_OF_$(SUBDIR))),$(eval $(call PKG_DEPEND_INT,$(d))))
  44. # ---------------------------
  45. # - objects in this directory
  46. #
  47. # the use of the variable $(OBJS) is not mandatory. it is mandatory however
  48. # to update $(ALL_OBJS) in a way that it contains the path and name of
  49. # all objects. otherwise we can not include the appropriate .d files.
  50. OBJS:=$(patsubst %.cpp,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.cpp))) \
  51. $(patsubst %.C,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.C))) \
  52. $(patsubst %.c,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.c)))
  53. ALL_OBJS += $(OBJS)
  54. # ----------------------------
  55. # - binaries in this directory
  56. #
  57. # output of binaries in this directory. none of the variables has to be used.
  58. # but everything you add to $(ALL_LIBRARIES) and $(ALL_BINARIES) will be
  59. # compiled with `make all`. be sure again to add the files with full path.
  60. LIBRARY_BASENAME:=$(call LIBNAME,$(SUBDIR))
  61. ifneq "$(SUBDIR)" ""
  62. ALL_LIBRARIES+=$(LIBDIR)$(LIBRARY_BASENAME).$(LINK_FILE_EXTENSION)
  63. endif
  64. # ---------------------
  65. # - binary dependencies
  66. #
  67. # there is no way of determining the binary dependencies automatically, so we
  68. # follow conventions. the current library depends on all sublibraries.
  69. # all other dependencies have to be added manually by specifying, that the
  70. # current .pc file depends on some other .pc file. binaries depending on
  71. # libraries should exclusivelly use the .pc files as well.
  72. $(LIBDIR)$(LIBRARY_BASENAME).a:$(OBJS) \
  73. $(call PRINT_INTLIB_DEPS,$(PKGDIR)$(LIBRARY_BASENAME).a,.$(LINK_FILE_EXTENSION))
  74. $(PKGDIR)$(LIBRARY_BASENAME).pc: \
  75. $(call PRINT_INTLIB_DEPS,$(PKGDIR)$(LIBRARY_BASENAME).pc,.pc)
  76. # -------------------
  77. # - subdir management
  78. #
  79. # as the last step, always add this line to correctly recover the subdirectory
  80. # of the makefile including this one!
  81. SUBDIR:=$(SUBDIR_before_$(SUBDIR))