Makefile 6.1 KB
Newer Older
1
2
3
4
# Makefile for pimpmobile module player
# Copyright (C) 2005-2007 Jrn Nystad and Erik Faye-Lund
# For conditions of distribution and use, see copyright notice in LICENSE.TXT

Erik Faye-Lund's avatar
Erik Faye-Lund committed
5
# default-configuration
Erik Faye-Lund's avatar
Erik Faye-Lund committed
6
TARGET    ?= arm-gba
Erik Faye-Lund's avatar
Erik Faye-Lund committed
7
HOST      ?= $(shell $(CC) -dumpmachine)
Erik Faye-Lund's avatar
Erik Faye-Lund committed
8
BUILD_DIR ?= build
9
CONFIG    ?= release
Erik Faye-Lund's avatar
Erik Faye-Lund committed
10

Erik Faye-Lund's avatar
Erik Faye-Lund committed
11
# some common unix utils
Erik Faye-Lund's avatar
Erik Faye-Lund committed
12
13
14
15
AWK   ?= awk
SORT  ?= sort
PR    ?= pr
CTAGS ?= ctags
Erik Faye-Lund's avatar
Erik Faye-Lund committed
16

17
18
19
#ifeq ($(strip $(DEVKITPRO)),)
#$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitPro")
#endif
20

21
ifneq ($(strip $(DEVKITPRO)),)
22
DEVKITARM = $(DEVKITPRO)/devkitARM
Erik Faye-Lund's avatar
Erik Faye-Lund committed
23
export PATH := $(DEVKITARM)/bin:$(PATH)
24
endif
Erik Faye-Lund's avatar
Erik Faye-Lund committed
25

Erik Faye-Lund's avatar
Erik Faye-Lund committed
26
ifdef COMSPEC
Erik Faye-Lund's avatar
Erik Faye-Lund committed
27
EXE_EXT = .exe
Erik Faye-Lund's avatar
Erik Faye-Lund committed
28
else
Erik Faye-Lund's avatar
Erik Faye-Lund committed
29
EXE_EXT =
Erik Faye-Lund's avatar
Erik Faye-Lund committed
30
31
endif

Erik Faye-Lund's avatar
Erik Faye-Lund committed
32
33
34
ifeq ($(TARGET), arm-gba)
TARGET_PREFIX ?= arm-eabi-
else
Erik Faye-Lund's avatar
Erik Faye-Lund committed
35
TARGET_PREFIX = $(TARGET)
Erik Faye-Lund's avatar
Erik Faye-Lund committed
36
37
endif

Erik Faye-Lund's avatar
Erik Faye-Lund committed
38
#$(eval $(call setup-gcc, out-prefix, toolchain-prefix))
39
define setup-gcc
Erik Faye-Lund's avatar
Erik Faye-Lund committed
40
41
42
43
44
45
	$(1)CC    = $(2)gcc
	$(1)CXX   = $(2)g++
	$(1)STRIP = $(2)strip
	$(1)LD    = $(2)ld
	$(1)AS    = $(2)as
	$(1)AR    = $(2)ar
46
47
endef

Erik Faye-Lund's avatar
Erik Faye-Lund committed
48
#$(eval $(call setup-armcc, out-prefix))
49
define setup-armcc
Erik Faye-Lund's avatar
Erik Faye-Lund committed
50
51
52
53
54
55
	$(1)CC    = armcc
	$(1)CXX   = armcpp
	$(1)STRIP = strip
	$(1)LD    = armlink
	$(1)AS    = armasm
	$(1)AR    = armar
56
57
endef

Erik Faye-Lund's avatar
Erik Faye-Lund committed
58
59
$(eval $(call setup-gcc,TARGET_, $(TARGET_PREFIX)))
# $(eval $(call setup-armcc,TARGET_))
Erik Faye-Lund's avatar
Erik Faye-Lund committed
60
$(eval $(call setup-gcc,,))
61

Erik Faye-Lund's avatar
Erik Faye-Lund committed
62
ifneq ($(findstring $(MAKEFLAGS),s),s)
Erik Faye-Lund's avatar
Erik Faye-Lund committed
63
64
65
66
67
	QUIET_CC   = @echo '   ' CC $@;
	QUIET_CXX  = @echo '   ' CXX $@;
	QUIET_AS   = @echo '   ' AS $@;
	QUIET_AR   = @echo '   ' AR $@;
	QUIET_LINK = @echo '   ' LINK $@;
