Make fixepoint.c as a shared library (libfixedpoint.a).

Change-Id: Icc10d6e85f890c432f191233a4d64e09f00be43d
Reviewed-on: http://gerrit.rockbox.org/456
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested-by: Michael Sevakis <jethead71@rockbox.org>
diff --git a/apps/SOURCES b/apps/SOURCES
index 6005460..e8944d5 100644
--- a/apps/SOURCES
+++ b/apps/SOURCES
@@ -163,7 +163,6 @@
 #if INPUT_SRC_CAPS != 0
 audio_path.c
 #endif /* INPUT_SRC_CAPS != 0 */
-fixedpoint.c
 pcmbuf.c
 codec_thread.c
 playback.c
diff --git a/apps/plugins/bounce.c b/apps/plugins/bounce.c
index ece8440..9e0ae7b 100644
--- a/apps/plugins/bounce.c
+++ b/apps/plugins/bounce.c
@@ -20,7 +20,7 @@
  **************************************************************************/
 #include "plugin.h"
 #include "time.h"
-#include "lib/fixedpoint.h"
+#include "fixedpoint.h"
 #include "lib/pluginlib_actions.h"
 
 
diff --git a/apps/plugins/bubbles.c b/apps/plugins/bubbles.c
index eef4f4d..e796afd 100644
--- a/apps/plugins/bubbles.c
+++ b/apps/plugins/bubbles.c
@@ -22,10 +22,10 @@
 ****************************************************************************/
 
 #include "plugin.h"
+#include "fixedpoint.h"
 
 #include "lib/xlcd.h"
 #include "lib/pluginlib_actions.h"
-#include "lib/fixedpoint.h"
 #include "lib/playback_control.h"
 #include "lib/highscore.h"
 
diff --git a/apps/plugins/clock/clock_draw_analog.c b/apps/plugins/clock/clock_draw_analog.c
index bda7241..62ada08 100644
--- a/apps/plugins/clock/clock_draw_analog.c
+++ b/apps/plugins/clock/clock_draw_analog.c
@@ -19,9 +19,9 @@
  *
  ****************************************************************************/
 
+#include "fixedpoint.h"
 #include "clock_draw_analog.h"
 #include "lib/xlcd.h"
-#include "lib/fixedpoint.h"
 #include "clock_bitmaps.h"
 #include "clock_bitmap_strings.h"
 
diff --git a/apps/plugins/cube.c b/apps/plugins/cube.c
index b6031af..34252e8 100644
--- a/apps/plugins/cube.c
+++ b/apps/plugins/cube.c
@@ -21,6 +21,7 @@
 *
 ***************************************************************************/
 #include "plugin.h"
+#include "fixedpoint.h"
 #include "lib/playergfx.h"
 #include "lib/pluginlib_exit.h"
 #if LCD_DEPTH > 1
@@ -31,7 +32,6 @@
 #include "lib/mylcd.h" /* MYLCD_CFG_GREYLIB or MYLCD_CFG_PGFX */
 #endif
 #include "lib/xlcd.h"
-#include "lib/fixedpoint.h"
 
 /* Loops that the values are displayed */
 #define DISP_TIME 30
diff --git a/apps/plugins/fft/math.h b/apps/plugins/fft/math.h
index ffacf1e..5545c49 100644
--- a/apps/plugins/fft/math.h
+++ b/apps/plugins/fft/math.h
@@ -3,7 +3,7 @@
 
 #include <inttypes.h>
 #include <math.h>
-#include "lib/fixedpoint.h"
+#include "fixedpoint.h"
 
 #define Q_MUL(a, b, bits) (( (int64_t) (a) * (int64_t) (b) ) >> (bits))
 #define Q15_MUL(a, b) Q_MUL(a,b,15)
diff --git a/apps/plugins/fire.c b/apps/plugins/fire.c
index 5813894..478296b 100644
--- a/apps/plugins/fire.c
+++ b/apps/plugins/fire.c
@@ -22,10 +22,10 @@
 ****************************************************************************/
 
 #include "plugin.h"
+#include "fixedpoint.h"
 #include "lib/helper.h"
 
 #include "lib/pluginlib_actions.h"
