Makefile 5.91 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
ifneq ($(strip $(DEVKITPRO)),)
18
DEVKITARM = $(DEVKITPRO)/devkitARM
Erik Faye-Lund's avatar
Erik Faye-Lund committed
19
export PATH := $(DEVKITARM)/bin:$(PATH)
20
endif
Erik Faye-Lund's avatar
Erik Faye-Lund committed
21

Erik Faye-Lund's avatar
Erik Faye-Lund committed
22
ifdef COMSPEC
Erik Faye-Lund's avatar
Erik Faye-Lund committed
23
EXE_EXT = .exe
Erik Faye-Lund's avatar
Erik Faye-Lund committed
24
else
Erik Faye-Lund's avatar
Erik Faye-Lund committed
25
EXE_EXT =
Erik Faye-Lund's avatar
Erik Faye-Lund committed
26
27
endif

Erik Faye-Lund's avatar
Erik Faye-Lund committed
28
ifeq ($(TARGET), arm-gba)
29
TARGET_PREFIX ?= arm-none-eabi-
Erik Faye-Lund's avatar
Erik Faye-Lund committed
30
else
Erik Faye-Lund's avatar
Erik Faye-Lund committed
31
TARGET_PREFIX = $(TARGET)
Erik Faye-Lund's avatar
Erik Faye-Lund committed
32
33
endif

34
define setup-gcc
Erik Faye-Lund's avatar
Erik Faye-Lund committed
35
36
37
38
39
40
	$(1)CC    = $(2)gcc
	$(1)CXX   = $(2)g++
	$(1)STRIP = $(2)strip
	$(1)LD    = $(2)ld
	$(1)AS    = $(2)as
	$(1)AR    = $(2)ar
41
42
endef

43
define setup-armcc
Erik Faye-Lund's avatar
Erik Faye-Lund committed
44
45
46
47
48
49
	$(1)CC    = armcc
	$(1)CXX   = armcpp
	$(1)STRIP = strip
	$(1)LD    = armlink
	$(1)AS    = armasm
	$(1)AR    = armar
50
51
endef

52
53
54
ifdef USE_ARMCC
$(eval $(call setup-armcc,TARGET_))
else
Erik Faye-Lund's avatar
Erik Faye-Lund committed
55
$(eval $(call setup-gcc,TARGET_, $(TARGET_PREFIX)))
56
57
endif

Erik Faye-Lund's avatar
Erik Faye-Lund committed
58
$(eval $(call setup-gcc,,))
59

Erik Faye-Lund's avatar
Erik Faye-Lund committed
60
ifneq ($(findstring $(MAKEFLAGS),s),s)
Erik Faye-Lund's avatar
Erik Faye-Lund committed
61
62
63
64
65
	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
66
endif
67

68
69
MKDIR = mkdir -p

70
ifeq ($(TARGET), arm-gba)
Erik Faye-Lund's avatar
Erik Faye-Lund committed
71
	TARGET_CPPFLAGS = -I$(DEVKITARM)/include -DTARGET_GBA
72
73
74
75
76
	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
77

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

ARM   = -marm
THUMB = -mthumb

Erik Faye-Lund's avatar
Erik Faye-Lund committed
88
SOURCES = \
Erik Faye-Lund's avatar
Erik Faye-Lund committed
89
90
91
92
93
	src/pimp_render.c      \
	src/pimp_envelope.c    \
	src/pimp_mod_context.c \
	src/pimp_math.c        \
	src/pimp_mixer.c
94

95
96
97
98
ifeq ($(TARGET), arm-gba)
	SOURCES += src/pimp_gba.c
endif

Erik Faye-Lund's avatar
Erik Faye-Lund committed
99
ARM_SOURCES = \
Erik Faye-Lund's avatar
Erik Faye-Lund committed
100
101
	src/pimp_math.c \
	src/pimp_mixer.c
Erik Faye-Lund's avatar
Erik Faye-Lund committed
102

103
PIMPCONV_SOURCES = \
Erik Faye-Lund's avatar
Erik Faye-Lund committed
104
105
106
107
	converter/pimpconv.c \
	converter/serializer.cpp \
	converter/serialize_module.c \
	converter/serialize_instrument.c \
108
	src/convert_sample.c \
Erik Faye-Lund's avatar
Erik Faye-Lund committed
109
	src/load_xm.c \
Erik Faye-Lund's avatar
Erik Faye-Lund committed
110
	src/load_mod.c \
Erik Faye-Lund's avatar
Erik Faye-Lund committed
111
	src/pimp_sample_bank.c
Erik Faye-Lund's avatar
Erik Faye-Lund committed
112

113
ifeq ($(CONFIG), debug)
114
	CPPFLAGS += -DDEBUG
115
116
	CXXFLAGS += -g -ggdb
	CFLAGS   += -g -ggdb
Erik Faye-Lund's avatar
Erik Faye-Lund committed
117
118
	SOURCES  += src/pimp_mixer_portable.c
	SOURCES  += src/pimp_debug.c
119
120
121
122
else
	CPPFLAGS += -DRELEASE -DNDEBUG
	CXXFLAGS += -O3 -fomit-frame-pointer
	CFLAGS   += -O3 -fomit-frame-pointer
