Makefile.inc 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # BINARY-DIRECTORY-MAKEFILE
  2. # conventions:
  3. # - there are no subdirectories, they are ignored!
  4. # - all ".C", ".cpp" and ".c" files in the current directory are considered
  5. # independent binaries, and linked as such.
  6. # - the binaries depend on the library of the parent directory
  7. # - the binary names are created with $(BINNAME), i.e. it will be more or less
  8. # the name of the .o file
  9. # - all binaries will be added to the default build list ALL_BINARIES
  10. # --------------------------------
  11. # - remember the last subdirectory
  12. #
  13. # set the variable $(SUBDIR) correctly to the current subdirectory. this
  14. # variable can be used throughout the current makefile.inc. The many
  15. # SUBDIR_before, _add, and everything are only required so that we can recover
  16. # the previous content of SUBDIR before exitting the makefile.inc
  17. SUBDIR_add:=$(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
  18. SUBDIR_before:=$(SUBDIR)
  19. SUBDIR:=$(strip $(SUBDIR_add))
  20. SUBDIR_before_$(SUBDIR):=$(SUBDIR_before)
  21. # ------------------------
  22. # - include subdirectories
  23. #
  24. # note the variables $(SUBDIRS_OF_$(SUBDIR)) are required later on to recover
  25. # the dependencies automatically. if you handle dependencies on your own, you
  26. # can also dump the $(SUBDIRS_OF_$(SUBDIR)) variable, and include the
  27. # makefile.inc of the subdirectories on your own...
  28. #SUBDIRS_OF_$(SUBDIR):=$(patsubst %/Makefile.inc,%,$(wildcard $(SUBDIR)*/Makefile.inc))
  29. #include $(SUBDIRS_OF_$(SUBDIR):%=%/Makefile.inc)
  30. # ----------------------------
  31. # - include local dependencies
  32. #
  33. # include the libdepend.inc file, which gives additional dependencies for the
  34. # libraries and binaries. additionally, an automatic dependency from the library
  35. # of the parent directory is added (commented out in the code below).
  36. -include $(SUBDIR)libdepend.inc
  37. PARENTDIR:=$(patsubst %/,%,$(dir $(patsubst %/,%,$(SUBDIR))))
  38. $(eval $(call PKG_DEPEND_INT,$(PARENTDIR)))
  39. # ---------------------------
  40. # - objects in this directory
  41. #
  42. # the use of the variable $(OBJS) is not mandatory. it is mandatory however
  43. # to update $(ALL_OBJS) in a way that it contains the path and name of
  44. # all objects. otherwise we can not include the appropriate .d files.
  45. OBJS:=$(patsubst %.cpp,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.cpp))) \
  46. $(patsubst %.C,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.C))) \
  47. $(shell grep -ls Q_OBJECT $(SUBDIR)*.h | sed -e's@^@/@;s@.*/@$(OBJDIR)moc_@;s@\.h$$@.o@') \
  48. $(patsubst %.c,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.c)))
  49. ALL_OBJS += $(OBJS)
  50. # ----------------------------
  51. # - binaries in this directory
  52. #
  53. # output of binaries in this directory. none of the variables has to be used.
  54. # but everything you add to $(ALL_LIBRARIES) and $(ALL_BINARIES) will be
  55. # compiled with `make all`. be sure again to add the files with full path.
  56. BINARIES:=$(patsubst %.o,$(BINDIR)%,$(filter-out moc_%,$(notdir $(OBJS))))
  57. ALL_BINARIES+=$(BINARIES)
  58. # ---------------------
  59. # - binary dependencies
  60. #
  61. # there is no way of determining the binary dependencies automatically, so we
  62. # follow conventions. each binary depends on the corresponding .o file and
  63. # on the libraries specified by the INTLIBS/EXTLIBS. these dependencies can be
  64. # specified manually or they are automatically stored in a .bd file.
  65. $(foreach head,$(wildcard $(SUBDIR)*.h),$(eval $(shell grep -q Q_OBJECT $(head) && echo $(head) | sed -e's@^@/@;s@.*/\(.*\)\.h$$@$(BINDIR)\1:$(OBJDIR)moc_\1.o@')))
  66. -include $(OBJS:%.o=%.bd)
  67. # -------------------
  68. # - subdir management
  69. #
  70. # as the last step, always add this line to correctly recover the subdirectory
  71. # of the makefile including this one!
  72. SUBDIR:=$(SUBDIR_before_$(SUBDIR))