defaults.mak 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. .SILENT:
  27. # Search for the build directory
  28. ifdef BUILD
  29. BUILD_POSSIBLE := $(BUILD) $(BASE)/$(BUILD)
  30. else
  31. BUILD_POSSIBLE := $(BASE) $(BASE)/build
  32. endif
  33. BUILDX:= $(foreach i,$(BUILD_POSSIBLE),$(wildcard $(i)/environment.mak*))
  34. BUILDX:= $(patsubst %/,%,$(firstword $(dir $(BUILDX))))
  35. ifeq ($(words $(BUILDX)),0)
  36. error-all:
  37. echo Can't find the build directory in $(BUILD_POSSIBLE) -- use BUILD=
  38. endif
  39. override BUILD := $(BUILDX)
  40. # Base definitions
  41. INCLUDE := $(BUILD)/include
  42. BIN := $(BUILD)/bin
  43. LIB := $(BIN)
  44. OBJ := $(BUILD)/obj/$(SUBDIR)
  45. DEP := $(OBJ)
  46. DOC := $(BUILD)/doc
  47. # Module types
  48. LIBRARY_H = $(BASE)/buildlib/library.mak
  49. DEBIANDOC_H = $(BASE)/buildlib/debiandoc.mak
  50. MANPAGE_H = $(BASE)/buildlib/manpage.mak
  51. PROGRAM_H = $(BASE)/buildlib/program.mak
  52. # Source location control
  53. # SUBDIRS specifies sub components of the module that
  54. # may be located in subdrictories of the source dir.
  55. # This should be declared before including this file
  56. SUBDIRS+=
  57. # Header file control.
  58. # TARGETDIRS indicitates all of the locations that public headers
  59. # will be published to.
  60. # This should be declared before including this file
  61. HEADER_TARGETDIRS+=
  62. # Options
  63. include $(BUILD)/environment.mak
  64. CPPFLAGS+= -I$(INCLUDE)
  65. LDFLAGS+= -L$(LIB)
  66. # Phony rules. Other things hook these by appending to the dependency
  67. # list
  68. .PHONY: headers library clean veryclean all binary program doc
  69. .PHONY: maintainer-clean dist-clean distclean pristine sanity
  70. all: binary doc
  71. binary: library program
  72. maintainer-clean dist-clean distclean pristine sanity: veryclean
  73. headers library clean veryclean program:
  74. # Header file control. We want all published interface headers to go
  75. # into the build directory from thier source dirs. We setup some
  76. # search paths here
  77. vpath %.h $(SUBDIRS)
  78. $(INCLUDE)/%.h $(addprefix $(INCLUDE)/,$(addsuffix /%.h,$(HEADER_TARGETDIRS))) : %.h
  79. cp $< $@
  80. # Dependency generation. We want to generate a .d file using gnu cpp.
  81. # For GNU systems the compiler can spit out a .d file while it is compiling,
  82. # this is specified with the INLINEDEPFLAG. Other systems might have a
  83. # makedep program that can be called after compiling, that's illistrated
  84. # by the DEPFLAG case.
  85. # Compile rules are expected to call this macro after calling the compiler
  86. ifdef INLINEDEPFLAG
  87. define DoDep
  88. sed -e "1s/.*:/$(subst /,\\/,$@):/" $(basename $(@F)).d > $(DEP)/$(basename $(@F)).d
  89. -rm -f $(basename $(@F)).d
  90. endef
  91. else
  92. ifdef DEPFLAG
  93. define DoDep
  94. $(CXX) $(DEPFLAG) $(CPPFLAGS) -o $@ $<
  95. sed -e "1s/.*:/$(subst /,\\/,$@):/" $(basename $(@F)).d > $(DEP)/$(basename $(@F)).d
  96. -rm -f $(basename $(@F)).d
  97. endef
  98. else
  99. define DoDep
  100. endef
  101. endif
  102. endif