From 5d51e44a2ccc4a5d62278b32d9eff186dda3915b Mon Sep 17 00:00:00 2001 From: YZ-Bruh Date: Fri, 2 Aug 2024 17:44:31 +0300 Subject: [PATCH] pmt: initial 2.7.0 update --- Makefile.inc | 12 +-- build/bash/additional-vars | 6 -- build/bash/check-makefiles | 5 +- build/bash/clean-makefiles | 24 ++--- build/bash/functions | 16 ++-- build/bash/gen-header | 12 +-- build/bash/gen-makefiles | 6 +- build/deb/mandoc/pmt.8.gz | Bin 1151 -> 1151 bytes build/main.mk | 14 +-- build/others/makefile.androidmk | 10 +-- build/others/makefile.applicationmk | 2 +- build/others/makefile.sourcedir | 51 +++++------ build/workflow/build.config | 4 +- include/pmt/{deprecates.h => Deprecates.h} | 8 +- include/pmt/ExternC.h | 30 +++++++ include/pmt/{help_msgs.h => HelpMessages.h} | 6 +- include/pmt/{pmt.h => PartitionManager.h} | 8 +- include/pmt/{stringkeys.h => StringKeys.h} | 6 +- include/pmt/{versioning.h => VersionVars.h} | 8 +- jni/Makefile | 53 +++++------ jni/{debugging.c => debug.c} | 4 +- jni/get_stat.c | 4 +- jni/help.c | 6 +- jni/lang_tools.c | 4 +- jni/languages.c | 4 +- jni/listpart.c | 2 +- jni/partitiontool.c | 2 +- jni/pmt.c | 93 +++++++++++--------- jni/root.c | 4 +- jni/tools.c | 4 +- jni/{versioning.c => version.c} | 6 +- 31 files changed, 223 insertions(+), 191 deletions(-) delete mode 100755 build/bash/additional-vars rename include/pmt/{deprecates.h => Deprecates.h} (96%) create mode 100755 include/pmt/ExternC.h rename include/pmt/{help_msgs.h => HelpMessages.h} (91%) rename include/pmt/{pmt.h => PartitionManager.h} (96%) rename include/pmt/{stringkeys.h => StringKeys.h} (98%) rename include/pmt/{versioning.h => VersionVars.h} (90%) rename jni/{debugging.c => debug.c} (96%) rename jni/{versioning.c => version.c} (93%) diff --git a/Makefile.inc b/Makefile.inc index 0040bdd..0bf34f6 100755 --- a/Makefile.inc +++ b/Makefile.inc @@ -15,8 +15,8 @@ # limitations under the License. # speficy -VERSION := 2.6.0 -VERSION_CODE := 260 +VERSION := 2.7.0 +VERSION_CODE := 270 TARGET := pmt # device arch info @@ -83,10 +83,10 @@ SRCS := $(wildcard $(SOURCE_DIR)/*.c) OBJS = $(SRCS:.c=.o) STATIC_LIBS := \ - lib$(TARGET)_root.a \ - lib$(TARGET)_debugging.a \ - lib$(TARGET)_listpart.a \ - lib$(TARGET)_partitiontool.a + $(TARGET)_root \ + $(TARGET)_debug \ + $(TARGET)_listpart \ + $(TARGET)_partitiontool # other directories in the out directory IN_OUT_DIR := \ diff --git a/build/bash/additional-vars b/build/bash/additional-vars deleted file mode 100755 index 0c188f3..0000000 --- a/build/bash/additional-vars +++ /dev/null @@ -1,6 +0,0 @@ -NDK_PROG=false -FORCE_GEN=false -THIS_IS=main -UPDATE_MAKEFILES=false -SOURCE_DIRNAME=src -OUT_DIRNAME=out diff --git a/build/bash/check-makefiles b/build/bash/check-makefiles index 677ff71..dcda562 100755 --- a/build/bash/check-makefiles +++ b/build/bash/check-makefiles @@ -14,7 +14,8 @@ # 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." +[ ! "${THIS_IS}" = "main" ] \ +&& abort "The caller is not the main makefile. Something's wrong." try_with="Try with force mode (FORCE_GEN=true)." @@ -24,7 +25,7 @@ else mfiles=("${OUT_DIR}/Makefile" "${SOURCE_DIR}/Makefile") fi -for mfile in ${mfiles[0]} ${mfiles[1]}; do +for mfile in ${mfiles[@]}; do [ -f "${mfile}" ] && \ if [ "${FORCE_GEN}" = "true" ]; then diff --git a/build/bash/clean-makefiles b/build/bash/clean-makefiles index 21cdd2e..f5a2bfc 100755 --- a/build/bash/clean-makefiles +++ b/build/bash/clean-makefiles @@ -17,25 +17,27 @@ . build/bash/vars . 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 - [ "${UPDATE_MAKEFILES}" = "true" ] || print " - Removing Android.mk..." - rm -f ${SOURCE_DIR}/Android.mk + [ "${UPDATE_MAKEFILES}" = "true" ] \ + || 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 - [ "${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 ${OUT_DIR}/Makefile - - [ "${UPDATE_MAKEFILES}" = "true" ] || print " - Removing source directory makefile" - rm -f ${SOURCE_DIR}/Makefile + rm -f ${SOURCE_DIR}/Makefile \ + ${OUT_DIR}/Makefile fi diff --git a/build/bash/functions b/build/bash/functions index d6a898b..3803203 100755 --- a/build/bash/functions +++ b/build/bash/functions @@ -16,22 +16,22 @@ 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 } 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() { - [ "${FORCE_GEN}" = "true" -a "${UPDATE_MAKEFILES}" = "true" ] && rm -f "$1" - touch "$1" || abort "failed to generate: $1" + [ "${FORCE_GEN}" = "true" -a "${UPDATE_MAKEFILES}" = "true" ] \ + && rm -f "${1}" + touch "${1}" || abort "failed to generate: ${1}" } -function print() -{ - echo -e "$1" -} +function print() { echo -e "${1}"; } diff --git a/build/bash/gen-header b/build/bash/gen-header index 4aa9e61..8dd7781 100755 --- a/build/bash/gen-header +++ b/build/bash/gen-header @@ -14,13 +14,13 @@ # 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_ROOT_DIR} ] \ +&& echo "Please set NDK_ROOT_DIR variable!" \ +&& exit 1 -[ -z ${NDK_PROJECT_PATH} ] && \ -echo "Please set NDK_PROJECT_PATH 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) diff --git a/build/bash/gen-makefiles b/build/bash/gen-makefiles index 199fad3..ce1c5dc 100755 --- a/build/bash/gen-makefiles +++ b/build/bash/gen-makefiles @@ -17,8 +17,10 @@ . 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." +[ ! "${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" diff --git a/build/deb/mandoc/pmt.8.gz b/build/deb/mandoc/pmt.8.gz index 05f51ee3a88be952cc4217bdf450ca988e36f11e..dbe28662c90ee8b868aab8b20c52c5361d227154 100755 GIT binary patch delta 52 zcmV-40L%aX2>%EoABzYGgXyeh1OsqwbS^jmomOp+lRyyu&aasClO|U%YND|sRRjpk K09YA<2><{e3lm5H delta 52 zcmV-40L%aX2>%EoABzYGkm09h1OsqwbS^jmomOp+lRyyu&aasClO|U%YK*ZWRRjo9 K+Mq^)2><{hpcDrH diff --git a/build/main.mk b/build/main.mk index 6e24cfd..778abe8 100755 --- a/build/main.mk +++ b/build/main.mk @@ -15,6 +15,7 @@ # limitations under the License. UPDATE_MAKEFILES = false +CLS_ADTS := "rm -f $(BUILD)/bash/additional-vars" all: $(MAKE_HIDE) $(SILENT) -C $(BUILD)/config || exit 1 @@ -46,7 +47,8 @@ clean: # helper function .PHONY: help help: - $(E) " ------- Partition Manager help ------- " && $(E_NS) + $(E) " ------- Partition Manager help ------- " \ + && $(E_NS) $(E) " Commands:" $(E) " $(MAKE) ==> Build Partition Manager." $(E) " $(MAKE) deb ==> Generate debian package for termux." @@ -85,13 +87,13 @@ gen-ndk-makefiles: $(eval NDK_PROG = true) $(call save-gen-vars) $(call gen-ndk-mfiles) - @ $(P) "" + @ $(CLS_ADTS) .PHONY: gen-makefiles gen-makefiles: $(call save-gen-vars) $(call gen-mfiles) - @ $(P) "" + @ $(CLS_ADTS) .PHONY: update-ndk-makefiles update-ndk-makefiles: @@ -101,6 +103,7 @@ update-ndk-makefiles: $(call save-gen-vars) $(call clean-ndk-mfiles) $(call gen-ndk-mfiles) + @ $(CLS_ADTS) .PHONY: update-makefiles update-makefiles: @@ -109,18 +112,19 @@ update-makefiles: $(call save-gen-vars) $(call clean-ndk-mfiles) $(call gen-mfiles) + @ $(CLS_ADTS) .PHONY: clean-ndk-makefiles clean-ndk-makefiles: $(eval NDK_PROG = true) $(call save-gen-vars) $(call clean-ndk-mfiles) - @ $(P) "" + @ $(CLS_ADTS) .PHONY: clean-makefiles clean-makefiles: $(call save-gen-vars) $(call clean-mfiles) - @ $(P) "" + @ $(CLS_ADTS) # end diff --git a/build/others/makefile.androidmk b/build/others/makefile.androidmk index e5c4094..0f8f7e3 100755 --- a/build/others/makefile.androidmk +++ b/build/others/makefile.androidmk @@ -15,7 +15,7 @@ # limitations under the License. ######## -# 2.6.0 +# 2.7.0 ######## LOCAL_PATH := $(call my-dir) @@ -49,8 +49,8 @@ include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) -LOCAL_MODULE := libpmt_debugging -LOCAL_SRC_FILES := debugging.c +LOCAL_MODULE := libpmt_debug +LOCAL_SRC_FILES := debug.c LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include LOCAL_CFLAGS := $(PMT_CFLAGS) @@ -79,7 +79,7 @@ include $(CLEAR_VARS) LOCAL_MODULE := pmt LOCAL_SRC_FILES := \ pmt.c \ - versioning.c \ + version.c \ get_stat.c \ tools.c \ lang_tools.c \ @@ -88,7 +88,7 @@ LOCAL_SRC_FILES := \ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include LOCAL_STATIC_LIBRARIES := \ libpmt_root \ - libpmt_debugging \ + libpmt_debug \ libpmt_partitiontool \ libpmt_list LOCAL_CFLAGS := $(PMT_CFLAGS) diff --git a/build/others/makefile.applicationmk b/build/others/makefile.applicationmk index 4dd48d0..96f57fd 100755 --- a/build/others/makefile.applicationmk +++ b/build/others/makefile.applicationmk @@ -15,7 +15,7 @@ # limitations under the License. ######## -# 2.6.0 +# 2.7.0 ######## # architecture diff --git a/build/others/makefile.sourcedir b/build/others/makefile.sourcedir index 9b3f8bc..04ef447 100755 --- a/build/others/makefile.sourcedir +++ b/build/others/makefile.sourcedir @@ -31,7 +31,7 @@ PMT_INCDIR := $(INCLUDE_DIR)/pmt # the presence of all source files that are on this list will be checked SRCS_REQ := \ - place-holder/debugging.c \ + place-holder/debug.c \ place-holder/help.c \ place-holder/get_stat.c \ place-holder/lang_tools.c \ @@ -40,34 +40,38 @@ SRCS_REQ := \ place-holder/pmt.c \ place-holder/root.c \ place-holder/tools.c \ - place-holder/versioning.c + place-holder/version.c # objects to be used when executable file is created OBJS_EXEC := \ $(SOURCE_DIR)/$(TARGET).o \ $(SOURCE_DIR)/help.o \ - $(SOURCE_DIR)/versioning.o \ + $(SOURCE_DIR)/version.o \ $(SOURCE_DIR)/get_stat.o \ $(SOURCE_DIR)/tools.o \ $(SOURCE_DIR)/lang_tools.o \ $(SOURCE_DIR)/languages.o HEADERS_REQ := \ - $(PMT_INCDIR)/pmt/deprecates.h \ - $(PMT_INCDIR)/pmt/help_msgs.h \ + $(PMT_INCDIR)/pmt/ExternC.h \ + $(PMT_INCDIR)/pmt/Deprecates.h \ + $(PMT_INCDIR)/pmt/HelpMessages.h \ $(PMT_INCDIR)/pmt/pmt.h \ - $(PMT_INCDIR)/pmt/stringkeys.h \ - $(PMT_INCDIR)/pmt/versioning.h + $(PMT_INCDIR)/pmt/StringKeys.h \ + $(PMT_INCDIR)/pmt/VersionVars.h PROGRESS_LIST := \ welcome \ + wait \ $(SRCS_REQ) \ $(HEADERS_REQ) \ pr_obj \ $(OBJS) \ make_outdirs \ + pr_sts \ $(STATIC_LIBS) \ make_executable \ + wait \ end_progress define check_hf @@ -88,17 +92,22 @@ welcome: && $(E_NS) $(E) " -------------------------------- " \ && $(E_NS) - @ if [ -f $(SOURCE_DIR)/debugging.o ]; then \ + @ if [ -f $(SOURCE_DIR)/debug.o ]; then \ $(E_NS) " - Please clean up before you build it." && echo; \ $(E_NS) " ----------------------------------- "; \ exit 1; \ fi $(E) " - Checking required source files..." - @ sleep 1 pr_obj: $(E) " - Building objects..." +pr_sts: + $(E) " - Making static libraries..." + +wait: + @ sleep 2 + make_outdirs: @ rm -rf $(IN_OUT_DIR) @ mkdir $(BINARY_DIR) @@ -122,31 +131,15 @@ $(PMT_INCDIR)/%.h: $(SOURCE_DIR)/%.o: $(SOURCE_DIR)/%.c $(E) " CC $(SOURCE_DIRNAME)/`basename $@`" @ $(CC) $(CFLAGS) -c "$<" || exit 1 - $(eval GEN_OBJS_MSG = ) -lib$(TARGET)_root.a: - $(E) " - Making static libraries..." - $(E) " AR $@" - @ $(AR) rcs "$@" "$(SOURCE_DIR)/root.o" || exit 1 - -lib$(TARGET)_debugging.a: - $(E) " AR $@" - @ $(AR) rcs "$@" "$(SOURCE_DIR)/debugging.o" - -lib$(TARGET)_listpart.a: - $(E) " AR $@" - @ $(AR) rcs "$@" "$(SOURCE_DIR)/listpart.o" - -lib$(TARGET)_partitiontool.a: - $(E) " AR $@" - @ $(AR) rcs "$@" "$(SOURCE_DIR)/partitiontool.o" - @ sleep 1 +$(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) -l$(TARGET)_root -l$(TARGET)_debugging -l$(TARGET)_listpart -l$(TARGET)_partitiontool -o $(TARGET) $(OBJS_EXEC) || exit 1 - @ sleep 1 + @ $(CC) $(CFLAGS) -L$(SOURCE_DIR) $(foreach st,$(STATIC_LIBS),$(shell echo -n -l$(st) )) -o $(TARGET) $(OBJS_EXEC) || exit 1 end_progress: @ abort_build() { \ diff --git a/build/workflow/build.config b/build/workflow/build.config index 3461a90..72577e2 100755 --- a/build/workflow/build.config +++ b/build/workflow/build.config @@ -1,5 +1,5 @@ -export PMT_VERSION="2.6.0" -export PMT_VERSION_CODE=260 +export PMT_VERSION="2.7.0" +export PMT_VERSION_CODE=270 export NDK_LINK="https://dl.google.com/android/repository/android-ndk-r27-linux.zip" export NDK_VERSION="r27" export NDK_IS="android-ndk" \ No newline at end of file diff --git a/include/pmt/deprecates.h b/include/pmt/Deprecates.h similarity index 96% rename from include/pmt/deprecates.h rename to include/pmt/Deprecates.h index 3d83949..678779a 100755 --- a/include/pmt/deprecates.h +++ b/include/pmt/Deprecates.h @@ -19,9 +19,9 @@ #ifndef __PMT_DEPRECATED_H #define __PMT_DEPRECATED_H -#include +#include -__BEGIN_DECLS +PMT_EXTERN_C_BEGIN #define deprecated_opt 1 #define changed_opt 2 @@ -41,6 +41,8 @@ __BEGIN_DECLS #define v230 "2.3.0" #define v240 "2.4.0" #define v250 "2.5.0" +#define v260 "2.6.0" +#define v270 "2.7.0" #define vUNK NULL 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) -__END_DECLS +PMT_EXTERN_C_END #endif diff --git a/include/pmt/ExternC.h b/include/pmt/ExternC.h new file mode 100755 index 0000000..7a84cea --- /dev/null +++ b/include/pmt/ExternC.h @@ -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 diff --git a/include/pmt/help_msgs.h b/include/pmt/HelpMessages.h similarity index 91% rename from include/pmt/help_msgs.h rename to include/pmt/HelpMessages.h index 0052f2a..15ece81 100755 --- a/include/pmt/help_msgs.h +++ b/include/pmt/HelpMessages.h @@ -19,11 +19,13 @@ #ifndef __PMT_HELP_MSGS_H #define __PMT_HELP_MSGS_H -__BEGIN_DECLS +#include + +PMT_EXTERN_C_BEGIN void help(void); -__END_DECLS +PMT_EXTERN_C_END #endif diff --git a/include/pmt/pmt.h b/include/pmt/PartitionManager.h similarity index 96% rename from include/pmt/pmt.h rename to include/pmt/PartitionManager.h index de28b49..f446193 100755 --- a/include/pmt/pmt.h +++ b/include/pmt/PartitionManager.h @@ -20,15 +20,13 @@ #error "Your compiler is NOT clang. Please build with LLVM clang." #endif -#include +#include -__BEGIN_DECLS +PMT_EXTERN_C_BEGIN #ifndef __PMT_H_ #define __PMT_H_ -#define PMT_PACKAGE_NAME "Partition Manager" - #ifdef INC_MAIN_LIBS #include #include @@ -118,6 +116,6 @@ void debug(LogLevel status, const char* _Nullable fmt, ...); #endif -__END_DECLS +PMT_EXTERN_C_END /* end of code */ diff --git a/include/pmt/stringkeys.h b/include/pmt/StringKeys.h similarity index 98% rename from include/pmt/stringkeys.h rename to include/pmt/StringKeys.h index e9d3de5..2885855 100755 --- a/include/pmt/stringkeys.h +++ b/include/pmt/StringKeys.h @@ -19,7 +19,9 @@ #ifndef __PMT_STRINGKEYS_ #define __PMT_STRINGKEYS_ -__BEGIN_DECLS +#include + +PMT_EXTERN_C_BEGIN /* The struct is a very good option for setting the languages of texts etc. */ struct pmt_langdb_general { @@ -112,7 +114,7 @@ struct pmt_langdb_langs { const char* _Nullable lang_pr; }; -__END_DECLS +PMT_EXTERN_C_END #endif /* __PMT_STRINGKEYS_ */ diff --git a/include/pmt/versioning.h b/include/pmt/VersionVars.h similarity index 90% rename from include/pmt/versioning.h rename to include/pmt/VersionVars.h index 8039d7c..83ec907 100755 --- a/include/pmt/versioning.h +++ b/include/pmt/VersionVars.h @@ -19,7 +19,9 @@ #ifndef __PMT_VERSIONING_H #define __PMT_VERSIONING_H -__BEGIN_DECLS +#include + +PMT_EXTERN_C_BEGIN #ifdef __NDK_BUILD #include @@ -28,10 +30,10 @@ __BEGIN_DECLS /* versioning */ #define PMT_MAJOR 2 -#define PMT_MINOR 6 +#define PMT_MINOR 7 #define PMT_PATCHLEVEL 0 -__END_DECLS +PMT_EXTERN_C_END #endif diff --git a/jni/Makefile b/jni/Makefile index 9b3f8bc..ac2a39c 100755 --- a/jni/Makefile +++ b/jni/Makefile @@ -31,7 +31,7 @@ PMT_INCDIR := $(INCLUDE_DIR)/pmt # the presence of all source files that are on this list will be checked SRCS_REQ := \ - place-holder/debugging.c \ + place-holder/debug.c \ place-holder/help.c \ place-holder/get_stat.c \ place-holder/lang_tools.c \ @@ -40,34 +40,38 @@ SRCS_REQ := \ place-holder/pmt.c \ place-holder/root.c \ place-holder/tools.c \ - place-holder/versioning.c + place-holder/version.c # objects to be used when executable file is created OBJS_EXEC := \ $(SOURCE_DIR)/$(TARGET).o \ $(SOURCE_DIR)/help.o \ - $(SOURCE_DIR)/versioning.o \ + $(SOURCE_DIR)/version.o \ $(SOURCE_DIR)/get_stat.o \ $(SOURCE_DIR)/tools.o \ $(SOURCE_DIR)/lang_tools.o \ $(SOURCE_DIR)/languages.o HEADERS_REQ := \ - $(PMT_INCDIR)/pmt/deprecates.h \ - $(PMT_INCDIR)/pmt/help_msgs.h \ - $(PMT_INCDIR)/pmt/pmt.h \ - $(PMT_INCDIR)/pmt/stringkeys.h \ - $(PMT_INCDIR)/pmt/versioning.h + $(PMT_INCDIR)/pmt/ExternC.h \ + $(PMT_INCDIR)/pmt/Deprecates.h \ + $(PMT_INCDIR)/pmt/HelpMessages.h \ + $(PMT_INCDIR)/pmt/PartitionManager.h \ + $(PMT_INCDIR)/pmt/StringKeys.h \ + $(PMT_INCDIR)/pmt/VersionVars.h PROGRESS_LIST := \ welcome \ + wait \ $(SRCS_REQ) \ $(HEADERS_REQ) \ pr_obj \ $(OBJS) \ make_outdirs \ + pr_sts \ $(STATIC_LIBS) \ make_executable \ + wait \ end_progress define check_hf @@ -88,17 +92,22 @@ welcome: && $(E_NS) $(E) " -------------------------------- " \ && $(E_NS) - @ if [ -f $(SOURCE_DIR)/debugging.o ]; then \ + @ if [ -f $(SOURCE_DIR)/debug.o ]; then \ $(E_NS) " - Please clean up before you build it." && echo; \ $(E_NS) " ----------------------------------- "; \ exit 1; \ fi $(E) " - Checking required source files..." - @ sleep 1 pr_obj: $(E) " - Building objects..." +pr_sts: + $(E) " - Making static libraries..." + +wait: + @ sleep 2 + make_outdirs: @ rm -rf $(IN_OUT_DIR) @ mkdir $(BINARY_DIR) @@ -122,31 +131,15 @@ $(PMT_INCDIR)/%.h: $(SOURCE_DIR)/%.o: $(SOURCE_DIR)/%.c $(E) " CC $(SOURCE_DIRNAME)/`basename $@`" @ $(CC) $(CFLAGS) -c "$<" || exit 1 - $(eval GEN_OBJS_MSG = ) -lib$(TARGET)_root.a: - $(E) " - Making static libraries..." - $(E) " AR $@" - @ $(AR) rcs "$@" "$(SOURCE_DIR)/root.o" || exit 1 - -lib$(TARGET)_debugging.a: - $(E) " AR $@" - @ $(AR) rcs "$@" "$(SOURCE_DIR)/debugging.o" - -lib$(TARGET)_listpart.a: - $(E) " AR $@" - @ $(AR) rcs "$@" "$(SOURCE_DIR)/listpart.o" - -lib$(TARGET)_partitiontool.a: - $(E) " AR $@" - @ $(AR) rcs "$@" "$(SOURCE_DIR)/partitiontool.o" - @ sleep 1 +$(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) -l$(TARGET)_root -l$(TARGET)_debugging -l$(TARGET)_listpart -l$(TARGET)_partitiontool -o $(TARGET) $(OBJS_EXEC) || exit 1 - @ sleep 1 + @ $(CC) $(CFLAGS) -L$(SOURCE_DIR) $(foreach st,$(STATIC_LIBS),$(shell echo -n -l$(st) )) -o $(TARGET) $(OBJS_EXEC) || exit 1 end_progress: @ abort_build() { \ diff --git a/jni/debugging.c b/jni/debug.c similarity index 96% rename from jni/debugging.c rename to jni/debug.c index fab4269..559d673 100755 --- a/jni/debugging.c +++ b/jni/debug.c @@ -22,8 +22,8 @@ extern "C" { #define INC_MAIN_LIBS -#include -#include +#include +#include void debug(LogLevel status, const char* _Nullable fmt, ...) { diff --git a/jni/get_stat.c b/jni/get_stat.c index 3d23815..981981e 100755 --- a/jni/get_stat.c +++ b/jni/get_stat.c @@ -23,8 +23,8 @@ extern "C" { #define INC_MAIN_LIBS #define INC_STAT -#include -#include +#include +#include /** * The target file is controlled by the stat function. diff --git a/jni/help.c b/jni/help.c index 0d99997..ac0a132 100755 --- a/jni/help.c +++ b/jni/help.c @@ -23,9 +23,9 @@ extern "C" { #define INC_MAIN_LIBS #define HELP -#include -#include -#include +#include +#include +#include extern char* bin_name; extern char* curr_lang; diff --git a/jni/lang_tools.c b/jni/lang_tools.c index a8c3a0c..d29af98 100755 --- a/jni/lang_tools.c +++ b/jni/lang_tools.c @@ -24,8 +24,8 @@ extern "C" { #define INC_DEBUGERS #define INC_STAT -#include -#include +#include +#include /* pmt's man doc file path on termux */ #define TERMUX_PMT_MANDOC "/data/data/com.termux/files/usr/share/man/man8/pmt.8.gz" diff --git a/jni/languages.c b/jni/languages.c index f785f76..9ab5040 100755 --- a/jni/languages.c +++ b/jni/languages.c @@ -22,8 +22,8 @@ extern "C" { #define INC_MAIN_LIBS -#include -#include +#include +#include struct pmt_langdb_general en = { .lang_by_s = "YZBruh & r0manas", diff --git a/jni/listpart.c b/jni/listpart.c index 4c38ff8..4718544 100755 --- a/jni/listpart.c +++ b/jni/listpart.c @@ -24,7 +24,7 @@ extern "C" { #define INC_DEBUGERS #define INC_DIRENT -#include +#include #include /* current /dev context */ diff --git a/jni/partitiontool.c b/jni/partitiontool.c index 0df2d47..80da622 100755 --- a/jni/partitiontool.c +++ b/jni/partitiontool.c @@ -22,7 +22,7 @@ extern "C" { #define INC_MAIN_LIBS -#include +#include static int accf(const char* _Nonnull target) { return access(target, F_OK); } diff --git a/jni/pmt.c b/jni/pmt.c index 943b896..5e75a97 100755 --- a/jni/pmt.c +++ b/jni/pmt.c @@ -26,10 +26,10 @@ extern "C" { #define INC_STAT #define INC_GETOPT -#include -#include -#include -#include +#include +#include +#include +#include #define opt_symbol "-" @@ -55,21 +55,6 @@ bool pmt_inst_on_termux = false; /* variable for use in control of '-' expression */ 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 * the beginning of the given word @@ -94,10 +79,32 @@ ctrl_arg(const char* _Nullable argv_holder) } /* classic main function (C binary here xd) */ -int main(int argc, char* argv[]) +int main(int argc, char** argv) { 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 */ if (loadlang() != 0) { @@ -117,7 +124,7 @@ int main(int argc, char* argv[]) /* check argument total */ 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 */ struct option option_table[] = { @@ -148,27 +155,27 @@ int main(int argc, char* argv[]) static int search_result = 3; static int opt; - if (strcmp(argv[1], "backup") == 0) + if (strcmp(args[1], "backup") == 0) { if (argc <= 2) LOGE("%s 0.\n", current->expected_backup_arg); - if (ctrl_arg(argv[2])) - target_partition = argv[2]; + if (ctrl_arg(args[2])) + target_partition = args[2]; else LOGE("%s.\n", current->not_spec_opt); out = target_partition; - if (argc > 3 && ctrl_arg(argv[3])) - out = argv[3]; + if (argc > 3 && ctrl_arg(args[3])) + out = args[3]; check_optsym(target_partition); check_optsym(out); pmt_backup = true; } - else if (strcmp(argv[1], "flash") == 0) + else if (strcmp(args[1], "flash") == 0) { if (argc <= 2) LOGE("%s 0.\n", current->expected_flash_arg); @@ -176,13 +183,13 @@ int main(int argc, char* argv[]) if (argc <= 3) LOGE("%s 1.\n", current->expected_flash_arg); - if (ctrl_arg(argv[2])) - target_partition = argv[2]; + if (ctrl_arg(args[2])) + target_partition = args[2]; else LOGE("%s.\n", current->not_spec_opt); - if (ctrl_arg(argv[3])) - target_flash_file = argv[3]; + if (ctrl_arg(args[3])) + target_flash_file = args[3]; else LOGE("%s.\n", current->not_spec_opt); @@ -191,7 +198,7 @@ int main(int argc, char* argv[]) pmt_flash = true; } - else if (strcmp(argv[1], "format") == 0) + else if (strcmp(args[1], "format") == 0) { if (argc <= 2) @@ -200,13 +207,13 @@ int main(int argc, char* argv[]) if (argc <= 3) LOGE("%s 1.\n", current->expected_format_arg); - if (ctrl_arg(argv[2])) - target_partition = argv[2]; + if (ctrl_arg(args[2])) + target_partition = args[2]; else LOGE("%s.\n", current->not_spec_opt); - if (ctrl_arg(argv[3])) - format_fs = argv[3]; + if (ctrl_arg(args[3])) + format_fs = args[3]; else LOGE("%s.\n", current->not_spec_opt); @@ -217,7 +224,7 @@ int main(int argc, char* argv[]) } /* 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 */ switch (opt) @@ -286,11 +293,11 @@ int main(int argc, char* argv[]) break; /* for invalid options */ 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; break; 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; } } @@ -318,15 +325,15 @@ int main(int argc, char* argv[]) if (pmt_setlang) { - LOGD("%s: %s\n", argv[0], current->switching_lang); + LOGD("%s: %s\n", args[0], current->switching_lang); setlang(langpr, 0); sleep(2); - LOGD("%s: %s.\n", argv[0], current->please_rerun); + LOGD("%s: %s.\n", args[0], current->please_rerun); return 0; } 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) { @@ -373,7 +380,7 @@ int main(int argc, char* argv[]) if (target_partition == NULL) { 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 { diff --git a/jni/root.c b/jni/root.c index 8f9edb7..4721d4f 100755 --- a/jni/root.c +++ b/jni/root.c @@ -23,8 +23,8 @@ extern "C" { #define INC_MAIN_LIBS #define INC_DEBUGERS -#include -#include +#include +#include /* root checker function */ void check_root(void) diff --git a/jni/tools.c b/jni/tools.c index 893b286..c566d00 100755 --- a/jni/tools.c +++ b/jni/tools.c @@ -26,8 +26,8 @@ extern "C" { #define INC_DEBUGERS #define INC_TOOLS_REQS -#include -#include +#include +#include #define count (1024 * 1024 * 1024) diff --git a/jni/versioning.c b/jni/version.c similarity index 93% rename from jni/versioning.c rename to jni/version.c index 7d58eb9..1de72ff 100755 --- a/jni/versioning.c +++ b/jni/version.c @@ -23,9 +23,9 @@ extern "C" { #define INC_MAIN_LIBS #define VERSIONING -#include -#include -#include +#include +#include +#include void version(void) {