2022-08-17 23:30:22 +08:00
|
|
|
#
|
|
|
|
# UPX top-level Makefile - needs GNU make and CMake >= 3.13
|
|
|
|
#
|
|
|
|
|
2023-01-05 07:57:01 +08:00
|
|
|
# INFO: this Makefile is just a convenience wrapper for calling CMake
|
|
|
|
|
2022-11-23 03:54:12 +08:00
|
|
|
# NOTE: if you only have an older CMake 3.x then you can invoke cmake manually like this:
|
2022-08-17 23:30:22 +08:00
|
|
|
# mkdir -p build/release
|
|
|
|
# cd build/release
|
|
|
|
# cmake ../..
|
2023-01-26 15:50:30 +08:00
|
|
|
# make -j (or use "cmake --build . --parallel")
|
2022-08-17 23:30:22 +08:00
|
|
|
|
|
|
|
CMAKE = cmake
|
|
|
|
UPX_CMAKE_BUILD_FLAGS += --parallel
|
2022-10-20 06:31:02 +08:00
|
|
|
ifneq ($(VERBOSE),)
|
|
|
|
UPX_CMAKE_BUILD_FLAGS += --verbose
|
2023-02-21 22:19:24 +08:00
|
|
|
UPX_CMAKE_CONFIG_FLAGS += -DCMAKE_VERBOSE_MAKEFILE=ON
|
2022-10-20 06:31:02 +08:00
|
|
|
endif
|
2023-01-18 06:43:24 +08:00
|
|
|
# enable this if you prefer Ninja for the actual builds:
|
|
|
|
#UPX_CMAKE_CONFIG_FLAGS += -G Ninja
|
2022-08-17 23:30:22 +08:00
|
|
|
|
|
|
|
#***********************************************************************
|
|
|
|
# default
|
|
|
|
#***********************************************************************
|
|
|
|
|
2023-01-02 02:43:57 +08:00
|
|
|
run_cmake_config = $(CMAKE) -S . -B $1 $(UPX_CMAKE_CONFIG_FLAGS) -DCMAKE_BUILD_TYPE=$2
|
|
|
|
run_cmake_build = $(CMAKE) --build $1 $(UPX_CMAKE_BUILD_FLAGS) --config $2
|
|
|
|
# avoid re-running run_cmake_config if CMakeCache.txt already exists
|
|
|
|
run_config = $(if $(wildcard $1/CMakeCache.txt),,$(call run_cmake_config,$1,$2))
|
|
|
|
run_build = $(call run_cmake_build,$1,$2)
|
2022-08-17 23:30:22 +08:00
|
|
|
|
2022-11-08 10:52:43 +08:00
|
|
|
.DEFAULT_GOAL = build/release
|
2022-08-17 23:30:22 +08:00
|
|
|
|
|
|
|
build/debug: PHONY
|
|
|
|
$(call run_config,$@,Debug)
|
|
|
|
$(call run_build,$@,Debug)
|
|
|
|
|
|
|
|
build/release: PHONY
|
|
|
|
$(call run_config,$@,Release)
|
|
|
|
$(call run_build,$@,Release)
|
|
|
|
|
2022-11-08 10:52:43 +08:00
|
|
|
# shortcuts
|
2023-01-29 18:39:57 +08:00
|
|
|
all: build/debug build/release
|
2022-11-08 10:52:43 +08:00
|
|
|
debug: build/debug
|
|
|
|
release: build/release
|
|
|
|
|
2022-12-20 18:40:48 +08:00
|
|
|
.PHONY: PHONY
|
2023-01-05 07:57:01 +08:00
|
|
|
.NOTPARALLEL: # because the actual builds use "cmake --parallel"
|
2023-01-25 04:52:10 +08:00
|
|
|
.SUFFIXES:
|
2022-12-20 18:40:48 +08:00
|
|
|
|
2023-01-26 15:50:30 +08:00
|
|
|
# END of Makefile; extra stuff follows
|
|
|
|
|
2022-08-17 23:30:22 +08:00
|
|
|
#***********************************************************************
|
2023-01-02 02:43:57 +08:00
|
|
|
# extra builds: some pre-defined build configurations
|
2022-08-17 23:30:22 +08:00
|
|
|
#***********************************************************************
|
|
|
|
|
2022-12-20 18:40:48 +08:00
|
|
|
define run_config_and_build
|
|
|
|
$(call run_config,$1,$2)
|
|
|
|
$(call run_build,$1,$2)
|
|
|
|
endef
|
2022-08-17 23:30:22 +08:00
|
|
|
|
|
|
|
# force building with clang/clang++
|
2023-01-02 02:43:57 +08:00
|
|
|
build/extra/clang/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
|
|
|
build/extra/clang/release: PHONY; $(call run_config_and_build,$@,Release)
|
|
|
|
build/extra/clang/%: export CC = clang
|
|
|
|
build/extra/clang/%: export CXX = clang++
|
2022-08-17 23:30:22 +08:00
|
|
|
|
2022-12-20 18:40:48 +08:00
|
|
|
# force building with clang/clang++ -m32
|
2023-01-02 02:43:57 +08:00
|
|
|
build/extra/clang-m32/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
|
|
|
build/extra/clang-m32/release: PHONY; $(call run_config_and_build,$@,Release)
|
|
|
|
build/extra/clang-m32/%: export CC = clang -m32
|
|
|
|
build/extra/clang-m32/%: export CXX = clang++ -m32
|
2022-12-20 18:40:48 +08:00
|
|
|
|
2023-01-13 12:37:28 +08:00
|
|
|
# force building with clang/clang++ -mx32
|
|
|
|
build/extra/clang-mx32/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
|
|
|
build/extra/clang-mx32/release: PHONY; $(call run_config_and_build,$@,Release)
|
|
|
|
build/extra/clang-mx32/%: export CC = clang -mx32
|
|
|
|
build/extra/clang-mx32/%: export CXX = clang++ -mx32
|
|
|
|
|
2022-12-20 18:40:48 +08:00
|
|
|
# force building with clang/clang++ -m64
|
2023-01-02 02:43:57 +08:00
|
|
|
build/extra/clang-m64/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
|
|
|
build/extra/clang-m64/release: PHONY; $(call run_config_and_build,$@,Release)
|
|
|
|
build/extra/clang-m64/%: export CC = clang -m64
|
|
|
|
build/extra/clang-m64/%: export CXX = clang++ -m64
|
2022-12-20 18:40:48 +08:00
|
|
|
|
|
|
|
# force building with gcc/g++
|
2023-01-02 02:43:57 +08:00
|
|
|
build/extra/gcc/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
|
|
|
build/extra/gcc/release: PHONY; $(call run_config_and_build,$@,Release)
|
|
|
|
build/extra/gcc/%: export CC = gcc
|
|
|
|
build/extra/gcc/%: export CXX = g++
|
2022-12-20 18:40:48 +08:00
|
|
|
|
|
|
|
# force building with gcc/g++ -m32
|
2023-01-02 02:43:57 +08:00
|
|
|
build/extra/gcc-m32/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
|
|
|
build/extra/gcc-m32/release: PHONY; $(call run_config_and_build,$@,Release)
|
|
|
|
build/extra/gcc-m32/%: export CC = gcc -m32
|
|
|
|
build/extra/gcc-m32/%: export CXX = g++ -m32
|
2022-12-20 18:40:48 +08:00
|
|
|
|
2023-01-06 08:48:32 +08:00
|
|
|
# force building with gcc/g++ -mx32
|
|
|
|
build/extra/gcc-mx32/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
|
|
|
build/extra/gcc-mx32/release: PHONY; $(call run_config_and_build,$@,Release)
|
|
|
|
build/extra/gcc-mx32/%: export CC = gcc -mx32
|
|
|
|
build/extra/gcc-mx32/%: export CXX = g++ -mx32
|
|
|
|
|
2023-01-13 12:37:28 +08:00
|
|
|
# force building with gcc/g++ -m64
|
|
|
|
build/extra/gcc-m64/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
|
|
|
build/extra/gcc-m64/release: PHONY; $(call run_config_and_build,$@,Release)
|
|
|
|
build/extra/gcc-m64/%: export CC = gcc -m64
|
|
|
|
build/extra/gcc-m64/%: export CXX = g++ -m64
|
|
|
|
|
2023-01-20 02:17:26 +08:00
|
|
|
# force building with clang Static Analyzer (scan-build)
|
|
|
|
build/extra/scan-build/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
|
|
|
build/extra/scan-build/release: PHONY; $(call run_config_and_build,$@,Release)
|
|
|
|
build/extra/scan-build/%: CMAKE := scan-build $(CMAKE)
|
|
|
|
build/extra/scan-build/%: export CCC_CC ?= clang
|
|
|
|
build/extra/scan-build/%: export CCC_CXX ?= clang++
|
|
|
|
|
2022-12-22 05:09:05 +08:00
|
|
|
# cross compiler: Linux glibc aarch64-linux-gnu
|
2023-01-02 02:43:57 +08:00
|
|
|
build/extra/cross-linux-aarch64/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
|
|
|
build/extra/cross-linux-aarch64/release: PHONY; $(call run_config_and_build,$@,Release)
|
|
|
|
build/extra/cross-linux-aarch64/%: export CC = aarch64-linux-gnu-gcc
|
|
|
|
build/extra/cross-linux-aarch64/%: export CXX = aarch64-linux-gnu-g++
|
2022-12-22 05:09:05 +08:00
|
|
|
|
|
|
|
# cross compiler: Linux glibc arm-linux-gnueabihf
|
2023-01-02 02:43:57 +08:00
|
|
|
build/extra/cross-linux-arm/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
|
|
|
build/extra/cross-linux-arm/release: PHONY; $(call run_config_and_build,$@,Release)
|
|
|
|
build/extra/cross-linux-arm/%: export CC = arm-linux-gnueabihf-gcc
|
|
|
|
build/extra/cross-linux-arm/%: export CXX = arm-linux-gnueabihf-g++ -Wno-psabi
|
2022-12-22 05:09:05 +08:00
|
|
|
|
2023-01-05 07:57:01 +08:00
|
|
|
# cross compiler: Windows x86 win32 MinGW
|
|
|
|
build/extra/cross-windows-mingw32/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
|
|
|
build/extra/cross-windows-mingw32/release: PHONY; $(call run_config_and_build,$@,Release)
|
2023-02-06 00:20:32 +08:00
|
|
|
build/extra/cross-windows-mingw32/%: export CC = i686-w64-mingw32-gcc -static
|
|
|
|
build/extra/cross-windows-mingw32/%: export CXX = i686-w64-mingw32-g++ -static
|
2022-12-20 18:40:48 +08:00
|
|
|
|
2023-01-05 07:57:01 +08:00
|
|
|
# cross compiler: Windows x64 win64 MinGW
|
|
|
|
build/extra/cross-windows-mingw64/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
|
|
|
build/extra/cross-windows-mingw64/release: PHONY; $(call run_config_and_build,$@,Release)
|
2023-02-06 00:20:32 +08:00
|
|
|
build/extra/cross-windows-mingw64/%: export CC = x86_64-w64-mingw32-gcc -static
|
|
|
|
build/extra/cross-windows-mingw64/%: export CXX = x86_64-w64-mingw32-g++ -static
|
2023-01-20 02:17:26 +08:00
|
|
|
|
2023-01-25 04:52:10 +08:00
|
|
|
# cross compiler: macOS arm64
|
|
|
|
build/extra/cross-darwin-arm64/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
|
|
|
build/extra/cross-darwin-arm64/release: PHONY; $(call run_config_and_build,$@,Release)
|
|
|
|
build/extra/cross-darwin-arm64/%: export CC = clang -target arm64-apple-darwin
|
|
|
|
build/extra/cross-darwin-arm64/%: export CXX = clang++ -target arm64-apple-darwin
|
|
|
|
|
|
|
|
# cross compiler: macOS x86_64
|
|
|
|
build/extra/cross-darwin-x86_64/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
|
|
|
build/extra/cross-darwin-x86_64/release: PHONY; $(call run_config_and_build,$@,Release)
|
|
|
|
build/extra/cross-darwin-x86_64/%: export CC = clang -target x86_64-apple-darwin
|
|
|
|
build/extra/cross-darwin-x86_64/%: export CXX = clang++ -target x86_64-apple-darwin
|
|
|
|
|
|
|
|
#***********************************************************************
|
2023-01-26 15:50:30 +08:00
|
|
|
# advanced: generic extra target
|
2023-01-25 04:52:10 +08:00
|
|
|
#***********************************************************************
|
|
|
|
|
|
|
|
# usage:
|
2023-01-26 15:50:30 +08:00
|
|
|
# make UPX_XTARGET=my-target CC="my-cc -flags" CXX="my-cxx -flags"
|
|
|
|
# make UPX_XTARGET=my-target CC="my-cc -flags" CXX="my-cxx -flags" xtarget/debug
|
2023-01-25 04:52:10 +08:00
|
|
|
|
2023-01-20 02:17:26 +08:00
|
|
|
ifneq ($(UPX_XTARGET),)
|
|
|
|
ifneq ($(CC),)
|
|
|
|
ifneq ($(CXX),)
|
2023-01-25 04:52:10 +08:00
|
|
|
|
2023-01-20 02:17:26 +08:00
|
|
|
UPX_XTARGET := $(UPX_XTARGET)
|
|
|
|
build/xtarget/$(UPX_XTARGET)/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
|
|
|
build/xtarget/$(UPX_XTARGET)/release: PHONY; $(call run_config_and_build,$@,Release)
|
|
|
|
build/xtarget/$(UPX_XTARGET)/%: export CC
|
|
|
|
build/xtarget/$(UPX_XTARGET)/%: export CXX
|
2023-01-25 04:52:10 +08:00
|
|
|
# shortcuts
|
|
|
|
xtarget/debug: build/xtarget/$(UPX_XTARGET)/debug
|
|
|
|
xtarget/release: build/xtarget/$(UPX_XTARGET)/release
|
|
|
|
# set new default
|
|
|
|
.DEFAULT_GOAL = xtarget/release
|
|
|
|
|
2023-01-20 02:17:26 +08:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
2022-12-12 12:32:04 +08:00
|
|
|
|
|
|
|
#***********************************************************************
|
2022-12-20 18:40:48 +08:00
|
|
|
# check git submodules
|
2022-12-12 12:32:04 +08:00
|
|
|
#***********************************************************************
|
2022-08-17 23:30:22 +08:00
|
|
|
|
2023-01-19 10:32:49 +08:00
|
|
|
SUBMODULES = doctest lzma-sdk ucl valgrind zlib
|
2023-01-18 06:43:24 +08:00
|
|
|
|
2023-01-18 16:28:12 +08:00
|
|
|
dummy := $(foreach m,$(SUBMODULES),$(if $(wildcard vendor/$m/[CL]*),$m,\
|
2023-01-18 06:43:24 +08:00
|
|
|
$(error ERROR: missing git submodule $m; run 'git submodule update --init')))
|