2019-09-27 22:36:50 +02:00
|
|
|
# vim: noexpandtab sts=8 sw=8 ts=8
|
|
|
|
|
|
|
|
#
|
|
|
|
# Overridable variables
|
|
|
|
#
|
|
|
|
|
|
|
|
V ?= @
|
|
|
|
BUILDDIR ?= build
|
|
|
|
|
|
|
|
#
|
|
|
|
# Internal variables
|
|
|
|
#
|
|
|
|
|
2020-05-11 00:23:53 +02:00
|
|
|
builddir_docker := $(BUILDDIR)/docker
|
2019-09-27 22:36:50 +02:00
|
|
|
|
2024-02-25 09:14:42 +01:00
|
|
|
docker_build_container_name := "bemanitools-build"
|
|
|
|
docker_build_image_name := "bemanitools-build:latest"
|
|
|
|
docker_dev_container_name := "bemanitools-dev"
|
|
|
|
docker_dev_image_name := "bemanitools-dev:latest"
|
2019-09-27 22:36:50 +02:00
|
|
|
|
2020-05-11 00:23:53 +02:00
|
|
|
depdir := $(BUILDDIR)/dep
|
|
|
|
objdir := $(BUILDDIR)/obj
|
|
|
|
bindir := $(BUILDDIR)/bin
|
|
|
|
|
|
|
|
toolchain_32 := i686-w64-mingw32-
|
|
|
|
toolchain_64 := x86_64-w64-mingw32-
|
|
|
|
|
|
|
|
gitrev := $(shell git rev-parse HEAD)
|
|
|
|
cppflags := -I src -I src/main -I src/test -DGITREV=$(gitrev)
|
|
|
|
cflags := -O2 -pipe -ffunction-sections -fdata-sections \
|
2020-08-21 14:34:22 +02:00
|
|
|
-Wall -std=c99 -DPSAPI_VERSION=1
|
2020-05-11 00:23:53 +02:00
|
|
|
cflags_release := -Werror
|
|
|
|
ldflags := -Wl,--gc-sections -static-libgcc
|
2019-09-27 22:36:50 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# The first target that GNU Make encounters becomes the default target.
|
|
|
|
# Define our ultimate target (`all') here, and also some helpers
|
|
|
|
#
|
|
|
|
|
2019-11-09 19:45:38 +01:00
|
|
|
all: build
|
2019-09-27 22:36:50 +02:00
|
|
|
|
2023-05-01 16:28:28 +02:00
|
|
|
FORCE:
|
|
|
|
|
2019-11-09 19:45:38 +01:00
|
|
|
.PHONY: \
|
2020-05-11 00:23:53 +02:00
|
|
|
build-docker \
|
2024-02-25 09:14:42 +01:00
|
|
|
dev-docker \
|
2019-11-09 19:45:38 +01:00
|
|
|
clean \
|
|
|
|
code-format \
|
2024-01-29 23:17:04 +01:00
|
|
|
doc-format \
|
2019-11-09 19:45:38 +01:00
|
|
|
print-building \
|
|
|
|
print-release \
|
|
|
|
run-tests \
|
2023-05-01 16:28:28 +02:00
|
|
|
version \
|
|
|
|
FORCE
|
2019-11-09 19:45:38 +01:00
|
|
|
|
|
|
|
release: \
|
|
|
|
print-release \
|
|
|
|
clean \
|
|
|
|
code-format \
|
2024-01-29 23:17:04 +01:00
|
|
|
doc-format \
|
2019-11-09 19:45:38 +01:00
|
|
|
all \
|
|
|
|
run-tests
|
|
|
|
|
|
|
|
build: \
|
|
|
|
print-building \
|
|
|
|
version
|
2019-09-27 22:36:50 +02:00
|
|
|
|
2019-10-19 23:10:52 +02:00
|
|
|
print-building:
|
2020-08-21 14:15:00 +02:00
|
|
|
$(V)echo "Build gitrev "$(gitrev)"..."
|
2019-10-19 23:10:52 +02:00
|
|
|
|
|
|
|
print-release:
|
2020-08-21 14:15:00 +02:00
|
|
|
$(V)echo "Starting release build..."
|
2019-09-27 22:36:50 +02:00
|
|
|
|
|
|
|
clean:
|
2020-08-21 14:15:00 +02:00
|
|
|
$(V)echo "Cleaning up..."
|
2019-09-27 22:36:50 +02:00
|
|
|
$(V)rm -rf $(BUILDDIR)
|
|
|
|
|
2019-10-19 23:10:52 +02:00
|
|
|
code-format:
|
2020-08-21 14:14:17 +02:00
|
|
|
$(V)echo "Applying clang-format..."
|
2023-03-21 23:36:09 +01:00
|
|
|
$(V)find src/main src/test -name '*.c' -o -name '*.h' | xargs clang-format -i -style=file
|
2019-10-19 23:10:52 +02:00
|
|
|
|
2024-01-29 23:17:04 +01:00
|
|
|
doc-format:
|
|
|
|
$(V)echo "Applying mdformat on all docs..."
|
|
|
|
$(V)find . -name '*.md' | xargs mdformat --wrap 100
|
|
|
|
|
2019-10-19 23:10:52 +02:00
|
|
|
run-tests:
|
2020-08-21 14:15:00 +02:00
|
|
|
$(V)echo "Running tests..."
|
|
|
|
$(V)./run-tests-wine.sh
|
2019-10-19 23:10:52 +02:00
|
|
|
|
|
|
|
# Generate a version file to identify the build
|
|
|
|
version:
|
2020-08-21 14:15:00 +02:00
|
|
|
$(V)echo "$(gitrev)" > version
|
2019-10-19 23:10:52 +02:00
|
|
|
|
2020-05-11 00:23:53 +02:00
|
|
|
build-docker:
|
2024-02-25 09:14:42 +01:00
|
|
|
$(V)docker rm -f $(docker_build_container_name) 2> /dev/null || true
|
2023-03-21 23:31:23 +01:00
|
|
|
$(V)docker \
|
|
|
|
build \
|
2024-02-25 09:14:42 +01:00
|
|
|
-t $(docker_build_image_name) \
|
|
|
|
-f Dockerfile.build \
|
2023-03-21 23:31:23 +01:00
|
|
|
.
|
|
|
|
$(V)docker \
|
|
|
|
run \
|
|
|
|
--volume $(shell pwd):/bemanitools \
|
2024-02-25 09:14:42 +01:00
|
|
|
--name $(docker_build_container_name) \
|
|
|
|
$(docker_build_image_name)
|
|
|
|
|
|
|
|
dev-docker:
|
|
|
|
$(V)docker rm -f $(docker_dev_container_name) 2> /dev/null || true
|
|
|
|
$(V)docker \
|
|
|
|
build \
|
|
|
|
-t $(docker_dev_image_name) \
|
|
|
|
-f Dockerfile.dev \
|
|
|
|
.
|
|
|
|
$(V)docker \
|
|
|
|
run \
|
|
|
|
--interactive \
|
|
|
|
--tty \
|
|
|
|
--volume $(shell pwd):/bemanitools \
|
|
|
|
--name $(docker_dev_container_name) \
|
|
|
|
$(docker_dev_image_name)
|
2023-03-21 23:31:23 +01:00
|
|
|
|
|
|
|
clean-docker:
|
2024-02-25 09:14:42 +01:00
|
|
|
$(V)docker rm -f $(docker_dev_container_name) || true
|
|
|
|
$(V)docker image rm -f $(docker_dev_image_name) || true
|
|
|
|
$(V)docker rm -f $(docker_build_container_name) || true
|
|
|
|
$(V)docker image rm -f $(docker_build_image_name) || true
|
2023-03-21 23:31:23 +01:00
|
|
|
$(V)rm -rf $(BUILDDIR)
|
2020-05-11 00:23:53 +02:00
|
|
|
|
2019-09-27 22:36:50 +02:00
|
|
|
#
|
|
|
|
# Pull in module definitions
|
|
|
|
#
|
|
|
|
|
|
|
|
deps :=
|
|
|
|
|
|
|
|
dlls :=
|
|
|
|
exes :=
|
|
|
|
imps :=
|
|
|
|
libs :=
|
|
|
|
|
|
|
|
avsdlls :=
|
|
|
|
avsexes :=
|
|
|
|
|
2019-10-06 21:17:56 +02:00
|
|
|
testdlls :=
|
2019-09-27 22:36:50 +02:00
|
|
|
testexes :=
|
|
|
|
|
|
|
|
include Module.mk
|
|
|
|
|
2019-10-06 21:17:56 +02:00
|
|
|
modules := $(dlls) $(exes) $(libs) $(avsdlls) $(avsexes) $(testdlls) $(testexes)
|
2019-09-27 22:36:50 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# $1: Bitness
|
|
|
|
# $2: AVS2 minor version
|
|
|
|
# $3: Module
|
|
|
|
#
|
|
|
|
|
|
|
|
define t_moddefs
|
|
|
|
|
|
|
|
cppflags_$3 += $(cppflags) -DBUILD_MODULE=$3
|
|
|
|
cflags_$3 += $(cflags)
|
2019-11-09 19:45:38 +01:00
|
|
|
release: cflags_$3 += $(cflags_release)
|
2019-09-27 22:36:50 +02:00
|
|
|
ldflags_$3 += $(ldflags)
|
|
|
|
srcdir_$3 ?= src/main/$3
|
|
|
|
|
|
|
|
endef
|
|
|
|
|
|
|
|
$(eval $(foreach module,$(modules),$(call t_moddefs,_,_,$(module))))
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
define t_bitness
|
|
|
|
|
|
|
|
subdir_$1_indep := indep-$1
|
|
|
|
bindir_$1_indep := $(bindir)/$$(subdir_$1_indep)
|
|
|
|
|
|
|
|
$$(bindir_$1_indep):
|
|
|
|
$(V)mkdir -p $$@
|
|
|
|
|
|
|
|
$$(eval $$(foreach imp,$(imps),$$(call t_import,$1,indep,$$(imp))))
|
|
|
|
$$(eval $$(foreach dll,$(dlls),$$(call t_linkdll,$1,indep,$$(dll))))
|
|
|
|
$$(eval $$(foreach exe,$(exes),$$(call t_linkexe,$1,indep,$$(exe))))
|
|
|
|
$$(eval $$(foreach lib,$(libs),$$(call t_archive,$1,indep,$$(lib))))
|
|
|
|
|
|
|
|
$$(eval $$(foreach avsver,$$(avsvers_$1),$$(call t_avsver,$1,$$(avsver))))
|
|
|
|
|
2019-10-06 21:17:56 +02:00
|
|
|
$$(eval $$(foreach dll,$(testdlls),$$(call t_linkdll,$1,indep,$$(dll))))
|
2019-09-27 22:36:50 +02:00
|
|
|
$$(eval $$(foreach exe,$(testexes),$$(call t_linkexe,$1,indep,$$(exe))))
|
|
|
|
|
|
|
|
endef
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
define t_avsver
|
|
|
|
|
|
|
|
subdir_$1_$2 := avs2_$2-$1
|
|
|
|
bindir_$1_$2 := $(bindir)/$$(subdir_$1_$2)
|
|
|
|
|
|
|
|
$$(bindir_$1_$2):
|
|
|
|
$(V)mkdir -p $$@
|
|
|
|
|
|
|
|
$$(eval $$(foreach imp,$(imps),$$(call t_import,$1,$2,$$(imp))))
|
|
|
|
$$(eval $$(foreach dll,$(avsdlls),$$(call t_linkdll,$1,$2,$$(dll))))
|
|
|
|
$$(eval $$(foreach exe,$(avsexes),$$(call t_linkexe,$1,$2,$$(exe))))
|
|
|
|
|
|
|
|
endef
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
define t_compile
|
|
|
|
|
|
|
|
depdir_$1_$2_$3 := $(depdir)/$$(subdir_$1_$2)/$3
|
|
|
|
abslib_$1_$2_$3 := $$(libs_$3:%=$$(bindir_$1_indep)/lib%.a)
|
|
|
|
absdpl_$1_$2_$3 := $$(deplibs_$3:%=$$(bindir_$1_$2)/lib%.a)
|
|
|
|
objdir_$1_$2_$3 := $(objdir)/$$(subdir_$1_$2)/$3
|
|
|
|
obj_$1_$2_$3 := $$(src_$3:%.c=$$(objdir_$1_$2_$3)/%.o) \
|
|
|
|
$$(rc_$3:%.rc=$$(objdir_$1_$2_$3)/%_rc.o)
|
|
|
|
|
|
|
|
deps += $$(src_$3:%.c=$$(depdir_$1_$2_$3)/%.d)
|
|
|
|
|
|
|
|
$$(depdir_$1_$2_$3):
|
|
|
|
$(V)mkdir -p $$@
|
|
|
|
|
|
|
|
$$(objdir_$1_$2_$3):
|
|
|
|
$(V)mkdir -p $$@
|
|
|
|
|
2023-05-01 16:28:28 +02:00
|
|
|
$$(volatile_$3:%.c=$$(objdir_$1_$2_$3)/%.o): FORCE
|
|
|
|
|
2019-09-27 22:36:50 +02:00
|
|
|
$$(objdir_$1_$2_$3)/%.o: $$(srcdir_$3)/%.c \
|
|
|
|
| $$(depdir_$1_$2_$3) $$(objdir_$1_$2_$3)
|
|
|
|
$(V)echo ... $$@
|
|
|
|
$(V)$$(toolchain_$1)gcc $$(cflags_$3) $$(cppflags_$3) \
|
|
|
|
-MMD -MF $$(depdir_$1_$2_$3)/$$*.d -MT $$@ -MP \
|
|
|
|
-DAVS_VERSION=$2 -c -o $$@ $$<
|
|
|
|
|
|
|
|
$$(objdir_$1_$2_$3)/%_rc.o: $$(srcdir_$3)/%.rc
|
|
|
|
$(V)echo ... $$@ [windres]
|
|
|
|
$(V)$$(toolchain_$1)windres $$(cppflags_$3) $$< $$@
|
|
|
|
|
|
|
|
endef
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
define t_archive
|
|
|
|
|
|
|
|
$(t_compile)
|
|
|
|
|
|
|
|
$$(bindir_$1_$2)/lib$3.a: $$(obj_$1_$2_$3) | $$(bindir_$1_$2)
|
|
|
|
$(V)echo ... $$@
|
|
|
|
$(V)$$(toolchain_$1)ar r $$@ $$^ 2> /dev/null
|
|
|
|
$(V)$$(toolchain_$1)ranlib $$@
|
|
|
|
|
|
|
|
endef
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
define t_linkdll
|
|
|
|
|
|
|
|
$(t_compile)
|
|
|
|
|
|
|
|
dll_$1_$2_$3 := $$(bindir_$1_$2)/$3.dll
|
|
|
|
implib_$1_$2_$3 := $$(bindir_$1_$2)/lib$3.a
|
|
|
|
|
|
|
|
$$(dll_$1_$2_$3) $$(implib_$1_$2_$3): $$(obj_$1_$2_$3) $$(abslib_$1_$2_$3) \
|
|
|
|
$$(absdpl_$1_$2_$3) \
|
|
|
|
$$(srcdir_$3)/$3.def | $$(bindir_$1_$2)
|
|
|
|
$(V)echo ... $$(dll_$1_$2_$3)
|
|
|
|
$(V)$$(toolchain_$1)gcc -shared \
|
|
|
|
-o $$(dll_$1_$2_$3) -Wl,--out-implib,$$(implib_$1_$2_$3) \
|
2021-12-31 11:23:31 +01:00
|
|
|
-Wl,--start-group $$^ -Wl,--end-group $$(ldflags_$3)
|
2019-09-27 22:36:50 +02:00
|
|
|
$(V)$$(toolchain_$1)strip $$(dll_$1_$2_$3)
|
|
|
|
$(V)$$(toolchain_$1)ranlib $$(implib_$1_$2_$3)
|
|
|
|
|
|
|
|
endef
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
define t_linkexe
|
|
|
|
|
|
|
|
$(t_compile)
|
|
|
|
|
|
|
|
exe_$1_$2_$3 := $$(bindir_$1_$2)/$3.exe
|
|
|
|
|
|
|
|
$$(exe_$1_$2_$3): $$(obj_$1_$2_$3) $$(abslib_$1_$2_$3) $$(absdpl_$1_$2_$3) \
|
|
|
|
| $$(bindir_$1_$2)
|
|
|
|
$(V)echo ... $$@
|
|
|
|
$(V)$$(toolchain_$1)gcc -o $$@ $$^ $$(ldflags_$3)
|
|
|
|
$(V)$$(toolchain_$1)strip $$@
|
|
|
|
|
|
|
|
endef
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
define t_import
|
|
|
|
|
|
|
|
impdef_$1_$2_$3 ?= src/imports/import_$1_$2_$3.def
|
|
|
|
|
|
|
|
$$(bindir_$1_$2)/lib$3.a: $$(impdef_$1_$2_$3) | $$(bindir_$1_$2)
|
|
|
|
$(V)echo ... $$@ [dlltool]
|
2020-10-04 08:24:17 +02:00
|
|
|
$(V)$$(toolchain_$1)dlltool --kill-at -l $$@ -d $$<
|
2019-09-27 22:36:50 +02:00
|
|
|
|
|
|
|
endef
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
$(eval $(foreach bitness,32 64,$(call t_bitness,$(bitness))))
|
|
|
|
|
|
|
|
#
|
|
|
|
# Pull in GCC-generated dependency files
|
|
|
|
#
|
|
|
|
|
|
|
|
-include $(deps)
|
|
|
|
|