Refactor build flags

This commit is contained in:
topjohnwu 2019-02-12 05:17:02 -05:00
parent b3fd79cbb9
commit ed027ec3ee
12 changed files with 27 additions and 24 deletions

View File

@ -191,7 +191,7 @@ def build_binary(args):
os.utime(os.path.join('native', 'jni', 'include', 'flags.h')) os.utime(os.path.join('native', 'jni', 'include', 'flags.h'))
# Basic flags # Basic flags
base_flags = f'MAGISK_VERSION="{config["version"]}" MAGISK_VER_CODE={config["versionCode"]}' base_flags = f'MAGISK_VERSION={config["version"]} MAGISK_VER_CODE={config["versionCode"]}'
if not args.release: if not args.release:
base_flags += ' MAGISK_DEBUG=1' base_flags += ' MAGISK_DEBUG=1'

View File

@ -12,7 +12,8 @@ android {
externalNativeBuild { externalNativeBuild {
ndkBuild { ndkBuild {
// Pass arguments to ndk-build. // Pass arguments to ndk-build.
arguments('B_MAGISK=1', 'B_INIT=1', 'B_BOOT=1', 'B_BXZ=1', 'MAGISK_DEBUG=1') arguments('B_MAGISK=1', 'B_INIT=1', 'B_BOOT=1',
'MAGISK_DEBUG=1', 'MAGISK_VERSION=debug', 'MAGISK_VER_CODE=INT_MAX')
} }
} }
} }

View File

@ -1,12 +1,12 @@
APP_ABI := armeabi-v7a x86 APP_ABI := armeabi-v7a x86
APP_CFLAGS := -Oz -std=gnu11 \ APP_CFLAGS := -Oz -std=gnu11 \
-DMAGISK_VERSION="${MAGISK_VERSION}" -DMAGISK_VER_CODE=${MAGISK_VER_CODE} -D__MVSTR=${MAGISK_VERSION} -D__MCODE=${MAGISK_VER_CODE}
APP_CPPFLAGS := -std=c++17 APP_CPPFLAGS := -std=c++17
APP_STL := c++_static APP_STL := c++_static
APP_PLATFORM := android-16 APP_PLATFORM := android-16
ifdef MAGISK_DEBUG ifdef MAGISK_DEBUG
APP_CFLAGS += -DMAGISK_DEBUG APP_CFLAGS += -D__MDBG
endif endif
# Busybox require some additional settings # Busybox require some additional settings

View File

