Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release: 0.1.0 prerelease #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/



Files:
*
Comment:
The `termux-core-package` repository is released under the `MIT` license, unless specified
differently in a file/directory or in any additional `Files` sections below.
License: [MIT](licenses/termux__termux-core-package__MIT.md)
185 changes: 185 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
export TERMUX_CORE_PKG__VERSION ?= 0.1.0
export TERMUX_CORE_PKG__ARCH
export TERMUX_CORE__INSTALL_PREFIX

export TERMUX__NAME ?= Termux# Default value: `Termux`
export TERMUX__LNAME ?= termux# Default value: `termux`

export TERMUX__REPOS_HOST_ORG_NAME ?= termux# Default value: `termux`
export TERMUX__REPOS_HOST_ORG_URL ?= https://github.com/$(TERMUX__REPOS_HOST_ORG_NAME)# Default value: `https://github.com/termux`

export TERMUX_APP__PACKAGE_NAME ?= com.termux# Default value: `com.termux`
export TERMUX_APP__DATA_DIR ?= /data/data/$(TERMUX_APP__PACKAGE_NAME)# Default value: `/data/data/com.termux`

export TERMUX__ROOTFS ?= $(TERMUX_APP__DATA_DIR)/files# Default value: `/data/data/com.termux/files`
export TERMUX__HOME ?= $(TERMUX__ROOTFS)/home# Default value: `/data/data/com.termux/files/home`
export TERMUX__PREFIX ?= $(TERMUX__ROOTFS)/usr# Default value: `/data/data/com.termux/files/usr`

export TERMUX_ENV__S_ROOT ?= TERMUX_# Default value: `TERMUX_`
export TERMUX_ENV__SS_TERMUX ?= _# Default value: `_`
export TERMUX_ENV__S_TERMUX ?= $(TERMUX_ENV__S_ROOT)$(TERMUX_ENV__SS_TERMUX)# Default value: `TERMUX__`
export TERMUX_ENV__SS_TERMUX_APP ?= APP__# Default value: `APP__`
export TERMUX_ENV__S_TERMUX_APP ?= $(TERMUX_ENV__S_ROOT)$(TERMUX_ENV__SS_TERMUX_APP)# Default value: `TERMUX_APP__`
export TERMUX_ENV__SS_TERMUX_CORE__TESTS ?= CORE__TESTS__# Default value: `CORE__TESTS__`
export TERMUX_ENV__S_TERMUX_CORE__TESTS ?= $(TERMUX_ENV__S_ROOT)$(TERMUX_ENV__SS_TERMUX_CORE__TESTS)# Default value: `TERMUX_CORE__TESTS__`

export TERMUX_PKGS__REPO_NAME ?= termux-packages# Default value: `termux-packages`
export TERMUX_PKGS__REPO_URL ?= $(TERMUX__REPOS_HOST_ORG_URL)/$(TERMUX_PKGS__REPO_NAME)# Default value: `https://github.com/termux/termux-packages`
export TERMUX_PKGS__BUILD__REPO_ROOT_DIR

export TERMUX_CORE_PKG__REPO_NAME ?= termux-core-package# Default value: `termux-core-package`
export TERMUX_CORE_PKG__REPO_URL ?= $(TERMUX__REPOS_HOST_ORG_URL)/$(TERMUX_CORE_PKG__REPO_NAME)# Default value: `https://github.com/termux/termux-core-package`
export TERMUX_CORE__TERMUX_REPLACE_TERMUX_CORE_SRC_SCRIPTS_FILE := $(TERMUX_PKGS__BUILD__REPO_ROOT_DIR)/packages/termux-core/build/scripts/termux-replace-termux-core-src-scripts