Erik Faye-Lund's avatar
Erik Faye-Lund committed
123
124
	SOURCES  += src/pimp_mixer_arm.S
	SOURCES  += src/pimp_mixer_clip_arm.S
125
126
127
endif

ifeq ($(PROFILING), 1)
Erik Faye-Lund's avatar
Erik Faye-Lund committed
128
	CFLAGS   += -finstrument-functions
129
	CXXFLAGS += -finstrument-functions
Erik Faye-Lund's avatar
Erik Faye-Lund committed
130
	SOURCES  += profiling/cyg-profile.c
131
132
endif

133
134
TARGET_BUILD_DIR = $(BUILD_DIR)/$(TARGET)/$(CONFIG)
HOST_BUILD_DIR = $(BUILD_DIR)/$(HOST)/$(CONFIG)
Erik Faye-Lund's avatar
Erik Faye-Lund committed
135

Erik Faye-Lund's avatar
Erik Faye-Lund committed
136
source-to-object = \
Erik Faye-Lund's avatar
Erik Faye-Lund committed
137
138
139
140
141
142
143
144
	$(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
145
146

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

Erik Faye-Lund's avatar
Erik Faye-Lund committed
149
150
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
151

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

154
.PHONY: all clean check check-syntax examples
155

Erik Faye-Lund's avatar
Erik Faye-Lund committed
156
all: lib/libpimp_gba.a bin/pimpconv$(EXE_EXT)
157
158

clean:
Erik Faye-Lund's avatar
Erik Faye-Lund committed
159
	$(RM) lib/libpimp_gba.a $(call make-target-objs, $(SOURCES)) $(call make-target-deps, $(SOURCES))
Erik Faye-Lund's avatar
Erik Faye-Lund committed
160
	$(RM) bin/pimpconv$(EXE_EXT) $(call make-host-objs, $(PIMPCONV_SOURCES)) $(call make-host-deps, $(PIMPCONV_SOURCES))
161
	$(MAKE) -C examples clean
Erik Faye-Lund's avatar
Erik Faye-Lund committed
162

Erik Faye-Lund's avatar
Erik Faye-Lund committed
163
distclean:
Erik Faye-Lund's avatar
Erik Faye-Lund committed
164
	$(RM) -r $(BUILD_DIR)
165

Erik Faye-Lund's avatar
Erik Faye-Lund committed
166
check:
Erik Faye-Lund's avatar
Erik Faye-Lund committed
167
	$(MAKE) -C t run
Erik Faye-Lund's avatar
Erik Faye-Lund committed
168
169

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

172
173
174
examples: lib/libpimp_gba.a bin/pimpconv$(EXE_EXT)
	$(MAKE) -C examples

Erik Faye-Lund's avatar
Erik Faye-Lund committed
175
176
177
TAGS:
	$(CTAGS) $(filter %.c,$(SOURCES))

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

181
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
182
bin/pimpconv$(EXE_EXT): $(call make-host-objs, $(PIMPCONV_SOURCES))
183
	$(QUIET_LINK)$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) $(OUTPUT_OPTION)
184

Erik Faye-Lund's avatar
Erik Faye-Lund committed
185
lib/libpimp_gba.a: $(OBJS)
186
	$(QUIET_AR)$(TARGET_AR) $(ARFLAGS) $@ $?
187

Erik Faye-Lund's avatar
Erik Faye-Lund committed
188
189
190
191
# 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
192
$(TARGET_BUILD_DIR)/%.o: ASFLAGS += $(TARGET_ASFLAGS)
Erik Faye-Lund's avatar
Erik Faye-Lund committed
193

194
# Override CC for host-builds
Erik Faye-Lund's avatar
Erik Faye-Lund committed
195
196
197
198
199
$(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++

200
### C
Erik Faye-Lund's avatar
Erik Faye-Lund committed
201

Erik Faye-Lund's avatar
Erik Faye-Lund committed
202
$(TARGET_BUILD_DIR)/%.iwram.o: %.c
203
	@$(MKDIR) $(dir $@)
204
	$(QUIET_CC)$(COMPILE.c) $(OUTPUT_OPTION) $< -MMD -MP -MF $(@:.o=.d)
205

Erik Faye-Lund's avatar
Erik Faye-Lund committed
206
$(TARGET_BUILD_DIR)/%.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
$(HOST_BUILD_DIR)/%.o: %.c
211
	@$(MKDIR) $(dir $@)
212
	$(QUIET_CC)$(COMPILE.c) $(OUTPUT_OPTION) $< -MMD -MP -MF $(@:.o=.d)
Erik Faye-Lund's avatar
Erik Faye-Lund committed
213
214

### C++
215

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

220
221
### ASM

Erik Faye-Lund's avatar
Erik Faye-Lund committed
222
$(TARGET_BUILD_DIR)/%.o: %.S
223
	@$(MKDIR) $(dir $@)
Erik Faye-Lund's avatar
Erik Faye-Lund committed
224
	$(QUIET_AS)$(COMPILE.S) $(OUTPUT_OPTION) $< -MMD -MP -MF $(@:.o=.d)
225
226

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