cosmetic changes
[openadk.git] / mk / package.mk
blobdf2c027b22c2d7a02b75f34077db3b893e8866a3
1 # This file is part of the OpenADK project. OpenADK is copyrighted
2 # material, please see the LICENCE file in the top-level directory.
4 all: build-all-pkgs
6 TCFLAGS:= ${TARGET_CFLAGS}
7 TCXXFLAGS:= ${TARGET_CFLAGS}
8 TCPPFLAGS:= ${TARGET_CPPFLAGS}
9 TLDFLAGS:= ${TARGET_LDFLAGS} -Wl,-rpath -Wl,/usr/lib \
10 -Wl,-rpath-link -Wl,${STAGING_DIR}/usr/lib \
11 -L${STAGING_DIR}/lib -L${STAGING_DIR}/usr/lib
12 ifeq ($(ADK_STATIC),y)
13 TCFLAGS:= ${TARGET_CFLAGS} -static
14 TCXXFLAGS:= ${TARGET_CFLAGS} -static
15 TCPPFLAGS:= ${TARGET_CPPFLAGS} -static
16 TLDFLAGS:= ${TARGET_LDFLAGS} -Wl,-rpath -Wl,/usr/lib \
17 -Wl,-rpath-link -Wl,${STAGING_DIR}/usr/lib \
18 -L${STAGING_DIR}/lib -L${STAGING_DIR}/usr/lib \
19 -static
20 endif
21 ifeq ($(ADK_NATIVE),y)
22 TCFLAGS:=
23 TCXXFLAGS:=
24 TCPPFLAGS:=
25 TLDFLAGS:=
26 endif
28 ifeq ($(ADK_DEBUG),)
29 TCPPFLAGS+= -DNDEBUG
30 endif
31 ifneq ($(ADK_DEBUG),)
32 CONFIGURE_ARGS+= --enable-debug
33 else
34 CONFIGURE_ARGS+= --disable-debug
35 endif
37 ifeq ($(ADK_NATIVE),y)
38 CONFIGURE_ENV+= CONFIG_SHELL='$(strip ${SHELL})' \
39 CFLAGS='$(strip ${TCFLAGS})' \
40 CXXFLAGS='$(strip ${TCXXFLAGS})' \
41 CPPFLAGS='$(strip ${TCPPFLAGS})' \
42 LDFLAGS='$(strip ${TLDFLAGS})' \
43 PKG_CONFIG_PATH='${STAGING_DIR}/usr/lib/pkgconfig' \
44 PKG_CONFIG_LIBDIR=/dev/null
45 else
46 CONFIGURE_ENV+= ${TARGET_CONFIGURE_OPTS} \
47 ${HOST_CONFIGURE_OPTS} \
48 CC='${TARGET_CC}' CXX='${TARGET_CXX}' \
49 CFLAGS='$(strip ${TCFLAGS})' \
50 CXXFLAGS='$(strip ${TCXXFLAGS})' \
51 CPPFLAGS='$(strip ${TCPPFLAGS})' \
52 LDFLAGS='$(strip ${TLDFLAGS})' \
53 PKG_CONFIG_PATH='${STAGING_DIR}/usr/lib/pkgconfig' \
54 PKG_CONFIG_LIBDIR=/dev/null \
55 CONFIG_SHELL='$(strip ${SHELL})' \
56 ac_cv_func_realloc_0_nonnull=yes \
57 ac_cv_func_malloc_0_nonnull=yes
58 endif
59 MAKE_FILE?= Makefile
60 # this is environment for 'make all' and 'make install'
61 MAKE_ENV?=
62 # this is arguments for 'make all' and 'make install'
63 XAKE_FLAGS?=
64 # this is arguments for 'make all' ONLY
65 MAKE_FLAGS?=
66 # this is arguments for 'make install' ONLY
67 FAKE_FLAGS?=
68 ALL_TARGET?= all
69 INSTALL_TARGET?= install
70 ifeq ($(ADK_NATIVE),y)
71 MAKE_ENV+= \
72 WRKDIR='${WRKDIR}' WRKDIST='${WRKDIST}' \
73 WRKSRC='${WRKSRC}' WRKBUILD='${WRKBUILD}' \
74 CFLAGS='$(strip ${TCFLAGS})' \
75 CXXFLAGS='$(strip ${TCXXFLAGS})' \
76 CPPFLAGS='$(strip ${TCPPFLAGS})' \
77 LDFLAGS='$(strip ${TLDFLAGS})'
78 else
79 MAKE_ENV+= PATH='${TARGET_PATH}' \
80 ${HOST_CONFIGURE_OPTS} \
81 WRKDIR='${WRKDIR}' WRKDIST='${WRKDIST}' \
82 WRKSRC='${WRKSRC}' WRKBUILD='${WRKBUILD}' \
83 PKG_CONFIG_PATH='${STAGING_DIR}/usr/lib/pkgconfig' \
84 PKG_CONFIG_LIBDIR=/dev/null \
85 CC='${TARGET_CC}' CXX='${TARGET_CXX}' \
86 AR='${TARGET_CROSS}ar' RANLIB='${TARGET_CROSS}ranlib' \
87 NM='${TARGET_CROSS}nm' \
88 CFLAGS='$(strip ${TCFLAGS})' \
89 CXXFLAGS='$(strip ${TCXXFLAGS})' \
90 CPPFLAGS='$(strip ${TCPPFLAGS})' \
91 LDFLAGS='$(strip ${TLDFLAGS})'
92 endif
93 MAKE_FLAGS+= ${XAKE_FLAGS}
94 FAKE_FLAGS+= ${XAKE_FLAGS}
96 ifeq ($(strip ${WRKDIR_BSD}),)
97 WRKDIR_BASE:= ${BUILD_DIR}
98 else
99 WRKDIR_BASE:= $(shell pwd)
100 endif
102 _EXTRACT_COOKIE= ${WRKDIST}/.extract_done
103 _PATCH_COOKIE= ${WRKDIST}/.prepared
104 _CONFIGURE_COOKIE= ${WRKBUILD}/.configure_done
105 _BUILD_COOKIE= ${WRKBUILD}/.build_done
106 _FAKE_COOKIE= ${WRKINST}/.fake_done
107 _IPKGS_COOKIE= ${PACKAGE_DIR}/.stamps/${PKG_NAME}\x01${PKG_VERSION}-${PKG_RELEASE}
109 _IN_PACKAGE:= 1
110 include ${TOPDIR}/mk/buildhlp.mk
111 -include info.mk
113 # defined in buildhlp.mk ('extract' can fail, use 'patch' then)
114 extract: ${_EXTRACT_COOKIE}
115 patch: ${_PATCH_COOKIE}
117 # defined below (will be moved to pkg-bottom.mk!)
118 configure: ${_CONFIGURE_COOKIE}
119 build: ${_BUILD_COOKIE}
120 fake: ${_FAKE_COOKIE}
122 # our recursive build entry point
123 build-all-pkgs: ${_IPKGS_COOKIE}
125 # there are some parameters to the PKG_template function
126 # 1.) Config.in identifier ADK_PACKAGE_$(1)
127 # 2.) name of the package, for single package mostly $(PKG_NAME)
128 # 3.) package version (upstream version) and package release (adk version),
129 # always $(PKG_VERSION)-$(PKG_RELEASE)
130 # 4.) dependencies to other packages, $(PKG_DEPENDS)
131 # 5.) description for the package, $(PKG_DESCR)
132 # 6.) section of the package, $(PKG_SECTION)
133 # 7.) special package options
134 # noscripts -> do not install scripts to $(STAGING_DIR)/target/scripts
135 # (needed for example for autoconf/automake)
136 # noremove -> do not remove files from $(STAGING_DIR)/target while
137 # cleaning (needed for toolchain packages like glibc/eglibc)
138 # should be package format independent and modular in the future
139 define PKG_template
140 IPKG_$(1)= $(PACKAGE_DIR)/$(2)_$(3)_${CPU_ARCH}.${PKG_SUFFIX}
141 IDIR_$(1)= $(WRKDIR)/fake-${CPU_ARCH}/pkg-$(2)
142 ifneq (${ADK_PACKAGE_$(1)}${DEVELOPER},)
143 ALL_IPKGS+= $$(IPKG_$(1))
144 ALL_IDIRS+= $${IDIR_$(1)}
145 endif
146 INFO_$(1)= $(PKG_STATE_DIR)/info/$(2).list
148 ifeq ($(ADK_PACKAGE_$(1)),y)
149 install-targets: $$(INFO_$(1))
150 endif
152 IDEPEND_$(1):= $$(strip $(4))
154 _ALL_CONTROLS+= $$(IDIR_$(1))/CONTROL/control
155 ICONTROL_$(1)?= $(WRKDIR)/.$(2).control
156 $$(IDIR_$(1))/CONTROL/control: ${_PATCH_COOKIE}
157 @echo "Package: $(2)" > $(WRKDIR)/.$(2).control
158 @echo "Section: $(6)" >> $(WRKDIR)/.$(2).control
159 @echo "Description: $(5)" >> $(WRKDIR)/.$(2).control
160 ${BASH} ${SCRIPT_DIR}/make-ipkg-dir.sh $${IDIR_$(1)} $${ICONTROL_$(1)} $(3) ${CPU_ARCH}
161 @adeps='$$(strip $${IDEPEND_$(1)})'; if [[ -n $$$$adeps ]]; then \
162 comma=; \
163 deps=; \
164 last=; \
165 for dep in $$$$adeps; do \
166 if [[ $$$$last = kernel && $$$$dep = \(* ]]; then \
167 deps="$$$$deps $$$$dep"; \
168 else \
169 deps="$$$$deps$$$$comma$$$$dep"; \
170 fi; \
171 comma=", "; \
172 last=$$$$dep; \
173 done; \
174 echo "Depends: $$$$deps" >>$${IDIR_$(1)}/CONTROL/control; \
176 @for file in conffiles preinst postinst prerm postrm; do \
177 [ ! -f ./files/$(2).$$$$file ] || cp ./files/$(2).$$$$file $$(IDIR_$(1))/CONTROL/$$$$file; \
178 done
180 $$(IPKG_$(1)): $$(IDIR_$(1))/CONTROL/control $${_FAKE_COOKIE}
181 ifeq ($(ADK_DEBUG),)
182 $${RSTRIP} $${IDIR_$(1)} $(MAKE_TRACE)
183 endif
184 @for file in $$$$(ls ./files/*.init 2>/dev/null); do \
185 fname=$$$$(echo $$$$file| sed -e "s#.*/##" -e "s#.init##"); \
186 check=$$$$(grep PKG $$$$file|cut -d ' ' -f 2); \
187 if [ "$$$$check" == $(2) ];then \
188 mkdir -p $$(IDIR_$(1))/etc/init.d && cp $$$$file $$(IDIR_$(1))/etc/init.d/$$$$fname; \
189 fi; \
190 done
191 @cd $${IDIR_$(1)}; for script in etc/init.d/*; do \
192 [[ -e $$$$script ]] || continue; \
193 chmod 0755 "$$$$script"; \
194 done
195 @mkdir -p $${PACKAGE_DIR} '$${STAGING_PARENT}/pkg' \
196 '$${STAGING_DIR}/scripts'
197 ifeq (,$(filter noremove,$(7)))
198 @if test -s '$${STAGING_PARENT}/pkg/$(1)'; then \
199 cd '$${STAGING_DIR}'; \
200 while read fn; do \
201 rm -f "$$$$fn"; \
202 done <'$${STAGING_PARENT}/pkg/$(1)'; \
204 endif
205 @rm -f '$${STAGING_PARENT}/pkg/$(1)'
206 @cd $${IDIR_$(1)}; \
207 x=$$$$(find tmp var -mindepth 1 2>/dev/null); if [[ -n $$$$x ]]; then \
208 echo 'WARNING: $${IPKG_$(1)} installs files into a' \
209 'ramdisk location:' >&2; \
210 echo "$$$$x" | sed 's/^/- /' >&2; \
211 fi; \
212 if [ "${PKG_NAME}" != "uClibc" -a "${PKG_NAME}" != "glibc" -a "${PKG_NAME}" != "eglibc" -a "${PKG_NAME}" != "libpthread" -a "${PKG_NAME}" != "libstdcxx" -a "${PKG_NAME}" != "libthread-db" ];then \
213 find lib \( -name lib\*.so\* -o -name lib\*.a \) \
214 -exec echo 'WARNING: $${IPKG_$(1)} installs files in /lib -' \
215 ' fix this!' >&2 \; -quit 2>/dev/null; fi; \
216 find usr ! -type d 2>/dev/null | \
217 grep -v -e '^usr/share' -e '^usr/man' -e '^usr/info' | \
218 tee '$${STAGING_PARENT}/pkg/$(1)' | \
219 cpio -apdlmu --quiet '$${STAGING_DIR}'
220 @cd '$${STAGING_DIR}'; grep 'usr/lib/.*\.la$$$$' \
221 '$${STAGING_PARENT}/pkg/$(1)' | while read fn; do \
222 chmod u+w $$$$fn; \
223 $(SED) "s,\(^libdir='\| \|-L\|^dependency_libs='\)/usr/lib,\1$(STAGING_DIR)/usr/lib,g" $$fn; \
224 done
225 ifeq (,$(filter noscripts,$(7)))
226 @cd '$${STAGING_DIR}'; grep 'usr/s*bin/' \
227 '$${STAGING_PARENT}/pkg/$(1)' | \
228 while read fn; do \
229 b="$$$$(dd if="$$$$fn" bs=2 count=1 2>/dev/null)"; \
230 [[ $$$$b = '#!' ]] || continue; \
231 cp "$$$$fn" scripts/; \
232 echo "scripts/$$$$(basename "$$$$fn")" \
233 >>'$${STAGING_PARENT}/pkg/$(1)'; \
234 done
235 endif
236 ifeq (,$(filter libmix,$(7)))
237 ifeq (,$(filter libonly,$(7)))
238 $${PKG_BUILD} $${IDIR_$(1)} $${PACKAGE_DIR} $(MAKE_TRACE)
239 endif
240 endif
242 clean-targets: clean-dev-$(1)
244 clean-dev-$(1):
245 ifeq (,$(filter noremove,$(7)))
246 @if test -s '$${STAGING_PARENT}/pkg/$(1)'; then \
247 cd '$${STAGING_DIR}'; \
248 while read fn; do \
249 rm -f "$$$$fn"; \
250 done <'$${STAGING_PARENT}/pkg/$(1)'; \
252 endif
253 @rm -f '$${STAGING_PARENT}/pkg/$(1)'
255 $$(INFO_$(1)): $$(IPKG_$(1))
256 $(PKG_INSTALL) $$(IPKG_$(1))
257 endef
259 install-targets:
260 install:
261 @$(CMD_TRACE) "installing... "
262 @$(MAKE) install-targets $(MAKE_TRACE)
264 clean-targets:
265 clean:
266 @$(CMD_TRACE) "cleaning... "
267 @$(MAKE) clean-targets $(MAKE_TRACE)
268 rm -rf ${WRKDIR} ${ALL_IPKGS} ${PACKAGE_DIR}/.stamps/${PKG_NAME}\x01*
270 distclean: clean
271 rm -f ${FULLDISTFILES}
273 .PHONY: all refetch extract patch configure \
274 build fake package install clean build-all-pkgs