diff --git a/README.md b/README.md index 090c61d2..2bbb46cf 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,27 @@ Generate a template for a new package: $ pmbootstrap newapkbuild "https://gitlab.com/postmarketOS/osk-sdl/-/archive/0.52/osk-sdl-0.52.tar.bz2" ``` +#### Default architecture + +Packages will be compiled for the architecture of the device running +pmbootstrap by default. For example, if your `x86_64` PC runs pmbootstrap, it +would build a package for `x86_64` with this command: +``` +$ pmbootstrap build hello-world +``` + +If you would rather build for the target device selected in `pmbootstrap init` +by default, then use the `build_default_device_arch` option: +``` +$ pmbootstrap config build_default_device_arch True +``` + +If your target device is `pine64-pinephone` for example, pmbootstrap will now +build this package for `aarch64`: +``` +$ pmbootstrap build hello-world +``` + ### Chroots Enter the `armhf` building chroot: ``` diff --git a/pmb/build/autodetect.py b/pmb/build/autodetect.py index adeced40..ad2a2b9b 100644 --- a/pmb/build/autodetect.py +++ b/pmb/build/autodetect.py @@ -40,7 +40,7 @@ def arch(args, pkgname): :returns: arch string like "x86_64" or "armhf". Preferred order, depending on what is supported by the APKBUILD: * native arch - * device arch + * device arch (this will be preferred instead if build_default_device_arch is true) * first arch in the APKBUILD """ aport = pmb.helpers.pmaports.find(args, pkgname) @@ -50,14 +50,19 @@ def arch(args, pkgname): apkbuild = pmb.parse.apkbuild(f"{aport}/APKBUILD") arches = apkbuild["arch"] - if ("noarch" in arches or - "all" in arches or - pmb.config.arch_native in arches): - return pmb.config.arch_native - arch_device = args.deviceinfo["arch"] - if arch_device in arches: - return arch_device + if args.build_default_device_arch: + preferred_arch = args.deviceinfo["arch"] + preferred_arch_2nd = pmb.config.arch_native + else: + preferred_arch = pmb.config.arch_native + preferred_arch_2nd = args.deviceinfo["arch"] + + if "noarch" in arches or "all" in arches or preferred_arch in arches: + return preferred_arch + + if preferred_arch_2nd in arches: + return preferred_arch_2nd try: return apkbuild["arch"][0] diff --git a/pmb/config/__init__.py b/pmb/config/__init__.py index 478c9bd9..6d95efe4 100644 --- a/pmb/config/__init__.py +++ b/pmb/config/__init__.py @@ -63,6 +63,7 @@ sudo = which_sudo() config_keys = [ "aports", "boot_size", + "build_default_device_arch", "build_pkgs_on_install", "ccache_size", "device", @@ -130,7 +131,8 @@ defaults = { "boot_size": "256", "extra_space": "0", "sudo_timer": False, - "qemu_redir_stdio": False + "qemu_redir_stdio": False, + "build_default_device_arch": False, }