Erik Faye-Lund's avatar
Erik Faye-Lund committed
68
endif
69

70
71
MKDIR = mkdir -p

72
ifeq ($(TARGET), arm-gba)
Erik Faye-Lund's avatar
Erik Faye-Lund committed
73
	TARGET_CPPFLAGS = -I$(DEVKITARM)/include -DTARGET_GBA
74
75
76
77
78
	TARGET_CFLAGS   = -mthumb-interwork -mlong-calls
	TARGET_CXXFLAGS = -mthumb-interwork -mlong-calls
	TARGET_LDFLAGS  = -mthumb-interwork -Wl,--gc-section
	TARGET_ASFLAGS  = -mthumb-interwork
endif
Erik Faye-Lund's avatar
Erik Faye-Lund committed
79

Erik Faye-Lund's avatar
Erik Faye-Lund committed
80
CPPFLAGS =
Erik Faye-Lund's avatar
Erik Faye-Lund committed
81
CFLAGS   = -pedantic -Wall -Wno-long-long
Erik Faye-Lund's avatar
Erik Faye-Lund committed
82
CXXFLAGS = -fconserve-space -fno-rtti -fno-exceptions
Erik Faye-Lund's avatar
Erik Faye-Lund committed
83
LDFLAGS  =
Erik Faye-Lund's avatar
Erik Faye-Lund committed
84
ASFLAGS  =
85
ARFLAGS  = rcs
86

Erik Faye-Lund's avatar
Erik Faye-Lund committed
87
88
89
90
91
92
ifeq ($(HOST), x86_64-linux-gnu)
	HOST_CFLAGS += -m32
	HOST_CXXFLAGS += -m32
	HOST_LDFLAGS += -m32
endif

93
94
95
ARM   = -marm
THUMB = -mthumb

Erik Faye-Lund's avatar
Erik Faye-Lund committed
96
SOURCES = \
Erik Faye-Lund's avatar
Erik Faye-Lund committed
97
98
99
100
101
	src/pimp_render.c      \
	src/pimp_envelope.c    \
	src/pimp_mod_context.c \
	src/pimp_math.c        \
	src/pimp_mixer.c
102

103
104
105
106
ifeq ($(TARGET), arm-gba)
	SOURCES += src/pimp_gba.c
endif

Erik Faye-Lund's avatar
Erik Faye-Lund committed
107
ARM_SOURCES = \
Erik Faye-Lund's avatar
Erik Faye-Lund committed
108
109
	src/pimp_math.c \
	src/pimp_mixer.c
Erik Faye-Lund's avatar
Erik Faye-Lund committed
110

111
PIMPCONV_SOURCES = \
Erik Faye-Lund's avatar
Erik Faye-Lund committed
112
113
114
115
	converter/pimpconv.c \
	converter/serializer.cpp \
	converter/serialize_module.c \
	converter/serialize_instrument.c \
116
	src/convert_sample.c \
Erik Faye-Lund's avatar
Erik Faye-Lund committed
117
	src/load_xm.c \
Erik Faye-Lund's avatar
Erik Faye-Lund committed
118
	src/load_mod.c \
Erik Faye-Lund's avatar
Erik Faye-Lund committed
119
	src/pimp_sample_bank.c
Erik Faye-Lund's avatar
Erik Faye-Lund committed
120

121
ifeq ($(CONFIG), debug)
122
	CPPFLAGS += -DDEBUG
123
124
	CXXFLAGS += -g -ggdb
	CFLAGS   += -g -ggdb
Erik Faye-Lund's avatar
Erik Faye-Lund committed
125
126
	SOURCES  += src/pimp_mixer_portable.c
	SOURCES  += src/pimp_debug.c
127
128
129
130
else
	CPPFLAGS += -DRELEASE -DNDEBUG
	CXXFLAGS += -O3 -fomit-frame-pointer
	CFLAGS   += -O3 -fomit-frame-pointer
Erik Faye-Lund's avatar
Erik Faye-Lund committed
131
132
	SOURCES  += src/pimp_mixer_arm.S
	SOURCES  += src/pimp_mixer_clip_arm.S
133
134
135
endif

ifeq ($(PROFILING), 1)
Erik Faye-Lund's avatar
Erik Faye-Lund committed
136
	CFLAGS   += -finstrument-functions
137
	CXXFLAGS += -finstrument-functions
