.EXPORT_ALL_VARIABLES:

SHELL := /bin/bash
DIST := xenial bionic centos7

################################
# NOTICE:
# ------
# Centos nginx version and package name is intentionally hardcodded
# Ported from https://git.xarth.tv/kmullin/twitch-packages
# The following is only used for ubuntu builds
################################
PACKAGE_NAME ?= video-nginx
PACKAGE_VERSION ?= 1.20.1

UNAME := $(shell uname -s)
ifeq ($(UNAME),Linux)
    OS := linux
    WGET := wget -c -q
else
    OS := darwin
    WGET := curl -fsSO
endif
PACKER_VERSION = 1.7.2
PACKER_ARCHIVE := packer_$(PACKER_VERSION)_$(OS)_amd64.zip

all: packer $(DIST)

$(PACKER_ARCHIVE):
	$(WGET) "https://releases.hashicorp.com/packer/$(PACKER_VERSION)/$(PACKER_ARCHIVE)"

packer: clean $(PACKER_ARCHIVE)
	unzip $(PACKER_ARCHIVE)

xenial: clean
	./packer build -var-file=src/variables/xenial.json src/packer.json
bionic: clean
	./packer build -var-file=src/variables/bionic.json src/packer.json
centos7: clean
	./packer build -var-file=src/variables/centos7.json src/packer.json
clean:
	rm -rf ip-*-twitch/ packer

.PHONY: all $(DIST) clean download
