pmt: improve build system

This commit is contained in:
2024-03-11 22:34:21 +03:00
committed by GitHub
parent c82a127e43
commit c8c0687519

View File

@@ -2,7 +2,7 @@ include mka/config.mk
# By YZBruh # By YZBruh
# Copyright 2024 YZBruh - Partition Backupper # Copyright 2024 YZBruh - Partition Manager
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
@@ -21,7 +21,9 @@ VERSION := 1.5.0
VERSION_CODE := 150 VERSION_CODE := 150
SOURCE_DIR := binary SOURCE_DIR := binary
TARGET := pmt TARGET := pmt
LANG := en
ARCH := $(shell uname -m) ARCH := $(shell uname -m)
CUR_DIR := $(shell pwd)
# code list # code list
SRCS := $(SOURCE_DIR)/$(TARGET).c SRCS := $(SOURCE_DIR)/$(TARGET).c
@@ -38,12 +40,12 @@ OBJS += $(SOURCE_DIR)/lister.o
OBJS += $(SOURCE_DIR)/flash.o OBJS += $(SOURCE_DIR)/flash.o
OBJS += $(SOURCE_DIR)/backup.o OBJS += $(SOURCE_DIR)/backup.o
# gcc flags OUT_DIR := $(CUR_DIR)/out
LDFLAGS := BINARY_DIR := $(OUT_DIR)/binary
LDLIBS := -lm PACKAGE_DIR := $(OUT_DIR)/package
# display # display
all: all:
@printf " --- Building Partition Manager --- \n"; \ @printf " --- Building Partition Manager --- \n"; \
printf "Version: $(VERSION)\n"; \ printf "Version: $(VERSION)\n"; \
printf "Version code: $(VERSION_CODE)\n"; \ printf "Version code: $(VERSION_CODE)\n"; \
@@ -58,15 +60,15 @@ all:
# build progress # build progress
.PHONY: $(TARGET) .PHONY: $(TARGET)
$(TARGET): $(OBJS) $(TARGET): $(OBJS)
$(LD) -o $@ $(LDFLAGS) $(OBJS) $(LIBS) $(CC) $(CFLAGS) -o $@ $(OBJS)
@mkdir -p out; \ @mkdir -p $(OUT_DIR); \
mkdir -p out/binary; \ mkdir -p $(BINARY_DIR); \
mkdir -p out/package; \ mkdir -p $(PACKAGE_DIR); \
mv pmt out/binary; \ mv pmt $(BINARY_DIR); \
printf "Generating gzip package...\n"; \ printf "Generating gzip package...\n"; \
cp out/binary/pmt out/package; \ cp $(BINARY_DIR)/pmt $(PACKAGE_DIR); \
gzip -f out/package/pmt; \ gzip -f $(PACKAGE_DIR)/pmt; \
mv out/package/pmt.gz out/package/pmt-$(ARCH)-en.gz; \ mv $(PACKAGE_DIR)/pmt.gz $(PACKAGE_DIR)/pmt-$(ARCH)-$(LANG).gz; \
printf " \n"; \ printf " \n"; \
printf " ------------------------------------- \n"; printf " ------------------------------------- \n";
@@ -82,7 +84,7 @@ clean:
clean-all: clean-all:
@printf "Cleaning (builded files [.o extended] and binary)...\n"; \ @printf "Cleaning (builded files [.o extended] and binary)...\n"; \
sleep 2; \ sleep 2; \
rm -rf $(OBJS) out; \ rm -rf $(OBJS) $(OUT_DIR); \
printf "Success\n"; printf "Success\n";
# helper function # helper function
@@ -91,7 +93,7 @@ help:
@printf " --------- Partition Manager help ---------\n"; \ @printf " --------- Partition Manager help ---------\n"; \
printf " \n"; \ printf " \n"; \
printf " Commands;\n"; \ printf " Commands;\n"; \
printf " make ==> Build Partition Backupper\n"; \ printf " make ==> Build Partition Manager\n"; \
printf " make clean ==> Clear files (Builded binaries are not deleted)\n"; \ printf " make clean ==> Clear files (Builded binaries are not deleted)\n"; \
printf " make clean-all ==> Clear files (Builded binaries are deleted)\n"; \ printf " make clean-all ==> Clear files (Builded binaries are deleted)\n"; \
printf " make install-termux ==> If you are using termux, it installs the compiled pmt into termux. So it allows you to use it like a normal command.\n"; \ printf " make install-termux ==> If you are using termux, it installs the compiled pmt into termux. So it allows you to use it like a normal command.\n"; \
@@ -100,22 +102,12 @@ help:
.PHONY: install-termux .PHONY: install-termux
install-termux: install-termux:
@arch=$$(uname -m); \ @if [ -f /data/data/com.termux/files/usr/bin/termux-open ]; then \
if [ "$$arch" = "aarch64" ]; then \
printf " ------------------------------------- \n"; \ printf " ------------------------------------- \n"; \
printf " pmt installer \n"; \ printf " pmt installer \n"; \
printf " ------------------------------------- \n"; \ printf " ------------------------------------- \n"; \
cp out/binary/pmt /data/data/com.termux/files/usr/bin/pmt; \ cp $(BINARY_DIR)/pmt /data/data/com.termux/files/usr/bin/pmt || exit 1; \
chmod 777 /data/data/com.termux/files/usr/bin/pmt; \ chmod 777 /data/data/com.termux/files/usr/bin/pmt || exit 1; \
printf " \n"; \
printf "Success.\n"; \
printf " \n"; \
elif [ "$$arch" = "armv7l" ]; then \
printf " ------------------------------------- \n"; \
printf " pmt installer \n"; \
printf " ------------------------------------- \n"; \
cp out/binary/pmt /data/data/com.termux/files/usr/bin/pmt; \
chmod 777 /data/data/com.termux/files/usr/bin/pmt; \
printf " \n"; \ printf " \n"; \
printf "Success.\n"; \ printf "Success.\n"; \
printf " \n"; \ printf " \n"; \