Erik Faye-Lund's avatar
Erik Faye-Lund committed
138
	SOURCES  += profiling/cyg-profile.c
139
140
endif

141
142
TARGET_BUILD_DIR = $(BUILD_DIR)/$(TARGET)/$(CONFIG)
HOST_BUILD_DIR = $(BUILD_DIR)/$(HOST)/$(CONFIG)
Erik Faye-Lund's avatar
Erik Faye-Lund committed
143

Erik Faye-Lund's avatar
Erik Faye-Lund committed
144
source-to-object = \
Erik Faye-Lund's avatar
Erik Faye-Lund committed
145
146
147
148
149
150
151
152
	$(subst .c,.o,        $(filter-out $(ARM_SOURCES), $(filter %.c,$1))) \
	$(subst .c,.iwram.o,  $(filter     $(ARM_SOURCES), $(filter %.c,$1))) \
	$(subst .cpp,.o,      $(filter-out $(ARM_SOURCES), $(filter %.cpp,$1))) \
	$(subst .cpp,.iwram.o,$(filter     $(ARM_SOURCES), $(filter %.cpp,$1))) \
	$(subst .S,.o,        $(filter-out $(ARM_SOURCES), $(filter %.S,$1))) \
	$(subst .S,.iwram.o,  $(filter     $(ARM_SOURCES), $(filter %.S,$1)))

source-to-depend = $(subst .o,.d, $(call source-to-object, $1))
Erik Faye-Lund's avatar
Erik Faye-Lund committed
153
154

make-target-objs = $(addprefix $(TARGET_BUILD_DIR)/, $(call source-to-object, $1))
Erik Faye-Lund's avatar
Erik Faye-Lund committed
155
make-host-objs   = $(addprefix $(HOST_BUILD_DIR)/,   $(call source-to-object, $1))
Erik Faye-Lund's avatar
Erik Faye-Lund committed
156

Erik Faye-Lund's avatar
Erik Faye-Lund committed
157
158
make-target-deps = $(addprefix $(TARGET_BUILD_DIR)/, $(call source-to-depend, $1))
make-host-deps   = $(addprefix $(HOST_BUILD_DIR)/,   $(call source-to-depend, $1))
Erik Faye-Lund's avatar
Erik Faye-Lund committed
159

Erik Faye-Lund's avatar
Erik Faye-Lund committed
160
OBJS = $(call make-target-objs, $(SOURCES))
161

Erik Faye-Lund's avatar
Erik Faye-Lund committed
162
.PHONY: all clean check check-syntax
163

Erik Faye-Lund's avatar
Erik Faye-Lund committed
164
all: lib/libpimp_gba.a bin/pimpconv$(EXE_EXT)
165
166

clean:
Erik Faye-Lund's avatar
Erik Faye-Lund committed
167
	$(RM) lib/libpimp_gba.a $(call make-target-objs, $(SOURCES)) $(call make-target-deps, $(SOURCES))
Erik Faye-Lund's avatar
Erik Faye-Lund committed
168
	$(RM) bin/pimpconv$(EXE_EXT) $(call make-host-objs, $(PIMPCONV_SOURCES)) $(call make-host-deps, $(PIMPCONV_SOURCES))
Erik Faye-Lund's avatar
Erik Faye-Lund committed
169

Erik Faye-Lund's avatar
Erik Faye-Lund committed
170
distclean:
Erik Faye-Lund's avatar
Erik Faye-Lund committed
171
	$(RM) -r $(BUILD_DIR)
172

Erik Faye-Lund's avatar
Erik Faye-Lund committed
173
check:
Erik Faye-Lund's avatar
Erik Faye-Lund committed
174
	$(MAKE) -C testbench run
Erik Faye-Lund's avatar
Erik Faye-Lund committed
175
176

check-syntax:
Erik Faye-Lund's avatar
Erik Faye-Lund committed
177
	$(TARGET_CC) $(CPPFLAGS) $(TARGET_CPPFLAGS) $(CFLAGS) -fsyntax-only $(filter %.c,$(SOURCES))
Erik Faye-Lund's avatar
Erik Faye-Lund committed
178

Erik Faye-Lund's avatar
Erik Faye-Lund committed
179
180
181
TAGS:
	$(CTAGS) $(filter %.c,$(SOURCES))

