2017-03-28 16:41:41 +00:00
|
|
|
#!/usr/bin/make -f
|
|
|
|
|
|
|
|
#
|
|
|
|
# \brief Build binary archives from source
|
|
|
|
# \author Norman Feske
|
|
|
|
# \date 2017-03-16
|
|
|
|
#
|
|
|
|
|
|
|
|
define HELP_MESSAGE
|
|
|
|
|
|
|
|
Build binary archives from source archives stored in the depot
|
|
|
|
|
|
|
|
usage:
|
|
|
|
|
|
|
|
$(firstword $(MAKEFILE_LIST)) <archive-path>...
|
|
|
|
|
|
|
|
The <archive-path> argument denotes the archive to create in the
|
|
|
|
form of a path. The first path element correponds to the identity
|
|
|
|
of the archive creator, the second element corresponds to the type
|
|
|
|
of the archive (bin or pkg), the third element specifies the target
|
|
|
|
architectures (e.g., x86_64), and the fourth element is the name
|
|
|
|
of the corresponding source archive including the version.
|
|
|
|
|
|
|
|
E.g., the user 'alan' may build the following archives:
|
|
|
|
|
2017-12-11 16:19:03 +00:00
|
|
|
alan/bin/x86_64/zlib/<version> - a binary archive of the zlib
|
2017-03-28 16:41:41 +00:00
|
|
|
library with the specified
|
|
|
|
version, built for the 64-bit
|
|
|
|
x86 architecture
|
|
|
|
|
2017-12-11 16:19:03 +00:00
|
|
|
alan/pkg/x86_32/wm/<version> - all binary archives needed by
|
2017-03-28 16:41:41 +00:00
|
|
|
the 'wm' package archive, built
|
|
|
|
for the 32-bit x86 architecture
|
|
|
|
|
|
|
|
The following arguments tweak the operation of the tool:
|
|
|
|
|
2017-12-14 19:11:59 +00:00
|
|
|
REBUILD=1 Replace existing archives with freshly created
|
2017-03-28 16:41:41 +00:00
|
|
|
ones.
|
|
|
|
|
|
|
|
VERBOSE= Show individual operations.
|
|
|
|
|
|
|
|
-j<N> Enable the parallel creation of packages where
|
|
|
|
<N> denotes the level of parallelism.
|
|
|
|
|
|
|
|
KEEP_BUILD_DIR=1 Do not remove build directories of built binary
|
|
|
|
packages. This is useful for debugging build
|
|
|
|
problems.
|
2021-06-29 10:06:26 +00:00
|
|
|
|
|
|
|
CCACHE=1 Compiler calls will use the C/C++ compiler cache.
|
2023-11-23 14:02:43 +00:00
|
|
|
|
|
|
|
DBG=1 Build 'dbg' archives containing debug info files
|
|
|
|
in addition to the corresponding 'bin' archives.
|
2017-03-28 16:41:41 +00:00
|
|
|
endef
|
|
|
|
|
|
|
|
export GENODE_DIR := $(realpath $(dir $(MAKEFILE_LIST))/../..)
|
|
|
|
|
|
|
|
include $(GENODE_DIR)/tool/depot/mk/front_end.inc
|
|
|
|
include $(GENODE_DIR)/tool/depot/mk/categorize_args.inc
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Collect dependencies for all specified arguments
|
|
|
|
#
|
|
|
|
# The following accessor functions used by 'mk/dependencies.inc'.
|
|
|
|
#
|
|
|
|
|
|
|
|
_file_within_archive = $(wildcard $(DEPOT_DIR)/$1/$2)
|
|
|
|
|
|
|
|
api_file = $(call _file_within_archive,$1,api)
|
|
|
|
used_apis_file = $(call _file_within_archive,$1,used_apis)
|
|
|
|
|
|
|
|
_pkg_archives_content = $(call file_content,$(call _file_within_archive,$1,archives))
|
|
|
|
|
|
|
|
pkg_src_archives = $(call grep_archive_type,src,$(call _pkg_archives_content,$1))
|
|
|
|
pkg_raw_archives = $(call grep_archive_type,raw,$(call _pkg_archives_content,$1))
|
|
|
|
pkg_pkg_archives = $(call grep_archive_type,pkg,$(call _pkg_archives_content,$1))
|
|
|
|
|
|
|
|
include $(GENODE_DIR)/tool/depot/mk/dependencies.inc
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Detect missing source archives
|
|
|
|
#
|
|
|
|
|
|
|
|
archive_exists_in_depot = $(wildcard $(DEPOT_DIR)/$1)
|
|
|
|
|
|
|
|
MISSING_ARCHIVES := $(sort \
|
|
|
|
$(foreach A,${ARCHIVES(bin)},\
|
|
|
|
$(if $(call archive_exists_in_depot,$(call src_of_bin,$A)),,$A)))
|
|
|
|
|
|
|
|
checked_source_archives_exist:
|
|
|
|
ifneq ($(MISSING_ARCHIVES),)
|
|
|
|
@echo "Error: archives missing in the depot ($(MISSING_ARCHIVES))"; false
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Generate makefile for archive-build stage
|
|
|
|
#
|
2023-11-23 14:02:43 +00:00
|
|
|
# The target pattern rules are needed to make sure that 'build_bin_archive'
|
|
|
|
# is called only once for each bin/dbg archive pair.
|
|
|
|
#
|
2017-03-28 16:41:41 +00:00
|
|
|
|
|
|
|
# determine binary-archive path within the depot
|
|
|
|
_dst_bin_spec_path = $(call archive_user,$1)/bin/$(call bin_archive_spec,$1)/
|
2023-11-23 14:02:43 +00:00
|
|
|
dst_bin_archive_path = $(call _dst_bin_spec_path,$1)$(call bin_archive_recipe,$1)/$(call bin_archive_version,$1)
|
|
|
|
dst_bin_archive_path_pattern = $(call _dst_bin_spec_path,$1)$(call bin_archive_recipe,$1)/%
|
|
|
|
|
|
|
|
# determine debug-archive path within the depot
|
|
|
|
_dst_dbg_spec_path = $(call archive_user,$1)/dbg/$(call bin_archive_spec,$1)/
|
|
|
|
dst_dbg_archive_path = $(call _dst_dbg_spec_path,$1)$(call bin_archive_recipe,$1)/$(call bin_archive_version,$1)
|
|
|
|
dst_dbg_archive_path_pattern = $(call _dst_dbg_spec_path,$1)$(call bin_archive_recipe,$1)/%
|
2017-03-28 16:41:41 +00:00
|
|
|
|
|
|
|
BUILD_MK_FILE := $(DEPOT_DIR)/var/build.mk
|
|
|
|
|
|
|
|
.PHONY: $(BUILD_MK_FILE)
|
|
|
|
|
|
|
|
wipe_existing_archives:
|
|
|
|
$(VERBOSE)rm -rf $(addprefix $(DEPOT_DIR)/,\
|
2023-11-23 14:02:43 +00:00
|
|
|
$(foreach A,${ARCHIVES(bin)},$(call dst_bin_archive_path,$A)))
|
|
|
|
$(VERBOSE)rm -rf $(addprefix $(DEPOT_DIR)/,\
|
|
|
|
$(foreach A,${ARCHIVES(dbg)},$(call dst_dbg_archive_path,$A)))
|
2017-03-28 16:41:41 +00:00
|
|
|
|
|
|
|
$(BUILD_MK_FILE): checked_source_archives_exist checked_no_uncategorized
|
|
|
|
$(VERBOSE)mkdir -p $(dir $@)
|
|
|
|
$(VERBOSE)( echo -e "all:\n"; \
|
|
|
|
echo "TOOL_DIR := $(GENODE_DIR)/tool"; \
|
|
|
|
$(foreach A,${ARCHIVES(bin)},\
|
2023-11-23 14:02:43 +00:00
|
|
|
bin_target=$(call dst_bin_archive_path,$A); \
|
|
|
|
bin_target_pattern=$(call dst_bin_archive_path_pattern,$A); \
|
|
|
|
dbg_target=$(call dst_dbg_archive_path,$A); \
|
|
|
|
dbg_target_pattern=$(call dst_dbg_archive_path_pattern,$A); \
|
2017-03-28 16:41:41 +00:00
|
|
|
user=$(call archive_user,$A); \
|
|
|
|
recipe=$(call bin_archive_recipe,$A); \
|
2017-12-11 16:19:03 +00:00
|
|
|
version=$(call bin_archive_version,$A); \
|
2017-03-28 16:41:41 +00:00
|
|
|
spec=$(call bin_archive_spec,$A); \
|
|
|
|
echo ""; \
|
2023-11-23 14:02:43 +00:00
|
|
|
echo "TARGETS += $$bin_target"; \
|
|
|
|
echo "TOOL($$bin_target) := build_bin_archive"; \
|
|
|
|
echo "ARGS($$bin_target) := $$recipe/$$version USER=$$user SPEC=$$spec"; \
|
|
|
|
echo ""; \
|
|
|
|
echo "ifneq (\$$(DBG),)"; \
|
|
|
|
echo "TARGETS += $$dbg_target"; \
|
|
|
|
echo "TOOL($$dbg_target) := build_bin_archive"; \
|
|
|
|
echo "ARGS($$dbg_target) := $$recipe/$$version USER=$$user SPEC=$$spec"; \
|
|
|
|
echo "endif"; \
|
|
|
|
echo -e "\n$$bin_target_pattern $$dbg_target_pattern:"; \
|
|
|
|
echo -e "\t\$$(MAKE) -f \$$(TOOL_DIR)/depot/mk/\$${TOOL(\$$@)}" \
|
|
|
|
"\$${ARGS(\$$@)} CCACHE=\$$(CCACHE) VERBOSE=\$$(VERBOSE)\n"; \
|
2017-03-28 16:41:41 +00:00
|
|
|
) \
|
|
|
|
echo -e "\nall: \$$(TARGETS)"; \
|
|
|
|
) > $@
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Invoke sub make to process generated makefile
|
|
|
|
#
|
|
|
|
execute_generated_build_mk_file: $(BUILD_MK_FILE)
|
|
|
|
$(VERBOSE)$(MAKE) $(if $(VERBOSE),--quiet) -f $(BUILD_MK_FILE) \
|
|
|
|
-C $(DEPOT_DIR) VERBOSE=$(VERBOSE)
|
|
|
|
|
2024-11-08 15:44:09 +00:00
|
|
|
#
|
|
|
|
# Utilities to check consistency of bin archives with their src and used APIS
|
|
|
|
#
|
|
|
|
_eq = $(and $(findstring x$(1),x$(2)), $(findstring x$(2),x$(1)))
|
|
|
|
_libapi = $(if $(wildcard $(DEPOT_DIR)/$1/api),$(call file_content,$(DEPOT_DIR)/$1/api),)
|
|
|
|
_apis_of_src = $(call _libapi,$1) $(call file_content,$(DEPOT_DIR)/$1/used_apis)
|
|
|
|
_api_archives_of_src = $(addprefix $(call archive_user,$1)/api/,$(call _apis_of_src,$1))
|
|
|
|
_api_hashes = $(foreach A,$(call _api_archives_of_src,$1),$(call file_content,$(DEPOT_DIR)/$A.hash))
|
|
|
|
_src_hash = $(call file_content,$(DEPOT_DIR)/$1.hash)
|
|
|
|
_src_and_api_hashes = $(call _src_hash,$1) $(call _api_hashes,$1)
|
|
|
|
_src_of_bin = $(call archive_user,$1)/src/$(call bin_archive_recipe,$1)/$(call bin_archive_version,$1)
|
|
|
|
_bin_ingredient_hashes = $(call _src_and_api_hashes,$(call _src_of_bin,$1))
|
|
|
|
_bin_hashes = $(call file_content,$(DEPOT_DIR)/$1.hash)
|
|
|
|
_bin_exists = $(wildcard $(DEPOT_DIR)/$1)
|
|
|
|
_bin_inconsistent = $(if $(call _bin_exists,$1),\
|
|
|
|
$(if $(call _eq,$(call _bin_ingredient_hashes,$1),$(call _bin_hashes,$1)),,$1))
|
|
|
|
|
2017-12-14 19:11:59 +00:00
|
|
|
ifneq ($(REBUILD),)
|
2017-03-28 16:41:41 +00:00
|
|
|
execute_generated_build_mk_file: wipe_existing_archives
|
2024-11-08 15:44:09 +00:00
|
|
|
else
|
|
|
|
INCONSISTENT_BIN_ARCHIVES = $(strip $(foreach I,${ARCHIVES(bin)},$(call _bin_inconsistent,$I)))
|
|
|
|
ifneq ($(INCONSISTENT_BIN_ARCHIVES),)
|
|
|
|
execute_generated_build_mk_file: report_bin_src_inconsistencies
|
2017-03-28 16:41:41 +00:00
|
|
|
endif
|
2024-11-08 15:44:09 +00:00
|
|
|
endif # REBUILD
|
|
|
|
|
|
|
|
report_bin_src_inconsistencies:
|
|
|
|
@( \
|
|
|
|
echo -e "\nError: the following bin archives do not match their src and apis:\n"; \
|
|
|
|
for i in $(INCONSISTENT_BIN_ARCHIVES); do echo -e " $$i"; done; \
|
|
|
|
echo -e "\nYou may consider removing those binary archives from the depot.\n" \
|
|
|
|
)
|
|
|
|
@false
|
2017-03-28 16:41:41 +00:00
|
|
|
|
|
|
|
$(MAKECMDGOALS): execute_generated_build_mk_file
|
|
|
|
@true
|
|
|
|
|