From a30681dff0c896464ebb3de81fcc737c114a6194 Mon Sep 17 00:00:00 2001
From: Felix Fietkau <nbd@openwrt.org>
Date: Thu, 26 Sep 2013 17:53:14 +0000
Subject: [PATCH] build: unify mips target cflags

Signed-off-by: Felix Fietkau <nbd@openwrt.org>

SVN-Revision: 38210
---
 include/target.mk                     | 7 ++++++-
 target/linux/ar71xx/Makefile          | 2 +-
 target/linux/cobalt/Makefile          | 3 ++-
 target/linux/lantiq/Makefile          | 2 +-
 target/linux/lantiq/ase/target.mk     | 1 -
 target/linux/lantiq/falcon/target.mk  | 1 -
 target/linux/lantiq/svip_be/target.mk | 1 -
 target/linux/lantiq/svip_le/target.mk | 1 -
 target/linux/lantiq/xrx200/target.mk  | 3 ++-
 target/linux/lantiq/xway/target.mk    | 3 ++-
 target/linux/malta/be/target.mk       | 1 -
 target/linux/malta/be64/target.mk     | 1 -
 target/linux/malta/le/target.mk       | 1 -
 target/linux/malta/le64/target.mk     | 1 -
 target/linux/octeon/Makefile          | 3 ++-
 target/linux/ramips/Makefile          | 1 -
 target/linux/ramips/mt7620a/target.mk | 3 ++-
 target/linux/ramips/rt288x/target.mk  | 2 +-
 target/linux/ramips/rt305x/target.mk  | 3 ++-
 target/linux/ramips/rt3883/target.mk  | 3 ++-
 target/linux/sibyte/Makefile          | 3 ++-
 21 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/include/target.mk b/include/target.mk
index 685013c73c..f9f378a8d8 100644
--- a/include/target.mk
+++ b/include/target.mk
@@ -204,7 +204,12 @@ ifeq ($(DUMP),1)
     endif
     CPU_CFLAGS += -mno-branch-likely
     CPU_CFLAGS_mips32 = -mips32 -mtune=mips32
+    CPU_CFLAGS_mips32r2 = -mips32r2 -mtune=mips32r2
     CPU_CFLAGS_mips64 = -mips64 -mtune=mips64 -mabi=64
+    CPU_CFLAGS_24kec = -mips32r2 -mtune=24kec
+    CPU_CFLAGS_34kc = -mips32r2 -mtune=34kc
+    CPU_CFLAGS_dsp = -mdsp
+    CPU_CFLAGS_dsp2 = -mdspr2
   endif
   ifeq ($(ARCH),i386)
     CPU_TYPE ?= i486
@@ -218,7 +223,7 @@ ifeq ($(DUMP),1)
     CPU_TYPE = sparc
     CPU_CFLAGS_ultrasparc = -mcpu=ultrasparc
   endif
-  DEFAULT_CFLAGS=$(CPU_CFLAGS) $(CPU_CFLAGS_$(CPU_TYPE))
+  DEFAULT_CFLAGS=$(strip $(CPU_CFLAGS) $(CPU_CFLAGS_$(CPU_TYPE)) $(CPU_CFLAGS_$(CPU_SUBTYPE)))
 endif
 
 define BuildTargets/DumpCurrent
diff --git a/target/linux/ar71xx/Makefile b/target/linux/ar71xx/Makefile
index ba63ded1de..e80cc5961b 100644
--- a/target/linux/ar71xx/Makefile
+++ b/target/linux/ar71xx/Makefile
@@ -10,7 +10,7 @@ ARCH:=mips
 BOARD:=ar71xx
 BOARDNAME:=Atheros AR7xxx/AR9xxx
 FEATURES:=squashfs targz mips16
-CFLAGS:=-Os -pipe -mips32r2 -mtune=34kc -mno-branch-likely
+CPU_TYPE=34kc
 SUBTARGETS:=generic nand
 
 LINUX_VERSION:=3.10.12
diff --git a/target/linux/cobalt/Makefile b/target/linux/cobalt/Makefile
index 632b61c70a..13d3fd05da 100644
--- a/target/linux/cobalt/Makefile
+++ b/target/linux/cobalt/Makefile
@@ -10,7 +10,8 @@ ARCH:=mipsel
 BOARD:=cobalt
 BOARDNAME:=Cobalt Microservers
 FEATURES:=targz pci ext4 display
