# Programa Python, motor JavaScript y simbolos incluidos; sin Siru ni Calcula.
PREFIX ?= /usr/local
prefix ?= $(PREFIX)
DESTDIR ?=
PYTHON ?= python3
NPM ?= npm
PRUEBA ?= 0
PARA ?= deb
CANAL ?= inestable
DESCARGAS ?=
LISTA_PAQUETES ?= ../subir.lista
SUMMAPACK_BIN ?=
CREAR_FUENTES = $(firstword $(wildcard ../summapack/bin/crear-fuentes /usr/bin/crear-fuentes /usr/local/bin/crear-fuentes))

.PHONY: all check install uninstall remove clean dist pkg deb rpm tgz subir bajar help
all: node_modules/.bin/netlistsvg

node_modules/.bin/netlistsvg: package.json package-lock.json
	$(NPM) ci --omit=dev --ignore-scripts --no-audit --no-fund

check: all
	$(PYTHON) pruebas/formas.py
	$(PYTHON) pruebas/paquetes.py

# Instalar no descarga dependencias ni ejecuta pruebas.
install:
	$(PYTHON) instalar.py "$(prefix)" "$(DESTDIR)"

uninstall remove:
	$(PYTHON) instalar.py --uninstall "$(prefix)" "$(DESTDIR)"

subir:
	$(PYTHON) paquetes.py subir --prueba="$(PRUEBA)" --lista="$(LISTA_PAQUETES)" --bin="$(SUMMAPACK_BIN)"

bajar:
	$(PYTHON) paquetes.py bajar --prueba="$(PRUEBA)" --para="$(PARA)" --canal="$(CANAL)" --destino="$(DESCARGAS)" --bin="$(SUMMAPACK_BIN)"

clean:
	@echo 'dibuja no genera objetos de compilacion.'

dist:
	@test -n "$(CREAR_FUENTES)" || { echo 'Falta crear-fuentes de SummaPack' >&2; exit 1; }
	$(CREAR_FUENTES) .

rpm: export SUMMA_REQUIERE_RPM=1

pkg deb rpm tgz:
	sp paquete $(CURDIR)/dibuja

help:
	@echo 'make; make check; sudo make install (PREFIX=/usr/local por omision)'
	@echo 'make install PREFIX="$$HOME/.local"; make uninstall con el mismo PREFIX'
	@echo 'sp paquete dibuja; sp binarios dibuja ubuntu'
	@echo 'make dist genera el archivo de fuentes sin instalar'
	@echo 'make subir PRUEBA=1; make subir (canal inestable)'
	@echo 'make bajar PARA=deb CANAL=inestable DESCARGAS=/ruta'
