15 Commits
2.5.0 ... 2.7.0

46 changed files with 883 additions and 818 deletions

View File

@@ -8,6 +8,7 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
id: checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Cleanup - name: Cleanup
@@ -25,7 +26,7 @@ jobs:
&& sudo apt install gh -y && sudo apt install gh -y
- name: Update and setup packages - name: Update and setup packages
id: setup-packages id: general-packages-progress
run: | run: |
sudo apt update \ sudo apt update \
&& sudo apt upgrade -y \ && sudo apt upgrade -y \
@@ -83,18 +84,18 @@ jobs:
. ${{ env.PMT_SRCDIR }}/build/workflow/relnotes > /home/pmt/release_body.txt . ${{ env.PMT_SRCDIR }}/build/workflow/relnotes > /home/pmt/release_body.txt
cd ${{ env.PMT_SRCDIR }} cd ${{ env.PMT_SRCDIR }}
zip -rq pmt-objs-local.zip obj/local/arm64-v8a obj/local/armeabi-v7a zip -rq pmt-objs-local.zip obj/local/arm64-v8a obj/local/armeabi-v7a
xz libs/arm64-v8a/pmt for arch in arm64-v8a armeabi-v7a; do
mv libs/arm64-v8a/pmt.xz ${PWD}/pmt-arm64-v8a.xz xz libs/${arch}/pmt
xz libs/armeabi-v7a/pmt mv libs/${arch}/pmt.xz ${PWD}/pmt-${arch}-$(date +%Y%m%d).xz
mv libs/armeabi-v7a/pmt.xz ${PWD}/pmt-armeabi-v7a.xz done
make CC="${CC_64}" AR="${AR}" for CC_COMP in ${CC_64} ${CC_32}; do
make deb FOR_THIS=64 make clean
mv out/debpackage/*.deb . make CC="${CC_COMP}" AR="${AR}" PMT_EXTRA_CFLAGS="-D__NDK_BUILD"
make clean [[ "${CC_COMP}" == *"aarch64"* ]] && make deb FOR_THIS=64
make CC="${CC_32}" AR="${AR}" [[ "${CC_COMP}" == *"armv7a"* ]] && make deb FOR_THIS=32
make deb FOR_THIS=32
mv out/debpackage/*.deb . mv out/debpackage/*.deb .
make clean make clean
done
working-directory: ${{ env.NDK_DIR }} working-directory: ${{ env.NDK_DIR }}
- name: Upload to release - name: Upload to release

View File

@@ -17,17 +17,17 @@ jobs:
COMM_MSG=$(git log -1 --pretty=%B) COMM_MSG=$(git log -1 --pretty=%B)
if [ "${GITHUB_EVENT_NAME}" == "push" ]; then if [ "${GITHUB_EVENT_NAME}" == "push" ]; then
if [[ "${COMM_MSG}" == *"initial"* ]]; then if [[ "${COMM_MSG}" == *"initial"* ]]; then
echo "build_and_release=true" >> $GITHUB_ENV echo "run_builder=true" >> $GITHUB_ENV
else else
echo "build_and_release=false" >> $GITHUB_ENV echo "run_builder=false" >> $GITHUB_ENV
fi fi
elif [ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]; then elif [ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]; then
echo "build_and_release=true" >> $GITHUB_ENV echo "run_builder=true" >> $GITHUB_ENV
fi fi
- name: Run release workflow - name: Run release workflow
id: run-rel-workflow id: run-rel-workflow
if: env.build_and_release == 'true' if: env.run_builder == 'true'
uses: benc-uk/workflow-dispatch@v1 uses: benc-uk/workflow-dispatch@v1
with: with:
workflow: 'build.yml' workflow: 'build.yml'

40
ADD-LANGUAGES.md Normal file → Executable file
View File

@@ -29,7 +29,6 @@ On this page, I will tell you how to add languages to pmt. This is not a difficu
missing operand missing operand
~ $ ~ $
C / C++ C / C++
const char* _Nonnull missing_operand = "missing operand."; const char* _Nonnull missing_operand = "missing operand.";
const std::string missing_operand = "missing operand."; const std::string missing_operand = "missing operand.";
@@ -51,9 +50,9 @@ On this page, I will tell you how to add languages to pmt. This is not a difficu
Code pieces (C) Code pieces (C)
struct pmt_langdb_general en = { struct pmt_langdb_general en = {
// other translations // other translations
.missing_operand = "missing operand"; .missing_operand = "missing operand",
.try_h = "Try"; .try_h = "Try",
.for_more = "for more information"; .for_more = "for more information",
// other translations // other translations
} }
@@ -66,14 +65,14 @@ In short, there are variables for texts. And I made these dynamic by using [stru
##### Translating main program texts (relevant part) ##### Translating main program texts (relevant part)
- Let's open our jni/languages.c source file. - Let's open our jni/languages.c source file.
- Now, let's create the translation with the ready-made struct structure (see jni/include/pmt-stringkeys.h for the structure). - Now, let's create the translation with the ready-made struct structure (see jni/include/StringKeys.h for the structure).
``` ```
// main // Main
struct pmt_langdb_general <LANGUAGE_PREFIX> = { // LANGUAGE_PREFIX must be the corresponding abbreviation of the language in English. For example, it's like en in English. struct pmt_langdb_general <LANGUAGE_PREFIX> = { // LANGUAGE_PREFIX must be the corresponding abbreviation of the language in English. For example, it's like en in English.
// translations // translations
} }
// example // Example
struct pmt_langdb_general en = { struct pmt_langdb_general en = {
// translation // translation
} }
@@ -87,15 +86,16 @@ In short, there are variables for texts. And I made these dynamic by using [stru
// other translations // other translations
} }
// example // Example
struct pmt_langdb_general en = { struct pmt_langdb_general en = {
.lang_by_s = "YZBruh & r0manas"; .lang_by_s = "YZBruh & r0manas",
.language = "English"; .language = "English",
.lang_prefix = "en"; .lang_prefix = "en",
// other translations // other translations
.by_str = "By" // Example for end translate
} }
// CRITIC WARNING: Do not add ';' to the end of the last translation text. But others always // CRITIC WARNING: Do not add ',' to the end of the last translation text. But others always...
``` ```
- Now do the others :) - Now do the others :)
- Now let me explain the documentation... - Now let me explain the documentation...
@@ -103,16 +103,18 @@ In short, there are variables for texts. And I made these dynamic by using [stru
##### Document texts translation (relevant part) ##### Document texts translation (relevant part)
- Let's open our jni/languages.c source file. - Let's open our jni/languages.c source file.
- Now, let's create the translation with the ready-made struct structure (see jni/include/pmt-stringkeys.h for the structure). - Now, let's create the translation with the ready-made struct structure (see jni/include/StringKeys.h for the structure).
``` ```
struct pmt_langdb_docs <LANGUAGE_PREFIX>_docs = { struct pmt_langdb_docs <LANGUAGE_PREFIX>_docs = {
// translations // translations
} }
// example // Example
struct pmt_langdb_docs en_docs = { struct pmt_langdb_docs en_docs = {
// translations // translations
} }
// CRITIC WARNING: Do not add ',' to the end of the last translation text. But others always...
``` ```
- Make translations by taking examples from existing ones. And definitely do it regularly by getting help message from pmt :D - Make translations by taking examples from existing ones. And definitely do it regularly by getting help message from pmt :D
@@ -124,8 +126,18 @@ In short, there are variables for texts. And I made these dynamic by using [stru
struct pmt_langdb_langs lang[] = { struct pmt_langdb_langs lang[] = {
{"en"}, {"en"},
{"tr"}, {"tr"},
// language prefix. {"<LANGUAGE_PREFIX>"},
{NULL} // PLEASE DO NOT ADD IT UNDER 'NULL'! {NULL} // PLEASE DO NOT ADD IT UNDER 'NULL'!
}; };
// Example
struct pmt_langdb_langs lang[] = {
{"en"},
{"tr"},
{"az"},
{NULL}
};
// Add the language you are translating into these existing language prefixes. I will fix the errors here (if there is an error) // Add the language you are translating into these existing language prefixes. I will fix the errors here (if there is an error)
``` ```

View File

@@ -1,19 +1,10 @@
### Version 2.5.0 Changelog ### Version 2.7.0 Changelog
- Fixed serious problems with version 2.4.0. - Operation support with pipe (|) operator has been added.
- Stabilization was held. - Build system has been made dynamic.
- The size calculation problem that was during flashtime was corrected. - Minor changes were made to the layout of bash scripts.
- Change in the syntax in flash and formatting processes was made. - Header names have been changed.
- Problems in file system selection are corrected in formatting process.
- Deprecation system created for deprecated/changed options.
- License display option deprecated.
- The language configuration file will now be stored and read entirely in /sdcard.
- Enabled C language extention warnings (-pedantic).
- Unnecessary codes were cleared and a more neat code was written.
- It was passed to make as old in the compilation system
- For NDK compilation with iterine make system Android.mk and Application.mk creation support added.
- More advanced make build system than before.
``` ```
END OF 2.5.0 UPDATE CHANGELOG END OF 2.7.0 UPDATE CHANGELOG
``` ```

View File

@@ -15,25 +15,23 @@
# limitations under the License. # limitations under the License.
# speficy # speficy
VERSION := 2.5.0 VERSION := 2.7.0
VERSION_CODE := 250 VERSION_CODE := 270
TARGET := pmt TARGET := pmt
# device arch info # device arch info
ARCH := $(shell uname -m) ARCH := $(shell uname -m)
# current directory # current directory
CUR_DIR = $(shell pwd)
OUT_DIRNAME ?= out OUT_DIRNAME ?= out
SOURCE_DIRNAME ?= jni SOURCE_DIRNAME ?= jni
# others needed important variables # others needed important variables
ifeq ($(THIS_IS),src) ifeq ($(THIS_IS),src)
BUILD := ../build BUILD := ../build
SOURCE_DIR := $(CUR_DIR) SOURCE_DIR := $(CURDIR)
OUT_DIR := ../$(OUT_DIRNAME) OUT_DIR := ../$(OUT_DIRNAME)
DEBUTILS_DIR := $(BUILD)/deb DEBUTILS_DIR := $(BUILD)/deb
INCLUDE_DIR := ../include
else ifeq ($(THIS_IS),debutils) else ifeq ($(THIS_IS),debutils)
BUILD := .. BUILD := ..
SOURCE_DIR := ../../$(SOURCE_DIRNAME) SOURCE_DIR := ../../$(SOURCE_DIRNAME)
@@ -42,12 +40,12 @@ else ifeq ($(THIS_IS),debutils)
else ifeq ($(THIS_IS),out) else ifeq ($(THIS_IS),out)
BUILD := ../build BUILD := ../build
SOURCE_DIR := ../$(SOURCE_DIRNAME) SOURCE_DIR := ../$(SOURCE_DIRNAME)
OUT_DIR := $(CUR_DIR) OUT_DIR := $(CURDIR)
DEBUTILS_DIR := $(BÜILD)/deb DEBUTILS_DIR := $(BÜILD)/deb
else ifeq ($(THIS_IS),main) else ifeq ($(THIS_IS),main)
BUILD := $(CUR_DIR)/build BUILD := $(CURDIR)/build
SOURCE_DIR := $(CUR_DIR)/$(SOURCE_DIRNAME) SOURCE_DIR := $(CURDIR)/$(SOURCE_DIRNAME)
OUT_DIR := $(CUR_DIR)/$(OUT_DIRNAME) OUT_DIR := $(CURDIR)/$(OUT_DIRNAME)
DEBUTILS_DIR := $(BUILD)/deb DEBUTILS_DIR := $(BUILD)/deb
endif endif
@@ -84,44 +82,11 @@ endif
SRCS := $(wildcard $(SOURCE_DIR)/*.c) SRCS := $(wildcard $(SOURCE_DIR)/*.c)
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)
# the presence of all source files that are on this list will be checked STATIC_LIBS := \
SRCS_REQ := \ $(TARGET)_root \
$(SOURCE_DIR)/debugging.c \ $(TARGET)_debug \
$(SOURCE_DIR)/docs.c \ $(TARGET)_listpart \
$(SOURCE_DIR)/get_stat.c \ $(TARGET)_partitiontool
$(SOURCE_DIR)/lang_tools.c \
$(SOURCE_DIR)/languages.c \
$(SOURCE_DIR)/partitiontool.c \
$(SOURCE_DIR)/pmt.c \
$(SOURCE_DIR)/root.c \
$(SOURCE_DIR)/tools.c \
$(SOURCE_DIR)/versioner.c
ifeq ($(THIS_IS),src)
HEADERS_REQ := \
$(INCLUDE_DIR)/pmt/deprecates.h \
$(INCLUDE_DIR)/pmt/docs.h \
$(INCLUDE_DIR)/pmt/pmt.h \
$(INCLUDE_DIR)/pmt/stringkeys.h \
$(INCLUDE_DIR)/pmt/versioning.h
endif
# objects to be used wgen static library files is created
STATICLIB_OBJS := \
$(SOURCE_DIR)/root.o \
$(SOURCE_DIR)/debugging.o \
$(SOURCE_DIR)/listpart.o \
$(SOURCE_DIR)/partitiontool.o
# objects to be used when executable file is created
OBJS_EXEC := \
$(SOURCE_DIR)/$(TARGET).o \
$(SOURCE_DIR)/docs.o \
$(SOURCE_DIR)/versioner.o \
$(SOURCE_DIR)/get_stat.o \
$(SOURCE_DIR)/tools.o \
$(SOURCE_DIR)/lang_tools.o \
$(SOURCE_DIR)/languages.o
# other directories in the out directory # other directories in the out directory
IN_OUT_DIR := \ IN_OUT_DIR := \
@@ -131,7 +96,7 @@ IN_OUT_DIR := \
# list of file/directory to be checked when the deb pack is created # list of file/directory to be checked when the deb pack is created
DEB_CHECKS := \ DEB_CHECKS := \
$(DEBUTILS_DIR) \ $(DEBUTILS_DIR)/ \
$(DEBUTILS_DIR)/DEBIAN \ $(DEBUTILS_DIR)/DEBIAN \
$(DEBUTILS_DIR)/DEBIAN/control_32 \ $(DEBUTILS_DIR)/DEBIAN/control_32 \
$(DEBUTILS_DIR)/DEBIAN/control_64 \ $(DEBUTILS_DIR)/DEBIAN/control_64 \
@@ -148,9 +113,11 @@ DEB_CHECKS := \
$(DEBUTILS_DIR)/data/data/com.termux/files/usr/share/man/man8 $(DEBUTILS_DIR)/data/data/com.termux/files/usr/share/man/man8
# for running make with silent mode # for running make with silent mode
hide := @ MAKE_HIDE := @ $(MAKE)
MAKE_HIDE := $(hide)$(MAKE)
SILENT := -s SILENT := -s
E := @ echo
E_NS := echo
P := printf
# color definations # color definations
RESET := \033[0m RESET := \033[0m

View File

@@ -32,12 +32,12 @@ Report bugs to <t.me/ShawkTeam | Topics | pmt>
#### Some notes #### Some notes
- pmt supports multiple languages. [See languages.](https://github.com/ShawkTeam/pmt/blob/2.5.0/LANGUAGES.md) - pmt supports multiple languages. [See languages.](https://github.com/ShawkTeam/pmt/blob/2.7.0/LANGUAGES.md)
- [Add language.](https://github.com/ShawkTeam/pmt/blob/2.5.0/ADD-LANGUAGES.md) - [Add language.](https://github.com/ShawkTeam/pmt/blob/2.7.0/ADD-LANGUAGES.md)
- Feel free to ask any questions you want. - Feel free to ask any questions you want.
- Packages are available in publications. - Packages are available in publications.
- If the logical partition flag is not used, a classic partition is tried to be processing by default. - If the logical partition flag is not used, a classic partition is tried to be processing by default.
- [Click to see special version changes.](https://github.com/ShawkTeam/pmt/blob/2.5.0/CHANGELOG.md) - [Click to see special version changes.](https://github.com/ShawkTeam/pmt/blob/2.7.0/CHANGELOG.md)
- We are always open to your suggestions and support (developing)! - We are always open to your suggestions and support (developing)!
### How is it built? ### How is it built?
@@ -47,7 +47,7 @@ Make or Android NDK is required to build.
- [Download Android NDK](https://developer.android.com/ndk/downloads) and extract the NDK package. - [Download Android NDK](https://developer.android.com/ndk/downloads) and extract the NDK package.
- Clone this repository. And get access to it. - Clone this repository. And get access to it.
``` ```
git clone https://github.com/ShawkTeam/pmt -b 2.5.0 git clone https://github.com/ShawkTeam/pmt -b 2.7.0
cd pmt cd pmt
``` ```
- Set the NDK working directory variable. - Set the NDK working directory variable.

View File

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

View File

@@ -14,7 +14,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
[ ! "${THIS_IS}" = "main" ] && abort "The caller is not the main makefile. Something's wrong." [ ! "${THIS_IS}" = "main" ] \
&& abort "The caller is not the main makefile. Something's wrong."
try_with="Try with force mode (FORCE_GEN=true)." try_with="Try with force mode (FORCE_GEN=true)."
@@ -24,7 +25,7 @@ else
mfiles=("${OUT_DIR}/Makefile" "${SOURCE_DIR}/Makefile") mfiles=("${OUT_DIR}/Makefile" "${SOURCE_DIR}/Makefile")
fi fi
for mfile in ${mfiles[0]} ${mfiles[1]}; do for mfile in ${mfiles[@]}; do
[ -f "${mfile}" ] && \ [ -f "${mfile}" ] && \
if [ "${FORCE_GEN}" = "true" ]; then if [ "${FORCE_GEN}" = "true" ]; then

View File

@@ -17,25 +17,27 @@
. build/bash/vars . build/bash/vars
. build/bash/functions . build/bash/functions
[ ! "${THIS_IS}" = "main" ] && abort "The caller is not the main makefile. Something's wrong." [ ! "${THIS_IS}" = "main" ] \
&& abort "The caller is not the main makefile. Something's wrong."
if [ "${NDK_PROG}" = "true" ]; then if [ "${NDK_PROG}" = "true" ]; then
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Removing Android.mk..." [ "${UPDATE_MAKEFILES}" = "true" ] \
rm -f ${SOURCE_DIR}/Android.mk || print " - Removing Android.mk..." \
&& print " - Removing Application.mk..."
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Removing Application.mk..." rm -f ${SOURCE_DIR}/Application.mk \
rm -f ${SOURCE_DIR}/Application.mk ${SOURCE_DIR}/Android.mk
else else
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Info: Main makefile won't be deleted." [ "${UPDATE_MAKEFILES}" = "true" ] \
|| print " - Info: Main makefile won't be deleted." \
&& print " - Removing output directory makefile..." \
&& print " - Removing source directory makefile..."
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Removing output directory makefile..." rm -f ${SOURCE_DIR}/Makefile \
rm -f ${OUT_DIR}/Makefile ${OUT_DIR}/Makefile
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Removing source directory makefile"
rm -f ${SOURCE_DIR}/Makefile
fi fi

View File

@@ -16,22 +16,22 @@
function abort() function abort()
{ {
[ -n "$1" ] && echo -e " - ${RED}${BOLD}Error:${BOLD_RESET}${RESET} $1" [ -n "${1}" ] \
&& echo -e " - ${RED}${BOLD}Error:${BOLD_RESET}${RESET} ${1}"
exit 1 exit 1
} }
function read_file() function read_file()
{ {
cat "$1" >> "$2" || abort "failed to read/write $1/$2" cat "${1}" >> "${2}" \
|| abort "failed to read/write ${1}/${2}"
} }
function gen() function gen()
{ {
[ "${FORCE_GEN}" = "true" -a "${UPDATE_MAKEFILES}" = "true" ] && rm -f "$1" [ "${FORCE_GEN}" = "true" -a "${UPDATE_MAKEFILES}" = "true" ] \
touch "$1" || abort "failed to generate: $1" && rm -f "${1}"
touch "${1}" || abort "failed to generate: ${1}"
} }
function print() function print() { echo -e "${1}"; }
{
echo -e "$1"
}

View File

@@ -14,16 +14,21 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
[ -z ${NDK_ROOT_DIR} ] && \ [ -z ${NDK_ROOT_DIR} ] \
echo "Please set NDK_ROOT_DIR variable!" && \ && echo "Please set NDK_ROOT_DIR variable!" \
exit 1 && exit 1
[ -z ${NDK_PROJECT_PATH} ] && \ [ -z ${NDK_PROJECT_PATH} ] \
echo "Please set NDK_PROJECT_PATH variable!" && \ && echo "Please set NDK_PROJECT_PATH variable!" \
exit 1 && exit 1
CC_IS="${NDK_ROOT_DIR}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang" CC_IS="${NDK_ROOT_DIR}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang"
CC_VERS=$(${CC_IS} --version | head -n 1) CC_VERS=$(${CC_IS} --version | head -n 1)
HEADER="${NDK_PROJECT_PATH}/include/pmt/generated/clang-version.h
mkdir -p ${NDK_PROJECT_PATH}/include/pmt/generated 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 touch "${HEADER}"
echo "/*" >> "${HEADER}"
cat "${NDK_PROJECT_PATH}/NOTICE" >> "${HEADER}"
echo -e "\n *\n*/" >> "${HEADER}"
echo -e "\n\n#define __NDK_CC_VERSION__ \"${CC_VERS}\"" >> "${HEADER}"