-CFLAGS:=-O2 -pipe -mtune=r5000
+CPU_TYPE := 5k
+CPU_CFLAGS_5k := -mtune=r5000
 MAINTAINER:=Florian Fainelli <florian@openwrt.org>
 
 LINUX_VERSION:=3.3.8
diff --git a/target/linux/lantiq/Makefile b/target/linux/lantiq/Makefile
index ccb30a1a87..fa98788318 100644
--- a/target/linux/lantiq/Makefile
+++ b/target/linux/lantiq/Makefile
@@ -13,7 +13,7 @@ SUBTARGETS=xway xrx200 ase falcon
 
 LINUX_VERSION:=3.10.12
 
-CFLAGS=-Os -pipe -mips32r2 -mno-branch-likely
+CPU_TYPE:=mips32r2
 
 define Target/Description
 	Build firmware images for Lantiq SoC
diff --git a/target/linux/lantiq/ase/target.mk b/target/linux/lantiq/ase/target.mk
index f1f0c07eb3..a052dd2ce7 100644
--- a/target/linux/lantiq/ase/target.mk
+++ b/target/linux/lantiq/ase/target.mk
@@ -2,7 +2,6 @@ ARCH:=mips
 SUBTARGET:=ase
 BOARDNAME:=Amazon-SE
 FEATURES:=squashfs atm
-CFLAGS+= -mtune=mips32r2
 
 DEFAULT_PACKAGES+=kmod-pppoa ppp-mod-pppoa linux-atm atm-tools br2684ctl kmod-ltq-dsl-ase ltq-dsl-app
 
diff --git a/target/linux/lantiq/falcon/target.mk b/target/linux/lantiq/falcon/target.mk
index b7af20c79c..14ac402473 100644
--- a/target/linux/lantiq/falcon/target.mk
+++ b/target/linux/lantiq/falcon/target.mk
@@ -3,7 +3,6 @@ SUBTARGET:=falcon
 BOARDNAME:=Falcon
 FEATURES:=squashfs
 DEVICE_TYPE:=other
-CFLAGS+= -mtune=mips32r2
 
 DEFAULT_PACKAGES+= kmod-ifxos gpon-base-files kmod-leds-gpio kmod-ledtrig-heartbeat \
 	kmod-gpon-optic-drv gpon-optic-drv kmod-gpon-onu-drv gpon-onu-drv \
diff --git a/target/linux/lantiq/svip_be/target.mk b/target/linux/lantiq/svip_be/target.mk
index ef8eeffa43..7cdd540590 100644
--- a/target/linux/lantiq/svip_be/target.mk
+++ b/target/linux/lantiq/svip_be/target.mk
@@ -3,7 +3,6 @@ SUBTARGET:=svip_be
 BOARDNAME:=SVIP Big Endian
 FEATURES:=squashfs
 DEVICE_TYPE:=other
-CFLAGS+= -mtune=mips32r2
 
 DEFAULT_PACKAGES+= uboot-svip hostapd-mini
 
diff --git a/target/linux/lantiq/svip_le/target.mk b/target/linux/lantiq/svip_le/target.mk
index d2ccdbcfe1..2c1ed07a4e 100644
--- a/target/linux/lantiq/svip_le/target.mk
+++ b/target/linux/lantiq/svip_le/target.mk
@@ -3,7 +3,6 @@ SUBTARGET:=svip_le
 BOARDNAME:=SVIP Little Endian
 FEATURES:=squashfs
 DEVICE_TYPE:=other
-CFLAGS+= -mtune=mips32r2
 
 DEFAULT_PACKAGES+= uboot-svip hostapd-mini
 
diff --git a/target/linux/lantiq/xrx200/target.mk b/target/linux/lantiq/xrx200/target.mk
index 0eb5937212..b0be140057 100644
--- a/target/linux/lantiq/xrx200/target.mk
+++ b/target/linux/lantiq/xrx200/target.mk
@@ -2,7 +2,8 @@ ARCH:=mips
 SUBTARGET:=xrx200
 BOARDNAME:=XRX200
 FEATURES:=squashfs atm mips16
