piston/packages/common.mk

79 lines
1.8 KiB
Makefile
Raw Normal View History

2021-02-27 06:28:08 +01:00
# Variables
PKG_SLUG=${NAME}-${VERSION}
BUILD_DIR=build/${PKG_SLUG}/
2021-02-19 04:09:56 +01:00
2021-02-27 06:28:08 +01:00
BIN_DIR=${BUILD_DIR}${PKG_SLUG}/
RUN_FILE=${BUILD_DIR}run
COMPILE_FILE=${BUILD_DIR}compile
ENV_FILE=${BIN_DIR}environment
2021-02-27 10:43:02 +01:00
INFO_FILE=${BUILD_DIR}pkg-info.json
PREFIX=/piston/packages/${NAME}/${VERSION}/${PKG_SLUG}
2021-02-19 04:09:56 +01:00
2021-02-27 06:28:08 +01:00
PKG_FILE=${PKG_SLUG}.pkg.tar.gz
2021-02-27 06:28:08 +01:00
VERSION_MINOR=$(shell grep -oP "\d+.\d+"<<<${VERSION})
VERSION_MAJOR=$(shell grep -oP "\d+"<<<${VERSION})
2021-02-19 04:09:56 +01:00
2021-02-27 06:28:08 +01:00
PKG_TARGETS=${BIN_DIR} ${ENV_FILE} ${RUN_FILE} ${INFO_FILE}
2021-02-19 04:09:56 +01:00
2021-02-19 06:06:07 +01:00
2021-02-27 06:28:08 +01:00
# Command Targets
2021-02-19 06:53:26 +01:00
2021-02-27 06:28:08 +01:00
.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
2021-02-20 15:29:47 +01:00
2021-02-27 06:28:08 +01:00
versions:
@echo ${VERSIONS}
name:
@echo ${NAME}
.NOTPARALLEL: build
build: ${BUILD_DIR} ${PKG_FILE} ${PKG_SLUG}.tf
2021-02-19 04:48:46 +01:00
clean:
2021-02-27 06:28:08 +01:00
rm -rf ${BUILD_DIR}
rm -f ${PKG_FILE}
rm -f ${PKG_SLUG}.tf
2021-02-27 06:28:08 +01:00
# mkdir
${BUILD_DIR}:
mkdir -p ${BUILD_DIR}
# Generated files
2021-02-19 06:53:26 +01:00
2021-02-27 06:28:08 +01:00
ifeq (${COMPILED}, true)
${PKG_FILE}: ${PKG_TARGETS} ${COMPILE_FILE}
endif
${PKG_FILE}: ${PKG_TARGETS}
tar -czC ${BUILD_DIR} -f $@ ${patsubst ${BUILD_DIR}%,%,$?}
2021-02-19 06:06:07 +01:00
2021-02-27 10:43:02 +01:00
$(patsubst %.json,%.jq,${INFO_FILE}):
2021-02-27 06:28:08 +01:00
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 $@
2021-02-27 06:28:08 +01:00
# Helpers
%/: %.tar.gz
mkdir -p $@
tar xzf $< --strip-components=1 -C $@
2021-02-27 07:50:23 +01:00
%/: %.tar.xz
mkdir -p $@
tar xf $< --strip-components=1 -C $@
%/: %.zip
mkdir -p $@
unzip $< -d $@
2021-02-27 06:28:08 +01:00
%.json: %.jq
jq '$(shell tr '\n' '|' < $<).' <<< "{}" > $@