-#include "lib/fixedpoint.h"
 
 #ifndef HAVE_LCD_COLOR
 #include "lib/grey.h"
diff --git a/apps/plugins/lib/SOURCES b/apps/plugins/lib/SOURCES
index d49605f..0a125db 100644
--- a/apps/plugins/lib/SOURCES
+++ b/apps/plugins/lib/SOURCES
@@ -4,7 +4,6 @@
 md5.c
 jhash.c
 configfile.c
-fixedpoint.c
 playback_control.c
 rgb_hsv.c
 highscore.c
diff --git a/apps/plugins/lib/fixedpoint.c b/apps/plugins/lib/fixedpoint.c
deleted file mode 100644
index 352e246..0000000
--- a/apps/plugins/lib/fixedpoint.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../../fixedpoint.c"
diff --git a/apps/plugins/lib/fixedpoint.h b/apps/plugins/lib/fixedpoint.h
deleted file mode 100644
index 811a1d9..0000000
--- a/apps/plugins/lib/fixedpoint.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/***************************************************************************
- *             __________               __   ___.
- *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
- *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
- *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
- *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
- *                     \/            \/     \/    \/            \/
- * $Id$
- *
- * Copyright (C) 2006 Jens Arnold
- *
- * Fixed point library for plugins
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#ifndef _FIXEDPOINT_H_PLUGINS
-#define _FIXEDPOINT_H_PLUGINS
-#include "../../../firmware/include/fixedpoint.h"
-#endif /* _FIXEDPOINT_H_PLUGINS */
diff --git a/apps/plugins/oscilloscope.c b/apps/plugins/oscilloscope.c
index 13cc359..a4ec6a8 100644
--- a/apps/plugins/oscilloscope.c
+++ b/apps/plugins/oscilloscope.c
@@ -22,13 +22,11 @@
 ****************************************************************************/
 
 #include "plugin.h"
+#include "fixedpoint.h"
 #include "lib/helper.h"
 #include "lib/pluginlib_exit.h"
-
 #include "lib/xlcd.h"
 #include "lib/configfile.h"
-#include "fixedpoint.h"
-#include "lib/fixedpoint.h"
 #include "lib/osd.h"
 
 /* variable button definitions */
diff --git a/apps/plugins/plasma.c b/apps/plugins/plasma.c
index 88afb85..5b2b3ae 100644
--- a/apps/plugins/plasma.c
+++ b/apps/plugins/plasma.c
@@ -25,6 +25,7 @@
 ****************************************************************************/
 
 #include "plugin.h"
+#include "fixedpoint.h"
 #include "lib/helper.h"
 #include "lib/pluginlib_actions.h"
 #include "lib/pluginlib_exit.h"
@@ -32,7 +33,6 @@
 #ifndef HAVE_LCD_COLOR
 #include "lib/grey.h"
 #endif
-#include "lib/fixedpoint.h"
 
 
 /******************************* Globals ***********************************/
diff --git a/apps/plugins/plugins.make b/apps/plugins/plugins.make
index 0fc8ba7..92769d7 100644
--- a/apps/plugins/plugins.make
+++ b/apps/plugins/plugins.make
@@ -53,7 +53,7 @@
 PLUGINSUBDIRS := $(call preprocess, $(APPSDIR)/plugins/SUBDIRS)
 endif
 
-PLUGIN_LIBS := $(PLUGINLIB) $(PLUGINBITMAPLIB) $(SETJMPLIB)
+PLUGIN_LIBS := $(PLUGINLIB) $(PLUGINBITMAPLIB) $(SETJMPLIB) $(FIXEDPOINTLIB)
 
 # include <dir>.make from each subdir (yay!)
 $(foreach dir,$(PLUGINSUBDIRS),$(eval include $(dir)/$(notdir $(dir)).make))
diff --git a/apps/plugins/vu_meter.c b/apps/plugins/vu_meter.c
index ec88444..107d46b 100644
--- a/apps/plugins/vu_meter.c
+++ b/apps/plugins/vu_meter.c
@@ -18,7 +18,7 @@
  *
  **************************************************************************/
 #include "plugin.h"
-#include "lib/fixedpoint.h"
+#include "fixedpoint.h"
 #include "lib/playback_control.h"
 
 