-CFLAGS+= -mtune=34kc -mdsp
+CPU_TYPE:=34kc
+CPU_SUBTYPE:=dsp
 
 DEFAULT_PACKAGES+=kmod-leds-gpio kmod-gpio-button-hotplug
 
diff --git a/target/linux/lantiq/xway/target.mk b/target/linux/lantiq/xway/target.mk
index ffbc4eaefe..3da4638da3 100644
--- a/target/linux/lantiq/xway/target.mk
+++ b/target/linux/lantiq/xway/target.mk
@@ -2,7 +2,8 @@ ARCH:=mips
 SUBTARGET:=xway
 BOARDNAME:=XWAY
 FEATURES:=squashfs atm mips16
-CFLAGS+= -mtune=34kc -mdsp
+CPU_TYPE:=34kc
+CPU_SUBTYPE:=dsp
 
 DEFAULT_PACKAGES+=kmod-leds-gpio kmod-gpio-button-hotplug
 
diff --git a/target/linux/malta/be/target.mk b/target/linux/malta/be/target.mk
index a4a00b7106..92ae58eb9d 100644
--- a/target/linux/malta/be/target.mk
+++ b/target/linux/malta/be/target.mk
@@ -3,7 +3,6 @@ ARCH_PACKAGES:=malta_mips
 SUBTARGET:=be
 BOARDNAME:=Big Endian
 FEATURES:=ramdisk mips16
-CFLAGS:=-Os -pipe -mips32r2 -mtune=mips32r2
 
 define Target/Description
 	Build BE firmware images for MIPS Malta CoreLV board running in
diff --git a/target/linux/malta/be64/target.mk b/target/linux/malta/be64/target.mk
index 88f7d41db2..dad3a1c6c5 100644
--- a/target/linux/malta/be64/target.mk
+++ b/target/linux/malta/be64/target.mk
@@ -3,7 +3,6 @@ ARCH_PACKAGES:=malta_mips64
 SUBTARGET:=be64
 BOARDNAME:=Big Endian (64-bits)
 FEATURES:=ramdisk
-CFLAGS:=-Os -pipe -mips64 -mtune=mips64
 
 define Target/Description
 	Build BE firmware images for MIPS Malta CoreLV board running in
diff --git a/target/linux/malta/le/target.mk b/target/linux/malta/le/target.mk
index e7c90e9235..35fcf4cfe1 100644
--- a/target/linux/malta/le/target.mk
+++ b/target/linux/malta/le/target.mk
@@ -3,7 +3,6 @@ ARCH_PACKAGES:=malta_mipsel
 SUBTARGET:=le
 BOARDNAME:=Little Endian
 FEATURES:=ramdisk mips16
-CFLAGS:=-Os -pipe -mips32r2 -mtune=mips32r2
 
 define Target/Description
 	Build LE firmware images for MIPS Malta CoreLV board running in
diff --git a/target/linux/malta/le64/target.mk b/target/linux/malta/le64/target.mk
index f20b3e82c5..26b53c12bd 100644
--- a/target/linux/malta/le64/target.mk
+++ b/target/linux/malta/le64/target.mk
@@ -3,7 +3,6 @@ ARCH_PACKAGES:=malta_mipsel64
 SUBTARGET:=le64
 BOARDNAME:=Little Endian (64-bits)
 FEATURES:=ramdisk
-CFLAGS:=-Os -pipe -mips64 -mtune=mips64
 
 define Target/Description
 	Build LE firmware images for MIPS Malta CoreLV board running in
diff --git a/target/linux/octeon/Makefile b/target/linux/octeon/Makefile
index 12fcacb585..a9fd5abfde 100644
--- a/target/linux/octeon/Makefile
+++ b/target/linux/octeon/Makefile
@@ -10,7 +10,8 @@ ARCH:=mips
 BOARD:=octeon
 BOARDNAME:=Cavium Networks Octeon
 FEATURES:=squashfs jffs2 pci usb
-CFLAGS:=-Os -pipe -march=octeon -fno-caller-saves
+CPU_TYPE:=octeon
+CPU_CFLAGS_octeon:=-march=octeon
 MAINTAINER:=John Crispin <blogic@openwrt.org>
 
 LINUX_VERSION:=3.10.12
