defaults.mak 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # -*- make -*-
  2. # This file configures the default environment for the make system
  3. # The way it works is fairly simple, each module is defined in it's
  4. # own *.mak file. It expects a set of variables to be set to values
  5. # for it to operate as expected. When included the module generates
  6. # the requested rules based on the contents of its control variables.
  7. # This works out very well and allows a good degree of flexability.
  8. # To accomidate some of the features we introduce the concept of
  9. # local variables. To do this we use the 'Computed Names' feature of
  10. # gmake. Each module declares a LOCAL scope and access it with,
  11. # $($(LOCAL)-VAR)
  12. # This works very well but it is important to rembember that within
  13. # a rule the LOCAL var is unavailble, it will have to be constructed
  14. # from the information in the rule invokation. For stock rules like
  15. # clean this is simple, we use a local clean rule called clean/$(LOCAL)
  16. # and then within the rule $(@F) gets back $(LOCAL)! Other rules will
  17. # have to use some other mechanism (filter perhaps?) The reason such
  18. # lengths are used is so that each directory can contain several 'instances'
  19. # of any given module
  20. # A build directory is used by default, all generated items get put into
  21. # there. However unlike automake this is not done with a VPATH build
  22. # (vpath builds break the distinction between #include "" and #include <>)
  23. # but by explicly setting the BUILD variable. Make is invoked from
  24. # within the source itself which is much more compatible with compilation
  25. # environments.
  26. ifndef NOISY
  27. .SILENT:
  28. endif
  29. # Search for the build directory
  30. ifdef BUILD
  31. BUILD_POSSIBLE := $(BUILD) $(BASE)/$(BUILD)
  32. else
  33. BUILD_POSSIBLE := $(BASE) $(BASE)/build
  34. endif
  35. BUILDX:= $(foreach i,$(BUILD_POSSIBLE),$(wildcard $(i)/environment.mak*))
  36. BUILDX:= $(patsubst %/,%,$(firstword $(dir $(BUILDX))))
  37. ifeq ($(words $(BUILDX)),0)
  38. error-all:
  39. echo Can't find the build directory in $(BUILD_POSSIBLE) -- use BUILD=
  40. endif
  41. override BUILD := $(BUILDX)
  42. # Base definitions
  43. INCLUDE := $(BUILD)/include
  44. BIN := $(BUILD)/bin
  45. LIB := $(BIN)
  46. OBJ := $(BUILD)/obj/$(SUBDIR)
  47. DEP := $(OBJ)
  48. DOC := $(BUILD)/docs
  49. # Module types
  50. LIBRARY_H = $(BASE)/buildlib/library.mak
  51. DEBIANDOC_H = $(BASE)/buildlib/debiandoc.mak
  52. MANPAGE_H = $(BASE)/buildlib/manpage.mak
  53. PROGRAM_H = $(BASE)/buildlib/program.mak
  54. # Source location control
  55. # SUBDIRS specifies sub components of the module that
  56. # may be located in subdrictories of the source dir.
  57. # This should be declared before including this file
  58. SUBDIRS+=
  59. # Header file control.
  60. # TARGETDIRS indicitates all of the locations that public headers
  61. # will be published to.
  62. # This should be declared before including this file
  63. HEADER_TARGETDIRS+=
  64. # Options
  65. include $(BUILD)/environment.mak
  66. CPPFLAGS+= -I$(INCLUDE)
  67. LDFLAGS+= -L$(LIB)
  68. # Phony rules. Other things hook these by appending to the dependency
  69. # list
  70. .PHONY: headers library clean veryclean all binary program doc
  71. .PHONY: maintainer-clean dist-clean distclean pristine sanity
  72. all: binary doc
  73. binary: library program
  74. maintainer-clean dist-clean distclean pristine sanity: veryclean
  75. headers library clean veryclean program:
  76. # Header file control. We want all published interface headers to go
  77. # into the build directory from thier source dirs. We setup some
  78. # search paths here
  79. vpath %.h $(SUBDIRS)
  80. $(INCLUDE)/%.h $(addprefix $(INCLUDE)/,$(addsuffix /%.h,$(HEADER_TARGETDIRS))) : %.h
  81. cp $< $@
  82. # Dependency generation. We want to generate a .d file using gnu cpp.
  83. # For GNU systems the compiler can spit out a .d file while it is compiling,
  84. # this is specified with the INLINEDEPFLAG. Other systems might have a
  85. # makedep program that can be called after compiling, that's illistrated
  86. # by the DEPFLAG case.
  87. # Compile rules are expected to call this macro after calling the compiler
  88. ifdef INLINEDEPFLAG
  89. define DoDep
  90. sed -e "1s/.*:/$(subst /,\\/,$@):/" $(basename $(@F)).d > $(DEP)/$(basename $(@F)).d
  91. -rm -f $(basename $(@F)).d
  92. endef
  93. else
  94. ifdef DEPFLAG
  95. define DoDep
  96. $(CXX) $(DEPFLAG) $(CPPFLAGS) -o $@ $<
  97. sed -e "1s/.*:/$(subst /,\\/,$@):/" $(basename $(@F)).d > $(DEP)/$(basename $(@F)).d
  98. -rm -f $(basename $(@F)).d
  99. endef
  100. else
  101. define DoDep
  102. endef
  103. endif
  104. endif