defaults.mak 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. I notice that the very latest gmake has the concept
  20. # of local variables for rules. It is possible this feature in conjunction
  21. # with the generated names will provide a very powerfull solution indeed!
  22. # A build directory is used by default, all generated items get put into
  23. # there. However unlike automake this is not done with a VPATH build
  24. # (vpath builds break the distinction between #include "" and #include <>)
  25. # but by explicly setting the BUILD variable. Make is invoked from
  26. # within the source itself which is much more compatible with compilation
  27. # environments.
  28. ifndef NOISY
  29. .SILENT:
  30. endif
  31. # Search for the build directory
  32. ifdef BUILD
  33. BUILD_POSSIBLE := $(BUILD) $(BASE)/$(BUILD)
  34. else
  35. BUILD_POSSIBLE := $(BASE) $(BASE)/build
  36. endif
  37. BUILDX:= $(foreach i,$(BUILD_POSSIBLE),$(wildcard $(i)/environment.mak*))
  38. BUILDX:= $(patsubst %/,%,$(firstword $(dir $(BUILDX))))
  39. ifeq ($(words $(BUILDX)),0)
  40. error-all:
  41. echo Can't find the build directory in $(BUILD_POSSIBLE) -- use BUILD=
  42. endif
  43. override BUILD := $(BUILDX)
  44. # Base definitions
  45. INCLUDE := $(BUILD)/include
  46. BIN := $(BUILD)/bin
  47. LIB := $(BIN)
  48. OBJ := $(BUILD)/obj/$(SUBDIR)
  49. DEP := $(OBJ)
  50. DOC := $(BUILD)/docs
  51. # Module types
  52. LIBRARY_H = $(BASE)/buildlib/library.mak
  53. DEBIANDOC_H = $(BASE)/buildlib/debiandoc.mak
  54. MANPAGE_H = $(BASE)/buildlib/manpage.mak
  55. PROGRAM_H = $(BASE)/buildlib/program.mak
  56. COPY_H = $(BASE)/buildlib/copy.mak
  57. ifdef STATICLIBS
  58. LIBRARY_H += $(BASE)/buildlib/staticlibrary.mak
  59. endif
  60. # Source location control
  61. # SUBDIRS specifies sub components of the module that
  62. # may be located in subdrictories of the source dir.
  63. # This should be declared before including this file
  64. SUBDIRS+=
  65. # Header file control.
  66. # TARGETDIRS indicitates all of the locations that public headers
  67. # will be published to.
  68. # This should be declared before including this file
  69. HEADER_TARGETDIRS+=
  70. # Options
  71. include $(BUILD)/environment.mak
  72. CPPFLAGS+= -I$(INCLUDE)
  73. LDFLAGS+= -L$(LIB)
  74. # Phony rules. Other things hook these by appending to the dependency
  75. # list
  76. .PHONY: headers library clean veryclean all binary program doc
  77. .PHONY: maintainer-clean dist-clean distclean pristine sanity
  78. all: binary doc
  79. binary: library program
  80. maintainer-clean dist-clean distclean pristine sanity: veryclean
  81. headers library clean veryclean program:
  82. # Header file control. We want all published interface headers to go
  83. # into the build directory from thier source dirs. We setup some
  84. # search paths here
  85. vpath %.h $(SUBDIRS)
  86. $(INCLUDE)/%.h $(addprefix $(INCLUDE)/,$(addsuffix /%.h,$(HEADER_TARGETDIRS))) : %.h
  87. cp $< $@
  88. # Dependency generation. We want to generate a .d file using gnu cpp.
  89. # For GNU systems the compiler can spit out a .d file while it is compiling,
  90. # this is specified with the INLINEDEPFLAG. Other systems might have a
  91. # makedep program that can be called after compiling, that's illistrated
  92. # by the DEPFLAG case.
  93. # Compile rules are expected to call this macro after calling the compiler
  94. ifdef INLINEDEPFLAG
  95. define DoDep
  96. sed -e "1s/.*:/$(subst /,\\/,$@):/" $(basename $(@F)).d > $(DEP)/$(@F).d
  97. -rm -f $(basename $(@F)).d
  98. endef
  99. else
  100. ifdef DEPFLAG
  101. define DoDep
  102. $(CXX) $(DEPFLAG) $(CPPFLAGS) -o $@ $<
  103. sed -e "1s/.*:/$(subst /,\\/,$@):/" $(basename $(@F)).d > $(DEP)/$(@F).d
  104. -rm -f $(basename $(@F)).d
  105. endef
  106. else
  107. define DoDep
  108. endef
  109. endif
  110. endif