@ -70,7 +70,7 @@ static void *request_handler(void *args) {
su_daemon_handler(client, &credential); su_daemon_handler(client, &credential);
break; break;
case CHECK_VERSION: case CHECK_VERSION:
write_string(client, xstr(MAGISK_VERSION) ":MAGISK"); write_string(client, MAGISK_VERSION ":MAGISK");
close(client); close(client);
break; break;
case CHECK_VERSION_CODE: case CHECK_VERSION_CODE:
@ -109,7 +109,7 @@ static void main_daemon() {
xdup2(fd, STDIN_FILENO); xdup2(fd, STDIN_FILENO);
close(fd); close(fd);
LOGI("Magisk v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") daemon started\n"); LOGI(SHOW_VER(Magisk) " daemon started\n");
// Get server stat // Get server stat
stat("/proc/self/exe", &SERVER_STAT); stat("/proc/self/exe", &SERVER_STAT);

View File

@ -13,7 +13,7 @@
[[noreturn]] static void usage() { [[noreturn]] static void usage() {
fprintf(stderr, fprintf(stderr,
"Magisk v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") (by topjohnwu) multi-call binary\n" FULL_VER(Magisk) " multi-call binary\n"
"\n" "\n"
"Usage: magisk [applet [arguments]...]\n" "Usage: magisk [applet [arguments]...]\n"
" or: magisk [options]...\n" " or: magisk [options]...\n"
@ -48,7 +48,7 @@ int magisk_main(int argc, char *argv[]) {
if (argc < 2) if (argc < 2)
usage(); usage();
if (strcmp(argv[1], "-c") == 0) { if (strcmp(argv[1], "-c") == 0) {
printf("%s (%d)\n", xstr(MAGISK_VERSION) ":MAGISK", MAGISK_VER_CODE); printf(MAGISK_VERSION ":MAGISK (" str(MAGISK_VER_CODE) ")\n");
return 0; return 0;
} else if (strcmp(argv[1], "-v") == 0) { } else if (strcmp(argv[1], "-v") == 0) {
int fd = connect_daemon(); int fd = connect_daemon();

View File

@ -1,15 +1,20 @@
#pragma once #pragma once
/* Include this header anywhere you access MAGISK_DEBUG, MAGISK_VERSION, MAGISK_VER_CODE. /* Include this header anywhere accessing MAGISK_DEBUG, MAGISK_VERSION, MAGISK_VER_CODE.
* *
* This file is only for more precise incremental builds. We can make sure code that uses * This file is for precise incremental builds. We can make sure code that uses
* external flags are re-compiled by updating the timestamp of this file * external flags are re-compiled by updating the timestamp of this file
* */ * */
#ifndef MAGISK_VERSION #define quote(s) #s
#define MAGISK_VERSION 99.99 #define str(s) quote(s)
#endif
#ifndef MAGISK_VER_CODE #define MAGISK_VERSION str(__MVSTR)
#define MAGISK_VER_CODE 99999 #define MAGISK_VER_CODE __MCODE
#define SHOW_VER(name) str(name) " v" MAGISK_VERSION "(" str(MAGISK_VER_CODE) ")"
#define FULL_VER(name) SHOW_VER(name) " (by topjohnwu)"
#ifdef __MDBG
#define MAGISK_DEBUG
#endif #endif

View File

@ -107,7 +107,7 @@ static void usage(char *arg0) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
cmdline_logging(); cmdline_logging();
fprintf(stderr, "MagiskBoot v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") (by topjohnwu) - Boot Image Modification Tool\n"); fprintf(stderr, FULL_VER(MagiskBoot) " - Boot Image Modification Tool\n");
umask(0); umask(0);
if (argc > 1 && strcmp(argv[1], "--cleanup") == 0) { if (argc > 1 && strcmp(argv[1], "--cleanup") == 0) {

View File

@ -17,7 +17,7 @@ bool hide_enabled = false;
[[noreturn]] static void usage(char *arg0) { [[noreturn]] static void usage(char *arg0) {
fprintf(stderr, fprintf(stderr,
"MagiskHide v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") (by topjohnwu)\n\n" FULL_VER(MagiskHide) "\n\n"
"Usage: %s [--option [arguments...] ]\n\n" "Usage: %s [--option [arguments...] ]\n\n"
"Options:\n" "Options:\n"
" --status Return the status of MagiskHide\n" " --status Return the status of MagiskHide\n"

View File

@ -86,7 +86,7 @@ static const char *type_msg_6 =
[[noreturn]] static void usage(char *arg0) { [[noreturn]] static void usage(char *arg0) {
fprintf(stderr, fprintf(stderr,
"MagiskPolicy v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") (by topjohnwu)\n\n" FULL_VER(MagiskPolicy) "\n\n"
"Usage: %s [--options...] [policy statements...]\n" "Usage: %s [--options...] [policy statements...]\n"
"\n" "\n"
"Options:\n" "Options:\n"

View File

@ -55,7 +55,7 @@ illegal:
[[noreturn]] static void usage(char* arg0) { [[noreturn]] static void usage(char* arg0) {
fprintf(stderr, fprintf(stderr,
"resetprop v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") (by topjohnwu & nkk71) - System Props Modification Tool\n\n" FULL_VER(resetprop) " - System Props Modification Tool\n\n"
"Usage: %s [flags] [options...]\n" "Usage: %s [flags] [options...]\n"
"\n" "\n"
"Options:\n" "Options:\n"

View File

@ -35,7 +35,7 @@ static void usage(int status) {
FILE *stream = (status == EXIT_SUCCESS) ? stdout : stderr; FILE *stream = (status == EXIT_SUCCESS) ? stdout : stderr;
fprintf(stream, fprintf(stream,
"MagiskSU v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ")\n\n" FULL_VER(MagiskSU) "\n\n"
"Usage: su [options] [-] [user [argument...]]\n\n" "Usage: su [options] [-] [user [argument...]]\n\n"
"Options:\n" "Options:\n"
" -c, --command COMMAND pass COMMAND to the invoked shell\n" " -c, --command COMMAND pass COMMAND to the invoked shell\n"
@ -151,7 +151,7 @@ int su_client_main(int argc, char *argv[]) {
printf("%d\n", MAGISK_VER_CODE); printf("%d\n", MAGISK_VER_CODE);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 'v': case 'v':
printf("%s\n", xstr(MAGISK_VERSION) ":MAGISKSU (topjohnwu)"); printf("%s\n", MAGISK_VERSION ":MAGISKSU");
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 'z': case 'z':
// Do nothing, placed here for legacy support :) // Do nothing, placed here for legacy support :)

View File

@ -11,9 +11,6 @@
extern "C" { extern "C" {
#endif #endif
#define str(a) #a
#define xstr(a) str(a)
typedef enum { typedef enum {
L_DEBUG, L_DEBUG,
L_INFO, L_INFO,