1# Time-stamp: <07/05/30 23:59:42 ptr>
2#
3# Copyright (c) 1997-1999, 2002, 2003, 2005, 2006
4# Petr Ovtchenkov
5#
6# Portion Copyright (c) 1999-2001
7# Parallel Graphics Ltd.
8#
9# Licensed under the Academic Free License version 3.0
10#
11
12PRGS_DIR_SRC =
13define prog_
14PRGS_DIR_SRC += $$(dir $${$(1)_SRC_CPP} $${$(1)_SRC_CC} $${$(1)_SRC_CXX} $${$(1)_SRC_C} $${$(1)_SRC_S} )
15$(1)_ALLBASE := $$(basename $$(notdir $${$(1)_SRC_CC} $${$(1)_SRC_CPP} $${$(1)_SRC_CXX} $${$(1)_SRC_C} $${$(1)_SRC_S} ) )
16$(1)_ALLOBJS    := $$(addsuffix .o,$${$(1)_ALLBASE})
17$(1)_ALLDEPS    := $$(addsuffix .d,$${$(1)_ALLBASE})
18
19$(1)_OBJ        := $$(addprefix $$(OUTPUT_DIR)/,$${$(1)_ALLOBJS})
20$(1)_OBJ_DBG    := $$(addprefix $$(OUTPUT_DIR_DBG)/,$${$(1)_ALLOBJS})
21$(1)_OBJ_STLDBG := $$(addprefix $$(OUTPUT_DIR_STLDBG)/,$${$(1)_ALLOBJS})
22
23$(1)_DEP        := $$(addprefix $$(OUTPUT_DIR)/,$${$(1)_ALLDEPS})
24$(1)_DEP_DBG    := $$(addprefix $$(OUTPUT_DIR_DBG)/,$${$(1)_ALLDEPS})
25$(1)_DEP_STLDBG := $$(addprefix $$(OUTPUT_DIR_STLDBG)/,$${$(1)_ALLDEPS})
26
27$(1)_RES        := $$(addprefix $$(OUTPUT_DIR)/,$${$(1)_ALLRESS})
28$(1)_RES_DBG    := $$(addprefix $$(OUTPUT_DIR_DBG)/,$${$(1)_ALLRESS})
29$(1)_RES_STLDBG := $$(addprefix $$(OUTPUT_DIR_STLDBG)/,$${$(1)_ALLRESS})
30
31ifeq ("$$(sort $${$(1)_SRC_CC} $${$(1)_SRC_CPP} $${$(1)_SRC_CXX})","")
32$(1)_NOT_USE_NOSTDLIB := 1
33_$(1)_C_SOURCES_ONLY := true
34endif
35
36endef
37
38$(foreach prg,$(PRGNAMES),$(eval $(call prog_,$(prg))))
39
40# If we have no C++ sources, let's use C compiler for linkage instead of C++.
41ifeq ("$(sort ${SRC_CC} ${SRC_CPP} ${SRC_CXX})","")
42NOT_USE_NOSTDLIB := 1
43_C_SOURCES_ONLY := true
44endif
45
46# if sources disposed in several dirs, calculate appropriate rules
47
48DIRS_UNIQUE_SRC := $(dir $(SRC_CPP) $(SRC_CC) $(SRC_CXX) $(SRC_C) $(SRC_S) )
49ifeq (${OSNAME},cygming)
50DIRS_UNIQUE_SRC := ${DIRS_UNIQUE_SRC} $(dir $(SRC_RC) )
51endif
52DIRS_UNIQUE_SRC := $(sort $(DIRS_UNIQUE_SRC) $(PRGS_DIR_SRC))
53
54# The rules below may be even simpler (i.e. define macro that generate
55# rules for COMPILE.xx), but this GNU make 3.80 unhappy with it;
56# GNU make 3.81 work fine, but 3.81 is new...
57# The code below verbose, but this is price for compatibility with 3.80
58
59define rule_o
60$$(OUTPUT_DIR$(1))/%.o:	$(2)%.cc
61	$$(COMPILE.cc) $$(OUTPUT_OPTION) $$<
62
63$$(OUTPUT_DIR$(1))/%.d:	$(2)%.cc
64	@$$(COMPILE.cc) $$(CCDEPFLAGS) $$< $$(DP_OUTPUT_DIR$(1))
65
66$$(OUTPUT_DIR$(1))/%.o:	$(2)%.cpp
67	$$(COMPILE.cc) $$(OUTPUT_OPTION) $$<
68
69$$(OUTPUT_DIR$(1))/%.d:	$(2)%.cpp
70	@$$(COMPILE.cc) $$(CCDEPFLAGS) $$< $$(DP_OUTPUT_DIR$(1))
71
72$$(OUTPUT_DIR$(1))/%.o:	$(2)%.cxx
73	$$(COMPILE.cc) $$(OUTPUT_OPTION) $$<
74
75$$(OUTPUT_DIR$(1))/%.d:	$(2)%.cxx
76	@$$(COMPILE.cc) $$(CCDEPFLAGS) $$< $$(DP_OUTPUT_DIR$(1))
77
78$$(OUTPUT_DIR$(1))/%.o:	$(2)%.c
79	$$(COMPILE.c) $$(OUTPUT_OPTION) $$<
80
81$$(OUTPUT_DIR$(1))/%.d:	$(2)%.c
82	@$$(COMPILE.c) $$(CCDEPFLAGS) $$< $$(DP_OUTPUT_DIR$(1))
83
84$$(OUTPUT_DIR$(1))/%.o:	$(2)%.s
85	$$(COMPILE.s) $$(OUTPUT_OPTION) $$<
86
87$$(OUTPUT_DIR$(1))/%.o:	$(2)%.S
88	$$(COMPILE.S) $$(OUTPUT_OPTION) $$<
89
90$$(OUTPUT_DIR$(1))/%.d:	$(2)%.S
91	@$$(COMPILE.S) $$(SDEPFLAGS) $$< $$(DP_OUTPUT_DIR$(1))
92endef
93
94define rule_rc
95$$(OUTPUT_DIR$(1))/%.res:	$(2)%.rc
96	$$(COMPILE.rc) $$(RC_OUTPUT_OPTION) $$<
97endef
98
99define rules_
100$(call rule_o,,$(1))
101ifneq ($(OUTPUT_DIR),$(OUTPUT_DIR_A))
102$(call rule_o,_A,$(1))
103endif
104$(call rule_o,_DBG,$(1))
105ifneq ($(OUTPUT_DIR_DBG),$(OUTPUT_DIR_A_DBG))
106$(call rule_o,_A_DBG,$(1))
107endif
108ifndef WITHOUT_STLPORT
109$(call rule_o,_STLDBG,$(1))
110ifneq ($(OUTPUT_DIR_STLDBG),$(OUTPUT_DIR_A_STLDBG))
111$(call rule_o,_A_STLDBG,$(1))
112endif
113endif
114ifeq ($(OSNAME),cygming)
115$(call rule_rc,,$(1))
116$(call rule_rc,_DBG,$(1))
117ifndef WITHOUT_STLPORT
118$(call rule_rc,_STLDBG,$(1))
119endif
120endif
121endef
122
123$(foreach dir,$(DIRS_UNIQUE_SRC),$(eval $(call rules_,$(dir))))
124
125ALLBASE    := $(basename $(notdir $(SRC_CC) $(SRC_CPP) $(SRC_CXX) $(SRC_C) $(SRC_S)))
126ifeq (${OSNAME},cygming)
127RCBASE    += $(basename $(notdir $(SRC_RC)))
128endif
129
130ALLOBJS    := $(addsuffix .o,$(ALLBASE))
131ALLDEPS    := $(addsuffix .d,$(ALLBASE))
132ALLRESS    := $(addsuffix .res,$(RCBASE))
133
134OBJ        := $(addprefix $(OUTPUT_DIR)/,$(ALLOBJS))
135OBJ_DBG    := $(addprefix $(OUTPUT_DIR_DBG)/,$(ALLOBJS))
136OBJ_STLDBG := $(addprefix $(OUTPUT_DIR_STLDBG)/,$(ALLOBJS))
137
138DEP        := $(addprefix $(OUTPUT_DIR)/,$(ALLDEPS))
139DEP_DBG    := $(addprefix $(OUTPUT_DIR_DBG)/,$(ALLDEPS))
140DEP_STLDBG := $(addprefix $(OUTPUT_DIR_STLDBG)/,$(ALLDEPS))
141
142RES        := $(addprefix $(OUTPUT_DIR)/,$(ALLRESS))
143RES_DBG    := $(addprefix $(OUTPUT_DIR_DBG)/,$(ALLRESS))
144RES_STLDBG := $(addprefix $(OUTPUT_DIR_STLDBG)/,$(ALLRESS))
145
146ifeq ($(OUTPUT_DIR),$(OUTPUT_DIR_A))
147OBJ_A      := $(OBJ)
148DEP_A      := $(DEP)
149else
150OBJ_A      := $(addprefix $(OUTPUT_DIR_A)/,$(ALLOBJS))
151DEP_A      := $(addprefix $(OUTPUT_DIR_A)/,$(ALLDEPS))
152endif
153
154ifeq ($(OUTPUT_DIR_DBG),$(OUTPUT_DIR_A_DBG))
155OBJ_A_DBG  := $(OBJ_DBG)
156DEP_A_DBG  := $(DEP_DBG)
157else
158OBJ_A_DBG  := $(addprefix $(OUTPUT_DIR_A_DBG)/,$(ALLOBJS))
159DEP_A_DBG  := $(addprefix $(OUTPUT_DIR_A_DBG)/,$(ALLDEPS))
160endif
161
162ifeq ($(OUTPUT_DIR_STLDBG),$(OUTPUT_DIR_A_STLDBG))
163OBJ_A_STLDBG := $(OBJ_STLDBG)
164DEP_A_STLDBG := $(DEP_STLDBG)
165else
166OBJ_A_STLDBG := $(addprefix $(OUTPUT_DIR_A_STLDBG)/,$(ALLOBJS))
167DEP_A_STLDBG := $(addprefix $(OUTPUT_DIR_A_STLDBG)/,$(ALLDEPS))
168endif
169
170