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