Makefile.inc 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. $(call PKG_DEPEND_INT,$(PARENTDIR))
  39. $(call PKG_DEPEND_EXT,CPPUNIT)
  40. # ---------------------------
  41. # - objects in this directory
  42. #
  43. # the use of the variable $(OBJS) is not mandatory. it is mandatory however
  44. # to update $(ALL_OBJS) in a way that it contains the path and name of
  45. # all objects. otherwise we can not include the appropriate .d files.
  46. OBJS:=$(patsubst %.cpp,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.cpp))) \
  47. $(patsubst %.C,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.C))) \
  48. $(shell grep -ls Q_OBJECT $(SUBDIR)*.h | sed -e's@^@/@;s@.*/@$(OBJDIR)moc_@;s@\.h$$@.o@') \
  49. $(patsubst %.c,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.c)))
  50. ALL_OBJS += $(OBJS)
  51. # ----------------------------
  52. # - binaries in this directory
  53. #
  54. # output of binaries in this directory. none of the variables has to be used.
  55. # but everything you add to $(ALL_LIBRARIES) and $(ALL_BINARIES) will be
  56. # compiled with `make all`. be sure again to add the files with full path.
  57. CHECKS:=$(BINDIR)$(call LIBNAME,$(SUBDIR))
  58. ALL_CHECKS+=$(CHECKS)
  59. # ---------------------
  60. # - binary dependencies
  61. #
  62. # there is no way of determining the binary dependencies automatically, so we
  63. # follow conventions. each binary depends on the corresponding .o file and
  64. # on the libraries specified by the INTLIBS/EXTLIBS. these dependencies can be
  65. # specified manually or they are automatically stored in a .bd file.
  66. $(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@')))
  67. $(eval $(foreach c,$(CHECKS),$(c):$(BUILDDIR)$(CPPUNIT_MAIN_OBJ) $(OBJS) $(call PRINT_INTLIB_DEPS,$(c),.a)))
  68. # -------------------
  69. # - subdir management
  70. #
  71. # as the last step, always add this line to correctly recover the subdirectory
  72. # of the makefile including this one!
  73. SUBDIR:=$(SUBDIR_before_$(SUBDIR))