treewide: add ORIG_PATH variable
[openwrt/staging/stintel.git] / target / imagebuilder / files / Makefile
index 0ce5f8b39be52062aeafa4fed06df6d1fc443699..5020373792450b5c6d7f06248d42464e79ffaac8 100644 (file)
@@ -13,6 +13,7 @@ export TOPDIR LC_ALL LANG
 export OPENWRT_VERBOSE=s
 all: help
 
+export ORIG_PATH:=$(if $(ORIG_PATH),$(ORIG_PATH),$(PATH))
 export PATH:=$(TOPDIR)/staging_dir/host/bin:$(PATH)
 
 ifneq ($(OPENWRT_BUILD),1)
@@ -27,6 +28,7 @@ include $(INCLUDE_DIR)/rootfs.mk
 
 include $(INCLUDE_DIR)/version.mk
 export REVISION
+export SOURCE_DATE_EPOCH
 
 define Helptext
 Available Commands:
@@ -34,8 +36,11 @@ Available Commands:
        info:   Show a list of available target profiles
        clean:  Remove images and temporary build files
        image:  Build an image (see below for more information).
+       manifest: Show all package that will be installed into the image
+       package_whatdepends: Show which packages have a dependency on this
+       package_depends: Show installation dependency of the package
 
-Building images:
+image:
        By default 'make image' will create an image with the default
        target profile and package set. You can use the following parameters
        to change that:
@@ -46,13 +51,29 @@ Building images:
        make image BIN_DIR="<path>" # alternative output directory for the images
        make image EXTRA_IMAGE_NAME="<string>" # Add this to the output image filename (sanitized)
        make image DISABLED_SERVICES="<svc1> [<svc2> [<svc3> ..]]" # Which services in /etc/init.d/ should be disabled
+       make image ADD_LOCAL_KEY=1 # store locally generated signing key in built images
+       make image ROOTFS_PARTSIZE="<size>" # override the default rootfs partition size in MegaBytes
 
-Print manifest:
+manifest:
        List "all" packages which get installed into the image.
        You can use the following parameters:
 
        make manifest PROFILE="<profilename>" # override the default target profile
        make manifest PACKAGES="<pkg1> [<pkg2> [<pkg3> ...]]" # include extra packages
+       make manifest STRIP_ABI=1 # remove ABI version from printed package names
+
+
+package_whatdepends:
+       List "all" packages that have a dependency on this package
+       You can use the following parameters:
+
+       make package_whatdepends PACKAGE="<pkg>"
+
+package_depends:
+       List "all" packages dependency of the package
+       You can use the following parameters:
+
+       make package_depends PACKAGE="<pkg>"
 
 endef
 $(eval $(call shexport,Helptext))
@@ -64,8 +85,10 @@ help: FORCE
 # override variables from rules.mk
 PACKAGE_DIR:=$(TOPDIR)/packages
 LISTS_DIR:=$(subst $(space),/,$(patsubst %,..,$(subst /,$(space),$(TARGET_DIR))))$(DL_DIR)
+export OPKG_KEYS:=$(TOPDIR)/keys
 OPKG:=$(call opkg,$(TARGET_DIR)) \
        -f $(TOPDIR)/repositories.conf \
+       --verify-program $(SCRIPT_DIR)/opkg-key \
        --cache $(DL_DIR) \
        --lists-dir $(LISTS_DIR)
 
@@ -98,6 +121,7 @@ staging_dir/host/.prereq-build: include/prereq-build.mk
 
 _call_info: FORCE
        echo 'Current Target: "$(TARGETID)"'
+       echo 'Current Architecture: "$(ARCH)"'
        echo 'Current Revision: "$(REVISION)"'
        echo 'Default Packages: $(DEFAULT_PACKAGES)'
        echo 'Available Profiles:'
@@ -126,14 +150,16 @@ _call_manifest: FORCE
        mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(DL_DIR)
        $(MAKE) package_reload >/dev/null
        $(MAKE) package_install >/dev/null
