pkg: new build system

This commit is contained in:
Thomas Hobson 2021-03-05 22:16:17 +13:00
parent d1b41e3c2f
commit eba1d3abcd
No known key found for this signature in database
GPG Key ID: 9F1FD9D87950DB6F
3 changed files with 24 additions and 114 deletions

4
packages/.gitignore vendored
View File

@ -1,3 +1,3 @@
build/ */build
*/output
*.pkg.tar.gz *.pkg.tar.gz
*.tf

View File

@ -1,40 +1,29 @@
# Wraps all other Makefiles PACKAGES=$(shell find * -maxdepth 0 -type d)
BUILD_PLATFORM=$(or ${PLATFORM},baremetal-$(shell grep -oP "^ID=\K.+" /etc/os-release))
# Variables help:
PKG_FILES=$(filter-out common.mk,$(wildcard *.mk)) @echo "You probably don't want to build all package"
PKG_SLUGS=$(foreach pkg, ${PKG_FILES}, $(addprefix $(shell make -f ${pkg} name VERSION=UNKNOWN)-, $(shell make -f ${pkg} versions VERSION=UNKNOWN))) @echo "If you do run $`make build-all$`"
@echo
@echo "Run $`make [language]-[version].pkg.tar.gz$` to build a specific language"
# Functions build build-all: $(addsuffix .pkg.tar.gz, ${PACKAGES})
CALL_MAKE=$(shell make -f $1 $2 VERSION=UNKNOWN) clean clean-all: $(addprefix clean-, ${PACKAGES})
define pkg_info clean-%: %/
$(eval PKG_SLUG=$(patsubst $1-%,%,$2)) rm -rf $</build $</output
$(eval PKG_VERSION=$(lastword $(subst -, ,${PKG_SLUG})))
$(eval PKG_NAME=$(patsubst %-${PKG_VERSION},%,${PKG_SLUG})) %.pkg.tar.gz: %/output %/run %/environment %/pkg-info.json
$(eval PKG_FILE=$(shell grep '^VERSIONS\s*=.*${PKG_VERSION}' $(shell grep "NAME\s*=\s*${PKG_NAME}" ${PKG_FILES} -l) -l)) rm -f $@
endef tar czf $@ -C $* $(patsubst $*/%,%,output run environment pkg-info.json $(shell find $*/compile)) --transform='s|output|$*|;s|environment|$*/environment|'
%/pkg-info.json: %/metadata.json
jq '.build_platform="${BUILD_PLATFORM}"' $< > $@
%/output: %/ %/build.sh
cd $< && chmod +x ./build.sh && ./build.sh
define per-lang
build-$(call CALL_MAKE, $1, name):: $$(addprefix build-$(call CALL_MAKE, $1, name)-, $$(call CALL_MAKE, $1, versions))
clean-$(call CALL_MAKE, $1, name):: $$(addprefix clean-$(call CALL_MAKE, $1, name)-, $$(call CALL_MAKE, $1, versions))
endef
# Targets
$(foreach e,${PKG_FILES}, $(eval $(call per-lang,${e})))
build build-all: $(foreach pkg, ${PKG_FILES}, build-$(call CALL_MAKE, ${pkg}, name))
$(addprefix build-, ${PKG_SLUGS}):
$(call pkg_info,build,$@)
$(MAKE) -f ${PKG_FILE} VERSION=${PKG_VERSION} build
clean clean-all: $(foreach pkg, ${PKG_FILES}, clean-$(call CALL_MAKE, ${pkg}, name))
rm -rf build/
$(addprefix clean-, ${PKG_SLUGS}):
$(call pkg_info,clean,$@)
$(MAKE) -f ${PKG_FILE} VERSION=${PKG_VERSION} clean

View File

@ -1,79 +0,0 @@
# Variables
PKG_SLUG=${NAME}-${VERSION}
BUILD_DIR=build/${PKG_SLUG}/
BIN_DIR=${BUILD_DIR}${PKG_SLUG}/
RUN_FILE=${BUILD_DIR}run
COMPILE_FILE=${BUILD_DIR}compile
ENV_FILE=${BIN_DIR}environment
INFO_FILE=${BUILD_DIR}pkg-info.json
PREFIX=/piston/packages/${NAME}/${VERSION}/${PKG_SLUG}
PKG_FILE=${PKG_SLUG}.pkg.tar.gz
VERSION_MINOR=$(shell grep -oP "\d+.\d+"<<<${VERSION})
VERSION_MAJOR=$(shell grep -oP "\d+"<<<${VERSION})
PKG_TARGETS=${BIN_DIR} ${ENV_FILE} ${RUN_FILE} ${INFO_FILE}
# Command Targets
.PHONY: catch versions name build clean
catch:
# Catch manual calling
# This is done to make sure people don't call without ${VERSION}, which can cause problems
@echo "Don't directly call individual scripts, instead call the common Makefile"
@exit 1
versions:
@echo ${VERSIONS}
name:
@echo ${NAME}
.NOTPARALLEL: build
build: ${BUILD_DIR} ${PKG_FILE} ${PKG_SLUG}.tf
clean:
rm -rf ${BUILD_DIR}
rm -f ${PKG_FILE}
rm -f ${PKG_SLUG}.tf
# mkdir
${BUILD_DIR}:
mkdir -p ${BUILD_DIR}
# Generated files
ifeq (${COMPILED}, true)
${PKG_FILE}: ${PKG_TARGETS} ${COMPILE_FILE}
endif
${PKG_FILE}: ${PKG_TARGETS}
tar -czC ${BUILD_DIR} -f $@ ${patsubst ${BUILD_DIR}%,%,$?}
$(patsubst %.json,%.jq,${INFO_FILE}):
echo '.language="${NAME}"' > $@
echo '.version="${VERSION}"' >> $@
echo '.author="${AUTHOR}"' >> $@
echo '.dependencies={}' >> $@
echo '.build_platform="$(or ${PLATFORM}, baremetal-$(shell grep -oP "^ID=\K\w+" /etc/os-release ))"' >> $@
$(foreach dep, ${DEPENDENCIES}, echo '.dependencies.$(word 1,$(subst =, ,${dep}))="$(word 2,$(subst =, ,${dep}))"' >> $@)
${PKG_SLUG}.tf:
cp ${NAME}.test $@
# Helpers
%/: %.tar.gz
mkdir -p $@
tar xzf $< --strip-components=1 -C $@
%/: %.tar.xz
mkdir -p $@
tar xf $< --strip-components=1 -C $@
%/: %.zip
mkdir -p $@
unzip $< -d $@
%.json: %.jq
jq '$(shell tr '\n' '|' < $<).' <<< "{}" > $@