diff --git a/flash/bootbox/bootbox.make b/flash/bootbox/bootbox.make
index 0c05eec..38a664d 100644
--- a/flash/bootbox/bootbox.make
+++ b/flash/bootbox/bootbox.make
@@ -9,5 +9,7 @@
 
 SRC += $(call preprocess,$(APPSDIR)/SOURCES)
 
+CORE_GCSECTIONS = yes
+
 # don't build rombox.ucl
 ARCHOSROM=
diff --git a/apps/fixedpoint.c b/lib/fixedpoint/fixedpoint.c
similarity index 97%
rename from apps/fixedpoint.c
rename to lib/fixedpoint/fixedpoint.c
index b212929..b5bbe68 100644
--- a/apps/fixedpoint.c
+++ b/lib/fixedpoint/fixedpoint.c
@@ -20,7 +20,6 @@
  * KIND, either express or implied.
  *
  ****************************************************************************/
-
 #include "fixedpoint.h"
 #include <stdlib.h>
 #include <stdbool.h>
@@ -143,8 +142,6 @@
     return y;
 }
 
-
-#if defined(PLUGIN) || defined(CODEC)
 /**
  * Fixed point square root via Newton-Raphson.
  * @param x square root argument.
@@ -207,10 +204,7 @@
 
     return g;
 }
-#endif  /* PLUGIN or CODEC */
 
-
-#if defined(PLUGIN)
 /**
  * Fixed point sinus using a lookup table
  * don't forget to divide the result by 16384 to get the actual sinus value
@@ -325,10 +319,7 @@
 
     return y;
 }
-#endif /* PLUGIN */
 
-
-#if (!defined(PLUGIN) && !defined(CODEC))
 /** MODIFIED FROM replaygain.c */
  
 #define FP_MUL_FRAC(x, y) fp_mul(x, y, fracbits)
@@ -407,12 +398,10 @@
     return FP_MUL_FRAC(k, xp);
 }
 
-
-#if 0   /* useful code, but not currently used */
 /** FIXED POINT LOG10
  * Return log10(x) as FP integer.  Argument is FP integer.
  */
-static long fp_log10(long n, unsigned int fracbits)
+long fp_log10(long n, unsigned int fracbits)
 {
     /* Calculate log2 of argument */
 
@@ -453,15 +442,12 @@
     return FP_MUL_FRAC(log2, (FP28_LOG10OF2 >> (28 - fracbits)));
 }
 
-
 /** CONVERT FACTOR TO DECIBELS */
 long fp_decibels(unsigned long factor, unsigned int fracbits)
 {
     /* decibels = 20 * log10(factor) */
     return FP_MUL_FRAC((20L << fracbits), fp_log10(factor, fracbits));
 }
-#endif  /* unused code */
-
 
 /** CONVERT DECIBELS TO FACTOR */
 long fp_factor(long decibels, unsigned int fracbits)
@@ -469,4 +455,3 @@
     /* factor = 10 ^ (decibels / 20) */
     return fp_exp10(FP_DIV_FRAC(decibels, (20L << fracbits)), fracbits);
 }
-#endif  /* !PLUGIN and !CODEC */
diff --git a/firmware/include/fixedpoint.h b/lib/fixedpoint/fixedpoint.h
similarity index 93%
rename from firmware/include/fixedpoint.h
rename to lib/fixedpoint/fixedpoint.h
index 584bd58..31d60ec 100644
--- a/firmware/include/fixedpoint.h
+++ b/lib/fixedpoint/fixedpoint.h
@@ -107,10 +107,19 @@
  */
 long fp_exp10(long x, unsigned int fracbits);
 
+/** FIXED POINT LOG10
+ * Return log10(x) as FP integer.  Argument is FP integer.
+ */
+long fp_log10(long n, unsigned int fracbits);
+
 /* fracbits in range 12 - 22 work well. Higher is better for
  * calculating dB, lower is better for calculating factor.
  */
-/* long fp_decibels(unsigned long factor, unsigned int fracbits); */
+
+/** CONVERT FACTOR TO DECIBELS */
+long fp_decibels(unsigned long factor, unsigned int fracbits);
+
+/** CONVERT DECIBELS TO FACTOR */
 long fp_factor(long decibels, unsigned int fracbits);
 
 #endif /* FIXEDPOINT_H */
