From 5c545bdb365a78b8995ddfa441a6018f7ff3c011 Mon Sep 17 00:00:00 2001
From: Andre Heider <a.heider@gmail.com>
Date: Thu, 2 Feb 2023 20:02:25 +0100
Subject: [PATCH] treewide: replace PKG_USE_MIPS16:=0 with
 PKG_BUILD_FLAGS:=no-mips16

Keep backwards compatibility via PKG_USE_MIPS16 for now, as this is
used in all package feeds.

Signed-off-by: Andre Heider <a.heider@gmail.com>
---
 include/package.mk                         | 21 +++++++++++++--------
 package/devel/binutils/Makefile            |  2 +-
 package/devel/perf/Makefile                |  2 +-
 package/devel/trace-cmd/Makefile           |  2 +-
 package/devel/valgrind/Makefile            |  2 +-
 package/kernel/broadcom-wl/Makefile        |  2 +-
 package/libs/elfutils/Makefile             |  1 -
 package/libs/gmp/Makefile                  |  2 +-
 package/libs/libaudit/Makefile             |  2 +-
 package/libs/mbedtls/Makefile              |  2 +-
 package/libs/nettle/Makefile               |  2 +-
 package/libs/openssl/Makefile              |  2 +-
 package/libs/wolfssl/Makefile              |  2 +-
 package/network/services/dropbear/Makefile |  2 +-
 package/network/utils/bpftools/Makefile    |  2 +-
 package/system/fstools/Makefile            |  2 +-
 package/system/usign/Makefile              |  2 +-
 package/utils/px5g-mbedtls/Makefile        |  2 +-
 package/utils/px5g-wolfssl/Makefile        |  2 +-
 19 files changed, 30 insertions(+), 26 deletions(-)

diff --git a/include/package.mk b/include/package.mk
index 8d14c17dbd..a1717a603d 100644
--- a/include/package.mk
+++ b/include/package.mk
@@ -11,7 +11,6 @@ include $(INCLUDE_DIR)/download.mk
 PKG_BUILD_DIR ?= $(BUILD_DIR)/$(if $(BUILD_VARIANT),$(PKG_NAME)-$(BUILD_VARIANT)/)$(PKG_NAME)$(if $(PKG_VERSION),-$(PKG_VERSION))
 PKG_INSTALL_DIR ?= $(PKG_BUILD_DIR)/ipkg-install
 PKG_BUILD_PARALLEL ?=
-PKG_USE_MIPS16 ?= 1
 PKG_SKIP_DOWNLOAD=$(USE_SOURCE_DIR)$(USE_GIT_TREE)$(USE_GIT_SRC_CHECKOUT)
 
 MAKE_J:=$(if $(MAKE_JOBSERVER),$(MAKE_JOBSERVER) $(if $(filter 3.% 4.0 4.1,$(MAKE_VERSION)),-j))
@@ -23,16 +22,15 @@ PKG_JOBS?=-j1
 else
 PKG_JOBS?=$(if $(PKG_BUILD_PARALLEL),$(MAKE_J),-j1)
 endif
-ifdef CONFIG_USE_MIPS16
-  ifeq ($(strip $(PKG_USE_MIPS16)),1)
-    TARGET_ASFLAGS_DEFAULT = $(filter-out -mips16 -minterlink-mips16,$(TARGET_CFLAGS))
-    TARGET_CFLAGS += -mips16 -minterlink-mips16
-  endif
-endif
 
 PKG_BUILD_FLAGS?=
+# TODO remove this when all packages moved to PKG_BUILD_FLAGS=no-mips16
+PKG_USE_MIPS16?=1
+ifneq ($(strip $(PKG_USE_MIPS16)),1)
+  PKG_BUILD_FLAGS+=no-mips16
+endif
 
-__unknown_flags=$(filter-out no-iremap,$(PKG_BUILD_FLAGS))
+__unknown_flags=$(filter-out no-iremap no-mips16,$(PKG_BUILD_FLAGS))
 ifneq ($(__unknown_flags),)
   $(error unknown PKG_BUILD_FLAGS: $(__unknown_flags))
 endif