-       $(OPKG) list-installed
+       $(OPKG) list-installed $(if $(STRIP_ABI),--strip-abi)
 
 package_index: FORCE
        @echo >&2
        @echo Building package index... >&2
        @mkdir -p $(TMP_DIR) $(TARGET_DIR)/tmp
        (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
-               gzip -9nc Packages > Packages.gz \
+               gzip -9nc Packages > Packages.gz; \
+               $(if $(CONFIG_SIGNATURE_CHECK), \
+                       $(STAGING_DIR_HOST)/bin/usign -S -m Packages -s $(BUILD_KEY)) \
        ) >/dev/null 2>/dev/null
        $(OPKG) update >&2 || true
 
@@ -165,9 +191,14 @@ prepare_rootfs: FORCE
        @echo Finalizing root filesystem...
 
        $(CP) $(TARGET_DIR) $(TARGET_DIR_ORIG)
+       $(if $(CONFIG_SIGNATURE_CHECK), \
+               $(if $(ADD_LOCAL_KEY), \
+                       OPKG_KEYS=$(TARGET_DIR)/etc/opkg/keys/ \
+                       $(SCRIPT_DIR)/opkg-key add $(BUILD_KEY).pub \
+               ) \
+       )
        $(call prepare_rootfs,$(TARGET_DIR),$(USER_FILES),$(DISABLED_SERVICES))
 
-
 build_image: FORCE
        @echo
        @echo Building images...
@@ -206,24 +237,44 @@ ifneq ($(PROFILE),)
   endif
 endif
 
+_check_keys: FORCE
+ifneq ($(CONFIG_SIGNATURE_CHECK),)
+       @if [ ! -s $(BUILD_KEY) -o ! -s $(BUILD_KEY).pub ]; then \
+               echo Generate local signing keys... >&2; \
+               $(STAGING_DIR_HOST)/bin/usign -G \
+                       -s $(BUILD_KEY) -p $(BUILD_KEY).pub -c "Local build key"; \
+               $(SCRIPT_DIR)/opkg-key add $(BUILD_KEY).pub; \
+       fi
+       if [ ! -s $(BUILD_KEY).ucert ]; then \
+               echo Generate local certificate... >&2; \
+               $(STAGING_DIR_HOST)/bin/ucert -I \
+                       -c $(BUILD_KEY).ucert \
+                       -p $(BUILD_KEY).pub \
+                       -s $(BUILD_KEY); \
+       fi
+endif
+
 image:
        $(MAKE) -s _check_profile
+       $(MAKE) -s _check_keys
        (unset PROFILE FILES PACKAGES MAKEFLAGS; \
        $(MAKE) -s _call_image \
                $(if $(PROFILE),USER_PROFILE="$(PROFILE_FILTER)") \
                $(if $(FILES),USER_FILES="$(FILES)") \
                $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES)") \
                $(if $(BIN_DIR),BIN_DIR="$(BIN_DIR)") \
-               $(if $(DISABLED_SERVICES),DISABLED_SERVICES="$(DISABLED_SERVICES)"))
+               $(if $(DISABLED_SERVICES),DISABLED_SERVICES="$(DISABLED_SERVICES)") \
+               $(if $(ROOTFS_PARTSIZE),CONFIG_TARGET_ROOTFS_PARTSIZE="$(ROOTFS_PARTSIZE)"))
 
 manifest: FORCE
        $(MAKE) -s _check_profile
+       $(MAKE) -s _check_keys
        (unset PROFILE FILES PACKAGES MAKEFLAGS; \
        $(MAKE) -s _call_manifest \
                $(if $(PROFILE),USER_PROFILE="$(PROFILE_FILTER)") \
                $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES)"))
 
-whatdepends: FORCE
+package_whatdepends: FORCE
 ifeq ($(PACKAGE),)
        @echo 'Variable `PACKAGE` is not set but required by `whatdepends`'
        @exit 1
@@ -231,4 +282,13 @@ endif
        @$(MAKE) -s package_reload
        @$(OPKG) whatdepends -A $(PACKAGE)
 
-.SILENT: help info image manifest whatdepends
+package_depends: FORCE
+ifeq ($(PACKAGE),)
+       @echo 'Variable `PACKAGE` is not set but required by `package_depends`'
+       @exit 1
+endif
+       @$(MAKE) -s package_reload
+       @$(OPKG) depends -A $(PACKAGE)
+
+
+.SILENT: help info image manifest package_whatdepends package_depends