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
29
30
ifeq ($(TARGET), arm-gba)
TARGET_PREFIX ?= arm-eabi-
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

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

91
92
93
ARM   = -marm
THUMB = -mthumb

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

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

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

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

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

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

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

Erik Faye-Lund's avatar
Erik Faye-Lund committed
142
source-to-object = \
Erik Faye-Lund's avatar
Erik Faye-Lund committed
143
144
145
146
147
148
149
150
	$(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
151
152

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

Erik Faye-Lund's avatar
Erik Faye-Lund committed
155
156
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
157

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

Erik Faye-Lund's avatar
Erik Faye-Lund committed
160
.PHONY: all clean check check-syntax
161

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

clean:
Erik Faye-Lund's avatar
Erik Faye-Lund committed
165
	$(RM) lib/libpimp_gba.a $(call make-target-objs, $(SOURCES)) $(call make-target-deps, $(SOURCES))
Erik Faye-Lund's avatar
Erik Faye-Lund committed
166
	$(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
167

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

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

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

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

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

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

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

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

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

202
### C
Erik Faye-Lund's avatar
Erik Faye-Lund committed
203

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

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

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

### C++
217

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

222
223
### ASM

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

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