base-files: reduce number of `mkdir` calls
[openwrt/openwrt.git] / package / base-files / Makefile
1 #
2 # Copyright (C) 2007-2021 OpenWrt.org
3 # Copyright (C) 2010 Vertical Communications
4 #
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
7 #
8
9 include $(TOPDIR)/rules.mk
10 include $(INCLUDE_DIR)/kernel.mk
11 include $(INCLUDE_DIR)/version.mk
12 include $(INCLUDE_DIR)/feeds.mk
13
14 PKG_NAME:=base-files
15 PKG_FLAGS:=nonshared
16 PKG_RELEASE:=$(COMMITCOUNT)
17
18 PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
19 PKG_BUILD_DEPENDS:=usign/host ucert/host
20 PKG_LICENSE:=GPL-2.0
21
22 # Extend depends from version.mk
23 PKG_CONFIG_DEPENDS += \
24 CONFIG_SIGNED_PACKAGES CONFIG_TARGET_INIT_PATH CONFIG_TARGET_PREINIT_DISABLE_FAILSAFE \
25 CONFIG_NAND_SUPPORT \
26 CONFIG_LEGACY_SDCARD_SUPPORT \
27 CONFIG_CLEAN_IPKG \
28 CONFIG_PER_FEED_REPO \
29 $(foreach feed,$(FEEDS_AVAILABLE),CONFIG_FEED_$(feed))
30
31 include $(INCLUDE_DIR)/package.mk
32
33 ifneq ($(DUMP),1)
34 STAMP_CONFIGURED:=$(strip $(STAMP_CONFIGURED))_$(shell echo $(CONFIG_TARGET_INIT_PATH) | $(MKHASH) md5)
35 TARGET:=-$(BOARD)
36 endif
37
38 define Package/base-files
39 SECTION:=base
40 CATEGORY:=Base system
41 DEPENDS:=+netifd +libc +jsonfilter +SIGNED_PACKAGES:usign +SIGNED_PACKAGES:openwrt-keyring +NAND_SUPPORT:ubi-utils +fstools +fwtool
42 TITLE:=Base filesystem for OpenWrt
43 URL:=http://openwrt.org/
44 VERSION:=$(PKG_RELEASE)-$(REVISION)
45 endef
46
47 define Package/base-files/conffiles
48 /etc/config/
49 /etc/config/network
50 /etc/config/system
51 /etc/dropbear/
52 /etc/ethers
53 /etc/group
54 /etc/hosts
55 /etc/inittab
56 /etc/iproute2/rt_protos
57 /etc/iproute2/rt_tables
58 /etc/passwd
59 /etc/profile
60 /etc/profile.d
61 /etc/protocols
62 /etc/rc.local
63 /etc/services
64 /etc/shadow
65 /etc/shells
66 /etc/shinit
67 /etc/sysctl.conf
68 /etc/sysupgrade.conf
69 $(call $(TARGET)/conffiles)
70 endef
71
72 define Package/base-files/description
73 This package contains a base filesystem and system scripts for OpenWrt.
74 endef
75
76 define ImageConfigOptions
77 mkdir -p $(1)/lib/preinit
78 echo 'pi_suppress_stderr="$(CONFIG_TARGET_PREINIT_SUPPRESS_STDERR)"' >$(1)/lib/preinit/00_preinit.conf
79 echo 'fs_failsafe_wait_timeout=$(if $(CONFIG_TARGET_PREINIT_TIMEOUT),$(CONFIG_TARGET_PREINIT_TIMEOUT),2)' >>$(1)/lib/preinit/00_preinit.conf
80 echo 'pi_init_path="$(TARGET_INIT_PATH)"' >>$(1)/lib/preinit/00_preinit.conf
81 echo 'pi_init_env=$(if $(CONFIG_TARGET_INIT_ENV),$(CONFIG_TARGET_INIT_ENV),"")' >>$(1)/lib/preinit/00_preinit.conf
82 echo 'pi_init_cmd=$(if $(CONFIG_TARGET_INIT_CMD),$(CONFIG_TARGET_INIT_CMD),"/sbin/init")' >>$(1)/lib/preinit/00_preinit.conf
83 echo 'pi_init_suppress_stderr="$(CONFIG_TARGET_INIT_SUPPRESS_STDERR)"' >>$(1)/lib/preinit/00_preinit.conf
84 echo 'pi_ifname=$(if $(CONFIG_TARGET_PREINIT_IFNAME),$(CONFIG_TARGET_PREINIT_IFNAME),"")' >>$(1)/lib/preinit/00_preinit.conf
85 echo 'pi_ip=$(if $(CONFIG_TARGET_PREINIT_IP),$(CONFIG_TARGET_PREINIT_IP),"192.168.1.1")' >>$(1)/lib/preinit/00_preinit.conf
86 echo 'pi_netmask=$(if $(CONFIG_TARGET_PREINIT_NETMASK),$(CONFIG_TARGET_PREINIT_NETMASK),"255.255.255.0")' >>$(1)/lib/preinit/00_preinit.conf
87 echo 'pi_broadcast=$(if $(CONFIG_TARGET_PREINIT_BROADCAST),$(CONFIG_TARGET_PREINIT_BROADCAST),"192.168.1.255")' >>$(1)/lib/preinit/00_preinit.conf
88 echo 'pi_preinit_net_messages="$(CONFIG_TARGET_PREINIT_SHOW_NETMSG)"' >>$(1)/lib/preinit/00_preinit.conf
89 echo 'pi_preinit_no_failsafe_netmsg="$(CONFIG_TARGET_PREINIT_SUPPRESS_FAILSAFE_NETMSG)"' >>$(1)/lib/preinit/00_preinit.conf
90 echo 'pi_preinit_no_failsafe="$(CONFIG_TARGET_PREINIT_DISABLE_FAILSAFE)"' >>$(1)/lib/preinit/00_preinit.conf
91 endef
92
93 define Build/Prepare
94 mkdir -p $(PKG_BUILD_DIR)
95 endef
96
97 define Build/Compile/Default
98
99 endef
100 Build/Compile = $(Build/Compile/Default)
101
102 ifdef CONFIG_SIGNED_PACKAGES
103 define Build/Configure
104 [ -s $(BUILD_KEY) -a -s $(BUILD_KEY).pub ] || \
105 $(STAGING_DIR_HOST)/bin/usign -G -s $(BUILD_KEY) -p $(BUILD_KEY).pub -c "Local build key"
106
107 [ -s $(BUILD_KEY).ucert ] || \
108 $(STAGING_DIR_HOST)/bin/ucert -I -c $(BUILD_KEY).ucert -p $(BUILD_KEY).pub -s $(BUILD_KEY)
109
110 endef
111
112 ifndef CONFIG_BUILDBOT
113 define Package/base-files/install-key
114 mkdir -p $(1)/etc/opkg/keys
115 $(CP) $(BUILD_KEY).pub $(1)/etc/opkg/keys/`$(STAGING_DIR_HOST)/bin/usign -F -p $(BUILD_KEY).pub`
116
117 endef
118 endif
119 endif
120
121 ifeq ($(CONFIG_NAND_SUPPORT),)
122 define Package/base-files/nand-support
123 rm -f $(1)/lib/upgrade/nand.sh
124 endef
125 endif
126
127 ifeq ($(CONFIG_LEGACY_SDCARD_SUPPORT),)
128 define Package/base-files/legacy-sdcard-support
129 rm -f $(1)/lib/upgrade/legacy-sdcard.sh
130 endef
131 endif
132
133
134 define Package/base-files/install
135 $(CP) ./files/* $(1)/
136 $(Package/base-files/install-key)
137 $(Package/base-files/nand-support)
138 $(Package/base-files/legacy-sdcard-support)
139 if [ -d $(GENERIC_PLATFORM_DIR)/base-files/. ]; then \
140 $(CP) $(GENERIC_PLATFORM_DIR)/base-files/* $(1)/; \
141 fi
142 if [ -d $(PLATFORM_DIR)/base-files/. ]; then \
143 $(CP) $(PLATFORM_DIR)/base-files/* $(1)/; \
144 fi
145 $(if $(filter-out $(PLATFORM_DIR),$(PLATFORM_SUBDIR)), \
146 if [ -d $(PLATFORM_SUBDIR)/base-files/. ]; then \
147 $(CP) $(PLATFORM_SUBDIR)/base-files/* $(1)/; \
148 fi; \
149 )
150
151 $(VERSION_SED_SCRIPT) \
152 $(1)/etc/banner \
153 $(1)/etc/device_info \
154 $(1)/etc/openwrt_release \
155 $(1)/etc/openwrt_version \
156 $(1)/usr/lib/os-release
157
158
159 $(SED) "s#%PATH%#$(TARGET_INIT_PATH)#g" \
160 $(1)/sbin/hotplug-call \
161 $(1)/etc/preinit \
162 $(1)/etc/profile
163
164 mkdir -p \
165 $(1)/CONTROL \
166 $(1)/dev \
167 $(1)/etc/config \
168 $(1)/etc/crontabs \
169 $(1)/etc/rc.d \
170 $(1)/overlay \
171 $(1)/lib/firmware \
172 $(1)/mnt \
173 $(1)/proc \
174 $(1)/tmp \
175 $(1)/usr/lib \
176 $(1)/usr/bin \
177 $(1)/sys \
178 $(1)/www \
179 $(1)/root
180
181 $(LN) /proc/mounts $(1)/etc/mtab
182 $(if $(LIB_SUFFIX),-$(LN) lib $(1)/lib$(LIB_SUFFIX))
183 $(if $(LIB_SUFFIX),-$(LN) lib $(1)/usr/lib$(LIB_SUFFIX))
184
185 ifneq ($(CONFIG_TARGET_ROOTFS_PERSIST_VAR),y)
186 rm -f $(1)/var
187 $(LN) tmp $(1)/var
188 else
189 mkdir -p $(1)/var
190 $(LN) /tmp/run $(1)/var/run
191 endif
192 $(LN) /tmp/resolv.conf /tmp/TZ /tmp/localtime $(1)/etc/
193
194 chmod 0600 $(1)/etc/shadow
195 chmod 1777 $(1)/tmp
196
197 $(call ImageConfigOptions,$(1))
198 $(call Package/base-files/install-target,$(1))
199 for conffile in $(1)/etc/config/*; do \
200 if [ -f "$$$$conffile" ]; then \
201 grep "$$$${conffile##$(1)}" $(1)/CONTROL/conffiles || \
202 echo "$$$${conffile##$(1)}" >> $(1)/CONTROL/conffiles; \
203 fi \
204 done
205
206 $(if $(CONFIG_INCLUDE_CONFIG), \
207 echo -e "# Build configuration for board $(BOARD)/$(SUBTARGET)/$(PROFILE)\n" >$(1)/etc/build.config; \
208 cat $(BIN_DIR)/config.buildinfo >>$(1)/etc/build.config; \
209 cat $(BIN_DIR)/feeds.buildinfo >>$(1)/etc/build.feeds; \
210 cat $(BIN_DIR)/version.buildinfo >>$(1)/etc/build.version)
211
212 $(if $(CONFIG_CLEAN_IPKG),, \
213 mkdir -p $(1)/etc/opkg; \
214 $(call FeedSourcesAppend,$(1)/etc/opkg/distfeeds.conf); \
215 $(VERSION_SED_SCRIPT) $(1)/etc/opkg/distfeeds.conf)
216 $(if $(CONFIG_IPK_FILES_CHECKSUMS),, \
217 rm -f $(1)/sbin/pkg_check)
218
219 $(if $(CONFIG_TARGET_PREINIT_DISABLE_FAILSAFE), \
220 rm -f $(1)/etc/banner.failsafe,)
221 endef
222
223 ifneq ($(DUMP),1)
224 -include $(PLATFORM_DIR)/base-files.mk
225 -include $(PLATFORM_SUBDIR)/base-files.mk
226 endif
227
228 $(eval $(call BuildPackage,base-files))