Makefile.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. $(shell grep -ls Q_OBJECT $(SUBDIR)*.h | sed -e's@^@/@;s@.*/@$(OBJDIR)moc_@;s@\.h$$@.o@') \
  53. $(patsubst %.c,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.c)))
  54. ALL_OBJS += $(OBJS)
  55. # ----------------------------
  56. # - binaries in this directory
  57. #
  58. # output of binaries in this directory. none of the variables has to be used.
  59. # but everything you add to $(ALL_LIBRARIES) and $(ALL_BINARIES) will be
  60. # compiled with `make all`. be sure again to add the files with full path.
  61. LIBRARY_BASENAME:=$(call LIBNAME,$(SUBDIR))
  62. ifneq "$(SUBDIR)" ""
  63. ALL_LIBRARIES+=$(LIBDIR)$(LIBRARY_BASENAME).$(LINK_FILE_EXTENSION)
  64. endif
  65. # ---------------------
  66. # - binary dependencies
  67. #
  68. # there is no way of determining the binary dependencies automatically, so we
  69. # follow conventions. the current library depends on all sublibraries.
  70. # all other dependencies have to be added manually by specifying, that the
  71. # current .pc file depends on some other .pc file. binaries depending on
  72. # libraries should exclusivelly use the .pc files as well.
  73. ifeq "$(SKIP_BUILD_$(OBJDIR))" "1"
  74. $(LIBDIR)$(LIBRARY_BASENAME).a:
  75. else
  76. $(LIBDIR)$(LIBRARY_BASENAME).a:$(OBJS) \
  77. $(call PRINT_INTLIB_DEPS,$(PKGDIR)$(LIBRARY_BASENAME).a,.$(LINK_FILE_EXTENSION))
  78. endif
  79. $(PKGDIR)$(LIBRARY_BASENAME).pc: \
  80. $(call PRINT_INTLIB_DEPS,$(PKGDIR)$(LIBRARY_BASENAME).pc,.pc)
  81. # -------------------
  82. # - subdir management
  83. #
  84. # as the last step, always add this line to correctly recover the subdirectory
  85. # of the makefile including this one!
  86. SUBDIR:=$(SUBDIR_before_$(SUBDIR))