diff --git a/target/linux/ramips/Makefile b/target/linux/ramips/Makefile
index 512a78f414..9a13a2c9a1 100644
--- a/target/linux/ramips/Makefile
+++ b/target/linux/ramips/Makefile
@@ -10,7 +10,6 @@ ARCH:=mipsel
 BOARD:=ramips
 BOARDNAME:=Ralink RT288x/RT3xxx
 SUBTARGETS:=rt305x rt3883 mt7620a rt288x
-CFLAGS:=-Os -pipe -mno-branch-likely
 FEATURES:=squashfs gpio
 
 LINUX_VERSION:=3.10.12
diff --git a/target/linux/ramips/mt7620a/target.mk b/target/linux/ramips/mt7620a/target.mk
index 4d4dd28ae9..3f4104d982 100644
--- a/target/linux/ramips/mt7620a/target.mk
+++ b/target/linux/ramips/mt7620a/target.mk
@@ -6,7 +6,8 @@ SUBTARGET:=mt7620a
 BOARDNAME:=MT7620a based boards
 ARCH_PACKAGES:=ramips_24kec
 FEATURES+=usb
-CFLAGS+= -march=24kec -mdsp
+CPU_TYPE:=24kec
+CPU_SUBTYPE:=dsp
 
 define Target/Description
 	Build firmware images for Ralink MT7620a based boards.
diff --git a/target/linux/ramips/rt288x/target.mk b/target/linux/ramips/rt288x/target.mk
index f826eab88e..2b11e4843e 100644
--- a/target/linux/ramips/rt288x/target.mk
+++ b/target/linux/ramips/rt288x/target.mk
@@ -4,7 +4,7 @@
 
 SUBTARGET:=rt288x
 BOARDNAME:=RT288x based boards
-CFLAGS+= -mips32r2 -mtune=mips32r2
+CPU_TYPE:=mips32r2
 
 define Target/Description
 	Build firmware images for Ralink RT288x based boards.
diff --git a/target/linux/ramips/rt305x/target.mk b/target/linux/ramips/rt305x/target.mk
index 527b829cb9..a98f415452 100644
--- a/target/linux/ramips/rt305x/target.mk
+++ b/target/linux/ramips/rt305x/target.mk
@@ -6,7 +6,8 @@ SUBTARGET:=rt305x
 BOARDNAME:=RT3x5x/RT5350 based boards
 ARCH_PACKAGES:=ramips_24kec
 FEATURES+=usb
-CFLAGS+= -march=24kec -mdsp
+CPU_TYPE:=24kec
+CPU_SUBTYPE:=dsp
 
 define Target/Description
 	Build firmware images for Ralink RT3x5x/RT5350 based boards.
diff --git a/target/linux/ramips/rt3883/target.mk b/target/linux/ramips/rt3883/target.mk
index 27c9020b52..8ccd67e4c1 100644
--- a/target/linux/ramips/rt3883/target.mk
+++ b/target/linux/ramips/rt3883/target.mk
@@ -6,7 +6,8 @@ SUBTARGET:=rt3883
 BOARDNAME:=RT3662/RT3883 based boards
 ARCH_PACKAGES:=ramips_24kec
 FEATURES+=usb pci
-CFLAGS+= -march=24kec -mdspr2
+CPU_TYPE:=24kec
+CPU_SUBTYPE:=dsp2
 
 define Target/Description
 	Build firmware images for Ralink RT3662/RT3883 based boards.
diff --git a/target/linux/sibyte/Makefile b/target/linux/sibyte/Makefile
index 440cff3b85..2370cac25d 100644
--- a/target/linux/sibyte/Makefile
+++ b/target/linux/sibyte/Makefile
@@ -10,7 +10,8 @@ ARCH:=mips
 BOARD:=sibyte
 BOARDNAME:=Broadcom/SiByte SB-1
 FEATURES:=fpu ramdisk broken
-CFLAGS:=-Os -pipe -march=sb1
+CPU_TYPE:=sb1
+CPU_CFLAGS_sb1:=-march=sb1
 MAINTAINER:=Imre Kaloz <kaloz@openwrt.org>
 
 LINUX_VERSION:=3.3.8
-- 
GitLab