defaults.mak 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 flexibility.
  8. # To accommodate 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 remember that within
  13. # a rule the LOCAL var is unavailable, it will have to be constructed
  14. # from the information in the rule invocation. 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 powerful 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 explicitly 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-$(shell uname -m) $(BASE)/build
  36. endif
  37. BUILDX:= $(foreach i,$(BUILD_POSSIBLE),$(wildcard $(i)/environment.mak*))
  38. ifeq ($(words $(BUILDX)),0)
  39. # Check for a busted wildcard function. We use this function in several
  40. # places, it must work.
  41. ifeq ($(words $(wildcard *)),0)
  42. error-all/environment.mak:
  43. echo You have a broken version of GNU Make - upgrade.
  44. error-out-and-die
  45. else
  46. error-all/environment.mak:
  47. echo Can not find the build directory in $(BUILD_POSSIBLE) -- use BUILD=
  48. error-out-and-die
  49. endif
  50. # Force include below to come to the error target
  51. BUILDX := error-all
  52. else
  53. BUILDX:= $(patsubst %/,%,$(firstword $(dir $(BUILDX))))
  54. endif
  55. override BUILD := $(BUILDX)
  56. # Base definitions
  57. INCLUDE := $(BUILD)/include
  58. BIN := $(BUILD)/bin
  59. LIB := $(BIN)
  60. OBJ := $(BUILD)/obj/$(SUBDIR)
  61. DEP := $(OBJ)
  62. DOC := $(BUILD)/docs
  63. PO := $(BUILD)/po
  64. LOCALE := $(BUILD)/locale
  65. PO_DOMAINS := $(BUILD)/po/domains
  66. # Module types
  67. LIBRARY_H = $(BASE)/buildlib/library.mak
  68. DOCBOOK_H = $(BASE)/buildlib/docbook.mak
  69. MANPAGE_H = $(BASE)/buildlib/manpage.mak
  70. PROGRAM_H = $(BASE)/buildlib/program.mak
  71. PYTHON_H = $(BASE)/buildlib/python.mak
  72. COPY_H = $(BASE)/buildlib/copy.mak
  73. PO4A_MANPAGE_H = $(BASE)/buildlib/po4a_manpage.mak
  74. FAIL_H = $(BASE)/buildlib/fail.mak
  75. PODOMAIN_H = $(BASE)/buildlib/podomain.mak
  76. include $(BUILD)/environment.mak
  77. ifdef STATICLIBS
  78. LIBRARY_H += $(BASE)/buildlib/staticlibrary.mak
  79. endif
  80. ifdef ONLYSTATICLIBS
  81. LIBRARY_H = $(BASE)/buildlib/staticlibrary.mak
  82. endif
  83. # Source location control
  84. # SUBDIRS specifies sub components of the module that
  85. # may be located in subdirectories of the source dir.
  86. # This should be declared before including this file
  87. SUBDIRS+=
  88. # Header file control.
  89. # TARGETDIRS indicates all of the locations that public headers
  90. # will be published to.
  91. # This should be declared before including this file
  92. HEADER_TARGETDIRS+=
  93. # Options
  94. CPPFLAGS+= -I$(INCLUDE)
  95. LDFLAGS+= -L$(LIB)
  96. # Directors to create
  97. MKDIRS := $(BIN)
  98. # Phony rules. Other things hook these by appending to the dependency
  99. # list
  100. .PHONY: headers library clean veryclean all binary program doc dirs
  101. .PHONY: maintainer-clean dist-clean distclean pristine sanity
  102. all: dirs binary doc
  103. binary: library program
  104. maintainer-clean dist-clean distclean pristine sanity: veryclean
  105. startup headers library clean veryclean program test update-po manpages docbook:
  106. veryclean:
  107. echo Very Clean done for $(SUBDIR)
  108. clean:
  109. echo Clean done for $(SUBDIR)
  110. dirs:
  111. mkdir -p $(patsubst %/,%,$(sort $(MKDIRS)))
  112. # Header file control. We want all published interface headers to go
  113. # into the build directory from their source dirs. We setup some
  114. # search paths here
  115. vpath %.h $(SUBDIRS)
  116. $(INCLUDE)/%.h $(addprefix $(INCLUDE)/,$(addsuffix /%.h,$(HEADER_TARGETDIRS))) : %.h
  117. cp $< $@
  118. # Dependency generation. We want to generate a .d file using gnu cpp.
  119. # For GNU systems the compiler can spit out a .d file while it is compiling,
  120. # this is specified with the INLINEDEPFLAG. Other systems might have a
  121. # makedep program that can be called after compiling, that's illustrated
  122. # by the DEPFLAG case.
  123. # Compile rules are expected to call this macro after calling the compiler
  124. ifdef GCC3DEP
  125. DFILE = $(DEP)/$(basename $(@F)).d
  126. else
  127. DFILE = $(basename $(@F)).d
  128. endif
  129. ifdef INLINEDEPFLAG
  130. define DoDep
  131. sed -e "1s/.*:/$(subst /,\\/,$@):/" $(DFILE) > $(DEP)/$(@F).d
  132. #sed -e "1s/.*:/$(subst /,\\/,$@):/" $(DEP)/$(basename $(@F)).d > $(DEP)/$(@F).d
  133. -rm -f $(basename $(@F)).d
  134. endef
  135. else
  136. ifdef DEPFLAG
  137. define DoDep
  138. $(CXX) $(DEPFLAG) $(CPPFLAGS) -o $@ $<
  139. sed -e "1s/.*:/$(subst /,\\/,$@):/" $(basename $(@F)).d > $(DEP)/$(@F).d
  140. -rm -f $(basename $(@F)).d
  141. endef
  142. else
  143. define DoDep
  144. endef
  145. endif
  146. endif
  147. # Automatic -j support
  148. ifeq ($(NUM_PROCS),1)
  149. PARALLEL_RUN=no
  150. endif
  151. ifndef PARALLEL_RUN
  152. PARALLEL_RUN=yes
  153. export PARALLEL_RUN
  154. # handle recursion
  155. ifneq ($(NUM_PROCS),)
  156. MAKEFLAGS += -j $(NUM_PROCS)
  157. endif
  158. endif
  159. # This makes sorting predictable
  160. export LC_COLLATE=C.UTF-8