# Check if TERMUX_PKGS__BUILD__REPO_ROOT_DIR and TERMUX_CORE__TERMUX_REPLACE_TERMUX_CORE_SRC_SCRIPTS_FILE are set and exist
ifeq ($(TERMUX_PKGS__BUILD__REPO_ROOT_DIR),)
$(error The TERMUX_PKGS__BUILD__REPO_ROOT_DIR variable is not set)
else ifneq ($(patsubst /%,,$(TERMUX_PKGS__BUILD__REPO_ROOT_DIR)),)
$(error The TERMUX_PKGS__BUILD__REPO_ROOT_DIR variable '$(TERMUX_PKGS__BUILD__REPO_ROOT_DIR)' is not set to an absolute path)
else ifneq ($(shell test -d "$(TERMUX_PKGS__BUILD__REPO_ROOT_DIR)" && echo 1 || echo 0), 1)
$(error The termux-pacakges build repo directory does not exist at TERMUX_PKGS__BUILD__REPO_ROOT_DIR '$(patsubst /%,,$(TERMUX_PKGS__BUILD__REPO_ROOT_DIR))' path)
else ifneq ($(shell test -f "$(TERMUX_CORE__TERMUX_REPLACE_TERMUX_CORE_SRC_SCRIPTS_FILE)" && echo 1 || echo 0), 1)
$(error The 'replace-termux-core-src-scripts' file does not exist at TERMUX_CORE__TERMUX_REPLACE_TERMUX_CORE_SRC_SCRIPTS_FILE '$(TERMUX_CORE__TERMUX_REPLACE_TERMUX_CORE_SRC_SCRIPTS_FILE)' path)
endif