@@ -46,6 +44,13 @@ ifeq ($(call pkg_build_flag,iremap,1),1)
   IREMAP_CFLAGS = $(call iremap,$(PKG_BUILD_DIR),$(notdir $(PKG_BUILD_DIR)))
   TARGET_CFLAGS += $(IREMAP_CFLAGS)
 endif
+ifdef CONFIG_USE_MIPS16
+  ifeq ($(call pkg_build_flag,mips16,1),1)
+    TARGET_ASFLAGS_DEFAULT = $(filter-out -mips16 -minterlink-mips16,$(TARGET_CFLAGS))
+    TARGET_CFLAGS += -mips16 -minterlink-mips16
+    TARGET_CXXFLAGS += -mips16 -minterlink-mips16
+  endif
+endif
 
 include $(INCLUDE_DIR)/hardening.mk
 include $(INCLUDE_DIR)/prereq.mk
diff --git a/package/devel/binutils/Makefile b/package/devel/binutils/Makefile
index 5166f26734..8547190e99 100644
--- a/package/devel/binutils/Makefile
+++ b/package/devel/binutils/Makefile
@@ -25,7 +25,7 @@ PKG_MAINTAINER:=Felix Fietkau <nbd@nbd.name>
 PKG_LICENSE:=GPL-3.0+
 PKG_CPE_ID:=cpe:/a:gnu:binutils
 PKG_BUILD_PARALLEL:=1
-PKG_USE_MIPS16:=0
+PKG_BUILD_FLAGS:=no-mips16
 
 include $(INCLUDE_DIR)/nls.mk
 include $(INCLUDE_DIR)/package.mk
diff --git a/package/devel/perf/Makefile b/package/devel/perf/Makefile
index d556e2d9f0..c0b2046bd6 100644
--- a/package/devel/perf/Makefile
+++ b/package/devel/perf/Makefile
@@ -12,7 +12,7 @@ PKG_NAME:=perf
 PKG_VERSION:=$(LINUX_VERSION)
 PKG_RELEASE:=4
 
-PKG_USE_MIPS16:=0
+PKG_BUILD_FLAGS:=no-mips16
 PKG_BUILD_PARALLEL:=1
 PKG_MAINTAINER:=Felix Fietkau <nbd@nbd.name>
 PKG_FLAGS:=nonshared
diff --git a/package/devel/trace-cmd/Makefile b/package/devel/trace-cmd/Makefile
index eac281820f..687907acaa 100644
--- a/package/devel/trace-cmd/Makefile
+++ b/package/devel/trace-cmd/Makefile
@@ -12,7 +12,7 @@ PKG_LICENSE:=GPL-2.0-only
 PKG_LICENSE_FILES:=COPYING
 
 PKG_INSTALL:=1
-PKG_USE_MIPS16:=0
+PKG_BUILD_FLAGS:=no-mips16
 PKG_BUILD_PARALLEL:=1
 
 include $(INCLUDE_DIR)/package.mk
diff --git a/package/devel/valgrind/Makefile b/package/devel/valgrind/Makefile
index bbd01ce37d..372a720d01 100644
--- a/package/devel/valgrind/Makefile
+++ b/package/devel/valgrind/Makefile
@@ -22,7 +22,7 @@ PKG_CPE_ID:=cpe:/a:valgrind:valgrind
 PKG_FIXUP = autoreconf
 PKG_INSTALL := 1
 PKG_BUILD_PARALLEL := 1
-PKG_USE_MIPS16:=0
+PKG_BUILD_FLAGS:=no-mips16
 PKG_SSP:=0
 
 STRIP:=:
diff --git a/package/kernel/broadcom-wl/Makefile b/package/kernel/broadcom-wl/Makefile
index 137e547bee..fe8045d4a9 100644
--- a/package/kernel/broadcom-wl/Makefile
+++ b/package/kernel/broadcom-wl/Makefile
@@ -24,7 +24,7 @@ endif
 
 PKG_EXTMOD_SUBDIRS:=driver driver-mini glue
 
-PKG_USE_MIPS16:=0
+PKG_BUILD_FLAGS:=no-mips16
 PKG_FLAGS:=nonshared
 
 include $(INCLUDE_DIR)/package.mk