Erik Faye-Lund's avatar
Erik Faye-Lund committed
182
183
$(call make-target-objs, $(filter-out $(ARM_SOURCES), $(SOURCES))): TARGET_CFLAGS += -mthumb
$(call make-target-objs, $(filter     $(ARM_SOURCES), $(SOURCES))): TARGET_CFLAGS += -marm
184

185
bin/pimpconv$(EXE_EXT): CC = $(HOST_CXX) # make sure we use the c++ compiler for this
Erik Faye-Lund's avatar
Erik Faye-Lund committed
186
bin/pimpconv$(EXE_EXT): $(call make-host-objs, $(PIMPCONV_SOURCES))
187
	$(QUIET_LINK)$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) $(OUTPUT_OPTION)
188

Erik Faye-Lund's avatar
Erik Faye-Lund committed
189
lib/libpimp_gba.a: $(OBJS)
190
	$(QUIET_AR)$(TARGET_AR) $(ARFLAGS) $@ $?
191

Erik Faye-Lund's avatar
Erik Faye-Lund committed
192
193
194
195
# Override CC for target-builds
$(TARGET_BUILD_DIR)/%.o: CC = $(TARGET_CC)
$(TARGET_BUILD_DIR)/%.o: CPPFLAGS += $(TARGET_CPPFLAGS)
$(TARGET_BUILD_DIR)/%.o: CFLAGS += $(TARGET_CFLAGS)
Erik Faye-Lund's avatar
Erik Faye-Lund committed
196
$(TARGET_BUILD_DIR)/%.o: ASFLAGS += $(TARGET_ASFLAGS)
Erik Faye-Lund's avatar
Erik Faye-Lund committed
197

198
# Override CC for host-builds
Erik Faye-Lund's avatar
Erik Faye-Lund committed
199
200
201
202
203
$(HOST_BUILD_DIR)/%.o: CFLAGS += $(HOST_CFLAGS)
$(HOST_BUILD_DIR)/%.o: CXXFLAGS += $(HOST_CXXFLAGS)
bin/pimpconv$(EXE_EXT): CC = $(CXX)
bin/pimpconv$(EXE_EXT): LDFLAGS += $(HOST_LDFLAGS) -lstdc++

204
### C
Erik Faye-Lund's avatar
Erik Faye-Lund committed
205

Erik Faye-Lund's avatar
Erik Faye-Lund committed
206
$(TARGET_BUILD_DIR)/%.iwram.o: %.c
207
	@$(MKDIR) $(dir $@)
208
	$(QUIET_CC)$(COMPILE.c) $(OUTPUT_OPTION) $< -MMD -MP -MF $(@:.o=.d)
209

Erik Faye-Lund's avatar
Erik Faye-Lund committed
210
$(TARGET_BUILD_DIR)/%.o: %.c
211
	@$(MKDIR) $(dir $@)
212
	$(QUIET_CC)$(COMPILE.c) $(OUTPUT_OPTION) $< -MMD -MP -MF $(@:.o=.d)
213

Erik Faye-Lund's avatar
Erik Faye-Lund committed
214
$(HOST_BUILD_DIR)/%.o: %.c
215
	@$(MKDIR) $(dir $@)
216
	$(QUIET_CC)$(COMPILE.c) $(OUTPUT_OPTION) $< -MMD -MP -MF $(@:.o=.d)
Erik Faye-Lund's avatar
Erik Faye-Lund committed
217
218

### C++
219

Erik Faye-Lund's avatar
Erik Faye-Lund committed
220
221
$(HOST_BUILD_DIR)/%.o: %.cpp
	@$(MKDIR) $(dir $@)
222
	$(QUIET_CXX)$(COMPILE.cpp) $(OUTPUT_OPTION) $< -MMD -MP -MF $(@:.o=.d)
Erik Faye-Lund's avatar
Erik Faye-Lund committed
223

224
225
### ASM

Erik Faye-Lund's avatar
Erik Faye-Lund committed
226
$(TARGET_BUILD_DIR)/%.o: %.S
227
	@$(MKDIR) $(dir $@)
Erik Faye-Lund's avatar
Erik Faye-Lund committed
228
	$(QUIET_AS)$(COMPILE.S) $(OUTPUT_OPTION) $< -MMD -MP -MF $(@:.o=.d)
229
230

# deps
Erik Faye-Lund's avatar
Erik Faye-Lund committed
231
232
-include $(call make-target-deps, $(SOURCES))
-include $(call make-host-deps, $(PIMPCONV_SOURCES))