1###############################################################################
2# vim:noexpandtab
3#
4# Global common definitions for build system
5#
6# Copyright (C) Nintendo.  All rights reserved.
7#
8# These coded instructions, statements, and computer programs contain
9# proprietary information of Nintendo of America Inc. and/or Nintendo
10# Company Ltd., and are protected by Federal copyright law.  They may
11# not be disclosed to third parties or copied or duplicated in any form,
12# in whole or in part, without the prior written consent of Nintendo.
13#
14###############################################################################
15
16# This file contains common definitions that exist across the build
17
18ifndef OS_SECURITY_LEVEL
19    OS_SECURITY_LEVEL = 0
20endif
21
22empty :=
23space := $(empty) $(empty)
24comma := ,
25COMPILE_WARNINGS_AS_ERRORS := TRUE
26CFLAGS := --Werror
27_@=@
28
29#
30# Message handling, if $(_@) != @ don't print noisy messages
31#
32ifeq ($(_@), @)
33	MOD_RULES_PHASE=@echo -e "------------------------------------------------------------------\n" $(1)
34	MOD_RULES_STEP=@echo -e $(1)
35else
36	MOD_RULES_PHASE=
37	MOD_RULES_STEP=
38endif
39
40###############################################################################
41#
42#  Environment variables
43#
44#  All environment variables use UNIX-style paths.  Paths are converted to
45#  mixed mode where required.
46#
47###############################################################################
48
49# Assumes these are already set properly as UNIX-style environment variables
50#
51# CAFE_ROOT - path to cafe tree
52# ENV_BIN   - path to environment tools
53# PLATFORM  - hardware name
54
55###############################################################################
56#
57#  Common constants
58#
59###############################################################################
60
61SYSTEM_ROOT        := $(CAFE_ROOT)/system
62
63BUILD_ROOT         := $(SYSTEM_ROOT)/src
64INCLUDE_DIR        := $(SYSTEM_ROOT)/include
65INCLUDE_DIR_DOS    := $(shell cygpath -m $(INCLUDE_DIR))
66BIN_ROOT           := $(SYSTEM_ROOT)/bin
67LIB_ROOT           := $(SYSTEM_ROOT)/lib
68OBJ_ROOT           := $(SYSTEM_ROOT)/obj
69TOOL_DIR           := $(BIN_ROOT)/tool
70
71BUILDMAKE_ROOT     := $(BUILD_ROOT)/build/make
72
73###############################################################################
74#
75#  choose tool desired architecture for tools that support 32 or 64 bits
76#
77###############################################################################
78ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
79TOOL_USED_ON_ARCH  := 64
80else
81ifeq ($(PROCESSOR_ARCHITEW6432),AMD64)
82# cygwin is lying to us
83TOOL_USED_ON_ARCH  := 64
84else
85TOOL_USED_ON_ARCH  := 32
86endif
87endif
88
89
90###############################################################################
91#
92#  Base Paths for a module
93#
94#  (should be called from current directory, or make -C <dir>, not make -f)
95#
96###############################################################################
97
98# CURDIR is set by makefile.
99MODULE_DIR           := $(CURDIR)
100
101# Get the path from src.
102# Remove the full path to src from the full path to module directory ignoring case
103# Use semicolon as separator so don't think any character in CAFE_ROOT is a delimiter
104#
105# DONE  - Replaced this call to the shell with an internal make command
106#         to do replacement. Do this to speed up the build
107#
108#MODULE_PATH_FROM_SRC ?= $(shell echo "$(MODULE_DIR)" | sed "s;\($(BUILD_ROOT)/\);;i")
109MODULE_PATH_FROM_SRC ?= $(subst $(BUILD_ROOT)/,,$(MODULE_DIR))
110
111###############################################################################
112#
113#  BUILD_TYPE flag (FDEBUG, DEBUG, NDEBUG, OS_SECURITY_LEVEL)
114#
115###############################################################################
116
117# For keeping backward compatibility
118ifeq ($(NDEBUG), TRUE)
119    BUILD_TYPE         := NDEBUG
120endif
121ifeq ($(NDEBUG), FALSE)
122    BUILD_TYPE         := DEBUG
123endif
124ifneq ($(OS_SECURITY_LEVEL), 0)
125    BUILD_TYPE         := OS_SECURITY_LEVEL
126endif
127
128###################################
129# Default for any ppc modules
130# - BUILD_TYPE  : DEBUG
131###################################
132ifeq ($(NDEBUG), )
133ifeq ($(BUILD_TYPE), )
134    BUILD_TYPE         := DEBUG
135endif
136endif
137
138###################################
139# Default for any ppc modules
140# - SUPPRESS_STRIP  : FALSE
141###################################
142ifeq ($(SUPPRESS_STRIP), )
143    SUPPRESS_STRIP         := FALSE
144endif
145
146###################################
147# Override build for any iop modules
148# - If BUILD_TYPE=DEBUG|NDEBUG|OS_SECURITY_LEVEL -> NDEBUG
149# - If BUILD_TYPE=FDEBUG       -> DEBUG
150###################################
151IS_IOP := $(patsubst iop%,STARTS_WITH_IOP,$(MODULE_PATH_FROM_SRC))
152ifeq ($(IS_IOP), STARTS_WITH_IOP)
153    ifeq ($(BUILD_TYPE), FDEBUG)
154        override BUILD_TYPE       := DEBUG
155    else
156        override BUILD_TYPE       := NDEBUG
157    endif
158endif
159
160###################################
161# FDEBUG
162# - Defines     : DEBUG
163# - Opt Lib     : off
164# - Debug Info  : generated
165###################################
166ifeq ($(BUILD_TYPE), FDEBUG)
167    DEBUG             := TRUE
168    NDEBUG            := FALSE
169    BUILD_TARGET      := FDEBUG
170else
171
172###################################
173# DEBUG
174# - Defines     : DEBUG
175# - Opt Lib     : on
176# - Debug Info  : stripped
177###################################
178ifeq ($(BUILD_TYPE), DEBUG)
179    DEBUG             := TRUE
180    NDEBUG            :=
181    BUILD_TARGET      := DEBUG
182else
183
184###################################
185# NDEBUG
186# - Defines     : NDEBUG
187# - Opt Lib     : on
188# - Debug Info  : stripped
189###################################
190ifeq ($(BUILD_TYPE), NDEBUG)
191    DEBUG             :=
192    NDEBUG            := TRUE
193    BUILD_TARGET      := NDEBUG
194else
195###################################
196# OS_SECURITY_LEVEL
197# - Defines     : NDEBUG
198# - Opt Lib     : on
199# - Debug Info  : stripped
200###################################
201ifeq ($(BUILD_TYPE), OS_SECURITY_LEVEL)
202    DEBUG             :=
203    NDEBUG            := TRUE
204    BUILD_TARGET      := OS_SECURITY_LEVEL
205else
206    $(error error: Unknown BUILD_TYPE. BUILD_TYPE should be OS_SECURITY_LEVEL, FDEBUG, DEBUG, or NDEBUG.)
207endif
208endif
209endif
210endif
211
212###############################################################################
213#
214#  Generic Paths relevant to a module
215#
216#  (should be called from current directory, or make -C <dir>, not make -f)
217#
218###############################################################################
219
220# Binaries and libraries for a specific platform
221BIN_DIR_NO_TARGET       := $(MODULE_DEPTH)/../bin/$(TOOLCHAIN)/$(PLATFORM)/$(MODULE_PATH_FROM_SRC)
222LIB_DIR_NO_TARGET       := $(LIB_ROOT)/$(TOOLCHAIN)/$(PLATFORM)
223BIN_DIR       := $(BIN_DIR_NO_TARGET)/$(BUILD_TARGET)
224LIB_DIR       := $(LIB_DIR_NO_TARGET)/$(BUILD_TARGET)
225KERNELLIB_DIR := $(LIB_ROOT)/$(TOOLCHAIN)/$(PLATFORM)/kernel/$(BUILD_TARGET)
226LOADERLIB_DIR := $(LIB_ROOT)/$(TOOLCHAIN)/$(PLATFORM)/loader/$(BUILD_TARGET)
227KDEBUGLIB_DIR := $(LIB_ROOT)/$(TOOLCHAIN)/$(PLATFORM)/kdebug/$(BUILD_TARGET)
228
229# Binaries and libraries for all platforms
230BIN_DIR_ALL   := $(BIN_ROOT)/all/$(MODULE_PATH_FROM_SRC)/$(BUILD_TARGET)
231LIB_DIR_ALL   := $(LIB_ROOT)/all/$(BUILD_TARGET)
232
233# OBJ_DIR must be relative to match dependency file generation
234# So don't use OBJ_ROOT (manually make sure these directories match paths)
235# Don't forget that OBJ_SEARCH_PATH is separately defined in commondefs.cos.??.mk
236OBJ_DIR       := $(MODULE_DEPTH)/../obj/$(TOOLCHAIN)/$(PLATFORM)/$(MODULE_PATH_FROM_SRC)/$(BUILD_TARGET)
237
238###############################################################################
239#
240#  PLATFORM and TOOLCHAIN
241#
242###############################################################################
243
244ifeq ($(TOOLCHAIN), ghs)
245    VALID_TOOLCHAIN := TRUE
246endif
247ifneq ($(VALID_TOOLCHAIN),TRUE)
248    $(error Please specify supported TOOLCHAIN environment variable)
249endif
250
251ifeq ($(PLATFORM), cafe)
252    EPPC            := TRUE
253    VALID_PLATFORM  := TRUE
254endif
255ifneq ($(VALID_PLATFORM),TRUE)
256    $(error Please specify supported PLATFORM environment variable)
257endif
258
259# Set parameters for the architecture target
260GTX_OPTIONS += -gpu 2
261GSH_OPTIONS += -gpu 2
262
263########################################################################
264#
265#  Suffixes
266#
267########################################################################
268
269LIBSUFFIX  := .a
270OBJSUFFIX  := .o
271BINSUFFIX  := .elf
272RPLSUFFIX  := .rpl
273RPXSUFFIX  := .rpx
274LCFSUFFIX  := .lcf
275LSTSUFFIX  := .lst
276WADSUFFIX  := .wad
277MCHSUFFIX  := .mch
278LZ77SUFFIX := .lz7
279DEPSUFFIX  := .dep
280
281###############################################################################
282#
283#  MACROS
284#
285###############################################################################
286
287MKDIRP         := mkdir -p
288
289# Usage: $(MACRO_INSTALL_FILE) <source filepath> <destination filepath>
290#        Install file as read and execute-only,
291#        to prevent mistakes for modifying installed headers.
292define MACRO_INSTALL_FILE
293    install -Dpv -m ugo=rx
294endef
295
296# Usage: $(MACRO_INSTALL_PREBUILTOBJ)
297#        Install object file and remove debug info references.
298#		 Remove write permissions to prevent mistakes for modifying objects.
299define MACRO_INSTALL_PREBUILTOBJ
300	install -Dpv -m ugo=rw $< $@
301	gstripdbg $(shell cygpath -m $@)
302	chmod a-w $@
303endef
304
305###############################################################################
306#
307#  Other configuration settings
308#  This section is only for Nintendo internal use.
309#
310###############################################################################
311
312