build: add generic build template for u-boot packages
[openwrt/.git] / include / u-boot.mk
1 PKG_NAME ?= u-boot
2
3 ifndef PKG_SOURCE_PROTO
4 PKG_SOURCE = $(PKG_NAME)-$(PKG_VERSION).tar.bz2
5 PKG_SOURCE_URL = \
6         http://sources.lede-project.org \
7         ftp://ftp.denx.de/pub/u-boot
8 endif
9
10 PKG_BUILD_DIR = $(BUILD_DIR)/$(PKG_NAME)-$(BUILD_VARIANT)/$(PKG_NAME)-$(PKG_VERSION)
11
12 PKG_TARGETS := bin
13 PKG_FLAGS:=nonshared
14
15 PKG_LICENSE:=GPL-2.0 GPL-2.0+
16 PKG_LICENSE_FILES:=Licenses/README
17
18 PKG_BUILD_PARALLEL:=1
19
20 export GCC_HONOUR_COPTS=s
21
22 define Package/u-boot/install/default
23         $(CP) $(patsubst %,$(PKG_BUILD_DIR)/%,$(UBOOT_IMAGE)) $(1)/
24 endef
25
26 Package/u-boot/install = $(Package/u-boot/install/default)
27
28 define U-Boot/Init
29   BUILD_TARGET:=
30   BUILD_SUBTARGET:=
31   BUILD_DEVICES:=
32   NAME:=
33   DEPENDS:=
34   HIDDEN:=
35   VARIANT:=$(1)
36   UBOOT_CONFIG:=$(1)
37   UBOOT_IMAGE:=u-boot.bin
38 endef
39
40 TARGET_DEP = TARGET_$(BUILD_TARGET)$(if $(BUILD_SUBTARGET),_$(BUILD_SUBTARGET))
41
42 define Build/U-Boot/Target
43   $(eval $(call U-Boot/Init,$(1)))
44   $(eval $(call U-Boot/Default,$(1)))
45   $(eval $(call U-Boot/$(1),$(1)))
46
47  define Package/u-boot-$(1)
48     SECTION:=boot
49     CATEGORY:=Boot Loaders
50     TITLE:=U-Boot for $(NAME)
51     VARIANT:=$(VARIANT)
52     DEPENDS:=@!IN_SDK $(DEPENDS)
53     HIDDEN:=$(HIDDEN)
54     ifneq ($(BUILD_TARGET),)
55       DEPENDS += @$(TARGET_DEP)
56       ifneq ($(BUILD_DEVICES),)
57         DEFAULT := y if ($(TARGET_DEP)_Default \
58                 $(patsubst %,|| $(TARGET_DEP)_DEVICE_%,$(BUILD_DEVICES)) \
59                 $(patsubst %,|| $(patsubst TARGET_%,TARGET_DEVICE_%,$(TARGET_DEP))_DEVICE_%,$(BUILD_DEVICES)))
60       endif
61     endif
62     URL:=http://www.denx.de/wiki/U-Boot
63   endef
64
65   define Package/u-boot-$(1)/install
66         $$(Package/u-boot/install)
67   endef
68 endef
69
70 define Build/Configure/U-Boot
71         +$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) $(UBOOT_CONFIGURE_VARS) $(UBOOT_CONFIG)_config
72 endef
73
74 DTC=$(wildcard $(LINUX_DIR)/scripts/dtc/dtc)
75
76 define Build/Compile/U-Boot
77         +$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
78                 CROSS_COMPILE=$(TARGET_CROSS) \
79                 $(if $(DTC),DTC="$(DTC)")
80 endef
81
82 define BuildPackage/U-Boot/Defaults
83   Build/Configure/Default = $$$$(Build/Configure/U-Boot)
84   Build/Compile/Default = $$$$(Build/Compile/U-Boot)
85 endef
86
87 define BuildPackage/U-Boot
88   $(eval $(call BuildPackage/U-Boot/Defaults))
89   $(foreach type,$(if $(DUMP),$(UBOOT_TARGETS),$(BUILD_VARIANT)), \
90     $(eval $(call Build/U-Boot/Target,$(type)))
91   )
92   $(eval $(call Build/DefaultTargets))
93   $(foreach type,$(if $(DUMP),$(UBOOT_TARGETS),$(BUILD_VARIANT)), \
94     $(call BuildPackage,u-boot-$(type))
95   )
96 endef