diff --git a/lib/fixedpoint/fixedpoint.make b/lib/fixedpoint/fixedpoint.make
new file mode 100644
index 0000000..9ee0e1f
--- /dev/null
+++ b/lib/fixedpoint/fixedpoint.make
@@ -0,0 +1,36 @@
+#             __________               __   ___.
+#   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+#   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+#   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+#   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+#                     \/            \/     \/    \/            \/
+
+FIXEDPOINTLIB := $(BUILDDIR)/lib/libfixedpoint.a
+FIXEDPOINTLIB_DIR := $(ROOTDIR)/lib/fixedpoint
+FIXEDPOINTLIB_SRC := $(FIXEDPOINTLIB_DIR)/fixedpoint.c
+FIXEDPOINTLIB_OBJ := $(call c2obj, $(FIXEDPOINTLIB_SRC))
+
+INCLUDES += -I$(FIXEDPOINTLIB_DIR)
+OTHER_SRC += $(FIXEDPOINTLIB_SRC)
+
+# If not SOFTWARECODECS, then only plugins depend upon us
+ifdef SOFTWARECODECS
+CORE_LIBS += $(FIXEDPOINTLIB)
+CORE_GCSECTIONS := yes
+endif
+
+FIXEDPOINTLIB_FLAGS := $(CFLAGS)
+
+# Do not use '-ffunction-sections' and '-fdata-sections' when compiling sdl-sim
+ifneq ($(findstring sdl-sim, $(APP_TYPE)), sdl-sim)
+    FIXEDPOINTLIB_FLAGS += -ffunction-sections -fdata-sections
+endif
+
+$(FIXEDPOINTLIB_OBJ): $(FIXEDPOINTLIB_SRC)
+	$(SILENT)mkdir -p $(dir $@)
+	$(call PRINTS,CC $(subst $(ROOTDIR)/,,$<))$(CC) \
+		$(FIXEDPOINTLIB_FLAGS) -c $< -o $@
+
+$(FIXEDPOINTLIB): $(FIXEDPOINTLIB_OBJ)
+	$(SILENT)$(shell rm -f $@)
+	$(call PRINTS,AR $(@F))$(AR) rcs $@ $^ >/dev/null
diff --git a/lib/rbcodec/codecs/adx.c b/lib/rbcodec/codecs/adx.c
index 0c67fc8..83ced5a 100644
--- a/lib/rbcodec/codecs/adx.c
+++ b/lib/rbcodec/codecs/adx.c
@@ -23,7 +23,7 @@
 #include "codeclib.h"
 #include "inttypes.h"
 #include "math.h"
-#include "lib/fixedpoint.h"
+#include "fixedpoint.h"
 
 CODEC_HEADER
 
diff --git a/lib/rbcodec/codecs/codecs.make b/lib/rbcodec/codecs/codecs.make
index eea8950..21bb933 100644
--- a/lib/rbcodec/codecs/codecs.make
+++ b/lib/rbcodec/codecs/codecs.make
@@ -19,7 +19,7 @@
 OTHER_INC += -I$(RBCODECLIB_DIR)/codecs/lib
 
 # extra libraries
-CODEC_LIBS := $(CODECLIB)
+CODEC_LIBS := $(CODECLIB) $(FIXEDPOINTLIB)
 
 # the codec libraries
 include $(RBCODECLIB_DIR)/codecs/demac/libdemac.make
diff --git a/lib/rbcodec/codecs/lib/SOURCES b/lib/rbcodec/codecs/lib/SOURCES
index 257dcb5..f4b951a 100644
--- a/lib/rbcodec/codecs/lib/SOURCES
+++ b/lib/rbcodec/codecs/lib/SOURCES
@@ -1,6 +1,5 @@
 #if CONFIG_CODEC == SWCODEC /* software codec platforms */
 codeclib.c
-fixedpoint.c
 ffmpeg_bitstream.c
 
 mdct_lookup.c
