kernel: move KERNEL_BUILD_DIR under BUILD_DIR to properly fix gcc/libc based dependencies
[openwrt.git] / package / Makefile
1 #
2 # Copyright (C) 2006-2010 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 curdir:=package
9
10 -include $(TMP_DIR)/.packagedeps
11 $(curdir)/builddirs:=$(sort $(package-) $(package-y) $(package-m))
12 $(curdir)/builddirs-install:=.
13 ifeq ($(SDK),1)
14 else
15   $(curdir)/builddirs-default:=. $(sort $(package-y) $(package-m))
16   $(curdir)/builddirs-prereq:=. $(sort $(prereq-y) $(prereq-m))
17 endif
18 ifneq ($(IGNORE_ERRORS),)
19   $(curdir)/builddirs-ignore-compile:= $(if $(filter n m y, $(IGNORE_ERRORS)),$(foreach m,$(IGNORE_ERRORS),$(package-$(subst n,,$(m)))),$(package-m) $(package-))
20 endif
21
22 ifdef CONFIG_USE_MKLIBS
23   define mklibs
24         rm -rf $(TMP_DIR)/mklibs-progs $(TMP_DIR)/mklibs-out
25         # first find all programs and add them to the mklibs list
26         find $(STAGING_DIR_ROOT) -type f -perm +100 -exec \
27                 file -r -N -F '' {} + | \
28                 awk ' /executable.*dynamically/ { print $$1 }' > $(TMP_DIR)/mklibs-progs
29         # find all loadable objects that are not regular libraries and add them to the list as well
30         find $(STAGING_DIR_ROOT) -type f -name \*.so\* -exec \
31                 file -r -N -F '' {} + | \
32                 awk ' /shared object/ { print $$1 }' >> $(TMP_DIR)/mklibs-progs
33         mkdir -p $(TMP_DIR)/mklibs-out
34         $(STAGING_DIR_HOST)/bin/mklibs -D \
35                 -d $(TMP_DIR)/mklibs-out \
36                 --sysroot $(STAGING_DIR_ROOT) \
37                 -L /lib \
38                 -L /usr/lib \
39                 -L /usr/lib/ebtables \
40                 --ldlib $(patsubst $(STAGING_DIR_ROOT)/%,/%,$(firstword $(wildcard \
41                         $(foreach name,ld-uClibc.so.* ld-linux.so.* ld-*.so, \
42                           $(STAGING_DIR_ROOT)/lib/$(name) \
43                         )))) \
44                 --target $(REAL_GNU_TARGET_NAME) \
45                 `cat $(TMP_DIR)/mklibs-progs` 2>&1
46         $(RSTRIP) $(TMP_DIR)/mklibs-out
47         for lib in `ls $(TMP_DIR)/mklibs-out/*.so.* 2>/dev/null`; do \
48                 LIB="$${lib##*/}"; \
49                 DEST="`ls "$(TARGET_DIR)/lib/$$LIB" "$(TARGET_DIR)/usr/lib/$$LIB" 2>/dev/null`"; \
50                 [ -n "$$DEST" ] || continue; \
51                 echo "Copying stripped library $$lib to $$DEST"; \
52                 cp "$$lib" "$$DEST" || exit 1; \
53         done
54   endef
55 endif
56
57 # where to build (and put) .ipk packages
58 OPKG:= \
59   IPKG_TMP=$(TMP_DIR)/ipkg \
60   IPKG_INSTROOT=$(TARGET_DIR) \
61   IPKG_CONF_DIR=$(STAGING_DIR)/etc \
62   IPKG_OFFLINE_ROOT=$(TARGET_DIR) \
63   $(XARGS) $(STAGING_DIR_HOST)/bin/opkg \
64         --offline-root $(TARGET_DIR) \
65         --force-depends \
66         --force-overwrite \
67         --force-postinstall \
68         --force-maintainer \
69         --add-dest root:/ \
70         --add-arch all:100 \
71         --add-arch $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(BOARD)):200
72
73 PACKAGE_INSTALL:=$(sort $(foreach pkg,$(package-y),$(lastword $(subst /,$(space),$(pkg)))))
74 PACKAGE_INSTALL_FILES:=$(patsubst %,$(PKG_INFO_DIR)/%.*.install,$(PACKAGE_INSTALL))
75
76 $(curdir)/cleanup: $(TMP_DIR)/.build
77         rm -rf $(STAGING_DIR_ROOT)
78
79 $(curdir)/install: $(TMP_DIR)/.build
80         - find $(STAGING_DIR_ROOT) -type d | $(XARGS) chmod 0755
81         rm -rf $(TARGET_DIR)
82         [ -d $(TARGET_DIR)/tmp ] || mkdir -p $(TARGET_DIR)/tmp
83         @$(FIND) `sed -e 's|.*|$(PACKAGE_DIR)/&_*.ipk|' $(PACKAGE_INSTALL_FILES)` | sort -u | $(OPKG) install
84         @for file in $(PACKAGE_INSTALL_FILES); do \
85                 [ -s $$file.flags ] || continue; \
86                 for flag in `cat $$file.flags`; do \
87                         $(OPKG) flag $$flag < $$file; \
88                 done; \
89         done || true
90         @-$(MAKE) package/preconfig
91         @if [ -d $(TOPDIR)/files ]; then \
92                 $(call file_copy,$(TOPDIR)/files/.,$(TARGET_DIR)); \
93         fi
94         @mkdir -p $(TARGET_DIR)/etc/rc.d
95         @( \
96                 cd $(TARGET_DIR); \
97                 for script in ./etc/init.d/*; do \
98                         grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
99                         IPKG_INSTROOT=$(TARGET_DIR) $$(which bash) ./etc/rc.common $$script enable; \
100                 done || true \
101         )
102         @-find $(TARGET_DIR) -name CVS   | $(XARGS) rm -rf
103         @-find $(TARGET_DIR) -name .svn  | $(XARGS) rm -rf
104         @-find $(TARGET_DIR) -name '.#*' | $(XARGS) rm -f
105         rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.postinst
106         $(if $(CONFIG_CLEAN_IPKG),rm -rf $(TARGET_DIR)/usr/lib/opkg)
107         $(call mklibs)
108
109 $(curdir)/index: FORCE
110         @(cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . 2>&1 > Packages && \
111                 gzip -9c Packages > Packages.gz \
112         )
113
114 $(curdir)/preconfig:
115
116 $(curdir)/flags-install:= -j1
117
118 $(eval $(call stampfile,$(curdir),package,prereq,.config))
119 $(eval $(call stampfile,$(curdir),package,cleanup,$(TMP_DIR)/.build))
120 $(eval $(call stampfile,$(curdir),package,compile,$(TMP_DIR)/.build))
121 $(eval $(call stampfile,$(curdir),package,install,$(TMP_DIR)/.build))
122
123 $(eval $(call subdir,$(curdir)))