pmt: initial 2.5.0 update

This commit is contained in:
2024-07-21 20:20:17 +03:00
parent 4f8e15935a
commit 91713b86be
59 changed files with 2238 additions and 888 deletions

6
build/bash/additional-vars Executable file
View File

@@ -0,0 +1,6 @@
NDK_PROG=false
FORCE_GEN=false
THIS_IS=main
UPDATE_MAKEFILES=false
SOURCE_DIRNAME=src
OUT_DIRNAME=out

36
build/bash/check-makefiles Executable file
View File

@@ -0,0 +1,36 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
[ ! "${THIS_IS}" = "main" ] && abort "The caller is not the main makefile. Something's wrong."
try_with="Try with force mode (FORCE_GEN=true)."
if [ "${NDK_PROG}" = "true" ]; then
mfiles=("${SOURCE_DIR}/Android.mk" "${SOURCE_DIR}/Application.mk")
else
mfiles=("${OUT_DIR}/Makefile" "${SOURCE_DIR}/Makefile")
fi
for mfile in ${mfiles[0]} ${mfiles[1]}; do
[ -f "${mfile}" ] && \
if [ "${FORCE_GEN}" = "true" ]; then
rm -f "${mfile}"
else
abort "$(output=$(dirname ${mfile}) && basename "${output}")/$(basename ${mfile}) exits."
fi
done

42
build/bash/clean-makefiles Executable file
View File

@@ -0,0 +1,42 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
. build/bash/vars
. build/bash/functions
[ ! "${THIS_IS}" = "main" ] && abort "The caller is not the main makefile. Something's wrong."
if [ "${NDK_PROG}" = "true" ]; then
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Removing Android.mk..."
rm -f ${SOURCE_DIR}/Android.mk
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Removing Application.mk..."
rm -f ${SOURCE_DIR}/Application.mk
else
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Info: Main makefile won't be deleted."
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Removing output directory makefile..."
rm -f ${OUT_DIR}/Makefile
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Removing source directory makefile"
rm -f ${SOURCE_DIR}/Makefile
fi
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Success."

37
build/bash/functions Executable file
View File

@@ -0,0 +1,37 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
function abort()
{
[ -n "$1" ] && echo -e " - ${RED}${BOLD}Error:${BOLD_RESET}${RESET} $1"
exit 1
}
function read_file()
{
cat "$1" >> "$2" || abort "failed to read/write $1/$2"
}
function gen()
{
[ "${FORCE_GEN}" = "true" -a "${UPDATE_MAKEFILES}" = "true" ] && rm -f "$1"
touch "$1" || abort "failed to generate: $1"
}
function print()
{
echo -e "$1"
}

29
build/bash/gen-header Executable file
View File

@@ -0,0 +1,29 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
[ -z ${NDK_ROOT_DIR} ] && \
echo "Please set NDK_ROOT_DIR variable!" && \
exit 1
[ -z ${NDK_PROJECT_PATH} ] && \
echo "Please set NDK_PROJECT_PATH variable!" && \
exit 1
CC_IS="${NDK_ROOT_DIR}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang"
CC_VERS=$(${CC_IS} --version | head -n 1)
mkdir -p ${NDK_PROJECT_PATH}/include/pmt/generated
echo -e "#define __NDK_CC_VERSION__ \"${CC_VERS}\"" > ${NDK_PROJECT_PATH}/include/pmt/generated/clang-version.h

64
build/bash/gen-makefiles Executable file
View File

@@ -0,0 +1,64 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
. build/bash/vars
. build/bash/functions
[ ! "${UPDATE_MAKEFILES}" = "true" ] && . build/bash/check-makefiles
[ ! "${THIS_IS}" = "main" ] && abort "The caller is not the main makefile. Something's wrong."
if [ "${UPDATE_MAKEFILES}" = "true" ]; then
GENR="Re-generating"
else
GENR="Generating"
fi
if [ "${NDK_PROG}" = "true" ]; then
gen "${SOURCE_DIR}/Android.mk"
gen "${SOURCE_DIR}/Application.mk"
else
gen "${CUR_DIR}/Makefile"
gen "${OUT_DIR}/Makefile"
gen "${SOURCE_DIR}/Makefile"
fi
if [ "${NDK_PROG}" = "true" ]; then
print " - ${GENR} Android.mk..."
read_file "${OTHERS}/makefile.androidmk" "${SOURCE_DIR}/Android.mk"
print " - ${GENR} Application.mk"
read_file "${OTHERS}/makefile.applicationmk" "${SOURCE_DIR}/Application.mk"
else
print " - Re-generating main makefile..."
rm -f "${CUR_DIR}/Makefile"
read_file "${OTHERS}/makefile.main" "${CUR_DIR}/Makefile"
print " - ${GENR} output directory makefile..."
read_file "${OTHERS}/makefile.outdir" "${OUT_DIR}/Makefile"
print " - ${GENR} source directory makefile..."
read_file "${OTHERS}/makefile.sourcedir" "${SOURCE_DIR}/Makefile"
fi
print " - Success."

