gems/Makefile
2021-05-27 17:37:41 -03:00

41 lines
1.5 KiB
Makefile

SHELL := bash
.DEFAULT_GOAL := help
.env:
cp .env.example $@
include .env
ccache_dir ?= $(HOME)/.ccache
gem_dir := .
gem_cache_dir := $(gem_dir)/cache
gem_binary_dir := $(gem_dir)/gems/$(ALPINE_VERSION)
help: always ## Ayuda
@grep "^[^\t]\+:.*##" Makefile | sed -re "s/(.*):.*##(.*)/\1;\2/" | column -s ";" -t | sed -re "s/^([^ ]+) /\x1B[38;5;197m\1\x1B[0m/"
%: ## Compila la gema (make puma v=5.3.0)
@test -n "$v" || echo "Falta la versión en el argumento v=" ; :
@test -n "$v" || exit 1
$(MAKE) $(gem_binary_dir)/$@-$(v)-x86_64-linux-musl.gem
# Compila la gema si no existe
$(gem_binary_dir)/%-x86_64-linux-musl.gem:
@echo "Compilando $*"
@test -n "$(HTTP_BASIC_USER)" || echo "Agrega las credenciales en el archivo .env" ; :
@test -n "$(HTTP_BASIC_USER)" || exit 1
@test -n "$(HTTP_BASIC_PASSWORD)" || echo "Agrega las credenciales en el archivo .env" ; :
@test -n "$(HTTP_BASIC_PASSWORD)" || exit 1
@echo "$(PATH)" | grep -q ccache || "Instala ccache para acelerar la compilación"
@docker run \
-v $(shell realpath "$(gem_dir)"):/srv/gems \
-v $(shell realpath "$(ccache_dir)"):/home/builder/.ccache \
-e HTTP_BASIC_USER="$(HTTP_BASIC_USER)" \
-e HTTP_BASIC_PASSWORD="$(HTTP_BASIC_PASSWORD)" \
-e GEM=$(shell echo $(notdir $*) | sed -re "s/-[^-]+$$//") \
-e VERSION=$(shell echo $(notdir $*) | sed -re "s/.*-([^-]+)$$/\1/") \
-e JOBS=$(shell grep processor /proc/cpuinfo | wc -l) \
--rm -it \
sutty/gem-compiler:latest || echo "No se pudo compilar $*"
.PHONY: always