xref: /OK3568_Linux_fs/buildroot/package/skeleton-init-common/skeleton-init-common.mk (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1################################################################################
2#
3# skeleton-init-common
4#
5################################################################################
6
7# The skeleton can't depend on the toolchain, since all packages depends on the
8# skeleton and the toolchain is a target package, as is skeleton.
9# Hence, skeleton would depends on the toolchain and the toolchain would depend
10# on skeleton.
11SKELETON_INIT_COMMON_ADD_TOOLCHAIN_DEPENDENCY = NO
12SKELETON_INIT_COMMON_ADD_SKELETON_DEPENDENCY = NO
13
14# The skeleton also handles the merged /usr case in the sysroot
15SKELETON_INIT_COMMON_INSTALL_STAGING = YES
16
17SKELETON_INIT_COMMON_PATH = system/skeleton
18
19define SKELETON_INIT_COMMON_INSTALL_TARGET_CMDS
20	$(call SYSTEM_RSYNC,$(SKELETON_INIT_COMMON_PATH),$(TARGET_DIR))
21	$(call SYSTEM_USR_SYMLINKS_OR_DIRS,$(TARGET_DIR))
22	$(call SYSTEM_LIB_SYMLINK,$(TARGET_DIR))
23	$(SED) 's,@PATH@,$(BR2_SYSTEM_DEFAULT_PATH),' $(TARGET_DIR)/etc/profile
24	$(INSTALL) -m 0644 support/misc/target-dir-warning.txt \
25		$(TARGET_DIR_WARNING_FILE)
26endef
27
28# We don't care much about what goes in staging, as long as it is
29# correctly setup for merged/non-merged /usr. The simplest is to
30# fill it in with the content of the skeleton.
31define SKELETON_INIT_COMMON_INSTALL_STAGING_CMDS
32	$(call SYSTEM_RSYNC,$(SKELETON_INIT_COMMON_PATH),$(STAGING_DIR))
33	$(call SYSTEM_USR_SYMLINKS_OR_DIRS,$(STAGING_DIR))
34	$(call SYSTEM_LIB_SYMLINK,$(STAGING_DIR))
35	$(INSTALL) -d -m 0755 $(STAGING_DIR)/usr/include
36endef
37
38SKELETON_INIT_COMMON_HOSTNAME = $(call qstrip,$(BR2_TARGET_GENERIC_HOSTNAME))
39SKELETON_INIT_COMMON_ISSUE = $(call qstrip,$(BR2_TARGET_GENERIC_ISSUE))
40SKELETON_INIT_COMMON_ROOT_PASSWD = $(call qstrip,$(BR2_TARGET_GENERIC_ROOT_PASSWD))
41SKELETON_INIT_COMMON_PASSWD_METHOD = $(call qstrip,$(BR2_TARGET_GENERIC_PASSWD_METHOD))
42SKELETON_INIT_COMMON_BIN_SH = $(call qstrip,$(BR2_SYSTEM_BIN_SH))
43
44ifneq ($(SKELETON_INIT_COMMON_HOSTNAME),)
45SKELETON_INIT_COMMON_HOSTS_LINE = $(SKELETON_INIT_COMMON_HOSTNAME)
46SKELETON_INIT_COMMON_SHORT_HOSTNAME = $(firstword $(subst ., ,$(SKELETON_INIT_COMMON_HOSTNAME)))
47ifneq ($(SKELETON_INIT_COMMON_HOSTNAME),$(SKELETON_INIT_COMMON_SHORT_HOSTNAME))
48SKELETON_INIT_COMMON_HOSTS_LINE += $(SKELETON_INIT_COMMON_SHORT_HOSTNAME)
49endif
50define SKELETON_INIT_COMMON_SET_HOSTNAME
51	mkdir -p $(TARGET_DIR)/etc
52	echo "$(SKELETON_INIT_COMMON_HOSTNAME)" > $(TARGET_DIR)/etc/hostname
53	$(SED) '$$a \127.0.1.1\t$(SKELETON_INIT_COMMON_HOSTS_LINE)' \
54		-e '/^127.0.1.1/d' $(TARGET_DIR)/etc/hosts
55endef
56SKELETON_INIT_COMMON_TARGET_FINALIZE_HOOKS += SKELETON_INIT_COMMON_SET_HOSTNAME
57endif
58
59ifneq ($(SKELETON_INIT_COMMON_ISSUE),)
60define SKELETON_INIT_COMMON_SET_ISSUE
61	mkdir -p $(TARGET_DIR)/etc
62	echo "$(SKELETON_INIT_COMMON_ISSUE)" > $(TARGET_DIR)/etc/issue
63endef
64SKELETON_INIT_COMMON_TARGET_FINALIZE_HOOKS += SKELETON_INIT_COMMON_SET_ISSUE
65endif
66
67ifeq ($(BR2_TARGET_ENABLE_ROOT_LOGIN),y)
68ifneq ($(filter $$1$$% $$5$$% $$6$$%,$(SKELETON_INIT_COMMON_ROOT_PASSWD)),)
69SKELETON_INIT_COMMON_ROOT_PASSWORD = '$(SKELETON_INIT_COMMON_ROOT_PASSWD)'
70else ifneq ($(SKELETON_INIT_COMMON_ROOT_PASSWD),)
71# This variable will only be evaluated in the finalize stage, so we can
72# be sure that host-mkpasswd will have already been built by that time.
73SKELETON_INIT_COMMON_ROOT_PASSWORD = "`$(MKPASSWD) -m "$(SKELETON_INIT_COMMON_PASSWD_METHOD)" "$(SKELETON_INIT_COMMON_ROOT_PASSWD)"`"
74endif
75else # !BR2_TARGET_ENABLE_ROOT_LOGIN
76SKELETON_INIT_COMMON_ROOT_PASSWORD = "*"
77endif
78define SKELETON_INIT_COMMON_SET_ROOT_PASSWD
79	$(SED) s,^root:[^:]*:,root:$(SKELETON_INIT_COMMON_ROOT_PASSWORD):, $(TARGET_DIR)/etc/shadow
80endef
81SKELETON_INIT_COMMON_TARGET_FINALIZE_HOOKS += SKELETON_INIT_COMMON_SET_ROOT_PASSWD
82
83ifeq ($(BR2_SYSTEM_BIN_SH_NONE),y)
84define SKELETON_INIT_COMMON_SET_BIN_SH
85	rm -f $(TARGET_DIR)/bin/sh
86endef
87else
88# Add /bin/sh to /etc/shells otherwise some login tools like dropbear
89# can reject the user connection. See man shells.
90define SKELETON_INIT_COMMON_ADD_SH_TO_SHELLS
91	grep -qsE '^/bin/sh$$' $(TARGET_DIR)/etc/shells \
92		|| echo "/bin/sh" >> $(TARGET_DIR)/etc/shells
93endef
94SKELETON_INIT_COMMON_TARGET_FINALIZE_HOOKS += SKELETON_INIT_COMMON_ADD_SH_TO_SHELLS
95ifneq ($(SKELETON_INIT_COMMON_BIN_SH),)
96define SKELETON_INIT_COMMON_SET_BIN_SH
97	ln -sf $(SKELETON_INIT_COMMON_BIN_SH) $(TARGET_DIR)/bin/sh
98	$(SED) '/^root:/s,[^/]*$$,$(SKELETON_INIT_COMMON_BIN_SH),' \
99		$(TARGET_DIR)/etc/passwd
100endef
101endif
102endif
103SKELETON_INIT_COMMON_TARGET_FINALIZE_HOOKS += SKELETON_INIT_COMMON_SET_BIN_SH
104
105$(eval $(generic-package))
106