View File

@@ -17,8 +17,10 @@
. build/bash/vars . build/bash/vars
. build/bash/functions . build/bash/functions
[ ! "${UPDATE_MAKEFILES}" = "true" ] && . build/bash/check-makefiles [ ! "${UPDATE_MAKEFILES}" = "true" ] \
[ ! "${THIS_IS}" = "main" ] && abort "The caller is not the main makefile. Something's wrong." && . build/bash/check-makefiles
[ ! "${THIS_IS}" = "main" ] \
&& abort "The caller is not the main makefile. Something's wrong."
if [ "${UPDATE_MAKEFILES}" = "true" ]; then if [ "${UPDATE_MAKEFILES}" = "true" ]; then
GENR="Re-generating" GENR="Re-generating"

View File

@@ -47,6 +47,6 @@ endif
# write current env configuration to oldenv.mk # write current env configuration to oldenv.mk
all: all:
@echo "CC := $(CC)" > oldenv.mk; \ @ echo "CC := $(CC)" > oldenv.mk
echo "AR := $(AR)" >> oldenv.mk; \ @ echo "AR := $(AR)" >> oldenv.mk
echo "CFLAGS := $(CFLAGS)" >> oldenv.mk @ echo "CFLAGS := $(CFLAGS)" >> oldenv.mk

View File

@@ -1,6 +1,6 @@
Source: pmt Source: pmt
Package: pmt Package: pmt
Version: 2.5.0 Version: 2.6.0
Architecture: arm Architecture: arm
Description: pmt is for reading, writing and formatting partitions of android devices Description: pmt is for reading, writing and formatting partitions of android devices
Section: misc Section: misc

View File

@@ -1,6 +1,6 @@
Source: pmt Source: pmt
Package: pmt Package: pmt
Version: 2.5.0 Version: 2.6.0
Architecture: aarch64 Architecture: aarch64
Description: pmt is for reading, writing and formatting partitions of android devices Description: pmt is for reading, writing and formatting partitions of android devices
Section: misc Section: misc

View File

@@ -32,76 +32,68 @@ else ifeq ($(FOR_THIS),32)
endif endif
ifneq ($(wildcard /dev/block/by-name),) ifneq ($(wildcard /dev/block/by-name),)
SUDO := su SUDO := su -c
else ifeq ($(wildcard /system/build.prop),) else ifeq ($(wildcard /system/build.prop),)
SUDO := sudo SUDO := sudo
else else
SUDO := SUDO :=
endif endif
# controls the presence of file/directory. usage: $(call check_local,<FILE_OR_DIRECTORY_PATH>,<PACKAGE_STAT: 1, NULL>) PROGRESS_LIST := \
define check_local startup \
# the first argument is taken and controlled by the file/directory with -e option $(DEB_CHECKS) \
if [ ! -e $1 ]; then \ check_binary \
if [ $2 = 1 ]; then \ prepare \
printf " - Package not builded! Please build package and try again.\n"; \ make_debian_pack
else \
printf " ==> Not found: $1\n"; \
fi; \
if [ -d "$(TEMP_DIR)" ]; then \
rm -rf $(TEMP_DIR); \
fi; \
exit 1; \
fi;
endef
# make deb package # make deb package
all: all: $(PROGRESS_LIST)
$(hide)printf " --------- Making deb package ---------\n"
# remove template directory startup:
$(call erase,$(TEMP_DIR)) $(E) " --------- Making deb package --------- "
$(hide)printf " - Checking files and directories (only neededs)...\n" @ rm -rf $(TEMP_DIR)
# check some files and directories with parsing DEB_CHECKS variable $(E) " - Checking files and directories (only neededs)..."
$(foreach deb_chfile, \
$(DEB_CHECKS), \ prepare:
$(call check_local,$(deb_chfile)) \ $(E) " - Copying files..."
) @ cp -r $(DEBUTILS_DIR)/data $(TEMP_DIR) || exit 1
# check build status @ rm -f $(DEBTERMUX_USR)/share/man/man8/dummy
$(call check_local, \ @ rm -f $(DEBTERMUX_USR)/bin/dummy
$(BINARY_DIR)/pmt, \ @ mkdir $(TEMP_DIR)/DEBIAN
1 \
) check_binary:
# make template and output directories @ if [ ! -f "$(BINARY_DIR)/pmt" ]; then \
$(call mdir,$(TEMP_DIR),"y") $(E_NS) " - pmt not builded! Please build and retry."; \
$(call mdir,$(DEB_DIR),"y") exit 1; \
$(hide)printf " - Copying files...\n" fi
# prepare $(E) " - Generating template directory..."
$(hide)cp -r $(DEBUTILS_DIR)/data $(TEMP_DIR) || exit 1 @ mkdir $(TEMP_DIR)
$(hide)rm -f $(DEBTERMUX_USR)/share/man/man8/dummy $(E) " - Generating debian package directory..."
$(hide)rm -f $(DEBTERMUX_USR)/bin/dummy @ mkdir $(DEB_DIR)
$(call mdir,$(TEMP_DIR)/DEBIAN)
$(hide)abort() { \ make_debian_pack:
if [ -d $(TEMP_DIR) ]; then \ @ abort() { \
rm -rf $(TEMP_DIR); \ [ -d $(TEMP_DIR) ] \
fi; \ && rm -rf $(TEMP_DIR); \
if [ -d $(DEB_DIR) ]; then \ [ -d $(DEB_DIR) ] \
rm -rf $(DEB_DIR); \ && rm -rf $(DEB_DIR); \
fi; \
exit 1; \ exit 1; \
}; \ }; \
if [ ! "$(FOR_THIS)" = "64" ] && [ ! "$(FOR_THIS)" = "32" ]; then \ if [ ! "$(FOR_THIS)" = "64" ] && [ ! "$(FOR_THIS)" = "32" ]; then \
printf " - İnvalid arch number: $(FOR_THIS)\n" && abort; \ $(E_NS) " - Invalid arch number: $(FOR_THIS) [maybe null]" && abort; \
fi; \ fi; \
printf " - Selected arm-$(FOR_THIS) package control file.\n"; \ $(E_NS) " - Selected arm-$(FOR_THIS) package control file."; \
cp $(DEBUTILS_DIR)/DEBIAN/control_$(FOR_THIS) $(TEMP_DIR)/DEBIAN/control || abort; \ 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 $(DEBUTILS_DIR)/mandoc/$(TARGET).8.gz $(DEBTERMUX_USR)/share/man/man8 || abort; \
cp $(BINARY_DIR)/$(TARGET) $(DEBTERMUX_USR)/bin || abort; \ cp $(BINARY_DIR)/$(TARGET) $(DEBTERMUX_USR)/bin || abort; \
printf " - Starting dpkg-deb...\n"; \ $(E_NS) " - Starting dpkg-deb..."; \
sleep 2; \ sleep 2; \
$(SUDO) chmod -R 755 *; \ $(SUDO) chmod -R 755 *; \
dpkg-deb -b $(TEMP_DIR) $(DEB_DIR)/$(TARGET)-$(DEB_ARCH_NAME).deb || abort; \ dpkg-deb -b $(TEMP_DIR) $(DEB_DIR)/$(TARGET)-$(DEB_ARCH_NAME).deb || abort; \
# cleanup template directory
rm -rf $(TEMP_DIR); \ rm -rf $(TEMP_DIR); \
printf " - Done!\n" $(E_NS) " - Done!"
$(DEBUTILS_DIR)/%:
@ [ ! -e "$@" ] && $(E_NS) " - Check failed! Not found: $@" && exit 1
# end # end

