32f0d2c75598147bc4d0f1512ab3166dfa8b4569
[openwrt/openwrt.git] / package / utils / busybox / Makefile
1 # SPDX-License-Identifier: GPL-2.0-or-later
2 #
3 # Copyright (C) 2006-2021 OpenWrt.org
4
5 include $(TOPDIR)/rules.mk
6
7 PKG_NAME:=busybox
8 PKG_VERSION:=1.33.1
9 PKG_RELEASE:=$(AUTORELEASE)
10 PKG_FLAGS:=essential
11
12 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
13 PKG_SOURCE_URL:=https://www.busybox.net/downloads \
14 http://sources.buildroot.net
15 PKG_HASH:=12cec6bd2b16d8a9446dd16130f2b92982f1819f6e1c5f5887b6db03f5660d28
16
17 PKG_BUILD_DEPENDS:=BUSYBOX_CONFIG_PAM:libpam
18 PKG_BUILD_PARALLEL:=1
19 PKG_CHECK_FORMAT_SECURITY:=0
20
21 #Busybox use it's own PIE config flag and LDFLAGS are used with ld, not gcc.
22 PKG_ASLR_PIE:=0
23
24 PKG_LICENSE:=GPL-2.0
25 PKG_LICENSE_FILES:=LICENSE archival/libarchive/bz/LICENSE
26 PKG_CPE_ID:=cpe:/a:busybox:busybox
27
28 BUSYBOX_SYM=$(if $(CONFIG_BUSYBOX_CUSTOM),CONFIG,DEFAULT)
29 BUSYBOX_IF_ENABLED=$(if $(CONFIG_BUSYBOX_$(BUSYBOX_SYM)_$(1)),$(2))
30
31 ifneq ($(CONFIG_BUSYBOX_$(BUSYBOX_SYM)_FEATURE_SUID),)
32 PKG_FILE_MODES:=/bin/busybox:root:root:4755
33 endif
34
35 include $(INCLUDE_DIR)/package.mk
36
37 ifeq ($(DUMP),)
38 STAMP_CONFIGURED:=$(strip $(STAMP_CONFIGURED))_$(shell grep '^CONFIG_BUSYBOX_' $(TOPDIR)/.config | $(MKHASH) md5)
39 endif
40
41 # All files provided by busybox will serve as fallback alternatives by opkg.
42 # There should be no need to enumerate ALTERNATIVES entries here
43 define Package/busybox/Default
44 SECTION:=base
45 CATEGORY:=Base system
46 MAINTAINER:=Felix Fietkau <nbd@nbd.name>
47 TITLE:=Core utilities for embedded Linux
48 URL:=http://busybox.net/
49 DEPENDS:=+BUSYBOX_CONFIG_PAM:libpam +BUSYBOX_CONFIG_NTPD:jsonfilter
50 USERID:=ntp=123:ntp=123
51 endef
52
53 define Package/busybox
54 $(call Package/busybox/Default)
55 CONFLICTS:=busybox-selinux
56 VARIANT:=default
57 endef
58
59 define Package/busybox-selinux
60 $(call Package/busybox/Default)
61 TITLE += with SELinux support
62 DEPENDS += +libselinux
63 VARIANT:=selinux
64 PROVIDES:=busybox
65 endef
66
67 define Package/busybox/description
68 The Swiss Army Knife of embedded Linux.
69 It slices, it dices, it makes Julian Fries.
70 endef
71
72 define Package/busybox/config
73 source "$(SOURCE)/Config.in"
74 endef
75
76 ifneq ($(CONFIG_BUSYBOX_$(BUSYBOX_SYM)_FEATURE_SYSLOG)$(CONFIG_BUSYBOX_$(BUSYBOX_SYM)_FEATURE_SYSLOGD_CFG),)
77 define Package/busybox/conffiles/syslog
78 /etc/syslog.conf
79 endef
80 endif
81
82 ifneq ($(CONFIG_BUSYBOX_$(BUSYBOX_SYM)_CROND),)
83 define Package/busybox/conffiles/crond
84 /etc/crontabs/
85 endef
86 endif
87
88 define Package/busybox/conffiles
89 $(Package/busybox/conffiles/syslog)
90 $(Package/busybox/conffiles/crond)
91 endef
92
93 Package/busybox-selinux/conffiles = $(Package/busybox/conffiles)
94
95 ifndef CONFIG_USE_MUSL
96 LDLIBS:=m crypt
97 endif
98
99 LDLIBS += $(call BUSYBOX_IF_ENABLED,PAM,pam pam_misc pthread)
100
101 ifeq ($(CONFIG_USE_GLIBC),y)
102 LDLIBS += $(call BUSYBOX_IF_ENABLED,NSLOOKUP,resolv)
103 endif
104
105 ifeq ($(BUILD_VARIANT),selinux)
106 LDLIBS += selinux sepol
107 endif
108
109 TARGET_CFLAGS += -flto
110 TARGET_LDFLAGS += -flto=jobserver -fuse-linker-plugin
111
112 MAKE_VARS :=
113 MAKE_FLAGS += \
114 EXTRA_CFLAGS="$(TARGET_CFLAGS) $(TARGET_CPPFLAGS)" \
115 EXTRA_LDFLAGS="$(TARGET_LDFLAGS)" \
116 LDLIBS="$(LDLIBS)" \
117 LD="$(TARGET_CC)" \
118 SKIP_STRIP=y
119 ifneq ($(findstring c,$(OPENWRT_VERBOSE)),)
120 MAKE_FLAGS += V=1
121 endif
122
123 define Build/Configure
124 rm -f $(PKG_BUILD_DIR)/.config
125 touch $(PKG_BUILD_DIR)/.config
126 ifeq ($(DEVICE_TYPE),nas)
127 echo "CONFIG_HDPARM=y" >> $(PKG_BUILD_DIR)/.config
128 endif
129 ifeq ($(BUILD_VARIANT),selinux)
130 cat $(TOPDIR)/$(SOURCE)/selinux.config >> $(PKG_BUILD_DIR)/.config
131 endif
132 grep 'CONFIG_BUSYBOX_$(BUSYBOX_SYM)' $(TOPDIR)/.config | sed -e "s,\\(# \)\\?CONFIG_BUSYBOX_$(BUSYBOX_SYM)_\\(.*\\),\\1CONFIG_\\2,g" >> $(PKG_BUILD_DIR)/.config
133 yes 'n' | $(MAKE) -C $(PKG_BUILD_DIR) $(MAKE_FLAGS) oldconfig
134 endef
135
136 define Build/Compile
137 $(call Build/Compile/Default, \
138 CONFIG_PREFIX="$(PKG_INSTALL_DIR)" \
139 all install \
140 )
141 endef
142
143 define Package/busybox/install
144 $(INSTALL_DIR) $(1)/etc/init.d
145 $(INSTALL_DIR) $(1)/usr/sbin
146 $(CP) $(PKG_INSTALL_DIR)/* $(1)/
147 ifneq ($(CONFIG_BUSYBOX_$(BUSYBOX_SYM)_FEATURE_SYSLOG)$(CONFIG_BUSYBOX_$(BUSYBOX_SYM)_FEATURE_SYSLOGD_CFG),)
148 touch $(1)/etc/syslog.conf
149 endif
150 ifneq ($(CONFIG_BUSYBOX_$(BUSYBOX_SYM)_CROND),)
151 $(INSTALL_BIN) ./files/cron $(1)/etc/init.d/cron
152 $(INSTALL_DIR) $(1)/etc/crontabs
153 endif
154 ifneq ($(CONFIG_BUSYBOX_$(BUSYBOX_SYM)_NTPD),)
155 $(INSTALL_BIN) ./files/sysntpd $(1)/etc/init.d/sysntpd
156 $(INSTALL_BIN) ./files/ntpd-hotplug $(1)/usr/sbin/ntpd-hotplug
157 $(INSTALL_DIR) $(1)/etc/capabilities $(1)/usr/share/acl.d
158 $(INSTALL_DATA) ./files/ntpd.capabilities $(1)/etc/capabilities/ntpd.json
159 $(INSTALL_DATA) ./files/ntpd_acl.json $(1)/usr/share/acl.d/ntpd.json
160 endif
161 -rm -rf $(1)/lib64
162 endef
163
164 Package/busybox-selinux/install = $(Package/busybox/install)
165
166 $(eval $(call BuildPackage,busybox))
167 $(eval $(call BuildPackage,busybox-selinux))