33
build/bash/vars Executable file
View File

@@ -0,0 +1,33 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
. build/bash/additional-vars
CUR_DIR=$(pwd)
SOURCE_DIR=${CUR_DIR}/${SOURCE_DIRNAME}
OUT_DIR=${CUR_DIR}/${OUT_DIRNAME}
BUILD=${CUR_DIR}/build
BASH_DIR=$(pwd)
OTHERS=${BUILD}/others
TOOLS=${BUILD}/tools
# font types, colors etc
BOLD="\e[1m"
BOLD_RESET="\e[0m"
RESET="\033[0m"
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[0;33m"

1
build/config/INS_STAT.mk Executable file
View File

@@ -0,0 +1 @@
INSTALL_SUCCESS := true

52
build/config/Makefile Executable file
View File

@@ -0,0 +1,52 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
include env.mk
#########################################
# #
# Apply Configuration #
# #
# Warning: please do not edit #
# #
#########################################
CC = clang
CFLAGS ?= "-O3 -I../include -std=c11 -pedantic -Wall -Wextra -Werror -Wno-nullability-extension -Wno-gnu-zero-variadic-macro-arguments $(PMT_EXTRA_CFLAGS)"
# set compiler setting (clang-gcc and ar)
ifneq ($(PMT_CC),)
CC ?= $(PMT_CC)
else
CC ?= clang
endif
ifneq ($(PMT_AR),)
AR ?= $(PMT_AR)
else
AR ?= ar
endif
# compiler flags settings
ifneq ($(PMT_ENABLE_DEBUG),)
CFLAGS += -gdwarf-5 -fsanitize=address
endif
# write current env configuration to oldenv.mk
all:
@echo "CC := $(CC)" > oldenv.mk; \
echo "AR := $(AR)" >> oldenv.mk; \
echo "CFLAGS := $(CFLAGS)" >> oldenv.mk

1
build/config/UNINS_STAT.mk Executable file
View File

@@ -0,0 +1 @@
UNINSTALLED_SUCCESS :=

38
build/config/env.mk Executable file
View File

@@ -0,0 +1,38 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#########################################
# #
# Configuration Flags #
# #
# Warning: you can edit #
# #
#########################################
# speficy c compiler (cc)
PMT_CC ?=
# speficy ar
PMT_AR ?=
# addionital compiler flags
PMT_EXTRA_CFLAGS ?=
# debugging mode (binary). it's enabling address sanitizer and source level debug information with dwarf version 5
PMT_ENABLE_DEBUG ?=
#########################################
#########################################

9
build/deb/DEBIAN/control_32 Executable file
View File

@@ -0,0 +1,9 @@
Source: pmt
Package: pmt
Version: 2.5.0
Architecture: arm
Description: pmt is for reading, writing and formatting partitions of android devices
Section: misc
Priority: optional
Maintainer: YZBruh <yagizzengin73@gmail.com>
Standards-Version: 4.5.0

9
build/deb/DEBIAN/control_64 Executable file
View File

@@ -0,0 +1,9 @@
Source: pmt
Package: pmt
Version: 2.5.0
Architecture: aarch64
Description: pmt is for reading, writing and formatting partitions of android devices
Section: misc
Priority: optional
Maintainer: YZBruh <yagizzengin73@gmail.com>
Standards-Version: 4.5.0

99
build/deb/deb.mk Executable file
View File

@@ -0,0 +1,99 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#####
# sub-make for making deb package
#####
THIS_IS := debutils
# include needed variables
include ../../Makefile.inc
TEMP_DIR := $(DEBUTILS_DIR)/template
ifeq ($(FOR_THIS),64)
DEB_ARCH_NAME := arm64-v8a
else ifeq ($(FOR_THIS),32)
DEB_ARCH_NAME := armeabi-v7a
endif
# controls the presence of file/directory. usage: $(call check_local,<FILE_OR_DIRECTORY_PATH>,<PACKAGE_STAT: 1, NULL>)
define check_local
# the first argument is taken and controlled by the file/directory with -e option
if [ ! -e $1 ]; then \
if [ $2 = 1 ]; then \
printf " - Package not builded! Please build package and try again.\n"; \
else \
printf " ==> Not found: $1\n"; \
fi; \
if [ -d "$(TEMP_DIR)" ]; then \
rm -rf $(TEMP_DIR); \
fi; \
exit 1; \
fi;
endef
# make deb package
all:
$(hide)printf " --------- Making deb package ---------\n"
# remove template directory
$(call erase,$(TEMP_DIR))
$(hide)printf " - Checking files and directories (only neededs)...\n"
# check some files and directories with parsing DEB_CHECKS variable
$(foreach deb_chfile, \
$(DEB_CHECKS), \
$(call check_local,$(deb_chfile)) \
)
# check build status
$(call check_local, \
$(BINARY_DIR)/pmt, \
1 \
)
# make template and output directories
$(call mdir,$(TEMP_DIR),"y")
$(call mdir,$(DEB_DIR),"y")
$(hide)printf " - Copying files...\n"
# prepare
$(hide)cp -r $(DEBUTILS_DIR)/data $(TEMP_DIR) || exit 1
$(hide)rm -f $(DEBTERMUX_USR)/share/man/man1/dummy
$(hide)rm -f $(DEBTERMUX_USR)/bin/dummy
$(call mdir,$(TEMP_DIR)/DEBIAN)
$(hide)abort() { \
if [ -d $(TEMP_DIR) ]; then \
rm -rf $(TEMP_DIR); \
fi; \
if [ -d $(DEB_DIR) ]; then \
rm -rf $(DEB_DIR); \
fi; \
exit 1; \
}; \
if [ ! "$(FOR_THIS)" = "64" ] && [ ! "$(FOR_THIS)" = "32" ]; then \
printf " - İnvalid arch number: $(FOR_THIS)\n" && abort; \
fi; \
printf " - Selected arm-$(FOR_THIS) package control file.\n"; \
cp $(DEBUTILS_DIR)/DEBIAN/control_$(FOR_THIS) $(TEMP_DIR)/DEBIAN/control || abort; \
cp $(DEBUTILS_DIR)/mandoc/$(TARGET).8.gz $(DEBTERMUX_USR)/share/man/man8 || abort; \
cp $(BINARY_DIR)/$(TARGET) $(DEBTERMUX_USR)/bin || abort; \
printf " - Starting dpkg-deb...\n"; \
sleep 2; \
chmod -R 755 *; \
dpkg-deb -b $(TEMP_DIR) $(DEB_DIR)/$(TARGET)-$(DEB_ARCH_NAME).deb || abort; \
# cleanup template directory
rm -rf $(TEMP_DIR); \
printf " - Done!\n"
# end

BIN
build/deb/mandoc/pmt.8.gz Executable file

Binary file not shown.

135
build/main.mk Executable file
View File

@@ -0,0 +1,135 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
UPDATE_MAKEFILES = false
all:
$(hide)# To save configuration, the makefile in the config directory
$(MAKE_HIDE) $(SILENT) -C $(BUILD)/config || exit 1
$(hide)# start the main build process
$(MAKE_HIDE) $(SILENT) -C $(SOURCE_DIRNAME) INC_OLDENV=true || exit 1
# cleaner functions
.PHONY: clean
clean:
$(hide)printf "Cleaning directories...\n"; \
# cleanup out/binary
$(hide)if [ -d $(BINARY_DIR) ]; then \
printf "==> $(OUT_DIRNAME)/`basename $(BINARY_DIR)`\n"; \
rm -rf "$(BINARY_DIR)"; \
fi; \
# cleanup out/package
$(hide)if [ -d $(PACKAGE_DIR) ]; then \
printf "==> $(OUT_DIRNAME)/`basename $(PACKAGE_DIR)`\n"; \
rm -rf "$(PACKAGE_DIR)"; \
fi; \
# cleanup out/static_libs
$(hide)if [ -d $(STATICLIB_DIR) ]; then \
printf "==> $(OUT_DIRNAME)/`basename $(STATICLIB_DIR)`\n"; \
rm -rf "$(STATICLIB_DIR)"; \
fi; \
# cleanup out/debpackage
$(hide)if [ -d $(DEB_DIR) ]; then \
printf "==> $(OUT_DIRNAME)/`basename $(DEB_DIR)`\n"; \
rm -rf "$(DEB_DIR)"; \
fi; \
sleep 2; \
# clean the objects by calling the receipt in the source directory
$(MAKE_HIDE) $(SILENT) -C $(SOURCE_DIRNAME) clean INC_OLDENV=false || exit 1
$(hide)sleep 1
$(hide)printf "Success.\n"
# helper function
.PHONY: help
help:
$(hide)printf " ------- Partition Manager help -------\n\n"
$(hide)printf " Commands:\n"
$(hide)printf " $(MAKE) ==> Build Partition Manager.\n"
$(hide)printf " $(MAKE) deb ==> Generate debian package for termux.\n"
$(hide)printf " $(MAKE) clean ==> Clear builded binary.\n"
$(hide)printf " $(MAKE) install ==> It installs $(TARGET) into termux.\n"
$(hide)printf " $(MAKE) uninstall ==> It uninstalls $(TARGET) into termux.\n"
$(hide)printf " $(MAKE) gen-makefiles ==> Generate makefiles for build.\n"
$(hide)printf " $(MAKE) gen-ndk-makefiles ==> Generate NDK makefiles for build.\n"
$(hide)printf " $(MAKE) clean-makefiles ==> Cleanup makefiles.\n"
$(hide)printf " $(MAKE) clean-ndk-makefiles ==> Cleanup NDK makefiles.\n"
$(hide)printf " $(MAKE) update-makefiles ==> Re-generate makefiles.\n"
$(hide)printf " $(MAKE) update-ndk-makefiles ==> Re-generate NDK makefiles.\n"
$(hide)printf " $(MAKE) help ==> Display this help message.\n\n"
# deb maker
.PHONY: deb
deb:
$(MAKE_HIDE) $(SILENT) -C $(DEBUTILS_DIR) -f deb.mk FOR_THIS=$(FOR_THIS) || exit 1
$(hide)printf ""
# install pmt in to termux
.PHONY: install
install:
$(MAKE_HIDE) $(SILENT) -C $(OUT_DIRNAME) install || exit 1
# uninstall pmt in to termux
.PHONY: uninstall
uninstall:
$(MAKE_HIDE) $(SILENT) -C $(OUT_DIRNAME) uninstall || exit 1
# clean ndk makefiles
.PHONY: gen-ndk-makefiles
gen-ndk-makefiles:
$(eval NDK_PROG = true)
$(call save-gen-vars)
$(call gen-ndk-mfiles)
$(hide)printf ""
.PHONY: gen-makefiles
gen-makefiles:
$(call save-gen-vars)
$(call gen-mfiles)
$(hide)printf ""
.PHONY: update-ndk-makefiles
update-ndk-makefiles:
$(hide)printf " ------ Updating NDK makefiles ------ \n"
$(eval NDK_PROG = true)
$(eval UPDATE_MAKEFILES = true)
$(call save-gen-vars)
$(call clean-ndk-mfiles)
$(call gen-ndk-mfiles)
$(hide)printf ""
.PHONY: update-makefiles
update-makefiles:
$(hide)printf " ------ Updating makefiles ------ \n"
$(eval UPDATE_MAKEFILES = true)
$(call save-gen-vars)
$(call clean-ndk-mfiles)
$(call gen-mfiles)
$(hide)printf ""
.PHONY: clean-ndk-makefiles
clean-ndk-makefiles:
$(eval NDK_PROG = true)
$(call save-gen-vars)
$(call clean-ndk-mfiles)
$(hide)printf ""
.PHONY: clean-makefiles
clean-makefiles:
$(call save-gen-vars)
$(call clean-mfiles)
$(hide)printf ""
# end

98
build/others/makefile.androidmk Executable file
View File

@@ -0,0 +1,98 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
########
# 2.5.0
########
LOCAL_PATH := $(call my-dir)
include $(LOCAL_PATH)/../build/config/env.mk
PMT_CFLAGS = \
-O3 \
-std=c11 \
-pedantic \
-Wall \
-Wextra \
-Werror \
-Wno-nullability-extension \
-Wno-gnu-zero-variadic-macro-arguments \
-D__NDK_BUILD \
$(EXTRA_COMPILER_FLAGS)
ifneq ($(PMT_ENABLE_DEBUG),)
PMT_CFLAGS += -gdwarf-5 -fsanitize=address
endif
include $(CLEAR_VARS)
LOCAL_MODULE := libpmt_root
LOCAL_SRC_FILES := root.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
LOCAL_CFLAGS := $(PMT_CFLAGS)
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libpmt_debugging
LOCAL_SRC_FILES := debugging.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
LOCAL_CFLAGS := $(PMT_CFLAGS)
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libpmt_partitiontool
LOCAL_SRC_FILES := partitiontool.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
LOCAL_CFLAGS := $(PMT_CFLAGS)
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libpmt_list
LOCAL_SRC_FILES := listpart.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
LOCAL_CFLAGS := $(PMT_CFLAGS)
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := pmt
LOCAL_SRC_FILES := \
pmt.c \
versioner.c \
get_stat.c \
tools.c \
lang_tools.c \
languages.c \
docs.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
LOCAL_STATIC_LIBRARIES := \
libpmt_root \
libpmt_debugging \
libpmt_partitiontool \
libpmt_list
LOCAL_CFLAGS := $(PMT_CFLAGS)
include $(BUILD_EXECUTABLE)
# end

View File

@@ -0,0 +1,30 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
########
# 2.5.0
########
# architecture
APP_ABI := \
arm64-v8a \
armeabi-v7a
APP_PLATFORM := android-21
APP_OPTIM := release
# end

26
build/others/makefile.main Executable file
View File

@@ -0,0 +1,26 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
THIS_IS = main
NDK_PROG ?= false
FORCE_GEN ?= false
# include needed variables
include Makefile.inc
include $(TOOLS)/gen-makefiles.mk
include $(TOOLS)/clean-makefiles.mk
include $(BUILD)/main.mk

126
build/others/makefile.outdir Executable file
View File

@@ -0,0 +1,126 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#####
# sub-make for installing-uninstalling
#####
THIS_IS := out
# include needed variables
include ../Makefile.inc
-include $(BUILD)/config/INS_STAT.mk
-include $(BUILD)/config/UNINS_STAT.mk
# create an empty target
all:
$(hide)printf ""
# installer
.PHONY: install
install:
# really termux?
$(hide)if [ -f $(TERMUX_BIN)/termux-open ]; then \
printf " ------------ $(TARGET) installer ------------ \n"; \
if [ -f $(TERMUX_BIN)/$(TARGET) ]; then \
printf " - $(TARGET) already installed\n"; \
exit; \
fi; \
if [ ! "$(INSTALL_SUCCESS)" = "true" ] && [ ! "$(INSTALL_SUCCESS)" = "" ]; then \
printf " - $(YELLOW)$(BOLD)Warning:$(BOLD_RESET)$(RESET) a previously-stayed failed installation process found\n"; \
fi; \
if [ -f $(DEB_DIR)/*.deb ]; then \
printf " - The created deb pack was found. It's setup...\n"; \
cd $(DEB_DIR) || exit 1; \
apt install ./*.deb || exit 1; \
if [ ! "$?" = "0" ]; then \
cd $(CUR_DIR); \
printf " - Success.\n\n"; \
echo "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \
echo "UNINSTALLED_SUCCESS := " > $(BUILD)/config/UNINS_STAT.mk; \
cd ..; \
exit 0; \
else \
cd $(CUR_DIR); \
printf " - $(RED)$(BOLD)Error:$(BOLD_RESET)$(RESET) installing failed!\n"; \
echo "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
cd ..; \
exit 1; \
fi; \
fi; \
if [ ! -f $(BINARY_DIR)/$(TARGET) ]; then \
printf " - $(RED)$(BOLD)Error:$(BOLD_RESET)$(RESET) Package not builded! Please build package and try again \n"; \
echo "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
exit 1; \
fi; \
printf " - Installing binary...\n"; \
if [ "`cp $(BINARY_DIR)/$(TARGET) /data/data/com.termux/files/usr/bin/$(TARGET)`" = "" ]; then \
printf " - Setting up permissions...\n"; \
else \
echo "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
exit 1; \
fi; \
if [ "`chmod 777 $(TERMUX_BIN)/$(TARGET)`" = "" ]; then \
printf " - Saving current status...\n"; \
echo "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \
else \
echo "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
exit 1; \
fi; \
printf " - Success.\n\n"; \
echo "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \
echo "UNINSTALLED_SUCCESS := " > $(BUILD)/config/UNINS_STAT.mk; \
else \
printf " - $(RED)$(BOLD)Error:$(BOLD_RESET)$(RESET) This function is only available on Termux.\n"; \
exit 1; \
fi
# uninstaller
.PHONY: uninstall
uninstall:
# really termux?
$(hide)if [ -f $(TERMUX_BIN)/termux-open ]; then \
printf " ----------- $(TARGET) uninstaller ----------- \n"; \
if [ ! -f $(TERMUX_BIN)/$(TARGET) ]; then \
printf " - $(TARGET) already uninstalled\n"; \
exit; \
fi; \
if [ ! "$(UNINSTALL_SUCCESS)" = "true" ] && [ ! "$(UNINSTALL_SUCCESS)" = "" ]; then \
printf " - $(YELLOW)$(BOLD)Warning:$(BOLD_RESET)$(RESET) a previously-stayed failed uninstallation process found\n"; \
fi; \
if [ -f $(TERMUX_USR)/share/man/man8/$(TARGET).8.gz ]; then \
printf " - It was found to be established by $(TARGET)'s deb pack. It's removed with apt...\n"; \
apt remove -y $(TARGET) || exit 1; \
printf " - Success.\n\n"; \
echo "UNINSTALLED_SUCCESS := true" > $(BUILD)/config/UNINS_STAT.mk; \
echo "INSTALL_SUCCESS := " > $(BUILD)/config/INS_STAT.mk; \
else \
printf " - It was found that pmt was manually established (with this makefile or copying). Manually removed...\n"; \
if [ "`rm $(TERMUX_BIN)/$(TARGET)`" = "" ]; then \
printf " - Success.\n\n"; \
echo "UNINSTALLED_SUCCESS := true" > $(BUILD)/config/UNINS_STAT.mk; \
echo "INSTALL_SUCCESS := " > $(BUILD)/config/INS_STAT.mk; \
else \
echo "UNINSTALLED_SUCCESS := false" > $(BUILD)/config/UNINS_STAT.mk; \
exit 1; \
fi; \
fi; \
else \
printf "$(RED)$(BOLD)Error:$(BOLD_RESET)$(RESET) This function is only available on Termux.\n"; \
exit 1; \
fi
# end

161
build/others/makefile.sourcedir Executable file
View File

@@ -0,0 +1,161 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#####
# sub-make for building package
#####
THIS_IS = src
include ../Makefile.inc
ifeq ($(INC_OLDENV),true)
include $(BUILD)/config/oldenv.mk
endif
# make objects. Usage $(call make_obj,<SRCFILE>)
define make_obj
$(eval OBJ := $(1:.c=.o))
$(call m_stat,CC,`basename $(SOURCE_DIR)`/`basename $(OBJ)`,n)
$(CC) $(CFLAGS) -c "$1" || exit 1;
$(hide)printf "\n"
endef
# make executable file with using static libraries and objects. Usage: $(call make_executable)
define make_executable
printf " - Making executable file...\n"; \
printf " LD $(TARGET)"; \
$(CC) $(CFLAGS) -L$(SOURCE_DIR) \
$(foreach s_obj_b, \
$(shell basename -a $(STATICLIB_OBJS)), \
$(eval s_obj_t_b = $(s_obj_b:.o=)) \
$(shell echo -lpmt_$(s_obj_t_b)) \
) \
-o $(TARGET) $(OBJS_EXEC) || exit 1;
endef
# make static library. Usage $(call make_staticlib,<LIBRARY_NAME>,<OBJECT(S)>)
define make_staticlib
echo -n " AR $1"; \
$(AR) rcs "$1" "$2" || exit 1; \
echo;
endef
# controls the presence of source file. usage: $(call check_cfile,<SOURCE_FILE>)
define check_cfile
# the first argument is taken and controlled by the file with -f option
printf " CHK src/`basename $1`\n"; \
if [ ! -f $1 ]; then \
printf " ==> Couldn't found required source file: src/`basename $1`\n"; \
if [ -d "$(TEMP_DIR)" ]; then \
rm -rf $(TEMP_DIR); \
fi; \
exit 1; \
fi;
endef
# controls the presence of header file. usage: $(call check_hfile,<SOURCE_FILE>)
define check_hfile
# the first argument is taken and controlled by the file with -f option
printf " CHK include/pmt/`basename $1`\n"; \
if [ ! -f $1 ]; then \
printf " ==> Couldn't found required header file: include/pmt/`basename $1`\n"; \
if [ -d "$(TEMP_DIR)" ]; then \
rm -rf $(TEMP_DIR); \
fi; \
exit 1; \
fi;
endef
# all target for building
all:
$(hide)rm -f $(BUILD)/config/oldenv.mk
$(hide)printf " ---- Partition Manager Builder ---- \n\n"
$(hide)printf " - Version: $(VERSION)\n"
$(hide)printf " - Version code: $(VERSION_CODE)\n\n"
$(hide)printf " -------------------------------- \n\n"
$(hide)if [ -f $(SOURCE_DIR)/debugging.o ]; then \
printf " - Please clean up before you build it.\n\n"; \
printf " ----------------------------------- \n"; \
exit 1; \
fi
$(hide)printf " - Checking required source files...\n"
$(hide)sleep 1
$(foreach src_cf, \
$(SRCS_REQ), \
$(call check_cfile,$(src_cf)) \
)
$(foreach src_hf, \
$(HEADERS_REQ), \
$(call check_hfile,$(src_hf)) \
)
$(hide)printf " - Building objects...\n"
$(hide)sleep 2
$(foreach csrc, \
$(SRCS), \
$(call make_obj,$(csrc)) \
)
$(foreach reqdir,$(IN_OUT_DIR),$(call mdir,$(reqdir)))
$(hide)printf " - Making static libraries...\n"
$(foreach s_obj, \
$(shell basename -a $(STATICLIB_OBJS)), \
$(eval s_obj_t = $(s_obj:.o=.a)) \
$(call make_staticlib,libpmt_$(s_obj_t),$(s_obj)) \
)
$(hide)sleep 1
$(call make_executable)
$(hide)sleep 1
$(hide)abort_build() { \
if [ -d "$(PACKAGE_DIR)" ]; then \
rm -rf "$(PACKAGE_DIR)"; \
fi; \
if [ -d "$(BINARY_DIR)" ]; then \
rm -rf "$(BINARY_DIR)"; \
fi; \
if [ -d "$(STATICLIB_DIR)" ]; then \
rm -rf "$(STATICLIB_DIR)"; \
fi; \
exit 1; \
}; \
mv $(TARGET) $(BINARY_DIR) || abort_build; \
mv *.a $(STATICLIB_DIR) || abort_build; \
printf "\n - Generating package...\n"; \
cp $(BINARY_DIR)/$(TARGET) $(PACKAGE_DIR) || abort_build; \
printf " XZ $(OUT_DIRNAME)/package/$(TARGET)-$(ARCH).xz"
xz $(PACKAGE_DIR)/$(TARGET) || abort_build; \
sleep 1; \
mv $(PACKAGE_DIR)/$(TARGET).xz $(PACKAGE_DIR)/$(TARGET)-$(ARCH).xz || abort_build; \
printf "\n - Success"; \
sleep 1; \
printf "\n\n ----------------------------------- \n"
.PHONY: clean
clean:
$(eval STATICLIBS = $(wildcard $(SOURCE_DIR)/*.a))
$(eval OBJS = $(wildcard $(SOURCE_DIR)/*.o))
$(info Cleaning files...)
$(foreach obj, \
$(OBJS), \
$(call m_stat_nn,$(SOURCE_DIRNAME)/$(shell basename $(obj))) \
$(call erase,$(obj)) \
)
$(foreach lib, \
$(STATICLIBS), \
$(call m_stat_nn,$(SOURCE_DIRNAME)/$(shell basename $(lib))) \
$(call erase,$(lib)) \
)
# end

31
build/tools/clean-makefiles.mk Executable file
View File

@@ -0,0 +1,31 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##################
# See "erase" funtion for build/util/utils.mk
##################
include $(TOOLS)/save-gen-vars.mk
define clean-ndk-mfiles
$(hide)[ "$(UPDATE_MAKEFILES)" = "true" ] || printf " ------ Cleaning NDK Makefiles ------ \n"
$(hide)cat $(BASH_DIR)/clean-makefiles | $(BIN)/bash
endef
define clean-mfiles
$(hide)[ "$(UPDATE_MAKEFILES)" = "true" ] || printf " ------ Cleaning Makefiles ------ \n"
$(hide)cat $(BASH_DIR)/clean-makefiles | $(BIN)/bash
endef

31
build/tools/gen-makefiles.mk Executable file
View File

@@ -0,0 +1,31 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##################
# See "save-gen-vars" funtion for build/tools/save-gen-vars.mk
##################
include $(TOOLS)/save-gen-vars.mk
define gen-ndk-mfiles
$(hide)[ "$(UPDATE_MAKEFILES)" = "true" ] || printf " ------ Generating NDK Makefiles ------ \n"
$(hide)cat $(BASH_DIR)/gen-makefiles | $(BIN)/bash
endef
define gen-mfiles
$(hide)[ "$(UPDATE_MAKEFILES)" = "true" ] || printf " ------ Generating Makefiles ------ \n"
$(hide)cat $(BASH_DIR)/gen-makefiles | $(BIN)/bash
endef

26
build/tools/save-gen-vars.mk Executable file
View File

@@ -0,0 +1,26 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
define save-gen-vars
$(hide)rm -f $(BASH_DIR)/additional-vars
$(call touch,$(BASH_DIR)/additional-vars)
$(hide)echo "NDK_PROG=$(NDK_PROG)" >> $(BASH_DIR)/additional-vars
$(hide)echo "FORCE_GEN=$(FORCE_GEN)" >> $(BASH_DIR)/additional-vars
$(hide)echo "THIS_IS=$(THIS_IS)" >> $(BASH_DIR)/additional-vars
$(hide)echo "UPDATE_MAKEFILES=$(UPDATE_MAKEFILES)" >> $(BASH_DIR)/additional-vars
$(hide)echo "SOURCE_DIRNAME=$(SOURCE_DIRNAME)" >> $(BASH_DIR)/additional-vars
$(hide)echo "OUT_DIRNAME=$(OUT_DIRNAME)" >> $(BASH_DIR)/additional-vars
endef

24
build/tools/update-makefiles.mk Executable file
View File

@@ -0,0 +1,24 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
ifneq ($(THIS_IS),main)
$(error The caller is not the main makefile. Something's wrong)
endif
UPDATE_MAKEFILES = true
include $(TOOLS)/clean-makefiles.mk
include $(TOOLS)/gen-makefiles.mk

58
build/util/utils.mk Executable file
View File

@@ -0,0 +1,58 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# generate any text based empty file. Usage: $(call touch,<PATH>)
define touch
$(hide)[ ! "$(FORCE_GEN)" = "true" ] || rm -f "$1"
$(hide)touch "$1" || exit 1
endef
# copy files. Usage: $(call copy,<SOURCE>,<COPY_PATH>)
define copy
cp "$1" "$2" || exit 1
endef
# copy dirs. Usage: $(call copydir,<SOURCE>,<COPY_PATH>)
define copydir
cp -r "$1" "$2" || exit 1
endef
# file/dir are deleted. usage: $(call erase,<file/directory>)
define erase
rm -rf "$1"
endef
# make directories. usage: $(call mdir,<PATH>,<PRINTSTATUS=y/NULL>)
define mdir
[ -z $2 ] || printf " - Generating `basename $1` dir...\n"; \
mkdir -p "$1" || exit 1;
endef
# make status. usage: $(call m_stat,"<MESSAGE>",<NEW_LINE_STATE: RANDOM>)
define m_stat
printf " $1 $2"
endef
# make status (not newline and using make functions). usage: $(call m_stat_nn,"<MESSAGE>")
define m_stat_nn
$(info ==> $(1))
endef
# Get file content and if speficed write target, write speficed file. Usage: $(call cat,<SOURCE>,<WRITE_PATH>)
define cat
[ -z "$2" ] && cat "$1" || exit 1
[ -n "$2" ] && cat "$1" >> "$2" || exit 1
endef

5
build/workflow/build.config Executable file
View File

@@ -0,0 +1,5 @@
export PMT_VERSION="2.5.0"
export PMT_VERSION_CODE=250
export NDK_LINK="https://dl.google.com/android/repository/android-ndk-r27-linux.zip"
export NDK_VERSION="r27"
export NDK_IS="android-ndk"

14
build/workflow/relnotes Executable file
View File

@@ -0,0 +1,14 @@
echo -e "Compiled with clang
${CC_VERSION}
VERSION: \`${PMT_VERSION}\`
VERSION CODE: \`${PMT_VERSION_CODE}\`
TARGET ARCHITECTURE: \`arm64-v8a\` (64-bit) and \`armeabi-v7a\` (32-bit)
Notes:
Builded with Android NDK ${NDK_VERSION}
Packages are compressed with xz.
Builded debian packages for termux.
Report bugs and suggestions.
[Click](https://github.com/ShawkTeam/pmt/blob/${PMT_VERSION}/CHANGELOG.md) for viewing version ${PMT_VERSION} changelog."