diff --git a/lib/rbcodec/codecs/lib/fixedpoint.c b/lib/rbcodec/codecs/lib/fixedpoint.c
deleted file mode 100644
index a66dcb1..0000000
--- a/lib/rbcodec/codecs/lib/fixedpoint.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../../../apps/fixedpoint.c"
diff --git a/lib/rbcodec/codecs/lib/fixedpoint.h b/lib/rbcodec/codecs/lib/fixedpoint.h
deleted file mode 100644
index 3d8e77c..0000000
--- a/lib/rbcodec/codecs/lib/fixedpoint.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/***************************************************************************
- *             __________               __   ___.
- *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
- *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
- *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
- *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
- *                     \/            \/     \/    \/            \/
- * $Id$
- *
- * Copyright (C) 2006 Jens Arnold
- *
- * Fixed point library for codecs
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#ifndef _FIXEDPOINT_H_CODECS
-#define _FIXEDPOINT_H_CODECS
-#include "../../../../firmware/include/fixedpoint.h"
-#endif /* _FIXEDPOINT_H_CODECS */
diff --git a/lib/rbcodec/rbcodec.make b/lib/rbcodec/rbcodec.make
index 7aac57b..bc4e54f 100644
--- a/lib/rbcodec/rbcodec.make
+++ b/lib/rbcodec/rbcodec.make
@@ -15,7 +15,9 @@
 INCLUDES += -I$(RBCODECLIB_DIR) -I$(RBCODECLIB_DIR)/codecs \
 			-I$(RBCODECLIB_DIR)/dsp -I$(RBCODECLIB_DIR)/metadata
 OTHER_SRC += $(RBCODECLIB_SRC)
-CORE_LIBS += $(RBCODECLIB)
+
+# libfixedpoint must go after in lib list but be made first
+CORE_LIBS := $(RBCODECLIB) $(CORE_LIBS)
 
 $(RBCODECLIB): $(RBCODECLIB_OBJ)
 	$(call PRINTS,AR $(@F))$(AR) rcs $@ $^ >/dev/null
diff --git a/lib/rbcodec/test/SOURCES b/lib/rbcodec/test/SOURCES
index a89af23..d1413c7 100644
--- a/lib/rbcodec/test/SOURCES
+++ b/lib/rbcodec/test/SOURCES
@@ -2,5 +2,4 @@
 ../../../firmware/common/strlcpy.c
 ../../../firmware/common/unicode.c
 ../../../firmware/common/structec.c
-../../../apps/fixedpoint.c
 ../../../uisimulator/common/io.c
diff --git a/tools/database/SOURCES b/tools/database/SOURCES
index 9c60fb1..5c9b971 100644
--- a/tools/database/SOURCES
+++ b/tools/database/SOURCES
@@ -1,5 +1,4 @@
 database.c
-../../apps/fixedpoint.c
 ../../apps/misc.c
 ../../apps/tagcache.c
 ../../firmware/common/crc32.c
diff --git a/tools/database/database.make b/tools/database/database.make
index 89a4aa7..8eae492 100644
--- a/tools/database/database.make
+++ b/tools/database/database.make
@@ -35,10 +35,13 @@
             -I$(ROOTDIR)/lib/rbcodec/dsp \
             -I$(APPSDIR) \
             -I$(BUILDDIR)
-
+            
+ifdef SOFTWARECODECS
+OTHERLIBS := $(FIXEDPOINTLIB)
+endif
 
 .SECONDEXPANSION: # $$(OBJ) is not populated until after this
 
-$(BUILDDIR)/$(BINARY): $$(DATABASE_OBJ)
+$(BUILDDIR)/$(BINARY): $$(DATABASE_OBJ) $(OTHERLIBS)
 	$(call PRINTS,LD $(BINARY))
-	$(SILENT)$(HOSTCC) -o $@ $+
+	$(SILENT)$(HOSTCC) $(call a2lnk $(OTHERLIBS)) -o $@ $+
diff --git a/tools/root.make b/tools/root.make
index c2d061b..6d62359 100644
--- a/tools/root.make
+++ b/tools/root.make
@@ -17,6 +17,7 @@
 CFLAGS = $(INCLUDES) $(DEFINES) $(GCCOPTS) 
 PPCFLAGS = $(filter-out -g -Dmain=SDL_main,$(CFLAGS)) # cygwin sdl-config fix
 ASMFLAGS = -D__ASSEMBLER__      # work around gcc 3.4.x bug with -std=gnu99, only meant for .S files