# If architecture not set, find it for the compiler based on which
# predefined architecture macro is defined. The `shell` function
# replaces newlines with a space and a literal space cannot be entered
# in a makefile as its used as a splitter, hence $(SPACE) variable is
# created and used for matching.
ifeq ($(TERMUX_CORE_PKG__ARCH),)
export PREDEFINED_MACROS := $(shell $(CC) -x c /dev/null -dM -E)
EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
ifneq (,$(findstring $(SPACE)#define __i686__ 1$(SPACE),$(SPACE)$(PREDEFINED_MACROS)$(SPACE)))
TERMUX_CORE_PKG__ARCH := i686
else ifneq (,$(findstring $(SPACE)#define __x86_64__ 1$(SPACE),$(SPACE)$(PREDEFINED_MACROS)$(SPACE)))
TERMUX_CORE_PKG__ARCH := x86_64
else ifneq (,$(findstring $(SPACE)#define __aarch64__ 1$(SPACE),$(SPACE)$(PREDEFINED_MACROS)$(SPACE)))
TERMUX_CORE_PKG__ARCH := aarch64
else ifneq (,$(findstring $(SPACE)#define __arm__ 1$(SPACE),$(SPACE)$(PREDEFINED_MACROS)$(SPACE)))
TERMUX_CORE_PKG__ARCH := arm
else
$(error Unsupported package arch)
endif
endif


ifeq ($(DESTDIR)$(PREFIX),)
TERMUX_CORE__INSTALL_PREFIX := $(TERMUX__PREFIX)
else
TERMUX_CORE__INSTALL_PREFIX := $(DESTDIR)$(PREFIX)
endif


# Escape `&`, `\` and `/` characters to be used as replacement string
# in sed `s/regexp/replacement/` expression.
# The `\` character needs to be escaped twice since used in command
# string with double quoted arguments, which are then passed to `sh`
# as a single quoted argument.
# - https://stackoverflow.com/a/29613573/14686958
TERMUX_PKGS__REPO_URL__ESCAPED := $(shell printf '%s' "$(TERMUX_PKGS__REPO_URL)" | sed -e '$$!{:a;N;$$!ba;}; s/[\]/\\\\&/g; s/[&/]/\\&/g; s/\n/\\&/g')
TERMUX_CORE_PKG__REPO_URL__ESCAPED := $(shell printf '%s' "$(TERMUX_CORE_PKG__REPO_URL)" | sed -e '$$!{:a;N;$$!ba;}; s/[\]/\\\\&/g; s/[&/]/\\&/g; s/\n/\\&/g')


BUILD_DIR := build
PREFIX_BUILD_DIR := $(BUILD_DIR)/usr
BIN_BUILD_DIR := $(PREFIX_BUILD_DIR)/bin
TESTS_BUILD_DIR := $(PREFIX_BUILD_DIR)/libexec/installed-tests/termux-core


TERMUX_CONSTANTS_SED_ARGS := \
-e "s%[@]TERMUX_CORE_PKG__VERSION[@]%$(TERMUX_CORE_PKG__VERSION)%g" \
-e "s%[@]TERMUX_CORE_PKG__ARCH[@]%$(TERMUX_CORE_PKG__ARCH)%g" \
-e "s%[@]TERMUX__LNAME[@]%$(TERMUX__LNAME)%g" \
-e "s%[@]TERMUX_APP__PACKAGE_NAME[@]%$(TERMUX_APP__PACKAGE_NAME)%g" \
-e "s%[@]TERMUX_APP__DATA_DIR[@]%$(TERMUX_APP__DATA_DIR)%g" \
-e "s%[@]TERMUX__ROOTFS[@]%$(TERMUX__ROOTFS)%g" \
-e "s%[@]TERMUX__HOME[@]%$(TERMUX__HOME)%g" \
-e "s%[@]TERMUX__PREFIX[@]%$(TERMUX__PREFIX)%g" \
-e "s%[@]TERMUX_ENV__S_ROOT[@]%$(TERMUX_ENV__S_ROOT)%g" \
-e "s%[@]TERMUX_ENV__S_TERMUX[@]%$(TERMUX_ENV__S_TERMUX)%g" \
-e "s%[@]TERMUX_ENV__S_TERMUX_APP[@]%$(TERMUX_ENV__S_TERMUX_APP)%g" \
-e "s%[@]TERMUX_ENV__S_TERMUX_CORE__TESTS[@]%$(TERMUX_ENV__S_TERMUX_CORE__TESTS)%g" \
-e "s%[@]TERMUX_PKGS__REPO_URL[@]%$(TERMUX_PKGS__REPO_URL__ESCAPED)%g" \
-e "s%[@]TERMUX_CORE_PKG__REPO_URL[@]%$(TERMUX_CORE_PKG__REPO_URL__ESCAPED)%g"

define replace-termux-constants
sed $(TERMUX_CONSTANTS_SED_ARGS) "$1.in" > "$2/$$(basename "$1" | sed "s/\.in$$//")"
endef


all: | pre-build
@echo "Building scripts/*"
@mkdir -p $(BIN_BUILD_DIR)
find src/scripts -maxdepth 1 -type f -name "*.in" -exec sh -c \
'sed $(TERMUX_CONSTANTS_SED_ARGS) "$$1" > $(BIN_BUILD_DIR)/"$$(basename "$$1" | sed "s/\.in$$//")"' sh "{}" \;
find $(BIN_BUILD_DIR) -maxdepth 1 -type f -exec chmod u+x "{}" \;
find src/scripts -maxdepth 1 -type l -exec cp -a "{}" $(BIN_BUILD_DIR)/ \;
"$(TERMUX_CORE__TERMUX_REPLACE_TERMUX_CORE_SRC_SCRIPTS_FILE)" $(BIN_BUILD_DIR)/*


@mkdir -p $(TESTS_BUILD_DIR)

@echo "Building tests/termux-core-tests"
$(call replace-termux-constants,tests/termux-core-tests,$(TESTS_BUILD_DIR))
chmod u+x $(TESTS_BUILD_DIR)/termux-core-tests


@echo "Building termux-core-package.json"
$(call replace-termux-constants,termux-core-package.json,$(BUILD_DIR))

@echo "Build termux-core-package successful"



pre-build: | clean
@echo "Building termux-core-package"
@mkdir -p $(BUILD_DIR)

clean:
rm -rf $(BUILD_DIR)

install:
@echo "Installing in $(TERMUX_CORE__INSTALL_PREFIX)"

install -d $(TERMUX_CORE__INSTALL_PREFIX)/bin
find $(BIN_BUILD_DIR) -maxdepth 1 \( -type f -o -type l \) -exec cp -a "{}" $(TERMUX_CORE__INSTALL_PREFIX)/bin/ \;

install -d $(TERMUX_CORE__INSTALL_PREFIX)/libexec/installed-tests/termux-core
find $(TESTS_BUILD_DIR) -maxdepth 1 -type f -exec install "{}" -t $(TERMUX_CORE__INSTALL_PREFIX)/libexec/installed-tests/termux-core/ \;

uninstall:
@echo "Uninstalling from $(TERMUX_CORE__INSTALL_PREFIX)"

find src/scripts -maxdepth 1 \( -type f -o -type l \) -exec sh -c \
'rm -f "$(TERMUX_CORE__INSTALL_PREFIX)/bin/$$(basename "$$1" | sed "s/\.in$$//")"' sh "{}" \;

rm -rf $(TERMUX_CORE__INSTALL_PREFIX)/libexec/installed-tests/termux-core



deb: all
termux-create-package $(BUILD_DIR)/termux-core-package.json



test: all
$(MAKE) TERMUX_CORE__INSTALL_PREFIX=install install

@echo "Running tests"
install/libexec/installed-tests/termux-core/termux-core-tests --tests-path="install/libexec/installed-tests/termux-core" -vvv all

test-runtime: all
$(MAKE) TERMUX_CORE__INSTALL_PREFIX=install install

@echo "Running runtime tests"
install/libexec/installed-tests/termux-core/termux-core-tests --tests-path="install/libexec/installed-tests/termux-core" -vvv runtime



.PHONY: all pre-build clean install uninstall deb test test-runtime
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
# termux-core-package

The [`termux-core`](https://github.com/termux/termux-core-package) package provides utils for Termux core. It provides core functionality for the Termux app that must exist in all Termux execution environments including forks, and is used by other Termux packages and also 3rd party packages.

### Contents

- [Project](#project)

---

 





## Project

**Check the `termux-core-package` project info [here](site/pages/en/projects/index.md), including `docs` and `releases` info.**

---

 
23 changes: 23 additions & 0 deletions licenses/termux__termux-core-package__MIT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
MIT License

Copyright (c) 2024 termux

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

- https://opensource.org/licenses/MIT
145 changes: 145 additions & 0 deletions site/pages/en/projects/docs/developer/build/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
---
page_ref: "@ARK_PROJECT__VARIANT@/termux/termux-core-package/docs/@ARK_DOC__VERSION@/developer/build/index.md"
---

# termux-core-package Build Docs

<!-- @ARK_DOCS__HEADER_PLACEHOLDER@ -->

The [`termux-core`](https://github.com/termux/termux-core-package) build instructions are available below. For install instructions, check [`install`](../../install/index.md) docs.

### Contents

- [Build Methods](#build-methods)

---

&nbsp;





## Build Methods

The `termux-core` package provided by Termux is built from the [`termux/termux-core-package`](https://github.com/termux/termux-core-package) repository. It can be built with the following methods.

- [Termux Packages Build Infrastructure](#termux-packages-build-infrastructure)
- [On Device With `make`](#on-device-with-make)

**The [Termux Packages Build Infrastructure](#termux-packages-build-infrastructure) is the recommended way to build `termux-core`.** If the `termux-core` package is built with the [Termux Packages Build Infrastructure](#termux-packages-build-infrastructure), then the Termux variable values in the `Makefile` are dynamically set to the values defined in the [`properties.sh`] file of the build infrastructure by passing them to `make` via the `$TERMUX_PKG_EXTRA_MAKE_ARGS` variable set in the [`packages/termux-core/build.sh`] file. If `termux-core` is built with `make` instead, then the hardcoded fallback/default Termux variable values in the `Makefile` will get used during build time, which may affect or break `termux-core` at runtime if current app/environment is different from the Termux default one (`TERMUX_APP__PACKAGE_NAME=com.termux` and `TERMUX__ROOTFS=/data/data/com.termux/files`). However, if `make` must be used for some reason, and building for a different app/environment than the Termux default, like for a Termux fork or alternate package name/rootfs, then manually update the hardcoded values in the `Makefile` or manually pass the alternate values to the `make` command.

## &nbsp;

&nbsp;



### Termux Packages Infrastructure

To build the `termux-core` package with the [`termux-packages`](https://github.com/termux/termux-packages) build infrastructure, the provided [`build-package.sh`](https://github.com/termux/termux-packages/blob/master/build-package.sh) script can be used. Check the [Build environment](https://github.com/termux/termux-packages/wiki/Build-environment) and [Building packages](https://github.com/termux/termux-packages/wiki/Building-packages) docs for how to build packages.

#### Default Sources

To build the `termux-core` package from its default repository release tag or git branch sources that are used for building the package provided in Termux repositories, just clone the `termux-packages` repository and build.

```shell
# Clone `termux-packages` repo and switch current working directory to it.
git clone https://github.com/termux/termux-packages.git
cd termux-packages

# (OPTIONAL) Run termux-packages docker container if running off-device.
./scripts/run-docker.sh

# Force build package and download dependencies from Termux packages repositories.
./build-package.sh -f -I termux-core
```

#### Local Sources

To build the `termux-core` package from its local sources or a pull request branch, clone the `termux-packages` repository, clone/create the `termux-core-package` repository locally, make required changes to the [`packages/termux-core/build.sh`] file to update the source url and then build.

Check [Build Local Package](https://github.com/termux/termux-packages/wiki/Building-packages#build-local-package) and [Package Build Local Source URLs](https://github.com/termux/termux-packages/wiki/Creating-new-package#package-build-local-source-urls) docs for more info on how to building packages from local sources.*

```shell
# Clone `termux-packages` repo and switch current working directory to it.
git clone https://github.com/termux/termux-packages.git
cd termux-packages

# Update `$TERMUX_PKG_SRCURL` variable in `packages/termux-core/build.sh`.
# We use `file:///path/to/source/dir` format for the local source URL.
TERMUX_PKG_SRCURL=file:///home/builder/termux-packages/sources/termux-core-package
TERMUX_PKG_SHA256=SKIP_CHECKSUM

# Clone/copy `termux-core-package` repo at `termux-packages/sources/termux-core-package`
# directory. Make sure current working directory is root directory of
# termux-packages repo when cloning.
git clone https://github.com/termux/termux-core-package.git sources/termux-core-package

# (OPTIONAL) Manually switch to different (pull) branch that exists on
# origin if required, or to the one defined in $TERMUX_PKG_GIT_BRANCH
# variable of build.sh file, as it will not be automatically checked out.
# By default, the repo default/current branch that's cloned
# will get built, which is usually `master` or `main`.
# Whatever is the current state of the source directory will
# be built as is, including any uncommitted changes to current
# branch.
(cd sources/termux-core-package; git checkout <branch_name>)

# (OPTIONAL) Run termux-packages docker container if running off-device.
./scripts/run-docker.sh

# Force build package and download dependencies from Termux packages repositories.
./build-package.sh -f -I termux-core
```

## &nbsp;

&nbsp;



### On Device With `make`

To build `termux-core` package on the device inside the Termux app with [`make`](https://www.gnu.org/software/make), check below. Do not use a PC to build the package as PC architecture may be different from target device architecture and the `clang` compiler wouldn't have been patched like Termux provided one is so that built packages are compatible with Termux, like patches done for `DT_RUNPATH`.

```shell
# Install dependencies.
pkg install clang git make termux-create-package

# Export path to `termux-packages` build repo directory needed to run
# `termux-replace-termux-core-src-scripts` script in `Makefile`.
export TERMUX_PKGS__BUILD__REPO_ROOT_DIR="/path/to/termux-packages/repo/dir"

# Clone/copy `termux-core-package` repo at `termux-core-package` directory
# and switch current working directory to it.
git clone https://github.com/termux/termux-core-package.git termux-core-package
cd termux-core-package

# Whatever is the current state of the `termux-core-package` directory will be built.
# If required, manually switch to different (pull) branch that exists on origin.
git checkout <branch_name>

# Remove any existing deb files in current directory.
rm -f termux-core_*.deb

# Build deb file for the architecture of the host device/clang compiler.
make deb

# Install.
# We use shell * glob expansion to automatically select the deb file
# regardless of `_<version>_<arch>.deb` suffix, that's why existing
# deb files were deleted earlier in case any existed with the wrong version.
dpkg -i termux-core_*.deb
```

---

&nbsp;





[`packages/termux-core/build.sh`]: https://github.com/termux/termux-packages/blob/master/packages/termux-core/build.sh
[`properties.sh`]: https://github.com/termux/termux-packages/blob/master/scripts/properties.sh
Loading