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