diff --git a/package/libs/elfutils/Makefile b/package/libs/elfutils/Makefile
index 2c68a94ba0..f7364c36be 100644
--- a/package/libs/elfutils/Makefile
+++ b/package/libs/elfutils/Makefile
@@ -21,7 +21,6 @@ PKG_CPE_ID:=cpe:/a:elfutils_project:elfutils
 
 PKG_FIXUP:=autoreconf
 PKG_INSTALL:=1
-PKG_USE_MIPS16:=1
 PKG_BUILD_DEPENDS:=!USE_GLIBC:argp-standalone
 
 include $(INCLUDE_DIR)/package.mk
diff --git a/package/libs/gmp/Makefile b/package/libs/gmp/Makefile
index eb7d808139..c9f886e764 100644
--- a/package/libs/gmp/Makefile
+++ b/package/libs/gmp/Makefile
@@ -20,7 +20,7 @@ PKG_INSTALL:=1
 PKG_FIXUP:=autoreconf
 PKG_LICENSE:=GPL-2.0-or-later
 
-PKG_USE_MIPS16:=0
+PKG_BUILD_FLAGS:=no-mips16
 
 include $(INCLUDE_DIR)/host-build.mk
 include $(INCLUDE_DIR)/package.mk
diff --git a/package/libs/libaudit/Makefile b/package/libs/libaudit/Makefile
index 13263c7deb..0d79c25365 100644
--- a/package/libs/libaudit/Makefile
+++ b/package/libs/libaudit/Makefile
@@ -22,7 +22,7 @@ PKG_CPE_ID:=cpe:/a:linux_audit_project:linux_audit
 
 PKG_FIXUP:=autoreconf
 
-PKG_USE_MIPS16:=0
+PKG_BUILD_FLAGS:=no-mips16
 PKG_INSTALL:=1
 
 include $(INCLUDE_DIR)/package.mk
diff --git a/package/libs/mbedtls/Makefile b/package/libs/mbedtls/Makefile
index 02d076d18f..7c167e2296 100644
--- a/package/libs/mbedtls/Makefile
+++ b/package/libs/mbedtls/Makefile
@@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
 PKG_NAME:=mbedtls
 PKG_VERSION:=2.28.2
 PKG_RELEASE:=2
-PKG_USE_MIPS16:=0
+PKG_BUILD_FLAGS:=no-mips16
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=https://codeload.github.com/ARMmbed/mbedtls/tar.gz/v$(PKG_VERSION)?
diff --git a/package/libs/nettle/Makefile b/package/libs/nettle/Makefile
index 8825da4be7..87eff5a1ec 100644
--- a/package/libs/nettle/Makefile
+++ b/package/libs/nettle/Makefile
@@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
 PKG_NAME:=nettle
 PKG_VERSION:=3.8.1
 PKG_RELEASE:=$(AUTORELEASE)
-PKG_USE_MIPS16:=0
+PKG_BUILD_FLAGS:=no-mips16
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=@GNU/nettle
diff --git a/package/libs/openssl/Makefile b/package/libs/openssl/Makefile
index 57ff056e90..7918d40347 100644
--- a/package/libs/openssl/Makefile
+++ b/package/libs/openssl/Makefile
@@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
 PKG_NAME:=openssl
 PKG_VERSION:=3.0.8
 PKG_RELEASE:=4
-PKG_USE_MIPS16:=0
+PKG_BUILD_FLAGS:=no-mips16
 
 PKG_BUILD_PARALLEL:=1
 
diff --git a/package/libs/wolfssl/Makefile b/package/libs/wolfssl/Makefile
index 6ad44a9acf..48e85b0bce 100644
--- a/package/libs/wolfssl/Makefile
+++ b/package/libs/wolfssl/Makefile
@@ -17,7 +17,7 @@ PKG_HASH:=b7ee150e49def77c765bc02aac92ddeb0bebefd4cb12aa263d8f95e405221fb8
 
 PKG_FIXUP:=libtool libtool-abiver
 PKG_INSTALL:=1
-PKG_USE_MIPS16:=0
+PKG_BUILD_FLAGS:=no-mips16
 PKG_BUILD_PARALLEL:=1
 PKG_LICENSE:=GPL-2.0-or-later
 PKG_LICENSE_FILES:=LICENSING COPYING
