Fixed or handling bug
[ntk/apt.git] / buildlib / program.mak
1 # -*- make -*-
2
3 # This creates a program
4
5 # Input
6 # $(SOURCE) - The source code to use
7 # $(PROGRAM) - The name of the program
8 # $(SLIBS) - Shared libs to link against
9 # $(LIB_MAKES) - Shared libary make files to depend on - to ensure we get
10 # remade when the shared library version increases.
11
12 # See defaults.mak for information about LOCAL
13
14 # Some local definitions
15 LOCAL := $(PROGRAM)
16 $(LOCAL)-OBJS := $(addprefix $(OBJ)/,$(addsuffix .o,$(notdir $(basename $(SOURCE)))))
17 $(LOCAL)-DEP := $(addprefix $(DEP)/,$(addsuffix .o.d,$(notdir $(basename $(SOURCE)))))
18 $(LOCAL)-BIN := $(BIN)/$(PROGRAM)
19 $(LOCAL)-SLIBS := $(SLIBS)
20 $(LOCAL)-MKS := $(addprefix $(BASE)/,$(LIB_MAKES))
21
22 # Install the command hooks
23 program: $(BIN)/$(PROGRAM)
24 clean: clean/$(LOCAL)
25 veryclean: veryclean/$(LOCAL)
26
27 # The clean rules
28 .PHONY: clean/$(LOCAL) veryclean/$(LOCAL)
29 clean/$(LOCAL):
30 -rm -f $($(@F)-OBJS) $($(@F)-DEP)
31 veryclean/$(LOCAL): clean/$(LOCAL)
32 -rm -f $($(@F)-BIN)
33
34 # The convience binary build rule
35 .PHONY: $(PROGRAM)
36 $(PROGRAM): $($(LOCAL)-BIN)
37
38 # The binary build rule
39 $($(LOCAL)-BIN): $($(LOCAL)-OBJS) $($(LOCAL)-MKS)
40 echo Building program $@
41 $(CXX) $(CXXFLAGS) $(LDFLAGS) $(LFLAGS) -o $@ $(filter %.o,$^) $($(@F)-SLIBS) $(LEFLAGS)
42
43 # Compilation rules
44 vpath %.cc $(SUBDIRS)
45 $(OBJ)/%.o: %.cc
46 echo Compiling $< to $@
47 $(CXX) -c $(INLINEDEPFLAG) $(CPPFLAGS) $(CXXFLAGS) -o $@ $<
48 $(DoDep)
49
50 # Include the dependencies that are available
51 The_DFiles = $(wildcard $($(LOCAL)-DEP))
52 ifneq ($(words $(The_DFiles)),0)
53 include $(The_DFiles)
54 endif