Binary file not shown.

View File

@@ -15,76 +15,71 @@
# limitations under the License. # limitations under the License.
UPDATE_MAKEFILES = false UPDATE_MAKEFILES = false
CLS_ADTS := rm -f $(BUILD)/bash/additional-vars
all: all:
$(hide)# To save configuration, the makefile in the config directory
$(MAKE_HIDE) $(SILENT) -C $(BUILD)/config || exit 1 $(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 $(MAKE_HIDE) $(SILENT) -C $(SOURCE_DIRNAME) INC_OLDENV=true || exit 1
# cleaner functions # cleaner functions
.PHONY: clean .PHONY: clean
clean: clean:
$(hide)printf "Cleaning directories...\n"; \ $(E) "Cleaning directories..."
# cleanup out/binary @ if [ -d $(BINARY_DIR) ]; then \
$(hide)if [ -d $(BINARY_DIR) ]; then \ $(E_NS) "==> $(OUT_DIRNAME)/`basename $(BINARY_DIR)`"; \
printf "==> $(OUT_DIRNAME)/`basename $(BINARY_DIR)`\n"; \ fi
rm -rf "$(BINARY_DIR)"; \ @ if [ -d $(PACKAGE_DIR) ]; then \
fi; \ $(E_NS) "==> $(OUT_DIRNAME)/`basename $(PACKAGE_DIR)`"; \
# cleanup out/package fi
$(hide)if [ -d $(PACKAGE_DIR) ]; then \ @ if [ -d $(STATICLIB_DIR) ]; then \
printf "==> $(OUT_DIRNAME)/`basename $(PACKAGE_DIR)`\n"; \ $(E_NS) "==> $(OUT_DIRNAME)/`basename $(STATICLIB_DIR)`"; \
rm -rf "$(PACKAGE_DIR)"; \ fi
fi; \ @ if [ -d $(DEB_DIR) ]; then \
# cleanup out/static_libs $(E_NS) "==> $(OUT_DIRNAME)/`basename $(DEB_DIR)`"; \
$(hide)if [ -d $(STATICLIB_DIR) ]; then \ fi
printf "==> $(OUT_DIRNAME)/`basename $(STATICLIB_DIR)`\n"; \ @ rm -rf $(IN_OUT_DIR)
rm -rf "$(STATICLIB_DIR)"; \ @ rm -rf $(DEB_DIR)
fi; \ @ sleep 2
# 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 $(MAKE_HIDE) $(SILENT) -C $(SOURCE_DIRNAME) clean INC_OLDENV=false || exit 1
$(hide)sleep 1 @ sleep 1
$(hide)printf "Success.\n" $(E) "Success."
# helper function # helper function
.PHONY: help .PHONY: help
help: help:
$(hide)printf " ------- Partition Manager help -------\n\n" $(E) " ------- Partition Manager help ------- " \
$(hide)printf " Commands:\n" && $(E_NS)
$(hide)printf " $(MAKE) ==> Build Partition Manager.\n" $(E) " Commands:"
$(hide)printf " $(MAKE) deb ==> Generate debian package for termux.\n" $(E) " $(MAKE) ==> Build Partition Manager."
$(hide)printf " $(MAKE) clean ==> Clear builded binary.\n" $(E) " $(MAKE) deb ==> Generate debian package for termux."
$(hide)printf " $(MAKE) install ==> It installs $(TARGET) into termux.\n" $(E) " $(MAKE) clean ==> Clear builded binary."
$(hide)printf " $(MAKE) uninstall ==> It uninstalls $(TARGET) into termux.\n" $(E) " $(MAKE) install ==> It installs $(TARGET) into termux."
$(hide)printf " $(MAKE) gen-makefiles ==> Generate makefiles for build.\n" $(E) " $(MAKE) uninstall ==> It uninstalls $(TARGET) into termux."
$(hide)printf " $(MAKE) gen-ndk-makefiles ==> Generate NDK makefiles for build.\n" $(E) " $(MAKE) gen-makefiles ==> Generate makefiles for build."
$(hide)printf " $(MAKE) clean-makefiles ==> Cleanup makefiles.\n" $(E) " $(MAKE) gen-ndk-makefiles ==> Generate NDK makefiles for build."
$(hide)printf " $(MAKE) clean-ndk-makefiles ==> Cleanup NDK makefiles.\n" $(E) " $(MAKE) clean-makefiles ==> Cleanup makefiles."
$(hide)printf " $(MAKE) update-makefiles ==> Re-generate makefiles.\n" $(E) " $(MAKE) clean-ndk-makefiles ==> Cleanup NDK makefiles."
$(hide)printf " $(MAKE) update-ndk-makefiles ==> Re-generate NDK makefiles.\n" $(E) " $(MAKE) update-makefiles ==> Re-generate makefiles."
$(hide)printf " $(MAKE) help ==> Display this help message.\n\n" $(E) " $(MAKE) update-ndk-makefiles ==> Re-generate NDK makefiles."
$(E) " $(MAKE) help ==> Display this help message." && $(E_NS)
# deb maker # deb maker
.PHONY: deb .PHONY: deb
deb: deb:
$(MAKE_HIDE) $(SILENT) -C $(DEBUTILS_DIR) -f deb.mk FOR_THIS=$(FOR_THIS) || exit 1 $(MAKE_HIDE) $(SILENT) -C $(DEBUTILS_DIR) -f deb.mk FOR_THIS=$(FOR_THIS) || exit 1
$(hide)printf "" $(P) ""
# install pmt in to termux # install pmt in to termux
.PHONY: install .PHONY: install
install: install:
$(MAKE_HIDE) $(SILENT) -C $(OUT_DIRNAME) install || exit 1 $(eval PROG := $@)
$(MAKE_HIDE) $(SILENT) -C $(OUT_DIRNAME) install PROG=$(PROG) || exit 1
# uninstall pmt in to termux # uninstall pmt in to termux
.PHONY: uninstall .PHONY: uninstall
uninstall: uninstall:
$(MAKE_HIDE) $(SILENT) -C $(OUT_DIRNAME) uninstall || exit 1 $(eval PROG := $@)
$(MAKE_HIDE) $(SILENT) -C $(OUT_DIRNAME) uninstall PROG=$(PROG) || exit 1
# clean ndk makefiles # clean ndk makefiles
.PHONY: gen-ndk-makefiles .PHONY: gen-ndk-makefiles
@@ -92,44 +87,44 @@ gen-ndk-makefiles:
$(eval NDK_PROG = true) $(eval NDK_PROG = true)
$(call save-gen-vars) $(call save-gen-vars)
$(call gen-ndk-mfiles) $(call gen-ndk-mfiles)
$(hide)printf "" @ $(CLS_ADTS)
.PHONY: gen-makefiles .PHONY: gen-makefiles
gen-makefiles: gen-makefiles:
$(call save-gen-vars) $(call save-gen-vars)
$(call gen-mfiles) $(call gen-mfiles)
$(hide)printf "" @ $(CLS_ADTS)
.PHONY: update-ndk-makefiles .PHONY: update-ndk-makefiles
update-ndk-makefiles: update-ndk-makefiles:
$(hide)printf " ------ Updating NDK makefiles ------ \n" $(E) " ------ Updating NDK makefiles ------ "
$(eval NDK_PROG = true) $(eval NDK_PROG = true)
$(eval UPDATE_MAKEFILES = true) $(eval UPDATE_MAKEFILES = true)
$(call save-gen-vars) $(call save-gen-vars)
$(call clean-ndk-mfiles) $(call clean-ndk-mfiles)
$(call gen-ndk-mfiles) $(call gen-ndk-mfiles)
$(hide)printf "" @ $(CLS_ADTS)
.PHONY: update-makefiles .PHONY: update-makefiles
update-makefiles: update-makefiles:
$(hide)printf " ------ Updating makefiles ------ \n" $(E) " ------ Updating makefiles ------ "
$(eval UPDATE_MAKEFILES = true) $(eval UPDATE_MAKEFILES = true)
$(call save-gen-vars) $(call save-gen-vars)
$(call clean-ndk-mfiles) $(call clean-ndk-mfiles)
$(call gen-mfiles) $(call gen-mfiles)
$(hide)printf "" @ $(CLS_ADTS)
.PHONY: clean-ndk-makefiles .PHONY: clean-ndk-makefiles
clean-ndk-makefiles: clean-ndk-makefiles:
$(eval NDK_PROG = true) $(eval NDK_PROG = true)
$(call save-gen-vars) $(call save-gen-vars)
$(call clean-ndk-mfiles) $(call clean-ndk-mfiles)
$(hide)printf "" @ $(CLS_ADTS)
.PHONY: clean-makefiles .PHONY: clean-makefiles
clean-makefiles: clean-makefiles:
$(call save-gen-vars) $(call save-gen-vars)
$(call clean-mfiles) $(call clean-mfiles)
$(hide)printf "" @ $(CLS_ADTS)
# end # end

View File

@@ -15,7 +15,7 @@
# limitations under the License. # limitations under the License.
######## ########
# 2.5.0 # 2.7.0
######## ########
LOCAL_PATH := $(call my-dir) LOCAL_PATH := $(call my-dir)
@@ -35,7 +35,7 @@ PMT_CFLAGS = \
$(EXTRA_COMPILER_FLAGS) $(EXTRA_COMPILER_FLAGS)
ifneq ($(PMT_ENABLE_DEBUG),) ifneq ($(PMT_ENABLE_DEBUG),)
PMT_CFLAGS += -gdwarf-5 -fsanitize=address PMT_CFLAGS += -gdwarf-5 -fsanitize=address -fsanitize=undefined
endif endif
include $(CLEAR_VARS) include $(CLEAR_VARS)
@@ -49,8 +49,8 @@ include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE := libpmt_debugging LOCAL_MODULE := libpmt_debug
LOCAL_SRC_FILES := debugging.c LOCAL_SRC_FILES := debug.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
LOCAL_CFLAGS := $(PMT_CFLAGS) LOCAL_CFLAGS := $(PMT_CFLAGS)
@@ -79,16 +79,16 @@ include $(CLEAR_VARS)
LOCAL_MODULE := pmt LOCAL_MODULE := pmt
LOCAL_SRC_FILES := \ LOCAL_SRC_FILES := \
pmt.c \ pmt.c \
versioner.c \ version.c \
get_stat.c \ get_stat.c \
tools.c \ tools.c \
lang_tools.c \ lang_tools.c \
languages.c \ languages.c \
docs.c help.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
LOCAL_STATIC_LIBRARIES := \ LOCAL_STATIC_LIBRARIES := \
libpmt_root \ libpmt_root \
libpmt_debugging \ libpmt_debug \
libpmt_partitiontool \ libpmt_partitiontool \
libpmt_list libpmt_list
LOCAL_CFLAGS := $(PMT_CFLAGS) LOCAL_CFLAGS := $(PMT_CFLAGS)

View File

@@ -15,7 +15,7 @@
# limitations under the License. # limitations under the License.
######## ########
# 2.5.0 # 2.7.0
######## ########
# architecture # architecture

View File

@@ -25,101 +25,126 @@ include ../Makefile.inc
-include $(BUILD)/config/INS_STAT.mk -include $(BUILD)/config/INS_STAT.mk
-include $(BUILD)/config/UNINS_STAT.mk -include $(BUILD)/config/UNINS_STAT.mk
INSTALL_PROGRESS_LIST := \
really_termux \
welcome \
check_ins_stat \
deb_installer \
really_builded \
install_binary
UNINSTALL_PROGRESS_LIST := \
really_termux \
welcome \
check_unins_stat \
uninstall_$(TARGET)
# create an empty target # create an empty target
all: all:
$(hide)printf "" $(P) ""
# installer # installer
.PHONY: install .PHONY: install
install: install: $(INSTALL_PROGRESS_LIST)
# really termux?
$(hide)if [ -f $(TERMUX_BIN)/termux-open ]; then \ # uninstaller
printf " ------------ $(TARGET) installer ------------ \n"; \ .PHONY: uninstall
if [ -f $(TERMUX_BIN)/$(TARGET) ]; then \ uninstall: $(UNINSTALL_PROGRESS_LIST)
printf " - $(TARGET) already installed\n"; \
exit; \ install_binary:
$(E) " - Installing binary..."
if cp $(BINARY_DIR)/$(TARGET) /data/data/com.termux/files/usr/bin/$(TARGET); then \
$(E_NS) " - Setting up permissions..."; \
else \
$(E_NS) "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
exit 1; \
fi; \ fi; \
if [ ! "$(INSTALL_SUCCESS)" = "true" ] && [ ! "$(INSTALL_SUCCESS)" = "" ]; then \ if chmod 777 $(TERMUX_BIN)/$(TARGET); then \
printf " - $(YELLOW)$(BOLD)Warning:$(BOLD_RESET)$(RESET) a previously-stayed failed installation process found\n"; \ $(E_NS) " - Saving current status..."; \
$(E_NS) "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \
else \
$(E_NS) "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
exit 1; \
fi; \ fi; \
$(P) " - Success.\n\n"; \
$(E_NS) "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \
$(E_NS) "UNINSTALLED_SUCCESS := " > $(BUILD)/config/UNINS_STAT.mk; \
uninstall_$(TARGET):
if [ -f $(TERMUX_USR)/share/man/man8/$(TARGET).8.gz ]; then \
$(E_NS) " - It was found to be established by $(TARGET)'s deb pack. It's removed with apt..."; \
apt remove -y $(TARGET) || exit 1; \
$(P) " - Success.\n\n"; \
$(E_NS) "UNINSTALLED_SUCCESS := true" > $(BUILD)/config/UNINS_STAT.mk; \
$(E_NS) "INSTALL_SUCCESS := " > $(BUILD)/config/INS_STAT.mk; \
else \
$(E_NS) " - It was found that pmt was manually established (with this makefile or copying). Manually removed..."; \
if rm $(TERMUX_BIN)/$(TARGET); then \
$(P) " - Success.\n\n"; \
$(E_NS) "UNINSTALLED_SUCCESS := true" > $(BUILD)/config/UNINS_STAT.mk; \
$(E_NS) "INSTALL_SUCCESS := " > $(BUILD)/config/INS_STAT.mk; \
else \
$(E_NS) "UNINSTALLED_SUCCESS := false" > $(BUILD)/config/UNINS_STAT.mk; \
exit 1; \
fi; \
fi
deb_installer:
if [ -f $(DEB_DIR)/*.deb ]; then \ if [ -f $(DEB_DIR)/*.deb ]; then \
printf " - The created deb pack was found. It's setup...\n"; \ $(E_NS) " - The created deb pack was found. It's setup..."; \
cd $(DEB_DIR) || exit 1; \ cd $(DEB_DIR) || exit 1; \
apt install ./*.deb || exit 1; \ apt install ./*.deb || exit 1; \
if [ ! "$?" = "0" ]; then \ if [ ! "$?" = "0" ]; then \
cd $(CUR_DIR); \ cd $(CUR_DIR); \
printf " - Success.\n\n"; \ $(P) " - Success.\n\n"; \
echo "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \ $(E_NS) "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \
echo "UNINSTALLED_SUCCESS := " > $(BUILD)/config/UNINS_STAT.mk; \ $(E_NS) "UNINSTALLED_SUCCESS := " > $(BUILD)/config/UNINS_STAT.mk; \
cd ..; \ cd ..; \
exit 0; \ exit 0; \
else \ else \
cd $(CUR_DIR); \ cd $(CUR_DIR); \
printf " - $(RED)$(BOLD)Error:$(BOLD_RESET)$(RESET) installing failed!\n"; \ $(P) " - $(RED)$(BOLD)Error:$(BOLD_RESET)$(RESET) installing failed!\n"; \
echo "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \ $(E_NS) "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
cd ..; \ cd ..; \
exit 1; \ exit 1; \
fi; \ fi; \
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"; \ check_ins_stat:
echo "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \ @ if [ ! "$(INSTALL_SUCCESS)" = "true" ] && [ ! "$(INSTALL_SUCCESS)" = "" ]; then \
$(P) " - $(YELLOW)$(BOLD)Warning:$(BOLD_RESET)$(RESET) a previously-stayed failed installation process found\n"; \
fi
check_unins_stat:
@ if [ ! "$(UNINSTALL_SUCCESS)" = "true" ] && [ ! "$(UNINSTALL_SUCCESS)" = "" ]; then \
$(P) " - $(YELLOW)$(BOLD)Warning:$(BOLD_RESET)$(RESET) a previously-stayed failed uninstallation process found\n"; \
fi
welcome:
$(E) " ----------- $(TARGET) $(PROG)er ----------- "
@ if [ "$(PROG)" = "uninstall" ]; then \
if [ ! -f $(TERMUX_BIN)/$(TARGET) ]; then \
$(E_NS) " - $(TARGET) already $(PROG)ed"; \
exit 1; \ exit 1; \
fi; \ fi; \
printf " - Installing binary...\n"; \ fi
if [ "`cp $(BINARY_DIR)/$(TARGET) /data/data/com.termux/files/usr/bin/$(TARGET)`" = "" ]; then \ @ if [ "$(PROG)" = "install" ]; then \
printf " - Setting up permissions...\n"; \ if [ -f $(TERMUX_BIN)/$(TARGET) ]; then \
else \ $(E_NS) " - $(TARGET) already $(PROG)ed"; \
echo "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
exit 1; \ exit 1; \
fi; \ fi; \
if [ "`chmod 777 $(TERMUX_BIN)/$(TARGET)`" = "" ]; then \ fi
printf " - Saving current status...\n"; \
echo "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \ really_termux:
else \ @ if [ ! -f $(TERMUX_BIN)/termux-open ]; then \
echo "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \ $(P) "$(RED)$(BOLD)Error:$(BOLD_RESET)$(RESET) This function is only available on Termux.\n"; \
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; \ exit 1; \
fi fi
# uninstaller really_builded:
.PHONY: uninstall if [ ! -f $(BINARY_DIR)/$(TARGET) ]; then \
uninstall: $(P) " - $(RED)$(BOLD)Error:$(BOLD_RESET)$(RESET) Package not builded! Please build package and try again \n"; \
# really termux? $(E_NS) "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
$(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; \ exit 1; \
fi fi

View File

@@ -26,121 +26,142 @@ ifeq ($(INC_OLDENV),true)
include $(BUILD)/config/oldenv.mk include $(BUILD)/config/oldenv.mk
endif endif
# make objects. Usage $(call make_obj,<SRCFILE>) INCLUDE_DIR := $(realpath ../include)
define make_obj PMT_INCDIR := $(INCLUDE_DIR)/pmt
$(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) # the presence of all source files that are on this list will be checked
define make_executable SRCS_REQ := \
printf " - Making executable file...\n"; \ place-holder/debug.c \
printf " LD $(TARGET)"; \ place-holder/help.c \
$(CC) $(CFLAGS) -L$(SOURCE_DIR) \ place-holder/get_stat.c \
$(foreach s_obj_b, \ place-holder/lang_tools.c \
$(shell basename -a $(STATICLIB_OBJS)), \ place-holder/languages.c \
$(eval s_obj_t_b = $(s_obj_b:.o=)) \ place-holder/partitiontool.c \
$(shell echo -lpmt_$(s_obj_t_b)) \ place-holder/pmt.c \
) \ place-holder/root.c \
-o $(TARGET) $(OBJS_EXEC) || exit 1; place-holder/tools.c \
endef place-holder/version.c
# make static library. Usage $(call make_staticlib,<LIBRARY_NAME>,<OBJECT(S)>) # objects to be used when executable file is created
define make_staticlib OBJS_EXEC := \
echo -n " AR $1"; \ $(SOURCE_DIR)/$(TARGET).o \
$(AR) rcs "$1" "$2" || exit 1; \ $(SOURCE_DIR)/help.o \
echo; $(SOURCE_DIR)/version.o \
endef $(SOURCE_DIR)/get_stat.o \
$(SOURCE_DIR)/tools.o \
$(SOURCE_DIR)/lang_tools.o \
$(SOURCE_DIR)/languages.o
# controls the presence of source file. usage: $(call check_cfile,<SOURCE_FILE>) HEADERS_REQ := \
define check_cfile $(PMT_INCDIR)/pmt/ExternC.h \
# the first argument is taken and controlled by the file with -f option $(PMT_INCDIR)/pmt/Deprecates.h \
printf " CHK src/`basename $1`\n"; \ $(PMT_INCDIR)/pmt/HelpMessages.h \
if [ ! -f $1 ]; then \ $(PMT_INCDIR)/pmt/pmt.h \
printf " ==> Couldn't found required source file: src/`basename $1`\n"; \ $(PMT_INCDIR)/pmt/StringKeys.h \
if [ -d "$(TEMP_DIR)" ]; then \ $(PMT_INCDIR)/pmt/VersionVars.h
rm -rf $(TEMP_DIR); \
fi; \
exit 1; \
fi;
endef
# controls the presence of header file. usage: $(call check_hfile,<SOURCE_FILE>) PROGRESS_LIST := \
define check_hfile welcome \
# the first argument is taken and controlled by the file with -f option wait \
printf " CHK include/pmt/`basename $1`\n"; \ $(SRCS_REQ) \
if [ ! -f $1 ]; then \ $(HEADERS_REQ) \
printf " ==> Couldn't found required header file: include/pmt/`basename $1`\n"; \ pr_obj \
if [ -d "$(TEMP_DIR)" ]; then \ $(OBJS) \
rm -rf $(TEMP_DIR); \ make_outdirs \
fi; \ pr_sts \
exit 1; \ $(STATIC_LIBS) \
fi; make_executable \
wait \
end_progress
define check_hf
@ [ ! -f "$1" ] \
&& $(E_NS) " ==> Couldn't found required header file: include/pmt/`basename $1`" \
&& exit 1
endef endef
# all target for building # all target for building
all: all: $(PROGRESS_LIST)
$(hide)rm -f $(BUILD)/config/oldenv.mk
$(hide)printf " ---- Partition Manager Builder ---- \n\n" welcome:
$(hide)printf " - Version: $(VERSION)\n" @ rm -f $(BUILD)/config/oldenv.mk
$(hide)printf " - Version code: $(VERSION_CODE)\n\n" @ echo " ---- Partition Manager Builder ---- " \
$(hide)printf " -------------------------------- \n\n" && $(E_NS)
$(hide)if [ -f $(SOURCE_DIR)/debugging.o ]; then \ $(E) " - Version: $(VERSION)"
printf " - Please clean up before you build it.\n\n"; \ $(E) " - Version code: $(VERSION_CODE)" \
printf " ----------------------------------- \n"; \ && $(E_NS)
$(E) " -------------------------------- " \
&& $(E_NS)
@ if [ -f $(SOURCE_DIR)/debug.o ]; then \
$(E_NS) " - Please clean up before you build it." && echo; \
$(E_NS) " ----------------------------------- "; \
exit 1; \ exit 1; \
fi fi
$(hide)printf " - Checking required source files...\n" $(E) " - Checking required source files..."
$(hide)sleep 1
$(foreach src_cf, \ pr_obj:
$(SRCS_REQ), \ $(E) " - Building objects..."
$(call check_cfile,$(src_cf)) \
) pr_sts:
$(foreach src_hf, \ $(E) " - Making static libraries..."
$(HEADERS_REQ), \
$(call check_hfile,$(src_hf)) \ wait:
) @ sleep 2
$(hide)printf " - Building objects...\n"
$(hide)sleep 2 make_outdirs:
$(foreach csrc, \ @ rm -rf $(IN_OUT_DIR)
$(SRCS), \ @ mkdir $(BINARY_DIR)
$(call make_obj,$(csrc)) \ @ mkdir $(PACKAGE_DIR)
) @ mkdir $(STATICLIB_DIR)
$(foreach reqdir,$(IN_OUT_DIR),$(call mdir,$(reqdir)))
$(hide)printf " - Making static libraries...\n" place-holder/%.c:
$(foreach s_obj, \ $(E) " CHK $(SOURCE_DIRNAME)/`basename $@`"
$(shell basename -a $(STATICLIB_OBJS)), \ @ if [ ! -f "$(SOURCE_DIR)/`basename $@`" ]; then \
$(eval s_obj_t = $(s_obj:.o=.a)) \ $(E_NS) " ==> Couldn't found required source file: $(SOURCE_DIRNAME)/`basename $@`"; \
$(call make_staticlib,libpmt_$(s_obj_t),$(s_obj)) \ exit 1; \
) fi
$(hide)sleep 1
$(call make_executable) $(PMT_INCDIR)/%.h:
$(hide)sleep 1 $(E) " CHK include/pmt/`basename $@`"
$(hide)abort_build() { \ @ if [ ! -f "$(INCLUDE_DIR)/pmt/`basename $@`" ]; then \
if [ -d "$(PACKAGE_DIR)" ]; then \ $(E_NS) " ==> Couldn't found required header file: include/pmt/`basename $@`"; \
rm -rf "$(PACKAGE_DIR)"; \ exit 1; \
fi; \ fi
if [ -d "$(BINARY_DIR)" ]; then \
rm -rf "$(BINARY_DIR)"; \ $(SOURCE_DIR)/%.o: $(SOURCE_DIR)/%.c
fi; \ $(E) " CC $(SOURCE_DIRNAME)/`basename $@`"
if [ -d "$(STATICLIB_DIR)" ]; then \ @ $(CC) $(CFLAGS) -c "$<" || exit 1
rm -rf "$(STATICLIB_DIR)"; \
fi; \ $(TARGET)_%:
$(E) " AR lib$@.a"
@ $(AR) rcs "lib$@.a" "$(SOURCE_DIR)/$$(echo "$@" | cut -d'_' -f2).o"
make_executable:
$(E) " - Making executable file..."
$(E) " LD $(TARGET)"
@ $(CC) $(CFLAGS) -L$(SOURCE_DIR) $(foreach st,$(STATIC_LIBS),$(shell echo -n -l$(st) )) -o $(TARGET) $(OBJS_EXEC) || exit 1
end_progress:
@ abort_build() { \
[ -d "$(PACKAGE_DIR)" ] \
&& rm -rf "$(PACKAGE_DIR)"; \
[ -d "$(BINARY_DIR)" ] \
&& rm -rf "$(BINARY_DIR)"; \
[ -d "$(STATICLIB_DIR)" ] \
&& rm -rf "$(STATICLIB_DIR)"; \
exit 1; \ exit 1; \
}; \ }; \
mv $(TARGET) $(BINARY_DIR) || abort_build; \ mv $(TARGET) $(BINARY_DIR) || abort_build; \
mv *.a $(STATICLIB_DIR) || abort_build; \ mv *.a $(STATICLIB_DIR) || abort_build; \
printf "\n - Generating package...\n"; \ $(E_NS) " - Generating package..."; \
cp $(BINARY_DIR)/$(TARGET) $(PACKAGE_DIR) || abort_build; \ cp $(BINARY_DIR)/$(TARGET) $(PACKAGE_DIR) || abort_build; \
printf " XZ $(OUT_DIRNAME)/package/$(TARGET)-$(ARCH).xz" $(E_NS) " XZ $(OUT_DIRNAME)/package/$(TARGET)-`date +%Y%m%d`.xz"
xz $(PACKAGE_DIR)/$(TARGET) || abort_build; \ xz $(PACKAGE_DIR)/$(TARGET) || abort_build; \
sleep 1; \ sleep 1; \
mv $(PACKAGE_DIR)/$(TARGET).xz $(PACKAGE_DIR)/$(TARGET)-$(ARCH).xz || abort_build; \ mv $(PACKAGE_DIR)/$(TARGET).xz $(PACKAGE_DIR)/$(TARGET)-`date +%Y%m%d`.xz || abort_build
printf "\n - Success"; \ $(E) " - Success" && $(E_NS)
sleep 1; \ @ sleep 1
printf "\n\n ----------------------------------- \n" $(E) " ----------------------------------- "
.PHONY: clean .PHONY: clean
clean: clean:

View File

@@ -21,11 +21,11 @@
include $(TOOLS)/save-gen-vars.mk include $(TOOLS)/save-gen-vars.mk
define clean-ndk-mfiles define clean-ndk-mfiles
$(hide)[ "$(UPDATE_MAKEFILES)" = "true" ] || printf " ------ Cleaning NDK Makefiles ------ \n" @ [ "$(UPDATE_MAKEFILES)" = "true" ] || printf " ------ Cleaning NDK Makefiles ------ \n"
$(hide)cat $(BASH_DIR)/clean-makefiles | $(BIN)/bash @ cat $(BASH_DIR)/clean-makefiles | $(BIN)/bash
endef endef
define clean-mfiles define clean-mfiles
$(hide)[ "$(UPDATE_MAKEFILES)" = "true" ] || printf " ------ Cleaning Makefiles ------ \n" @ [ "$(UPDATE_MAKEFILES)" = "true" ] || printf " ------ Cleaning Makefiles ------ \n"
$(hide)cat $(BASH_DIR)/clean-makefiles | $(BIN)/bash @ cat $(BASH_DIR)/clean-makefiles | $(BIN)/bash
endef endef

View File

@@ -21,11 +21,11 @@
include $(TOOLS)/save-gen-vars.mk include $(TOOLS)/save-gen-vars.mk
define gen-ndk-mfiles define gen-ndk-mfiles
$(hide)[ "$(UPDATE_MAKEFILES)" = "true" ] || printf " ------ Generating NDK Makefiles ------ \n" @ [ "$(UPDATE_MAKEFILES)" = "true" ] || printf " ------ Generating NDK Makefiles ------ \n"
$(hide)cat $(BASH_DIR)/gen-makefiles | $(BIN)/bash @ cat $(BASH_DIR)/gen-makefiles | $(BIN)/bash
endef endef
define gen-mfiles define gen-mfiles
$(hide)[ "$(UPDATE_MAKEFILES)" = "true" ] || printf " ------ Generating Makefiles ------ \n" @ [ "$(UPDATE_MAKEFILES)" = "true" ] || printf " ------ Generating Makefiles ------ \n"
$(hide)cat $(BASH_DIR)/gen-makefiles | $(BIN)/bash @ cat $(BASH_DIR)/gen-makefiles | $(BIN)/bash
endef endef

View File

@@ -15,12 +15,12 @@
# limitations under the License. # limitations under the License.
define save-gen-vars define save-gen-vars
$(hide)rm -f $(BASH_DIR)/additional-vars @ rm -f $(BASH_DIR)/additional-vars
$(call touch,$(BASH_DIR)/additional-vars) $(call touch,$(BASH_DIR)/additional-vars)
$(hide)echo "NDK_PROG=$(NDK_PROG)" >> $(BASH_DIR)/additional-vars @ echo "NDK_PROG=$(NDK_PROG)" >> $(BASH_DIR)/additional-vars
$(hide)echo "FORCE_GEN=$(FORCE_GEN)" >> $(BASH_DIR)/additional-vars @ echo "FORCE_GEN=$(FORCE_GEN)" >> $(BASH_DIR)/additional-vars
$(hide)echo "THIS_IS=$(THIS_IS)" >> $(BASH_DIR)/additional-vars @ echo "THIS_IS=$(THIS_IS)" >> $(BASH_DIR)/additional-vars
$(hide)echo "UPDATE_MAKEFILES=$(UPDATE_MAKEFILES)" >> $(BASH_DIR)/additional-vars @ echo "UPDATE_MAKEFILES=$(UPDATE_MAKEFILES)" >> $(BASH_DIR)/additional-vars
$(hide)echo "SOURCE_DIRNAME=$(SOURCE_DIRNAME)" >> $(BASH_DIR)/additional-vars @ echo "SOURCE_DIRNAME=$(SOURCE_DIRNAME)" >> $(BASH_DIR)/additional-vars
$(hide)echo "OUT_DIRNAME=$(OUT_DIRNAME)" >> $(BASH_DIR)/additional-vars @ echo "OUT_DIRNAME=$(OUT_DIRNAME)" >> $(BASH_DIR)/additional-vars
endef endef

View File

@@ -16,8 +16,8 @@
# generate any text based empty file. Usage: $(call touch,<PATH>) # generate any text based empty file. Usage: $(call touch,<PATH>)
define touch define touch
$(hide)[ ! "$(FORCE_GEN)" = "true" ] || rm -f "$1" @ [ ! "$(FORCE_GEN)" = "true" ] || rm -f "$1"
$(hide)touch "$1" || exit 1 @ touch "$1" || exit 1
endef endef
# copy files. Usage: $(call copy,<SOURCE>,<COPY_PATH>) # copy files. Usage: $(call copy,<SOURCE>,<COPY_PATH>)

View File

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

View File

@@ -19,9 +19,9 @@
#ifndef __PMT_DEPRECATED_H #ifndef __PMT_DEPRECATED_H
#define __PMT_DEPRECATED_H #define __PMT_DEPRECATED_H
#include <sys/cdefs.h> #include <pmt/ExternC.h>
__BEGIN_DECLS PMT_EXTERN_C_BEGIN
#define deprecated_opt 1 #define deprecated_opt 1
#define changed_opt 2 #define changed_opt 2
@@ -41,6 +41,8 @@ __BEGIN_DECLS
#define v230 "2.3.0" #define v230 "2.3.0"
#define v240 "2.4.0" #define v240 "2.4.0"
#define v250 "2.5.0" #define v250 "2.5.0"
#define v260 "2.6.0"
#define v270 "2.7.0"
#define vUNK NULL #define vUNK NULL
struct pmt_deprecates { struct pmt_deprecates {
@@ -92,7 +94,7 @@ __deprecated_opt_handle(int opt, const char* opt_long, const char* depr_msg)
#define DEPR_HANDLE(x, y, z) __deprecated_opt_handle(x, y, z) #define DEPR_HANDLE(x, y, z) __deprecated_opt_handle(x, y, z)
__END_DECLS PMT_EXTERN_C_END
#endif #endif

30
include/pmt/ExternC.h Executable file
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.
*/
#ifndef __PMT_EXTERN_C_H_
#define __PMT_EXTERN_C_H_
#ifdef __cplusplus
#define PMT_EXTERN_C_BEGIN extern "C" {
#define PMT_EXTERN_C_END }
#else
#define PMT_EXTERN_C_BEGIN
#define PMT_EXTERN_C_END
#endif
#endif

View File

@@ -16,14 +16,16 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef __PMT_DOCS_H #ifndef __PMT_HELP_MSGS_H
#define __PMT_DOCS_H #define __PMT_HELP_MSGS_H
__BEGIN_DECLS #include <pmt/ExternC.h>
PMT_EXTERN_C_BEGIN
void help(void); void help(void);
__END_DECLS PMT_EXTERN_C_END
#endif #endif

View File

@@ -16,23 +16,28 @@
* limitations under the License. * limitations under the License.
*/ */
#include <sys/cdefs.h> #if !defined(__clang__) && !defined(__NDK_BUILD)
#error "Your compiler is NOT clang. Please build with LLVM clang."
#endif
__BEGIN_DECLS #include <pmt/ExternC.h>
PMT_EXTERN_C_BEGIN
#ifndef __PMT_H_ #ifndef __PMT_H_
#define __PMT_H_ #define __PMT_H_
#define PMT_PACKAGE_NAME "Partition Manager"
#ifdef INC_MAIN_LIBS #ifdef INC_MAIN_LIBS
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#if !defined(HELP) || !defined(VERSIONING)
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#endif
#endif #endif
#ifdef INC_GETOPT #ifdef INC_GETOPT
@@ -111,6 +116,6 @@ void debug(LogLevel status, const char* _Nullable fmt, ...);
#endif #endif
__END_DECLS PMT_EXTERN_C_END
/* end of code */ /* end of code */

View File

@@ -19,7 +19,9 @@
#ifndef __PMT_STRINGKEYS_ #ifndef __PMT_STRINGKEYS_
#define __PMT_STRINGKEYS_ #define __PMT_STRINGKEYS_
__BEGIN_DECLS #include <pmt/ExternC.h>
PMT_EXTERN_C_BEGIN
/* The struct is a very good option for setting the languages of texts etc. */ /* The struct is a very good option for setting the languages of texts etc. */
struct pmt_langdb_general { struct pmt_langdb_general {
@@ -112,7 +114,7 @@ struct pmt_langdb_langs {
const char* _Nullable lang_pr; const char* _Nullable lang_pr;
}; };
__END_DECLS PMT_EXTERN_C_END
#endif /* __PMT_STRINGKEYS_ */ #endif /* __PMT_STRINGKEYS_ */

View File

@@ -19,7 +19,9 @@
#ifndef __PMT_VERSIONING_H #ifndef __PMT_VERSIONING_H
#define __PMT_VERSIONING_H #define __PMT_VERSIONING_H
__BEGIN_DECLS #include <pmt/ExternC.h>
PMT_EXTERN_C_BEGIN
#ifdef __NDK_BUILD #ifdef __NDK_BUILD
#include <android/ndk-version.h> #include <android/ndk-version.h>
@@ -28,10 +30,10 @@ __BEGIN_DECLS
/* versioning */ /* versioning */
#define PMT_MAJOR 2 #define PMT_MAJOR 2
#define PMT_MINOR 5 #define PMT_MINOR 7
#define PMT_PATCHLEVEL 0 #define PMT_PATCHLEVEL 0
__END_DECLS PMT_EXTERN_C_END
#endif #endif

View File

@@ -26,121 +26,142 @@ ifeq ($(INC_OLDENV),true)
include $(BUILD)/config/oldenv.mk include $(BUILD)/config/oldenv.mk
endif endif
# make objects. Usage $(call make_obj,<SRCFILE>) INCLUDE_DIR := $(realpath ../include)
define make_obj PMT_INCDIR := $(INCLUDE_DIR)/pmt
$(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) # the presence of all source files that are on this list will be checked
define make_executable SRCS_REQ := \
printf " - Making executable file...\n"; \ place-holder/debug.c \
printf " LD $(TARGET)"; \ place-holder/help.c \
$(CC) $(CFLAGS) -L$(SOURCE_DIR) \ place-holder/get_stat.c \
$(foreach s_obj_b, \ place-holder/lang_tools.c \
$(shell basename -a $(STATICLIB_OBJS)), \ place-holder/languages.c \
$(eval s_obj_t_b = $(s_obj_b:.o=)) \ place-holder/partitiontool.c \
$(shell echo -lpmt_$(s_obj_t_b)) \ place-holder/pmt.c \
) \ place-holder/root.c \
-o $(TARGET) $(OBJS_EXEC) || exit 1; place-holder/tools.c \
endef place-holder/version.c
# make static library. Usage $(call make_staticlib,<LIBRARY_NAME>,<OBJECT(S)>) # objects to be used when executable file is created
define make_staticlib OBJS_EXEC := \
echo -n " AR $1"; \ $(SOURCE_DIR)/$(TARGET).o \
$(AR) rcs "$1" "$2" || exit 1; \ $(SOURCE_DIR)/help.o \
echo; $(SOURCE_DIR)/version.o \
endef $(SOURCE_DIR)/get_stat.o \
$(SOURCE_DIR)/tools.o \
$(SOURCE_DIR)/lang_tools.o \
$(SOURCE_DIR)/languages.o
# controls the presence of source file. usage: $(call check_cfile,<SOURCE_FILE>) HEADERS_REQ := \
define check_cfile $(PMT_INCDIR)/pmt/ExternC.h \
# the first argument is taken and controlled by the file with -f option $(PMT_INCDIR)/pmt/Deprecates.h \
printf " CHK $(SOURCE_DIRNAME)/`basename $1`\n"; \ $(PMT_INCDIR)/pmt/HelpMessages.h \
if [ ! -f $1 ]; then \ $(PMT_INCDIR)/pmt/PartitionManager.h \
printf " ==> Couldn't found required source file: $(SOURCE_DIRNAME)/`basename $1`\n"; \ $(PMT_INCDIR)/pmt/StringKeys.h \
if [ -d "$(TEMP_DIR)" ]; then \ $(PMT_INCDIR)/pmt/VersionVars.h
rm -rf $(TEMP_DIR); \
fi; \
exit 1; \
fi;
endef
# controls the presence of header file. usage: $(call check_hfile,<SOURCE_FILE>) PROGRESS_LIST := \
define check_hfile welcome \
# the first argument is taken and controlled by the file with -f option wait \
printf " CHK include/pmt/`basename $1`\n"; \ $(SRCS_REQ) \
if [ ! -f $1 ]; then \ $(HEADERS_REQ) \
printf " ==> Couldn't found required header file: include/pmt/`basename $1`\n"; \ pr_obj \
if [ -d "$(TEMP_DIR)" ]; then \ $(OBJS) \
rm -rf $(TEMP_DIR); \ make_outdirs \
fi; \ pr_sts \
exit 1; \ $(STATIC_LIBS) \
fi; make_executable \
wait \
end_progress
define check_hf
@ [ ! -f "$1" ] \
&& $(E_NS) " ==> Couldn't found required header file: include/pmt/`basename $1`" \
&& exit 1
endef endef
# all target for building # all target for building
all: all: $(PROGRESS_LIST)
$(hide)rm -f $(BUILD)/config/oldenv.mk
$(hide)printf " ---- Partition Manager Builder ---- \n\n" welcome:
$(hide)printf " - Version: $(VERSION)\n" @ rm -f $(BUILD)/config/oldenv.mk
$(hide)printf " - Version code: $(VERSION_CODE)\n\n" @ echo " ---- Partition Manager Builder ---- " \
$(hide)printf " -------------------------------- \n\n" && $(E_NS)
$(hide)if [ -f $(SOURCE_DIR)/debugging.o ]; then \ $(E) " - Version: $(VERSION)"
printf " - Please clean up before you build it.\n\n"; \ $(E) " - Version code: $(VERSION_CODE)" \
printf " ----------------------------------- \n"; \ && $(E_NS)
$(E) " -------------------------------- " \
&& $(E_NS)
@ if [ -f $(SOURCE_DIR)/debug.o ]; then \
$(E_NS) " - Please clean up before you build it." && echo; \
$(E_NS) " ----------------------------------- "; \
exit 1; \ exit 1; \
fi fi
$(hide)printf " - Checking required source files...\n" $(E) " - Checking required source files..."
$(hide)sleep 1
$(foreach src_cf, \ pr_obj:
$(SRCS_REQ), \ $(E) " - Building objects..."
$(call check_cfile,$(src_cf)) \
) pr_sts:
$(foreach src_hf, \ $(E) " - Making static libraries..."
$(HEADERS_REQ), \
$(call check_hfile,$(src_hf)) \ wait:
) @ sleep 2
$(hide)printf " - Building objects...\n"
$(hide)sleep 2 make_outdirs:
$(foreach csrc, \ @ rm -rf $(IN_OUT_DIR)
$(SRCS), \ @ mkdir $(BINARY_DIR)
$(call make_obj,$(csrc)) \ @ mkdir $(PACKAGE_DIR)
) @ mkdir $(STATICLIB_DIR)
$(foreach reqdir,$(IN_OUT_DIR),$(call mdir,$(reqdir)))
$(hide)printf " - Making static libraries...\n" place-holder/%.c:
$(foreach s_obj, \ $(E) " CHK $(SOURCE_DIRNAME)/`basename $@`"
$(shell basename -a $(STATICLIB_OBJS)), \ @ if [ ! -f "$(SOURCE_DIR)/`basename $@`" ]; then \
$(eval s_obj_t = $(s_obj:.o=.a)) \ $(E_NS) " ==> Couldn't found required source file: $(SOURCE_DIRNAME)/`basename $@`"; \
$(call make_staticlib,libpmt_$(s_obj_t),$(s_obj)) \ exit 1; \
) fi
$(hide)sleep 1
$(call make_executable) $(PMT_INCDIR)/%.h:
$(hide)sleep 1 $(E) " CHK include/pmt/`basename $@`"
$(hide)abort_build() { \ @ if [ ! -f "$(INCLUDE_DIR)/pmt/`basename $@`" ]; then \
if [ -d "$(PACKAGE_DIR)" ]; then \ $(E_NS) " ==> Couldn't found required header file: include/pmt/`basename $@`"; \
rm -rf "$(PACKAGE_DIR)"; \ exit 1; \
fi; \ fi
if [ -d "$(BINARY_DIR)" ]; then \
rm -rf "$(BINARY_DIR)"; \ $(SOURCE_DIR)/%.o: $(SOURCE_DIR)/%.c
fi; \ $(E) " CC $(SOURCE_DIRNAME)/`basename $@`"
if [ -d "$(STATICLIB_DIR)" ]; then \ @ $(CC) $(CFLAGS) -c "$<" || exit 1
rm -rf "$(STATICLIB_DIR)"; \
fi; \ $(TARGET)_%:
$(E) " AR lib$@.a"
@ $(AR) rcs "lib$@.a" "$(SOURCE_DIR)/$$(echo "$@" | cut -d'_' -f2).o"
make_executable:
$(E) " - Making executable file..."
$(E) " LD $(TARGET)"
@ $(CC) $(CFLAGS) -L$(SOURCE_DIR) $(foreach st,$(STATIC_LIBS),$(shell echo -n -l$(st) )) -o $(TARGET) $(OBJS_EXEC) || exit 1
end_progress:
@ abort_build() { \
[ -d "$(PACKAGE_DIR)" ] \
&& rm -rf "$(PACKAGE_DIR)"; \
[ -d "$(BINARY_DIR)" ] \
&& rm -rf "$(BINARY_DIR)"; \
[ -d "$(STATICLIB_DIR)" ] \
&& rm -rf "$(STATICLIB_DIR)"; \
exit 1; \ exit 1; \
}; \ }; \
mv $(TARGET) $(BINARY_DIR) || abort_build; \ mv $(TARGET) $(BINARY_DIR) || abort_build; \
mv *.a $(STATICLIB_DIR) || abort_build; \ mv *.a $(STATICLIB_DIR) || abort_build; \
printf "\n - Generating package...\n"; \ $(E_NS) " - Generating package..."; \
cp $(BINARY_DIR)/$(TARGET) $(PACKAGE_DIR) || abort_build; \ cp $(BINARY_DIR)/$(TARGET) $(PACKAGE_DIR) || abort_build; \
printf " XZ $(OUT_DIRNAME)/package/$(TARGET)-`date +%Y%m%d`.xz" $(E_NS) " XZ $(OUT_DIRNAME)/package/$(TARGET)-`date +%Y%m%d`.xz"
xz $(PACKAGE_DIR)/$(TARGET) || abort_build; \ xz $(PACKAGE_DIR)/$(TARGET) || abort_build; \
sleep 1; \ sleep 1; \
mv $(PACKAGE_DIR)/$(TARGET).xz $(PACKAGE_DIR)/$(TARGET)-`date +%Y%m%d`.xz || abort_build; \ mv $(PACKAGE_DIR)/$(TARGET).xz $(PACKAGE_DIR)/$(TARGET)-`date +%Y%m%d`.xz || abort_build
printf "\n - Success"; \ $(E) " - Success" && $(E_NS)
sleep 1; \ @ sleep 1
printf "\n\n ----------------------------------- \n" $(E) " ----------------------------------- "
.PHONY: clean .PHONY: clean
clean: clean:

View File

@@ -22,13 +22,11 @@ extern "C" {
#define INC_MAIN_LIBS #define INC_MAIN_LIBS
#include <pmt/pmt.h> #include <pmt/PartitionManager.h>
#include <pmt/stringkeys.h> #include <pmt/StringKeys.h>
void debug(LogLevel status, const char* _Nullable fmt, ...) void debug(LogLevel status, const char* _Nullable fmt, ...)
{ {
if (fmt == NULL) exit(1);
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);

View File

@@ -23,8 +23,8 @@ extern "C" {
#define INC_MAIN_LIBS #define INC_MAIN_LIBS
#define INC_STAT #define INC_STAT
#include <pmt/pmt.h> #include <pmt/PartitionManager.h>
#include <pmt/stringkeys.h> #include <pmt/StringKeys.h>
/** /**
* The target file is controlled by the stat function. * The target file is controlled by the stat function.

View File

@@ -21,10 +21,11 @@ extern "C" {
#endif #endif
#define INC_MAIN_LIBS #define INC_MAIN_LIBS
#define HELP
#include <pmt/pmt.h> #include <pmt/PartitionManager.h>
#include <pmt/stringkeys.h> #include <pmt/StringKeys.h>
#include <pmt/docs.h> #include <pmt/HelpMessages.h>
extern char* bin_name; extern char* bin_name;
extern char* curr_lang; extern char* curr_lang;

View File

@@ -24,8 +24,8 @@ extern "C" {
#define INC_DEBUGERS #define INC_DEBUGERS
#define INC_STAT #define INC_STAT
#include <pmt/pmt.h> #include <pmt/PartitionManager.h>
#include <pmt/stringkeys.h> #include <pmt/StringKeys.h>
/* pmt's man doc file path on termux */ /* pmt's man doc file path on termux */
#define TERMUX_PMT_MANDOC "/data/data/com.termux/files/usr/share/man/man8/pmt.8.gz" #define TERMUX_PMT_MANDOC "/data/data/com.termux/files/usr/share/man/man8/pmt.8.gz"
@@ -54,7 +54,7 @@ langctrl(const char* _Nonnull lang_)
int loadlang(void) int loadlang(void)
{ {
static char lang_fpr[10] = "en"; static char lang_fpr[3] = "en";
langconf = NULL; langconf = NULL;
if (get_stat(TERMUX_PMT_MANDOC, "file") == 0) if (get_stat(TERMUX_PMT_MANDOC, "file") == 0)

View File

@@ -22,8 +22,8 @@ extern "C" {
#define INC_MAIN_LIBS #define INC_MAIN_LIBS
#include <pmt/pmt.h> #include <pmt/PartitionManager.h>
#include <pmt/stringkeys.h> #include <pmt/StringKeys.h>
struct pmt_langdb_general en = { struct pmt_langdb_general en = {
.lang_by_s = "YZBruh & r0manas", .lang_by_s = "YZBruh & r0manas",

View File

@@ -24,8 +24,8 @@ extern "C" {
#define INC_DEBUGERS #define INC_DEBUGERS
#define INC_DIRENT #define INC_DIRENT
#include <pmt/pmt.h> #include <pmt/PartitionManager.h>
#include <pmt/stringkeys.h> #include <pmt/StringKeys.h>
/* current /dev context */ /* current /dev context */
#define CUR_DEV_CNTX "/dev/block/by-name" #define CUR_DEV_CNTX "/dev/block/by-name"
@@ -86,30 +86,22 @@ list(const char* operation, const char* target_dir)
/* list existing partitions */ /* list existing partitions */
int listpart(void) int listpart(void)
{ {
static char acc_cxt[350];
if (pmt_use_cust_cxt) if (pmt_use_cust_cxt)
{ sprintf(acc_cxt, "%s", cust_cxt);
if (list("access", cust_cxt) != 0) else
sprintf(acc_cxt, "%s", CUR_DEV_CNTX);
if (list("access", acc_cxt) != 0)
{ {
if (!pmt_force_mode) if (!pmt_force_mode)
LOGE("%s: `%s': %s\n", current->not_open, cust_cxt, strerror(errno)); LOGE("%s: `%s': %s\n", current->not_open, acc_cxt, strerror(errno));
else else
return 1; return 1;
} }
else else
list("print", cust_cxt); list("print", acc_cxt);
}
else
{
if (list("access", CUR_DEV_CNTX) != 0)
{
if (!pmt_force_mode)
LOGE("%s: `%s': %s\n", current->not_open, CUR_DEV_CNTX, strerror(errno));
else
return 1;
}
else
list("print", CUR_DEV_CNTX);
}
if (pmt_logical) if (pmt_logical)
{ {

View File

@@ -22,7 +22,7 @@ extern "C" {
#define INC_MAIN_LIBS #define INC_MAIN_LIBS
#include <pmt/pmt.h> #include <pmt/PartitionManager.h>
static int static int
accf(const char* _Nonnull target) { return access(target, F_OK); } accf(const char* _Nonnull target) { return access(target, F_OK); }

View File

@@ -26,10 +26,12 @@ extern "C" {
#define INC_STAT #define INC_STAT
#define INC_GETOPT #define INC_GETOPT
#include <pmt/pmt.h> #include <pmt/PartitionManager.h>
#include <pmt/stringkeys.h> #include <pmt/StringKeys.h>
#include <pmt/deprecates.h> #include <pmt/Deprecates.h>
#include <pmt/docs.h> #include <pmt/HelpMessages.h>
#define opt_symbol "-"
/* add value to variables that are added globally and are not worth */ /* add value to variables that are added globally and are not worth */
char* out = NULL; char* out = NULL;
@@ -51,24 +53,8 @@ bool pmt_force_mode = false;
bool pmt_inst_on_termux = false; bool pmt_inst_on_termux = false;
/* variable for use in control of '-' expression */ /* variable for use in control of '-' expression */
static const char* opt_symbol = "-";
static char common_symbol_rule[350]; static char common_symbol_rule[350];
#if !defined(__clang__)
static char*
strdup(const char* s)
{
size_t len = strlen(s) + 1;
char* copy = malloc(len);
if (copy) {
memcpy(copy, s, len);
}
return copy;
}
#endif
/** /**
* He controls whether the '-' sign at * He controls whether the '-' sign at
* the beginning of the given word * the beginning of the given word
@@ -93,10 +79,32 @@ ctrl_arg(const char* _Nullable argv_holder)
} }
/* classic main function (C binary here xd) */ /* classic main function (C binary here xd) */
int main(int argc, char* argv[]) int main(int argc, char** argv)
{ {
bin_name = argv[0]; bin_name = argv[0];
int argc_n = argc;
char buf[256];
char** args = malloc((argc + 1) * sizeof(char *));
/* copy original arguments */
for (int i = 0; i < argc; i++)
args[i] = argv[i];
if (!isatty(fileno(stdin)))
{
while (fgets(buf, sizeof(buf), stdin) != NULL)
{
buf[strcspn(buf, "\n")] = 0;
args = realloc(args, (argc_n + 1) * sizeof(char *));
args[argc_n] = strdup(buf);
argc_n++;
}
}
argc = argc_n;
/* load language */ /* load language */
if (loadlang() != 0) if (loadlang() != 0)
{ {
@@ -116,7 +124,7 @@ int main(int argc, char* argv[])
/* check argument total */ /* check argument total */
if (argc < 2) if (argc < 2)
LOGE("%s.\n%s `%s --help' %s.\n", current->missing_operand, current->try_h, argv[0], current->for_more); LOGE("%s.\n%s `%s --help' %s.\n", current->missing_operand, current->try_h, args[0], current->for_more);
/* a structure for long arguments */ /* a structure for long arguments */
struct option option_table[] = { struct option option_table[] = {
@@ -147,27 +155,27 @@ int main(int argc, char* argv[])
static int search_result = 3; static int search_result = 3;
static int opt; static int opt;
if (strcmp(argv[1], "backup") == 0) if (strcmp(args[1], "backup") == 0)
{ {
if (argc <= 2) if (argc <= 2)
LOGE("%s 0.\n", current->expected_backup_arg); LOGE("%s 0.\n", current->expected_backup_arg);
if (ctrl_arg(argv[2])) if (ctrl_arg(args[2]))
target_partition = argv[2]; target_partition = args[2];
else else
LOGE("%s.\n", current->not_spec_opt); LOGE("%s.\n", current->not_spec_opt);
out = target_partition; out = target_partition;
if (argc > 3 && ctrl_arg(argv[3])) if (argc > 3 && ctrl_arg(args[3]))
out = argv[3]; out = args[3];
check_optsym(target_partition); check_optsym(target_partition);
check_optsym(out); check_optsym(out);
pmt_backup = true; pmt_backup = true;
} }
else if (strcmp(argv[1], "flash") == 0) else if (strcmp(args[1], "flash") == 0)
{ {
if (argc <= 2) if (argc <= 2)
LOGE("%s 0.\n", current->expected_flash_arg); LOGE("%s 0.\n", current->expected_flash_arg);
@@ -175,13 +183,13 @@ int main(int argc, char* argv[])
if (argc <= 3) if (argc <= 3)
LOGE("%s 1.\n", current->expected_flash_arg); LOGE("%s 1.\n", current->expected_flash_arg);
if (ctrl_arg(argv[2])) if (ctrl_arg(args[2]))
target_partition = argv[2]; target_partition = args[2];
else else
LOGE("%s.\n", current->not_spec_opt); LOGE("%s.\n", current->not_spec_opt);
if (ctrl_arg(argv[3])) if (ctrl_arg(args[3]))
target_flash_file = argv[3]; target_flash_file = args[3];
else else
LOGE("%s.\n", current->not_spec_opt); LOGE("%s.\n", current->not_spec_opt);
@@ -190,7 +198,7 @@ int main(int argc, char* argv[])
pmt_flash = true; pmt_flash = true;
} }
else if (strcmp(argv[1], "format") == 0) else if (strcmp(args[1], "format") == 0)
{ {
if (argc <= 2) if (argc <= 2)
@@ -199,13 +207,13 @@ int main(int argc, char* argv[])
if (argc <= 3) if (argc <= 3)
LOGE("%s 1.\n", current->expected_format_arg); LOGE("%s 1.\n", current->expected_format_arg);
if (ctrl_arg(argv[2])) if (ctrl_arg(args[2]))
target_partition = argv[2]; target_partition = args[2];
else else
LOGE("%s.\n", current->not_spec_opt); LOGE("%s.\n", current->not_spec_opt);
if (ctrl_arg(argv[3])) if (ctrl_arg(args[3]))
format_fs = argv[3]; format_fs = args[3];
else else
LOGE("%s.\n", current->not_spec_opt); LOGE("%s.\n", current->not_spec_opt);
@@ -216,7 +224,7 @@ int main(int argc, char* argv[])
} }
/* control for each argument */ /* control for each argument */
while ((opt = getopt_long(argc, argv, "bFrDlc:psfS:vL", option_table, NULL)) != -1) while ((opt = getopt_long(argc, args, "bFrDlc:psfS:vL", option_table, NULL)) != -1)
{ {
/* process arguments */ /* process arguments */
switch (opt) switch (opt)
@@ -285,11 +293,11 @@ int main(int argc, char* argv[])
break; break;
/* for invalid options */ /* for invalid options */
case '?': case '?':
LOGD("%s `%s --help' %s\n", current->try_h, argv[0], current->for_more); LOGD("%s `%s --help' %s\n", current->try_h, args[0], current->for_more);
return 1; return 1;
break; break;
default: default:
LOGD("%s: %s [backup] [flash] [format] [-l | --logical] [-c | --context] [-p | --list] [-s | --silent] [-v | --version] [--help]\n", current->usage_head, argv[0]); LOGD("%s: %s [backup] [flash] [format] [-l | --logical] [-c | --context] [-p | --list] [-s | --silent] [-v | --version] [--help]\n", current->usage_head, args[0]);
return 1; return 1;
} }
} }
@@ -317,15 +325,15 @@ int main(int argc, char* argv[])
if (pmt_setlang) if (pmt_setlang)
{ {
LOGD("%s: %s\n", argv[0], current->switching_lang); LOGD("%s: %s\n", args[0], current->switching_lang);
setlang(langpr, 0); setlang(langpr, 0);
sleep(2); sleep(2);
LOGD("%s: %s.\n", argv[0], current->please_rerun); LOGD("%s: %s.\n", args[0], current->please_rerun);
return 0; return 0;
} }
if (!pmt_backup && !pmt_flash && !pmt_format) if (!pmt_backup && !pmt_flash && !pmt_format)
LOGE("%s.\n%s `%s --help` %s\n", current->no_target, current->try_h, argv[0], current->for_more); LOGE("%s.\n%s `%s --help` %s\n", current->no_target, current->try_h, args[0], current->for_more);
if (pmt_format) if (pmt_format)
{ {
@@ -372,7 +380,7 @@ int main(int argc, char* argv[])
if (target_partition == NULL) if (target_partition == NULL)
{ {
if (!pmt_force_mode) if (!pmt_force_mode)
LOGE("%s\n%s `%s --help' %s\n", current->req_part_name, current->try_h, argv[0], current->for_more); LOGE("%s\n%s `%s --help' %s\n", current->req_part_name, current->try_h, args[0], current->for_more);
} }
else else
{ {

View File

@@ -23,8 +23,8 @@ extern "C" {
#define INC_MAIN_LIBS #define INC_MAIN_LIBS
#define INC_DEBUGERS #define INC_DEBUGERS
#include <pmt/pmt.h> #include <pmt/PartitionManager.h>
#include <pmt/stringkeys.h> #include <pmt/StringKeys.h>
/* root checker function */ /* root checker function */
void check_root(void) void check_root(void)

View File

@@ -26,8 +26,10 @@ extern "C" {
#define INC_DEBUGERS #define INC_DEBUGERS
#define INC_TOOLS_REQS #define INC_TOOLS_REQS
#include <pmt/pmt.h> #include <pmt/PartitionManager.h>
#include <pmt/stringkeys.h> #include <pmt/StringKeys.h>
#define count (1024 * 1024 * 1024)
/** /**
* it is meant to calculate the size of the quickly given file. * it is meant to calculate the size of the quickly given file.
@@ -79,38 +81,35 @@ int pmt(unsigned short progress_code)
{ {
/* required variables */ /* required variables */
static int srcf, targetf; static int srcf, targetf;
static char backupper_path[512]; static char acc_part_path[512];
static char ppath[100];
static char formatter_cmd[200]; static char formatter_cmd[200];
static char outf[512]; static char outf[512];
static char flasher_path[512];
static char buffer[BFSIZE]; static char buffer[BFSIZE];
static ssize_t readed_data; static ssize_t readed_data;
static unsigned long long copied_data = 0; static unsigned long long copied_data = 0;
static unsigned long long count = 1024 * 1024 * 1024;
if (pmt_use_logical)
sprintf(acc_part_path, "/dev/block/mapper/%s", target_partition);
else
{
if (pmt_use_cust_cxt)
sprintf(acc_part_path, "%s/%s", cust_cxt, target_partition);
else
sprintf(acc_part_path, "/dev/block/by-name/%s", target_partition);
}
search_partition(acc_part_path);
if (progress_code == 1) if (progress_code == 1)
{ {
if (!pmt_use_logical) if (calc_flsz(acc_part_path) != -1)
{ LOGD("%s: %.2fM\n", current->part_disk_sz, calc_flsz(acc_part_path));
if (pmt_use_cust_cxt)
sprintf(backupper_path, "%s/%s", cust_cxt, target_partition);
else
sprintf(backupper_path, "/dev/block/by-name/%s", target_partition);
}
else
sprintf(backupper_path, "/dev/block/mapper/%s", target_partition);
search_partition(backupper_path);
if (calc_flsz(backupper_path) != -1)
LOGD("%s: %.2f\n", current->part_disk_sz, calc_flsz(backupper_path));
else else
LOGW("%s\n", current->part_disk_sz_fail); LOGW("%s\n", current->part_disk_sz_fail);
srcf = open(backupper_path, O_RDONLY); srcf = open(acc_part_path, O_RDONLY);
if (srcf == -1) if (srcf == -1)
LOGE("%s: %s: %s\n", current->not_read, backupper_path, strerror(errno)); LOGE("%s: %s: %s\n", current->not_read, acc_part_path, strerror(errno));
/* determine output */ /* determine output */
if (strcmp(out, target_partition) == 0) if (strcmp(out, target_partition) == 0)
@@ -133,7 +132,7 @@ int pmt(unsigned short progress_code)
{ {
if (get_stat(outf, "file") == 0) if (get_stat(outf, "file") == 0)
remove(outf); remove(outf);
LOGF("%s: %s: %s\n", current->not_write, backupper_path, strerror(errno)); LOGF("%s: %s: %s\n", current->not_write, acc_part_path, strerror(errno));
} }
copied_data += writed_data; copied_data += writed_data;
@@ -147,35 +146,19 @@ int pmt(unsigned short progress_code)
} }
else if (progress_code == 2) else if (progress_code == 2)
{ {
/* determine device block */
/* for classic */
if (!pmt_use_logical)
{
if (pmt_use_cust_cxt)
sprintf(flasher_path, "%s/%s", cust_cxt, target_partition);
else
sprintf(flasher_path, "/dev/block/by-name/%s", target_partition);
/* for logical */
}
else
sprintf(flasher_path, "/dev/block/mapper/%s", target_partition);
/* check partition */
search_partition(flasher_path);
if (calc_flsz(target_flash_file) != -1) if (calc_flsz(target_flash_file) != -1)
LOGD("%s: %.2f\n", current->flash_file_sz, calc_flsz(target_flash_file)); LOGD("%s: %.2fM\n", current->flash_file_sz, calc_flsz(target_flash_file));
else else
LOGW("%s\n", current->flash_file_sz_fail); LOGW("%s\n", current->flash_file_sz_fail);
if (calc_flsz(flasher_path) != -1) if (calc_flsz(acc_part_path) != -1)
LOGD("%s: %.2f\n", current->part_disk_sz, calc_flsz(flasher_path)); LOGD("%s: %.2fM\n", current->part_disk_sz, calc_flsz(acc_part_path));
else else
LOGW("%s\n", current->part_disk_sz_fail); LOGW("%s\n", current->part_disk_sz_fail);
if (calc_flsz(target_flash_file) != -1 && calc_flsz(flasher_path) != -1) if (calc_flsz(target_flash_file) != -1 && calc_flsz(acc_part_path) != -1)
{ {
if (calc_flsz(target_flash_file) > calc_flsz(flasher_path)) if (calc_flsz(target_flash_file) > calc_flsz(acc_part_path))
LOGE("%s\n", current->ffile_more_part); LOGE("%s\n", current->ffile_more_part);
} }
@@ -183,16 +166,16 @@ int pmt(unsigned short progress_code)
if (srcf == -1) if (srcf == -1)
LOGF("%s: %s: %s\n", current->not_read, target_flash_file, strerror(errno)); LOGF("%s: %s: %s\n", current->not_read, target_flash_file, strerror(errno));
targetf = open(target_partition, O_WRONLY | O_CREAT | O_TRUNC, 0660); targetf = open(acc_part_path, O_WRONLY | O_CREAT | O_TRUNC, 0660);
if (targetf == -1) if (targetf == -1)
LOGF("%s: %s: %s\n", current->not_read, target_partition, strerror(errno)); LOGF("%s: %s: %s\n", current->not_read, acc_part_path, strerror(errno));
/* start writing */ /* start writing */
while ((readed_data = read(srcf, buffer, BFSIZE)) > 0 && copied_data < count) while ((readed_data = read(srcf, buffer, BFSIZE)) > 0 && copied_data < count)
{ {
ssize_t writed_data = write(targetf, buffer, readed_data); ssize_t writed_data = write(targetf, buffer, readed_data);
if (writed_data != readed_data) if (writed_data != readed_data)
LOGF("%s: %s: %s\n", current->not_write, backupper_path, strerror(errno)); LOGF("%s: %s: %s\n", current->not_write, acc_part_path, strerror(errno));
copied_data += writed_data; copied_data += writed_data;
} }
@@ -204,28 +187,13 @@ int pmt(unsigned short progress_code)
} }
else if (progress_code == 3) else if (progress_code == 3)
{ {
/* generate partition extn */
if (!pmt_use_logical)
{
if (pmt_use_cust_cxt)
sprintf(ppath, "%s/%s", cust_cxt, target_partition);
else
sprintf(ppath, "/dev/block/by-name/%s", target_partition);
/* for logical */
}
else
sprintf(ppath, "/dev/block/mapper/%s", target_partition);
/* check partition */
search_partition(ppath);
/* get target partition block size */ /* get target partition block size */
struct statvfs file_sys_inf; struct statvfs file_sys_inf;
if (statvfs(ppath, &file_sys_inf) != 0) if (statvfs(acc_part_path, &file_sys_inf) != 0)
LOGE("%s\n", current->cannot_get_bsz); LOGE("%s\n", current->cannot_get_bsz);
/* generate mke2fs command */ /* generate mke2fs command */
sprintf(formatter_cmd, "mke2fs -Fq -t %s -b %lu %s", format_fs, file_sys_inf.f_bsize, ppath); sprintf(formatter_cmd, "mke2fs -Fq -t %s -b %lu %s", format_fs, file_sys_inf.f_bsize, acc_part_path);
/* run command */ /* run command */
if (system(formatter_cmd) != 0) if (system(formatter_cmd) != 0)

View File

@@ -21,10 +21,11 @@ extern "C" {
#endif #endif
#define INC_MAIN_LIBS #define INC_MAIN_LIBS
#define VERSIONING
#include <pmt/pmt.h> #include <pmt/PartitionManager.h>
#include <pmt/stringkeys.h> #include <pmt/StringKeys.h>
#include <pmt/versioning.h> #include <pmt/VersionVars.h>
void version(void) void version(void)
{ {
@@ -40,7 +41,7 @@ void version(void)
#if defined(__clang__) && !defined(__NDK_BUILD) #if defined(__clang__) && !defined(__NDK_BUILD)
LOGD("%s: clang %d.%d.%d\n", current->compiler_str, __clang_major__, __clang_minor__, __clang_patchlevel__); LOGD("%s: clang %d.%d.%d\n", current->compiler_str, __clang_major__, __clang_minor__, __clang_patchlevel__);
#elif defined(__clang__) && defined(__NDK_BUILD) #elif defined(__NDK_BUILD)
LOGD("%s\n", __NDK_CC_VERSION__); LOGD("%s\n", __NDK_CC_VERSION__);
#endif #endif
} }

View File

@@ -25,101 +25,126 @@ include ../Makefile.inc
-include $(BUILD)/config/INS_STAT.mk -include $(BUILD)/config/INS_STAT.mk
-include $(BUILD)/config/UNINS_STAT.mk -include $(BUILD)/config/UNINS_STAT.mk
INSTALL_PROGRESS_LIST := \
really_termux \
welcome \
check_ins_stat \
deb_installer \
really_builded \
install_binary
UNINSTALL_PROGRESS_LIST := \
really_termux \
welcome \
check_unins_stat \
uninstall_$(TARGET)
# create an empty target # create an empty target
all: all:
$(hide)printf "" $(P) ""
# installer # installer
.PHONY: install .PHONY: install
install: install: $(INSTALL_PROGRESS_LIST)
# really termux?
$(hide)if [ -f $(TERMUX_BIN)/termux-open ]; then \ # uninstaller
printf " ------------ $(TARGET) installer ------------ \n"; \ .PHONY: uninstall
if [ -f $(TERMUX_BIN)/$(TARGET) ]; then \ uninstall: $(UNINSTALL_PROGRESS_LIST)
printf " - $(TARGET) already installed\n"; \
exit; \ install_binary:
$(E) " - Installing binary..."
if cp $(BINARY_DIR)/$(TARGET) /data/data/com.termux/files/usr/bin/$(TARGET); then \
$(E_NS) " - Setting up permissions..."; \
else \
$(E_NS) "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
exit 1; \
fi; \ fi; \
if [ ! "$(INSTALL_SUCCESS)" = "true" ] && [ ! "$(INSTALL_SUCCESS)" = "" ]; then \ if chmod 777 $(TERMUX_BIN)/$(TARGET); then \
printf " - $(YELLOW)$(BOLD)Warning:$(BOLD_RESET)$(RESET) a previously-stayed failed installation process found\n"; \ $(E_NS) " - Saving current status..."; \
$(E_NS) "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \
else \
$(E_NS) "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
exit 1; \
fi; \ fi; \
$(P) " - Success.\n\n"; \
$(E_NS) "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \
$(E_NS) "UNINSTALLED_SUCCESS := " > $(BUILD)/config/UNINS_STAT.mk; \
uninstall_$(TARGET):
if [ -f $(TERMUX_USR)/share/man/man8/$(TARGET).8.gz ]; then \
$(E_NS) " - It was found to be established by $(TARGET)'s deb pack. It's removed with apt..."; \
apt remove -y $(TARGET) || exit 1; \
$(P) " - Success.\n\n"; \
$(E_NS) "UNINSTALLED_SUCCESS := true" > $(BUILD)/config/UNINS_STAT.mk; \
$(E_NS) "INSTALL_SUCCESS := " > $(BUILD)/config/INS_STAT.mk; \
else \
$(E_NS) " - It was found that pmt was manually established (with this makefile or copying). Manually removed..."; \
if rm $(TERMUX_BIN)/$(TARGET); then \
$(P) " - Success.\n\n"; \
$(E_NS) "UNINSTALLED_SUCCESS := true" > $(BUILD)/config/UNINS_STAT.mk; \
$(E_NS) "INSTALL_SUCCESS := " > $(BUILD)/config/INS_STAT.mk; \
else \
$(E_NS) "UNINSTALLED_SUCCESS := false" > $(BUILD)/config/UNINS_STAT.mk; \
exit 1; \
fi; \
fi
deb_installer:
if [ -f $(DEB_DIR)/*.deb ]; then \ if [ -f $(DEB_DIR)/*.deb ]; then \
printf " - The created deb pack was found. It's setup...\n"; \ $(E_NS) " - The created deb pack was found. It's setup..."; \
cd $(DEB_DIR) || exit 1; \ cd $(DEB_DIR) || exit 1; \
apt install ./*.deb || exit 1; \ apt install ./*.deb || exit 1; \
if [ ! "$?" = "0" ]; then \ if [ ! "$?" = "0" ]; then \
cd $(CUR_DIR); \ cd $(CUR_DIR); \
printf " - Success.\n\n"; \ $(P) " - Success.\n\n"; \
echo "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \ $(E_NS) "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \
echo "UNINSTALLED_SUCCESS := " > $(BUILD)/config/UNINS_STAT.mk; \ $(E_NS) "UNINSTALLED_SUCCESS := " > $(BUILD)/config/UNINS_STAT.mk; \
cd ..; \ cd ..; \
exit 0; \ exit 0; \
else \ else \
cd $(CUR_DIR); \ cd $(CUR_DIR); \
printf " - $(RED)$(BOLD)Error:$(BOLD_RESET)$(RESET) installing failed!\n"; \ $(P) " - $(RED)$(BOLD)Error:$(BOLD_RESET)$(RESET) installing failed!\n"; \
echo "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \ $(E_NS) "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
cd ..; \ cd ..; \
exit 1; \ exit 1; \
fi; \ fi; \
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"; \ check_ins_stat:
echo "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \ @ if [ ! "$(INSTALL_SUCCESS)" = "true" ] && [ ! "$(INSTALL_SUCCESS)" = "" ]; then \
$(P) " - $(YELLOW)$(BOLD)Warning:$(BOLD_RESET)$(RESET) a previously-stayed failed installation process found\n"; \
fi
check_unins_stat:
@ if [ ! "$(UNINSTALL_SUCCESS)" = "true" ] && [ ! "$(UNINSTALL_SUCCESS)" = "" ]; then \
$(P) " - $(YELLOW)$(BOLD)Warning:$(BOLD_RESET)$(RESET) a previously-stayed failed uninstallation process found\n"; \
fi
welcome:
$(E) " ----------- $(TARGET) $(PROG)er ----------- "
@ if [ "$(PROG)" = "uninstall" ]; then \
if [ ! -f $(TERMUX_BIN)/$(TARGET) ]; then \
$(E_NS) " - $(TARGET) already $(PROG)ed"; \
exit 1; \ exit 1; \
fi; \ fi; \
printf " - Installing binary...\n"; \ fi
if [ "`cp $(BINARY_DIR)/$(TARGET) /data/data/com.termux/files/usr/bin/$(TARGET)`" = "" ]; then \ @ if [ "$(PROG)" = "install" ]; then \
printf " - Setting up permissions...\n"; \ if [ -f $(TERMUX_BIN)/$(TARGET) ]; then \
else \ $(E_NS) " - $(TARGET) already $(PROG)ed"; \
echo "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
exit 1; \ exit 1; \
fi; \ fi; \
if [ "`chmod 777 $(TERMUX_BIN)/$(TARGET)`" = "" ]; then \ fi
printf " - Saving current status...\n"; \
echo "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \ really_termux:
else \ @ if [ ! -f $(TERMUX_BIN)/termux-open ]; then \
echo "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \ $(P) "$(RED)$(BOLD)Error:$(BOLD_RESET)$(RESET) This function is only available on Termux.\n"; \
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; \ exit 1; \
fi fi
# uninstaller really_builded:
.PHONY: uninstall if [ ! -f $(BINARY_DIR)/$(TARGET) ]; then \
uninstall: $(P) " - $(RED)$(BOLD)Error:$(BOLD_RESET)$(RESET) Package not builded! Please build package and try again \n"; \
# really termux? $(E_NS) "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
$(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; \ exit 1; \
fi fi