blob: fca37aa763f5e1067536a5ce922210149b7169a9 [file] [log] [blame]
Björn Stenbergc6b3d382008-11-20 11:27:31 +00001# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
Björn Stenberga091d202008-11-25 19:54:23 +00007# $Id$
Björn Stenbergc6b3d382008-11-20 11:27:31 +00008#
9
10# single-file plugins:
Thomas Jarosche3a3e2c2011-02-24 23:35:16 +000011is_app_build =
12ifdef APP_TYPE
13ifneq ($(APP_TYPE),sdl-sim)
14 is_app_build = yes
15endif
16endif
17
18ifdef is_app_build
19PLUGINS_SRC = $(call preprocess, $(APPSDIR)/plugins/SOURCES.app_build)
20else
Björn Stenbergc6b3d382008-11-20 11:27:31 +000021PLUGINS_SRC = $(call preprocess, $(APPSDIR)/plugins/SOURCES)
Thomas Jarosche3a3e2c2011-02-24 23:35:16 +000022endif
Björn Stenbergc6b3d382008-11-20 11:27:31 +000023OTHER_SRC += $(PLUGINS_SRC)
Jens Arnoldf82c9442009-03-04 23:41:58 +000024ROCKS1 := $(PLUGINS_SRC:.c=.rock)
25ROCKS1 := $(subst $(ROOTDIR),$(BUILDDIR),$(ROCKS1))
26
27ROCKS := $(ROCKS1)
Björn Stenbergc6b3d382008-11-20 11:27:31 +000028
Maurus Cuelenaere21bca652009-10-28 22:48:22 +000029ROCKS1 := $(ROCKS1:%.lua=)
30
Björn Stenbergc6b3d382008-11-20 11:27:31 +000031# libplugin.a
32PLUGINLIB := $(BUILDDIR)/apps/plugins/libplugin.a
33PLUGINLIB_SRC = $(call preprocess, $(APPSDIR)/plugins/lib/SOURCES)
34OTHER_SRC += $(PLUGINLIB_SRC)
35
36PLUGINLIB_OBJ := $(PLUGINLIB_SRC:.c=.o)
37PLUGINLIB_OBJ := $(PLUGINLIB_OBJ:.S=.o)
38PLUGINLIB_OBJ := $(subst $(ROOTDIR),$(BUILDDIR),$(PLUGINLIB_OBJ))
39
Jens Arnoldc21e2e62009-03-02 00:16:44 +000040### build data / rules
Thomas Martitz57613ea2010-07-10 13:49:49 +000041ifndef APP_TYPE
Rafaël Carréa9e2a712010-01-24 15:32:23 +000042CONFIGFILE := $(FIRMDIR)/export/config/$(MODELNAME).h
Jens Arnoldc21e2e62009-03-02 00:16:44 +000043PLUGIN_LDS := $(APPSDIR)/plugins/plugin.lds
44PLUGINLINK_LDS := $(BUILDDIR)/apps/plugins/plugin.link
45OVERLAYREF_LDS := $(BUILDDIR)/apps/plugins/overlay_ref.link
46endif
Teruaki Kawashima2edeb562010-10-17 11:40:39 +000047OTHER_SRC += $(ROOTDIR)/apps/plugins/plugin_crt0.c
Thomas Martitzcae4ae22010-08-24 14:30:46 +000048PLUGIN_CRT0 := $(BUILDDIR)/apps/plugins/plugin_crt0.o
Björn Stenbergc6b3d382008-11-20 11:27:31 +000049# multifile plugins (subdirs):
Thomas Jarosche3a3e2c2011-02-24 23:35:16 +000050ifdef is_app_build
51PLUGINSUBDIRS := $(call preprocess, $(APPSDIR)/plugins/SUBDIRS.app_build)
52else
Björn Stenbergc6b3d382008-11-20 11:27:31 +000053PLUGINSUBDIRS := $(call preprocess, $(APPSDIR)/plugins/SUBDIRS)
Thomas Jarosche3a3e2c2011-02-24 23:35:16 +000054endif
Björn Stenbergc6b3d382008-11-20 11:27:31 +000055
56# include <dir>.make from each subdir (yay!)
57$(foreach dir,$(PLUGINSUBDIRS),$(eval include $(dir)/$(notdir $(dir)).make))
58
Björn Stenberg52320b82009-01-12 21:56:46 +000059OTHER_INC += -I$(APPSDIR)/plugins -I$(APPSDIR)/plugins/lib
Björn Stenbergc6b3d382008-11-20 11:27:31 +000060
61# special compile flags for plugins:
Jens Arnoldc21e2e62009-03-02 00:16:44 +000062PLUGINFLAGS = -I$(APPSDIR)/plugins -DPLUGIN $(CFLAGS)
Björn Stenbergc6b3d382008-11-20 11:27:31 +000063
Jens Arnoldf82c9442009-03-04 23:41:58 +000064# single-file plugins depend on their respective .o
65$(ROCKS1): $(BUILDDIR)/%.rock: $(BUILDDIR)/%.o
66
67# dependency for all plugins
Thomas Martitzcae4ae22010-08-24 14:30:46 +000068$(ROCKS): $(APPSDIR)/plugin.h $(PLUGINLINK_LDS) $(PLUGINLIB) $(PLUGINBITMAPLIB) $(PLUGIN_CRT0) $(LIBSETJMP)
Björn Stenbergc6b3d382008-11-20 11:27:31 +000069
70$(PLUGINLIB): $(PLUGINLIB_OBJ)
Björn Stenberg303b4552008-11-20 16:49:55 +000071 $(SILENT)$(shell rm -f $@)
Jens Arnold6421f942009-03-01 09:04:15 +000072 $(call PRINTS,AR $(@F))$(AR) rcs $@ $^ >/dev/null
Björn Stenbergc6b3d382008-11-20 11:27:31 +000073
Rafaël Carréa9e2a712010-01-24 15:32:23 +000074$(PLUGINLINK_LDS): $(PLUGIN_LDS) $(CONFIGFILE)
Björn Stenbergc6b3d382008-11-20 11:27:31 +000075 $(call PRINTS,PP $(@F))
Björn Stenberg7167a7a2008-11-20 16:07:01 +000076 $(shell mkdir -p $(dir $@))
Björn Stenbergc6b3d382008-11-20 11:27:31 +000077 $(call preprocess2file,$<,$@,-DLOADADDRESS=$(LOADADDRESS))
78
Jens Arnoldc21e2e62009-03-02 00:16:44 +000079$(OVERLAYREF_LDS): $(PLUGIN_LDS)
80 $(call PRINTS,PP $(@F))
81 $(shell mkdir -p $(dir $@))
82 $(call preprocess2file,$<,$@,-DOVERLAY_OFFSET=0)
83
Björn Stenbergc6b3d382008-11-20 11:27:31 +000084$(BUILDDIR)/credits.raw credits.raw: $(DOCSDIR)/CREDITS
85 $(call PRINTS,Create credits.raw)perl $(APPSDIR)/plugins/credits.pl < $< > $(BUILDDIR)/$(@F)
86
87# special dependencies
Jens Arnoldc21e2e62009-03-02 00:16:44 +000088$(BUILDDIR)/apps/plugins/wav2wv.rock: $(BUILDDIR)/apps/codecs/libwavpack.a $(PLUGINLIB)
Björn Stenbergc6b3d382008-11-20 11:27:31 +000089
Andree Buschmann6a989b82011-09-07 19:21:57 +000090# Do not use '-ffunction-sections' and '-fdata-sections' when compiling sdl-sim
91ifeq ($(findstring sdl-sim, $(APP_TYPE)), sdl-sim)
92 PLUGINLIBFLAGS = $(PLUGINFLAGS)
93else
94 PLUGINLIBFLAGS = $(PLUGINFLAGS) -ffunction-sections -fdata-sections
95endif
96
Jens Arnoldf42b9342009-03-03 08:28:50 +000097# special pattern rule for compiling plugin lib (with function and data sections)
Björn Stenbergc6b3d382008-11-20 11:27:31 +000098$(BUILDDIR)/apps/plugins/lib/%.o: $(ROOTDIR)/apps/plugins/lib/%.c
99 $(SILENT)mkdir -p $(dir $@)
Andree Buschmann6a989b82011-09-07 19:21:57 +0000100 $(call PRINTS,CC $(subst $(ROOTDIR)/,,$<))$(CC) -I$(dir $<) $(PLUGINLIBFLAGS) -c $< -o $@
Björn Stenbergc6b3d382008-11-20 11:27:31 +0000101
102# special pattern rule for compiling plugins with extra flags
Teruaki Kawashimae3fc65c2010-01-17 13:03:10 +0000103$(BUILDDIR)/apps/plugins/%.o: $(ROOTDIR)/apps/plugins/%.c
Björn Stenbergc6b3d382008-11-20 11:27:31 +0000104 $(SILENT)mkdir -p $(dir $@)
105 $(call PRINTS,CC $(subst $(ROOTDIR)/,,$<))$(CC) -I$(dir $<) $(PLUGINFLAGS) -c $< -o $@
106
Thomas Martitz57613ea2010-07-10 13:49:49 +0000107ifdef APP_TYPE
Nils Wallménius331b23d2011-06-07 11:56:23 +0000108 PLUGINLDFLAGS = $(SHARED_LDFLAG) # <-- from Makefile
109 PLUGINFLAGS += $(SHARED_CFLAGS) # <-- from Makefile
Björn Stenbergc6b3d382008-11-20 11:27:31 +0000110else
111 PLUGINLDFLAGS = -T$(PLUGINLINK_LDS) -Wl,--gc-sections -Wl,-Map,$*.map
Jens Arnoldc21e2e62009-03-02 00:16:44 +0000112 OVERLAYLDFLAGS = -T$(OVERLAYREF_LDS) -Wl,--gc-sections -Wl,-Map,$*.refmap
Björn Stenbergc6b3d382008-11-20 11:27:31 +0000113endif
Frank Gevaertsb8286d42010-07-03 20:58:22 +0000114PLUGINLDFLAGS += $(GLOBAL_LDOPTS)
Björn Stenbergc6b3d382008-11-20 11:27:31 +0000115
Thomas Martitzcae4ae22010-08-24 14:30:46 +0000116$(BUILDDIR)/%.rock:
Björn Stenbergc6b3d382008-11-20 11:27:31 +0000117 $(call PRINTS,LD $(@F))$(CC) $(PLUGINFLAGS) -o $(BUILDDIR)/$*.elf \
118 $(filter %.o, $^) \
Jens Arnoldc21e2e62009-03-02 00:16:44 +0000119 $(filter %.a, $+) \
Björn Stenbergc6b3d382008-11-20 11:27:31 +0000120 -lgcc $(PLUGINLDFLAGS)
Thomas Martitz0bc64a62012-01-03 21:15:11 +0000121ifndef APP_TYPE
122 $(SILENT)$(OC) -O binary $(BUILDDIR)/$*.elf $@ # objcopy native
123else ifeq (,$(findstring sdl-sim,$(APP_TYPE)))
124 $(SILENT)$(OC) -S -x $(BUILDDIR)/$*.elf $@ # objcopy hosted
Björn Stenberg838c74f2008-11-20 12:09:36 +0000125else
Thomas Martitz0bc64a62012-01-03 21:15:11 +0000126 $(SILENT)cp $(BUILDDIR)/$*.elf $@ # no objcopy, keep debug symbols
Jens Arnoldc21e2e62009-03-02 00:16:44 +0000127endif
128
Maurus Cuelenaere21bca652009-10-28 22:48:22 +0000129$(BUILDDIR)/apps/plugins/%.lua: $(ROOTDIR)/apps/plugins/%.lua
130 $(call PRINTS,CP $(subst $(ROOTDIR)/,,$<))cp $< $(BUILDDIR)/apps/plugins/
131
Thomas Martitzcae4ae22010-08-24 14:30:46 +0000132$(BUILDDIR)/%.refmap: $(APPSDIR)/plugin.h $(OVERLAYREF_LDS) $(PLUGINLIB) $(PLUGINBITMAPLIB) $(LIBSETJMP) $(PLUGIN_CRT0)
Jens Arnoldc21e2e62009-03-02 00:16:44 +0000133 $(call PRINTS,LD $(@F))$(CC) $(PLUGINFLAGS) -o /dev/null \
134 $(filter %.o, $^) \
Jens Arnold6436b392009-03-02 08:16:36 +0000135 $(filter %.a, $+) \
Jens Arnoldc21e2e62009-03-02 00:16:44 +0000136 -lgcc $(OVERLAYLDFLAGS)