# Top-level make includes for GARStow ports. # # Copyright (C) 2001 Nick Moffitt # Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016, 2017, 2019, 2020, 2021, 2022 Adam Sampson # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ifneq "$(strip $(USE))" "" # Rather than including this file, pull in a library file instead. USE_NEXT := $(firstword $(USE)) USE := $(wordlist 2,$(words $(USE)),$(USE)) include ../../gar.lib/$(USE_NEXT) else # No library files to include. # Comment this out to make much verbosity #.SILENT: # This is useful for $(wordlist ...) tricks. SPACE = $(subst X,,X X) GARDIR ?= ../.. GARDIR_ABSOLUTE := $(shell cd $(GARDIR) && pwd) SCRIPTSDIR = $(GARDIR_ABSOLUTE)/gar.scripts # The architecture we're building *on*, and building *for*. # These will be inherited through the environment in sub-makes. ifndef GARARCH_BUILD GARARCH_BUILD := $(shell $(SCRIPTSDIR)/garstow get-arch --build) endif ifndef GARARCH_HOST GARARCH_HOST := $(shell $(SCRIPTSDIR)/garstow get-arch) endif ifeq "$(GARARCH_BUILD)" "$(GARARCH_HOST)" archdir = archwork = else # Prefix to apply to directories when installing non-native packages. archdir = $(crossdir)/$(GARARCH_HOST) # Prefix to apply to working directories. archwork = cross/$(GARARCH_HOST)/ endif # All the crossbuildable architectures. (Useful for CROSSBUILDABLE.) CROSS_GARARCHS = \ linux-amd64 \ linux-armv7 \ linux-armv8 \ linux-ia32 \ linux-m68k \ linux-rv64 # Function to convert a GARARCH string to a GNU-style architecture triple. # When adding a new triple here, also update: # - linuxarch in gar.lib/linux.mk # - configure rule in gar.lib/meson.mk # - cross_tool_re in gar.scripts/fast_wrapper.ml # - all_deps and arch_triples in gar.scripts/gar-wrapper # - gararch_cpus in gar.scripts/garstowlib/config.py arch_to_triple = $(if \ $(filter linux-amd64,$(1)),x86_64-pc-linux-gnu,$(if \ $(filter linux-armv7,$(1)),arm-linux-gnueabihf,$(if \ $(filter linux-armv8,$(1)),aarch64-linux-gnu,$(if \ $(filter linux-ia32,$(1)),i686-pc-linux-gnu,$(if \ $(filter linux-m68k,$(1)),m68k-linux-gnu,$(if \ $(filter linux-rv64,$(1)),riscv64-linux-gnu,$(if \ ,,$(error Unknown architecture for arch_to_triple)))))))) # The GNU-style triples for the architectures. TRIPLE_BUILD ?= $(call arch_to_triple,$(GARARCH_BUILD)) TRIPLE_HOST ?= $(call arch_to_triple,$(GARARCH_HOST)) # Crossbuilding tools, for use in environments and make arguments, under the # names normally used by make. This will be empty for native builds. CROSS_TOOLS ?= $(if $(archdir), \ AR=$(TRIPLE_HOST)-ar \ AS=$(TRIPLE_HOST)-as \ CC=$(TRIPLE_HOST)-gcc \ CXX=$(TRIPLE_HOST)-g++ \ LD=$(TRIPLE_HOST)-ld \ NM=$(TRIPLE_HOST)-nm \ OBJCOPY=$(TRIPLE_HOST)-objcopy \ OBJDUMP=$(TRIPLE_HOST)-objdump \ RANLIB=$(TRIPLE_HOST)-ranlib \ READELF=$(TRIPLE_HOST)-readelf \ STRIP=$(TRIPLE_HOST)-strip \ ) # The architecture of the machine this package is built for. # A package can override this to "any" if it's not architecture-specific. GARARCH ?= $(GARARCH_HOST) FILEDIR ?= files PATCHESDIR ?= patches DOWNLOADDIR ?= $(archwork)download COOKIEDIR ?= $(archwork)cookies WORKDIR ?= $(archwork)work STAGEDIR ?= $(archwork)dest PACKAGEDIR ?= $(archwork)pkg WORKSRC ?= $(WORKDIR)/$(DISTNAME) EXTRACTDIR ?= $(WORKDIR) SCRATCHDIR ?= tmp CHECKSUM_FILE ?= checksums MANIFEST_FILE ?= manifest GPG_KEYRING ?= ./gpg-keyring packagesdir ?= $(prefix)/packages # Setup for the build user. BUILD_CHOWN = chown -R $(BUILD_USER):$(BUILD_GROUP) BUILD_HOME = $(CURDIR)/$(WORKDIR)/.home RUN_AS_ARGS = \ --home $(BUILD_HOME) \ $(BUILD_USER) \ env AS_BUILD_USER_WITH_NET = $(SCRIPTSDIR)/run-as \ $(RUN_AS_ARGS) AS_BUILD_USER = $(SCRIPTSDIR)/run-as \ $(if $(USE_NONET),--netns) \ $(RUN_AS_ARGS) # Components of GARVERSION. GARVERSION1 ?= $(subst $(SPACE),.,$(wordlist 1,1,$(subst .,$(SPACE),$(GARVERSION)))) GARVERSION2 ?= $(subst $(SPACE),.,$(wordlist 2,2,$(subst .,$(SPACE),$(GARVERSION)))) GARVERSION3 ?= $(subst $(SPACE),.,$(wordlist 3,3,$(subst .,$(SPACE),$(GARVERSION)))) GARVERSION12 ?= $(subst $(SPACE),.,$(wordlist 1,2,$(subst .,$(SPACE),$(GARVERSION)))) GARVERSION123 ?= $(subst $(SPACE),.,$(wordlist 1,3,$(subst .,$(SPACE),$(GARVERSION)))) UPSTREAMNAME ?= $(GARNAME) DISTNAME ?= $(UPSTREAMNAME)-$(GARVERSION) DISTEXT ?= .tar.gz DISTFILES ?= $(DISTNAME)$(DISTEXT) SIGEXT ?= SIGFILES ?= $(if $(SIGEXT),$(addsuffix $(SIGEXT),$(DISTFILES))) ALLFILES ?= $(DISTFILES) $(PATCHFILES) $(SIGFILES) PATCHESFILES ?= $(wildcard $(PATCHESDIR)/*.diff) # LIBDEPS need to be installed to use the port (e.g. from a garball). # BUILDDEPS need to be installed (in addition to LIBDEPS) to build the port. # STATICDEPS are like BUILDDEPS, except the port must be rebuilt if their hash # changes. This is intended for dependencies on static libraries or data. # A package can be listed in both LIBDEPS and STATICDEPS. # TESTDEPS need to be installed (in addition to LIBDEPS and BUILDDEPS) to run # the package's tests, but you can still build the port without them, # so you're allowed to have circular dependencies in TESTDEPS. # # XXX This isn't quite flexible enough for cross-building: at present, we # assume LIBDEPS and STATICDEPS should be installed for the host architecture, # and BUILDDEPS and TESTDEPS for the build architecture. # For rules that do nothing, display what dependencies they # successfully completed DONADA = @echo " [$@] complete. Finished rules: $+" # TODO: write a stub rule to print out the name of a rule when it # *does* do something, and handle indentation intelligently. # Build the package but don't install it by default. all: package $(DONADA) #################### DIRECTORY MAKERS #################### # This is to make dirs as needed by the base rules $(sort $(COOKIEDIR) $(FILEDIR)): @mkdir -p $@ $(sort $(DOWNLOADDIR) $(WORKDIR) $(EXTRACTDIR) $(WORKSRC) $(SCRATCHDIR)): @mkdir -p $@ @$(BUILD_CHOWN) $@ $(COOKIEDIR)/%: @mkdir -p $@ # include the configuration file to override any of these variables include $(GARDIR)/gar.conf.mk include $(GARDIR)/gar.env.mk include $(GARDIR)/gar.master.mk include $(GARDIR)/gar.lib.mk # Include Makefile fragments from ports we depend upon, if they exist. -include $(addprefix $(GARDIR)/,$(addsuffix /depend.mk,$(LIBDEPS) $(STATICDEPS) $(BUILDDEPS))) -include $(addprefix $(GARDIR)/,$(addsuffix /export.mk,$(LIBDEPS) $(STATICDEPS))) -include $(addprefix $(GARDIR)/,$(addsuffix /export-$(GARARCH).mk,$(LIBDEPS) $(STATICDEPS))) # These stubs are wildcarded, so that the port maintainer can # define something like "pre-configure" and it won't conflict, # while the configure target can call "pre-configure" safely even # if the port maintainer hasn't defined it. # # in addition to the pre- rules, the maintainer may wish # to set a "pre-everything" rule, which runs before the first # actual target. pre-%: @true post-%: @true # ========================= MAIN RULES ========================= # The main rules are the ones that the user can specify as a # target on the "make" command-line. Currently, they are: # fetch-list fetch checksum makesum extract checkpatch patch # build install reinstall uninstall package # (some may not be complete yet). # # Each of these rules has dependencies that run in the following # order: # - run the previous main rule in the chain (e.g., install # depends on build) # - run the pre- rule for the target (e.g., configure would # then run pre-configure) # - generate a set of files to depend on. These are typically # cookie files in $(COOKIEDIR), but in the case of fetch are # actual downloaded files in $(DOWNLOADDIR) # - run the post- rule for the target # # The main rules also run the $(DONADA) code, which prints out # what just happened when all the dependencies are finished. # fetch - Retrieves $(DISTFILES) (and $(PATCHFILES) if defined) # into $(DOWNLOADDIR) as necessary. fetch: pre-everything $(COOKIEDIR) $(DOWNLOADDIR) $(WORKDIR) pre-fetch $(addprefix $(DOWNLOADDIR)/,$(ALLFILES)) post-fetch $(DONADA) SUMMEDFILES = $(filter-out $(NOCHECKSUM),$(ALLFILES)) # checksum - Use $(CHECKSUM_FILE) to ensure that your # distfiles are valid. checksum: fetch pre-checksum $(addprefix checksum-,$(SUMMEDFILES)) post-checksum $(DONADA) # makesum - Regenerate $(CHECKSUM_FILE). makesum: fetch $(addprefix $(DOWNLOADDIR)/,$(SUMMEDFILES)) @if [ -n "$(SUMMEDFILES)" ]; then \ (cd $(DOWNLOADDIR) && sha256sum --tag $(SUMMEDFILES)) >$(CHECKSUM_FILE); \ else \ rm -f $(CHECKSUM_FILE); \ fi # checksig - Use signatures in $(SIGFILES) to check downloaded files. ALL_CHECKSIG_RULES = pre-checksig $(addprefix checksig-,$(SIGFILES)) post-checksig checksig: checksum $(COOKIEDIR) $(if $(SKIP_CHECKSIG),,$(ALL_CHECKSIG_RULES)) $(DONADA) # get-keyring - Print the keyring filename. get-keyring: @echo "$(CURDIR)/$(GPG_KEYRING)" # garchive - Copy downloaded files to $(GARCHIVEDIR) garchive: checksig $(COOKIEDIR) pre-garchive $(addprefix garchive-,$(ALLFILES)) post-garchive $(DONADA) # extract - Unpacks $(DISTFILES) into $(EXTRACTDIR) (patches are "zcatted" into the patch program) extract: garchive $(EXTRACTDIR) $(COOKIEDIR) pre-extract $(addprefix extract-,$(filter-out $(NOEXTRACT),$(DISTFILES))) post-extract $(DONADA) # patch - Apply any provided patches to the source. patch: extract $(WORKSRC) pre-patch $(addprefix __patch_,$(PATCHFILES)) $(patsubst $(PATCHESDIR)/%,__patches_%,$(PATCHESFILES)) post-patch $(DONADA) # makepatch - Generate a new diff based on changes in $(WORKSRC). makepatch: $(SCRATCHDIR) $(FILEDIR) $(PATCHESDIR)/new.diff $(DONADA) # Provide PRE_ and POST_ variables for each of the scripts types. # This is because it's useful to default the main _SCRIPTS variables to # something (often something complicated) in a library .mk file, but some ports # still want to have custom scripts. ALL_CONFIGURE_SCRIPTS = $(PRE_CONFIGURE_SCRIPTS) $(CONFIGURE_SCRIPTS) $(POST_CONFIGURE_SCRIPTS) ALL_BUILD_SCRIPTS = $(PRE_BUILD_SCRIPTS) $(BUILD_SCRIPTS) $(POST_BUILD_SCRIPTS) ALL_TEST_SCRIPTS = $(if $(BOOTSTRAP),,$(PRE_TEST_SCRIPTS) $(TEST_SCRIPTS) $(POST_TEST_SCRIPTS)) ALL_INSTALL_SCRIPTS = $(PRE_INSTALL_SCRIPTS) $(INSTALL_SCRIPTS) $(POST_INSTALL_SCRIPTS) # setup - Set up the build environment. setup: patch $(addprefix setup-,$(SETUP_RULES)) $(DONADA) # configure - Configure the source tree for compilation. ALL_CONFIGURE_RULES = pre-configure $(addprefix configure-,$(ALL_CONFIGURE_SCRIPTS)) post-configure need-configure: need-build @rm -rf $(addprefix $(COOKIEDIR)/,$(ALL_CONFIGURE_RULES) configure) configure: setup $(ALL_CONFIGURE_RULES) $(DONADA) # build - Compile the source tree. ALL_BUILD_RULES = build-setup-wrappers pre-build $(addprefix build-,$(ALL_BUILD_SCRIPTS)) post-build need-build: need-test @rm -rf $(addprefix $(COOKIEDIR)/,$(ALL_BUILD_RULES) build) build: configure $(ALL_BUILD_RULES) $(DONADA) # buildsh - Start a shell as the build user. buildsh: @$(STATUS) "Starting $(SHELL) as build user..." @cd $(if $(WORKOBJ),$(WORKOBJ),$(WORKSRC)) && $(BUILD_CTX) $(SHELL) # test - Run the source tree's self-tests. ALL_TEST_RULES = pre-test $(addprefix test-,$(ALL_TEST_SCRIPTS)) post-test need-test: need-stage @rm -rf $(addprefix $(COOKIEDIR)/,$(ALL_TEST_RULES) test) test: build $(if $(SKIP_TESTS),,$(ALL_TEST_RULES)) $(DONADA) # stage - Install from the source tree into the staging dir. ALL_STAGE_RULES = install-staging-begin pre-install $(addprefix install-,$(ALL_INSTALL_SCRIPTS)) post-install install-normalise install-staging-end need-stage: need-package @rm -rf $(addprefix $(COOKIEDIR)/,$(ALL_STAGE_RULES) stage) stage: test $(ALL_STAGE_RULES) $(DONADA) # package - Convert the staging dir into an installable package. ALL_PACKAGE_RULES = $(addprefix package-,$(PACKAGE_RULES)) need-package: need-install @rm -rf $(addprefix $(COOKIEDIR)/,$(ALL_PACKAGE_RULES) package) package: stage $(ALL_PACKAGE_RULES) $(DONADA) PACKAGE_FAIL = ($(MAKE) need-package; false) # install - Install the package on the current system. need-install: @rm -rf $(COOKIEDIR)/install install: package @$(SCRIPTSDIR)/garstow --arch $(GARARCH_HOST) --root '$(archdir)' \ install-garball `cat $(COOKIEDIR)/garballs` \ || $(PACKAGE_FAIL) # reconfigure - Configure, without cleaning, and install again. # (This is only really useful if you've built successfully but made a change to # the source tree since -- e.g. stubbing out a test, or setting a configure # variable.) reconfigure: @$(MAKE) need-configure @$(MAKE) install # rebuild - Build, without cleaning, and install again. # (As above.) rebuild: @$(MAKE) need-build @$(MAKE) install # reinstall - Wipe out the staging dir and install again. reinstall: @$(MAKE) need-stage @$(MAKE) install # repackage - Rebuild the package metadata and garball only. repackage: @$(MAKE) need-package @$(MAKE) install # Update a package: clean out the old stuff, download a new version, # rebuild the checksums and install it. update: $(MAKE) clean $(MAKE) makesum $(MAKE) configure $(MAKE) install # The same, but only configure. upconf: $(MAKE) clean $(MAKE) makesum $(MAKE) configure # The clean rule. It must be run if you want to re-download a # file after a successful checksum (or just remove the checksum # cookie, but that would be lame and unportable). clean: @rm -rf $(DOWNLOADDIR) $(COOKIEDIR) $(WORKSRC) $(WORKDIR) $(EXTRACTDIR) $(SCRATCHDIR) $(SCRATCHDIR)-$(COOKIEDIR) $(STAGEDIR) $(PACKAGEDIR) *~ # these targets do not have actual corresponding files .PHONY: all fetch checksum makesum checksig garchive extract patch makepatch setup need-configure configure need-build build need-test test need-stage stage need-package package need-install install reconfigure rebuild reinstall update upconf ci clean .NOTPARALLEL: endif