From 184d45b73d642dde84bc9f02eb7a0fc4d81a2137 Mon Sep 17 00:00:00 2001 From: ignaciogarcia Date: Mon, 31 Oct 2022 09:33:25 +0100 Subject: [PATCH] PEMA-107 Add Makefile help and colors Ignore errors in non-essential recipes. --- android/external/Makefile | 53 ++++++++++++++------ android/external/Makefile.conf | 12 ++++- android/external/MakefileTemplate | 77 ++++++++++++++++++----------- android/external/createMakefile.sh | 1 - android/external/downloads/Makefile | 21 +++++--- android/external/help.mk | 27 ++++++++++ 6 files changed, 139 insertions(+), 52 deletions(-) create mode 100644 android/external/help.mk diff --git a/android/external/Makefile b/android/external/Makefile index ba6a46c..aeb84ec 100644 --- a/android/external/Makefile +++ b/android/external/Makefile @@ -21,75 +21,100 @@ endif .PHONY: all build clean clean-all build-arm build-arm64 build-x86 build-x86_64 showAllSetups \ showx86Setup showx86_64Setup showArmSetup showArm64Setup createMakefiles cleanMakefiles \ - refreshMakefiles + refreshMakefiles help +## Build dependencies for the archs passed. Example: make build archs=x86 arm64. If no archs passed, build for all 4 archs. build: $(if $(archs),$(foreach wrd, $(archs), build-$(wrd)), all) +## Build dependencies for all 4 archs all: build-arm build-arm64 build-x86 build-x86_64 +## Call armeabi-v7a Makefile (build dependencies for arm arch) build-arm: armeabi-v7a/Makefile downloads/downloads.stamp $(MAKE) -C armeabi-v7a +## Create Makefile for arm (armeabi-v7a) arch armeabi-v7a/Makefile: sh createMakefile.sh armeabi-v7a +## Call arm64-v8a Makefile (build dependencies for arm64 arch) build-arm64: arm64-v8a/Makefile downloads/downloads.stamp $(MAKE) -C arm64-v8a +## Create Makefile for arm64 (arm64-v8a) arch arm64-v8a/Makefile: sh createMakefile.sh arm64-v8a +## Call x86 Makefile (build dependencies for x86 arch) build-x86: x86/Makefile downloads/downloads.stamp $(MAKE) -C x86 +## Create Makefile for x86 arch x86/Makefile: sh createMakefile.sh x86 +## Call x86_64 Makefile (build dependencies for x86_64 arch) build-x86_64: x86_64/Makefile downloads/downloads.stamp $(MAKE) -C x86_64 +## Create Makefile for x86_64 arch x86_64/Makefile: sh createMakefile.sh x86_64 +## Clean generated artifacts for all archs clean: -$(MAKE) -C armeabi-v7a clean -$(MAKE) -C arm64-v8a clean -$(MAKE) -C x86 clean -$(MAKE) -C x86_64 clean +## Clean generated artifacts for all archs and remove downloaded files clean-all: clean $(MAKE) -C downloads clean - rm -rf build - rm -rf arm64-v8a - rm -rf armeabi-v7a - rm -rf x86 - rm -rf x86_64 + -rm -rf build + -rm -rf arm64-v8a + -rm -rf armeabi-v7a + -rm -rf x86 + -rm -rf x86_64 +## Download dependency files downloads/downloads.stamp: $(MAKE) -C downloads assets: +## Show setup values for all Makefiles (Needs for Makefiles to be already created first) showAllSetups: showx86Setup showx86_64Setup showArmSetup showArm64Setup +## Show setup values for x86 Makefile showx86Setup: - $(MAKE) -C x86 showsetup + -$(MAKE) -C x86 showsetup +## Show setup values for x86_64 Makefile showx86_64Setup: - $(MAKE) -C x86_64 showsetup + -$(MAKE) -C x86_64 showsetup +## Show setup values for arm (armeabi-v7a) Makefile showArmSetup: - $(MAKE) -C armeabi-v7a showsetup + -$(MAKE) -C armeabi-v7a showsetup +## Show setup values for arm64 (arm64-v8a) Makefile showArm64Setup: - $(MAKE) -C arm64-v8a showsetup + -$(MAKE) -C arm64-v8a showsetup +## Create all arch Makefiles createMakefiles: armeabi-v7a/Makefile arm64-v8a/Makefile x86/Makefile x86_64/Makefile +## Delete all arch Makefiles cleanMakefiles: - rm armeabi-v7a/Makefile - rm arm64-v8a/Makefile - rm x86/Makefile - rm x86_64/Makefile + -rm armeabi-v7a/Makefile + -rm arm64-v8a/Makefile + -rm x86/Makefile + -rm x86_64/Makefile +## Refresh all arch Makefiles (delete and re-create all arch Makefiles) refreshMakefiles: cleanMakefiles createMakefiles + +include help.mk +helpHeader='pEpJNIAdapter/android/external Makefile' +helpPurpose='Cross-compile external dependencies of pEpEngine for the 4 Android archs \(x86, x86_64, arm, arm64\)' diff --git a/android/external/Makefile.conf b/android/external/Makefile.conf index f9102f8..3b684a3 100644 --- a/android/external/Makefile.conf +++ b/android/external/Makefile.conf @@ -1,4 +1,14 @@ -# TODO: Tiddy up +# TODO: Tiddy up +# COLORS +BOLD := $(shell tput bold) +RED := $(shell tput -Txterm setaf 1) +GREEN := $(shell tput -Txterm setaf 2) +YELLOW := $(shell tput -Txterm setaf 3) +CYAN := $(shell tput -Txterm setaf 6) +PURPLE := $(shell tput -Txterm setaf 5) +WHITE := $(shell tput -Txterm setaf 7) +RESET := $(shell tput -Txterm sgr0) + ### Android NDK Common conf NDK_TOOLCHAIN_COMPILER ?= clang diff --git a/android/external/MakefileTemplate b/android/external/MakefileTemplate index eb5bb49..38598d9 100644 --- a/android/external/MakefileTemplate +++ b/android/external/MakefileTemplate @@ -23,8 +23,10 @@ include ../PerArchMakefile.conf #------------------------------------------------------------------------------# +## Same as build all: build +## Build dependencies for arch [ARCH] build: showsetup uuid-prebuild sequoia-ffi-install libetpan-build #------------------------------------------------------------------------------# @@ -48,25 +50,26 @@ export ac_cv_func_malloc_0_nonnull=yes #------------------------------------------------------------------------------# # debugging stuff +## Show setup values for [ARCH] Makefile showsetup: - @echo "============================================== CURRENT SETUP ====================================================" - @echo "NDK_TOOLCHAIN: $(NDK_TOOLCHAIN)" - @echo "NDK_TOOLCHAIN_COMPILER: $(NDK_TOOLCHAIN_COMPILER)" - @echo "NDK_TOOLCHAIN_TARGET: $(NDK_TOOLCHAIN_TARGET)" - @echo "TEMP_WORK_PATH: $(TEMP_WORK_PATH)" - @echo "LOCAL: $(LOCAL)" - @echo "APP_ABI: $(APP_ABI)" - @echo "HOST: $(HOST)" - @echo "SEQUOIA_ARCH: $(SEQUOIA_ARCH)" - @echo "CC: $(CC)" - @echo "LD: $(LD)" - @echo "AR: $(AR)" - @echo "AS: $(AS)" - @echo "STRIP: $(STRIP)" - @echo "RANLIB: $(RANLIB)" - @echo "CFLAGS: $(CFLAGS)" - @echo "LDFLAGS: $(LDFLAGS)" - @echo "============================================== CURRENT SETUP END ====================================================" + @echo "${YELLOW}============================================== CURRENT SETUP ====================================================${RESET}" + @echo "${YELLOW}NDK_TOOLCHAIN: $(NDK_TOOLCHAIN)${RESET}" + @echo "${YELLOW}NDK_TOOLCHAIN_COMPILER: $(NDK_TOOLCHAIN_COMPILER)${RESET}" + @echo "${YELLOW}NDK_TOOLCHAIN_TARGET: $(NDK_TOOLCHAIN_TARGET)${RESET}" + @echo "${YELLOW}TEMP_WORK_PATH: $(TEMP_WORK_PATH)${RESET}" + @echo "${YELLOW}LOCAL: $(LOCAL)${RESET}" + @echo "${YELLOW}APP_ABI: $(APP_ABI)${RESET}" + @echo "${YELLOW}HOST: $(HOST)${RESET}" + @echo "${YELLOW}SEQUOIA_ARCH: $(SEQUOIA_ARCH)${RESET}" + @echo "${YELLOW}CC: $(CC)${RESET}" + @echo "${YELLOW}LD: $(LD)${RESET}" + @echo "${YELLOW}AR: $(AR)${RESET}" + @echo "${YELLOW}AS: $(AS)${RESET}" + @echo "${YELLOW}STRIP: $(STRIP)${RESET}" + @echo "${YELLOW}RANLIB: $(RANLIB)${RESET}" + @echo "${YELLOW}CFLAGS: $(CFLAGS)${RESET}" + @echo "${YELLOW}LDFLAGS: $(LDFLAGS)${RESET}" + @echo "${YELLOW}============================================== CURRENT SETUP END ====================================================${RESET}" #------------------------------------------------------------------------------# # libiconv @@ -94,8 +97,10 @@ $(LOCAL)/lib/libiconv.a: libiconv/lib/.libs/libiconv.a $(MAKE) -C libiconv DESTDIR=$(DESTDIR) prefix=$(prefix) install ls -l $(LOCAL)/lib/libiconv.a +## Build iconv libiconv-build: libiconv/lib/.libs/libiconv.a +## Install iconv libiconv-install: $(LOCAL)/lib/libiconv.a #------------------------------------------------------------------------------# @@ -111,6 +116,7 @@ libetpan/Makefile: libetpan.src.stamp | $(LOCAL)/lib/libiconv.a cp -r libetpan/build-android/libetpan-android-$(ANDROID_ETPAN_BUILD_VERSION)/include/* $(LOCAL)/include/ touch $@ +## Build etpan libetpan-build: libetpan/Makefile #------------------------------------------------------------------------------# @@ -142,6 +148,7 @@ uuid-build: uuid/.libs/libuuid.so $(LOCAL)/include/uuid.h: uuid/Makefile mkdir -p $(LOCAL)/include && cd uuid && cp uuid.h $(LOCAL)/include +## Prebuild uuid uuid-prebuild: uuid/jni/Android.mk $(LOCAL)/include/uuid.h uuid/jni/Android.mk: uuid.src.stamp @@ -152,6 +159,7 @@ uuid/jni/Android.mk: uuid.src.stamp #------------------------------------------------------------------------------# # Sequoia +## Build sequoia dependencies sequoia-deps-build: $(LOCAL)/lib/libssl.so $(LOCAL)/lib/libnettle.so #------------------------------------------------------------------------------# @@ -176,8 +184,10 @@ $(LOCAL)/lib/libssl.so: openssl/libssl.so cp libssl.a $(LOCAL)/lib ls -l $(LOCAL)/lib/libssl.so +## Build openssl openssl-build: openssl/libssl.so +## Install openssl openssl-install: $(LOCAL)/lib/libssl.so @@ -207,8 +217,10 @@ $(LOCAL)/lib/libgmp.so: gmp/.libs/libgmp.so ls -l $(LOCAL)/lib/libgmp.so touch $@ +## Build gmp gmp-build: gmp/.libs/libgmp.so +## Install gmp gmp-install: $(LOCAL)/lib/libgmp.so @@ -239,8 +251,10 @@ $(LOCAL)/lib/libnettle.so: nettle/libnettle.so cp nettle/libnettle.so $(LOCAL)/lib/libnettle.so cp nettle/libhogweed.so $(LOCAL)/lib/libhogweed.so +## Build nettle nettle-build: nettle/libnettle.so +## Install nettle nettle-install: $(LOCAL)/lib/libnettle.so @@ -278,9 +292,10 @@ $(LOCAL)/lib/libsequoia_openpgp_ffi.so: $(CARGO_TARGET_DIR)/$(SEQUOIA_ARCH)/rele cp $(CARGO_TARGET_DIR)/$(SEQUOIA_ARCH)/release/libsequoia_openpgp_ffi.* $(LOCAL)/lib/ cp -r sequoia/openpgp-ffi/include/* $(LOCAL)/include - +## Build sequoia-ffi sequoia-ffi-build: $(CARGO_TARGET_DIR)/$(SEQUOIA_ARCH)/release/libsequoia_openpgp_ffi.so +## Install sequoia-ffi sequoia-ffi-install: $(LOCAL)/lib/libssl.so $(LOCAL)/lib/libnettle.so $(LOCAL)/lib/libsequoia_openpgp_ffi.so #------------------------------------------------------------------------------# @@ -312,20 +327,23 @@ sequoia-ffi-install: $(LOCAL)/lib/libssl.so $(LOCAL)/lib/libnettle.so $(LOCAL)/l #------------------------------------------------------------------------------# # clean %-clean: - rm -rf $* - rm -rf $*.src.stamp + -rm -rf $* + -rm -rf $*.src.stamp clean-assets: - rm -rf $(ASSETS) + -rm -rf $(ASSETS) +## Delete install destination folder clean-install: - rm -rf $(LOCAL) + -rm -rf $(LOCAL) +## Remove generated artifacts clean: $(EXTERNAL_SRCS_CLEAN) clean-assets clean-install libetpan-clean +## Remove generated artifacts and files clean-all: clean - rm -rf *.git - rm -rf *.stamp + -rm -rf *.git + -rm -rf *.stamp #------------------------------------------------------------------------------# .PHONY = clean clean-install clean-assets libetpan-clean \ @@ -336,9 +354,9 @@ clean-all: clean sequoia-deps-build \ openssl-build openssl-install \ nettle-build nettle-install \ - sequoia-ffi-build sequoia-ffi-install\ + sequoia-ffi-build sequoia-ffi-install \ assets \ - $(EXTERNAL_LOCAL_GITS_UPDATE) $(EXTERNAL_SRCS) $(EXTERNAL_SRCS_CLEAN)\ + $(EXTERNAL_LOCAL_GITS_UPDATE) $(EXTERNAL_SRCS) $(EXTERNAL_SRCS_CLEAN) \ showsetup #------------------------------------------------------------------------------# @@ -346,4 +364,7 @@ clean-all: clean .SECONDEXPANSION: # src %-src: %.src.stamp - @echo $< \ No newline at end of file + @echo $< + +include ../help.mk +helpPurpose='Cross-compile external dependencies of pEpEngine for arch [ARCH]' diff --git a/android/external/createMakefile.sh b/android/external/createMakefile.sh index 4bdc8f9..1f8e528 100644 --- a/android/external/createMakefile.sh +++ b/android/external/createMakefile.sh @@ -1,6 +1,5 @@ #!/bin/zsh #emulate -LR bash -#cd ~code/android/pEpJNIAdapter/external ARCH_DEST="$1" mkdir "$ARCH_DEST" diff --git a/android/external/downloads/Makefile b/android/external/downloads/Makefile index cc2bc09..2a2616b 100644 --- a/android/external/downloads/Makefile +++ b/android/external/downloads/Makefile @@ -13,20 +13,26 @@ include ../Makefile.conf #------------------------------------------------------------------------------# # Build parameters +## Download all dependencies all: downloads.stamp downloads.stamp: download-iconv download-uuid download-sequoia-deps download-etpan download-sequoia touch $@ +## Download iconv download-iconv: libiconv-1.15.tar.gz +## Download and patch uuid download-uuid: ossp-uuid_1.6.2.orig-patched.tar.gz +## Download sequoia dependencies download-sequoia-deps: openssl-$(OPENSSL_VERSION).tar.gz gmp-$(GMP_VERSION).tar.bz2 \ nettle-$(NETTLE_VERSION)-patched.tar.gz +## Download etpan download-etpan: libetpan.git.stamp +## Download sequoia download-sequoia: sequoia.git.stamp # Download source and patch it @@ -107,15 +113,14 @@ git_update: $(EXTERNAL_LOCAL_GITS_UPDATE) #------------------------------------------------------------------------------# clean: - rm -rf *.git - rm -rf *.stamp - rm -rf *.tar.gz - rm -rf *.tar.bz2 - rm -rf ../arm64-v8a/ndk-standalone-toolchain - rm -rf ../armeabi-v7a/ndk-standalone-toolchain - rm -rf ../x86/ndk-standalone-toolchain - rm -rf ../x86_64/ndk-standalone-toolchain + -rm -rf *.git + -rm -rf *.stamp + -rm -rf *.tar.gz + -rm -rf *.tar.bz2 .PHONY: all clean download-iconv \ download-uuid download-etpan \ download-sequoia-deps download-sequoia + +include ../help.mk +helpPurpose='Download all files and packages needed to compile external dependencies for pEpEngine' diff --git a/android/external/help.mk b/android/external/help.mk new file mode 100644 index 0000000..472769f --- /dev/null +++ b/android/external/help.mk @@ -0,0 +1,27 @@ +mkfileName = $(firstword $(MAKEFILE_LIST)) +helpHeader = $(notdir $(abspath $(dir $(mkfileName))))/$(mkfileName) + +TARGET_MAX_CHAR_NUM=21 +## Show help +help: + @echo '' + @echo '${BOLD}${CYAN}============= $(helpHeader) =============${RESET}' + @echo '' + @echo '${BOLD}Purpose:${RESET}' + @echo ' $(helpPurpose)' + @echo '' + @echo '${BOLD}Usage:${RESET}' + @echo ' ${YELLOW}make${RESET} ${GREEN}${RESET}' + @echo '' + @echo '${BOLD}Targets:${RESET}' + @awk '/^[a-zA-Z\-\_0-9]+:/ { \ + helpMessage = match(lastLine, /^## (.*)/); \ + if (helpMessage) { \ + helpCommand = substr($$1, 0, index($$1, ":")-1); \ + helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \ + printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \ + } \ + } \ + { lastLine = $$0 }' $(MAKEFILE_LIST) + +.PHONY: help-base