diff --git a/package/network/services/dropbear/Makefile b/package/network/services/dropbear/Makefile
index eaf14c5533..ddd19bfa55 100644
--- a/package/network/services/dropbear/Makefile
+++ b/package/network/services/dropbear/Makefile
@@ -23,7 +23,7 @@ PKG_CPE_ID:=cpe:/a:matt_johnston:dropbear_ssh_server
 
 PKG_BUILD_PARALLEL:=1
 PKG_ASLR_PIE_REGULAR:=1
-PKG_USE_MIPS16:=0
+PKG_BUILD_FLAGS:=no-mips16
 PKG_FIXUP:=autoreconf
 PKG_FLAGS:=nonshared
 
diff --git a/package/network/utils/bpftools/Makefile b/package/network/utils/bpftools/Makefile
index a1ae22b93f..047d2a0967 100644
--- a/package/network/utils/bpftools/Makefile
+++ b/package/network/utils/bpftools/Makefile
@@ -19,7 +19,7 @@ PKG_ABI_VERSION:=$(call abi_version_str,$(PKG_SOURCE_DATE))
 
 PKG_MAINTAINER:=Tony Ambardar <itugrok@yahoo.com>
 
-PKG_USE_MIPS16:=0
+PKG_BUILD_FLAGS:=no-mips16
 PKG_BUILD_PARALLEL:=1
 PKG_INSTALL:=1
 
diff --git a/package/system/fstools/Makefile b/package/system/fstools/Makefile
index 912ed80ba2..379f5d8c9d 100644
--- a/package/system/fstools/Makefile
+++ b/package/system/fstools/Makefile
@@ -20,7 +20,7 @@ CMAKE_INSTALL:=1
 PKG_LICENSE:=GPL-2.0
 PKG_LICENSE_FILES:=
 
-PKG_USE_MIPS16:=0
+PKG_BUILD_FLAGS:=no-mips16
 PKG_FLAGS:=nonshared
 
 PKG_BUILD_DEPENDS := util-linux
diff --git a/package/system/usign/Makefile b/package/system/usign/Makefile
index 5267ce15f3..0d2d07017c 100644
--- a/package/system/usign/Makefile
+++ b/package/system/usign/Makefile
@@ -10,7 +10,7 @@ PKG_SOURCE_VERSION:=f1f65026a94137c91b5466b149ef3ea3f20091e9
 PKG_MIRROR_HASH:=3f6569a5e63fdfd032976ac0f79d736d3935101ac1b97fb370514b013c5e6bb6
 CMAKE_INSTALL:=1
 PKG_CHECK_FORMAT_SECURITY:=1
-PKG_USE_MIPS16:=0
+PKG_BUILD_FLAGS:=no-mips16
 
 PKG_LICENSE:=ISC
 PKG_LICENSE_FILES:=
diff --git a/package/utils/px5g-mbedtls/Makefile b/package/utils/px5g-mbedtls/Makefile
index 42ffd39ce3..6de5e55d06 100644
--- a/package/utils/px5g-mbedtls/Makefile
+++ b/package/utils/px5g-mbedtls/Makefile
@@ -11,7 +11,7 @@ PKG_NAME:=px5g-mbedtls
 PKG_RELEASE:=9
 PKG_LICENSE:=LGPL-2.1
 
-PKG_USE_MIPS16:=0
+PKG_BUILD_FLAGS:=no-mips16
 
 PKG_MAINTAINER:=Jo-Philipp Wich <jo@mein.io>
 
diff --git a/package/utils/px5g-wolfssl/Makefile b/package/utils/px5g-wolfssl/Makefile
index 687a999ca7..be2d4af30c 100644
--- a/package/utils/px5g-wolfssl/Makefile
+++ b/package/utils/px5g-wolfssl/Makefile
@@ -8,7 +8,7 @@ PKG_NAME:=px5g-wolfssl
 PKG_RELEASE:=$(COMMITCOUNT).2
 PKG_LICENSE:=GPL-2.0-or-later
 
-PKG_USE_MIPS16:=0
+PKG_BUILD_FLAGS:=no-mips16
 
 PKG_MAINTAINER:=Paul Spooren <mail@aparcar.org>
 
-- 
2.30.2