+CORE_LDOPTS = $(GLOBAL_LDOPTS)  # linker ops specifically for core build
 
 TOOLS = $(TOOLSDIR)/rdf2binary $(TOOLSDIR)/convbdf \
 	$(TOOLSDIR)/codepages $(TOOLSDIR)/scramble $(TOOLSDIR)/bmp2rb \
@@ -90,10 +91,15 @@
   endif
 endif
 
+ifeq (,$(findstring bootloader,$(APPSDIR)))
+  ifeq (,$(findstring checkwps,$(APP_TYPE)))
+    include $(ROOTDIR)/lib/fixedpoint/fixedpoint.make
+  endif
+endif
+
 ifneq (,$(findstring bootloader,$(APPSDIR)))
   include $(APPSDIR)/bootloader.make
 else ifneq (,$(findstring bootbox,$(APPSDIR)))
-  BOOTBOXLDOPTS = -Wl,--gc-sections
   include $(APPSDIR)/bootbox.make
 else ifneq (,$(findstring checkwps,$(APP_TYPE)))
   include $(APPSDIR)/checkwps.make
@@ -104,10 +110,10 @@
   include $(ROOTDIR)/lib/rbcodec/test/warble.make
   include $(ROOTDIR)/lib/tlsf/libtlsf.make
   include $(ROOTDIR)/lib/rbcodec/rbcodec.make
-else
+else # core
   include $(APPSDIR)/apps.make
-  include $(ROOTDIR)/lib/rbcodec/rbcodec.make
   include $(APPSDIR)/lang/lang.make
+  include $(ROOTDIR)/lib/rbcodec/rbcodec.make
 
   ifdef ENABLEDPLUGINS
     include $(APPSDIR)/plugins/bitmaps/pluginbitmaps.make
@@ -132,6 +138,14 @@
 
 endif # bootloader
 
+# One or more subdir makefiles requested --gc-sections?
+ifdef CORE_GCSECTIONS
+  # Do not use '--gc-sections' when compiling sdl-sim
+  ifneq ($(findstring sdl-sim, $(APP_TYPE)), sdl-sim)
+    CORE_LDOPTS += -Wl,--gc-sections
+  endif
+endif # CORE_GCSECTIONS
+
 OBJ := $(SRC:.c=.o)
 OBJ := $(OBJ:.S=.o)
 OBJ += $(BMP:.bmp=.o)
@@ -205,16 +219,16 @@
 		-L$(BUILDDIR)/firmware -lfirmware \
 		-L$(RBCODEC_BLD)/codecs $(call a2lnk, $(VOICESPEEXLIB)) \
 		-L$(BUILDDIR)/lib $(call a2lnk, $(CORE_LIBS)) \
-		-lgcc $(BOOTBOXLDOPTS) $(GLOBAL_LDOPTS) \
-		-T$(LINKRAM) -Wl,-Map,$(BUILDDIR)/rockbox.map
+		-lgcc -T$(LINKRAM) \
+		$(CORE_LDOPTS) -Wl,-Map,$(BUILDDIR)/rockbox.map
 
 $(BUILDDIR)/rombox.elf : $$(OBJ) $(FIRMLIB) $(VOICESPEEXLIB) $(CORE_LIBS) $$(LINKROM)
 	$(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -Os -nostdlib -o $@ $(OBJ) \
 		-L$(BUILDDIR)/firmware -lfirmware \
 		-L$(RBCODEC_BLD)/codecs $(call a2lnk, $(VOICESPEEXLIB)) \
 		-L$(BUILDDIR)/lib $(call a2lnk, $(CORE_LIBS)) \
-		-lgcc $(BOOTBOXLDOPTS) $(GLOBAL_LDOPTS) \
-		-T$(LINKROM) -Wl,-Map,$(BUILDDIR)/rombox.map
+		-lgcc -T$(LINKROM) \
+		$(CORE_LDOPTS) -Wl,-Map,$(BUILDDIR)/rombox.map
 
 $(BUILDDIR)/rockbox.bin : $(BUILDDIR)/rockbox.elf
 	$(call PRINTS,OC $(@F))$(call objcopy,$<,$@)