libselinux: fix compilation with musl 1.2.4
[openwrt/staging/jow.git] / package / libs / libselinux / Makefile
1 #
2 # This is free software, licensed under the GNU General Public License v2.
3 # See /LICENSE for more information.
4 #
5
6 include $(TOPDIR)/rules.mk
7
8 PKG_NAME:=libselinux
9 PKG_VERSION:=3.3
10 PKG_RELEASE:=2
11
12 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
13 PKG_SOURCE_URL:=https://github.com/SELinuxProject/selinux/releases/download/$(PKG_VERSION)
14 PKG_HASH:=acfdee27633d2496508c28727c3d41d3748076f66d42fccde2e6b9f3463a7057
15 HOST_BUILD_DEPENDS:=libsepol/host pcre/host
16
17 PKG_LICENSE:=libselinux-1.0
18 PKG_LICENSE_FILES:=LICENSE
19 PKG_MAINTAINER:=Thomas Petazzoni <thomas.petazzoni@bootlin.com>
20 PKG_CPE_ID:=cpe:/a:selinuxproject:libselinux
21
22 HOST_BUILD_DEPENDS:=libsepol/host musl-fts/host pcre/host
23
24 include $(INCLUDE_DIR)/package.mk
25 include $(INCLUDE_DIR)/host-build.mk
26
27 LIBSELINUX_UTILS := \
28 avcstat \
29 compute_av \
30 compute_create \
31 compute_member \
32 compute_relabel \
33 getconlist \
34 getdefaultcon \
35 getenforce \
36 getfilecon \
37 getpidcon \
38 getsebool \
39 getseuser \
40 matchpathcon \
41 policyvers \
42 sefcontext_compile \
43 selabel_digest \
44 selabel_get_digests_all_partial_matches \
45 selabel_lookup \
46 selabel_lookup_best_match \
47 selabel_partial_match \
48 selinux_check_access \
49 selinux_check_securetty_context \
50 selinuxenabled \
51 selinuxexeccon \
52 setenforce \
53 setfilecon \
54 togglesebool \
55 validatetrans
56
57 LIBSELINUX_ALTS := \
58 getenforce \
59 getsebool \
60 matchpathcon \
61 selinuxenabled \
62 setenforce
63
64 $(eval $(foreach a,$(LIBSELINUX_ALTS),ALTS_$(a):=300:/usr/sbin/$(a):/usr/sbin/libselinux-$(a)$(newline)))
65
66 define Package/libselinux/Default
67 TITLE:=Runtime SELinux library
68 URL:=http://selinuxproject.org/page/Main_Page
69 endef
70
71 define Package/libselinux
72 $(call Package/libselinux/Default)
73 SECTION:=libs
74 CATEGORY:=Libraries
75 DEPENDS:=+libsepol +libpcre +USE_MUSL:musl-fts
76 endef
77
78 define Package/libselinux/description
79 libselinux is the runtime SELinux library that provides
80 interfaces (e.g. library functions for the SELinux kernel
81 APIs like getcon(), other support functions like
82 getseuserbyname()) to SELinux-aware applications. libselinux
83 may use the shared libsepol to manipulate the binary policy
84 if necessary (e.g. to downgrade the policy format to an
85 older version supported by the kernel) when loading policy.
86 endef
87
88 define GenUtilPkg
89 define Package/$(1)
90 $(call Package/libselinux/Default)
91 TITLE+= $(2) utility
92 SECTION:=utils
93 DEPENDS:=+libselinux
94 CATEGORY:=Utilities
95 SUBMENU:=libselinux tools
96 ALTERNATIVES:=$(ALTS_$(2))
97 endef
98
99 define Package/$(1)/description
100 libselinux version of the $(2) utility.
101 endef
102 endef
103
104 $(foreach a,$(LIBSELINUX_UTILS),$(eval $(call GenUtilPkg,libselinux-$(a),$(a))))
105
106 # Needed to link libselinux utilities, which link against
107 # libselinux.so, which indirectly depends on libpcre.so, installed in
108 # $(STAGING_DIR_HOSTPKG).
109 HOST_LDFLAGS += -Wl,-rpath="$(STAGING_DIR_HOSTPKG)/lib"
110
111 HOST_MAKE_FLAGS += \
112 PREFIX=$(STAGING_DIR_HOSTPKG) \
113 SHLIBDIR=$(STAGING_DIR_HOSTPKG)/lib \
114 FTS_LDLIBS=-lfts
115
116 ifeq ($(CONFIG_USE_MUSL),y)
117 MAKE_FLAGS += FTS_LDLIBS=-lfts
118 TARGET_CFLAGS += -D_LARGEFILE64_SOURCE
119 endif
120
121 MAKE_FLAGS += \
122 SHLIBDIR=/usr/lib \
123 OS=Linux
124
125 define Build/Compile
126 $(call Build/Compile/Default,all)
127 endef
128
129 define Build/Install
130 $(call Build/Install/Default,install)
131 endef
132
133 define Build/InstallDev
134 $(INSTALL_DIR) $(1)/usr/include
135 $(CP) $(PKG_INSTALL_DIR)/usr/include/* $(1)/usr/include/
136 $(INSTALL_DIR) $(1)/usr/lib
137 $(CP) $(PKG_INSTALL_DIR)/usr/lib/* $(1)/usr/lib/
138 $(INSTALL_DIR) $(1)/usr/lib/pkgconfig
139 $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/libselinux.pc $(1)/usr/lib/pkgconfig/
140 $(SED) 's,/usr/include,$$$${prefix}/include,g' $(1)/usr/lib/pkgconfig/libselinux.pc
141 $(SED) 's,/usr/lib,$$$${exec_prefix}/lib,g' $(1)/usr/lib/pkgconfig/libselinux.pc
142 endef
143
144 define Package/libselinux/install
145 $(INSTALL_DIR) $(1)/usr/lib
146 $(CP) $(PKG_INSTALL_DIR)/usr/lib/libselinux.so.* $(1)/usr/lib/
147 endef
148
149 define BuildUtil
150 define Package/$(1)/install
151 $(INSTALL_DIR) $$(1)/usr/sbin
152 $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/$(2) $$(1)/usr/sbin/$(if $(ALTS_$(2)),libselinux-$(2),$(2))
153 endef
154
155 $$(eval $$(call BuildPackage,$(1)))
156 endef
157
158 $(eval $(call HostBuild))
159 $(eval $(call BuildPackage,libselinux))
160 $(foreach a,$(LIBSELINUX_UTILS),$(eval $(call BuildUtil,libselinux-$(a),$(a))))