# Licensed to Stichting The Commons Conservancy (TCC) under one or more
# contributor license agreements.  See the AUTHORS file distributed with
# this work for additional information regarding copyright ownership.
# TCC licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

BUILD_NUMBER ?= 0

MAJOR_VERSION=0
MINOR_VERSION=9
RELEASE_VERSION=0
VERSION=$(MAJOR_VERSION).$(MINOR_VERSION).$(RELEASE_VERSION)
VERSIONEX=$(VERSION).$(BUILD_NUMBER)

TARGET_ROOT = $(PWD)/target/pkg
TARGET_APP = $(TARGET_ROOT)/Applications/Redwax\ SignText.app
TARGET_PKG = target/Redwax-SignText-$(VERSIONEX).pkg

FIREFOX_PATH = /Library/Application\ Support/Mozilla/NativeMessagingHosts

PROJ = xcodebuild -project Redwax\ SignText/Redwax\ SignText.xcodeproj -configuration Debug MARKETING_VERSION=$(VERSION) CURRENT_PROJECT_VERSION=$(BUILD_NUMBER)
PKG_BUILD = pkgbuild --version $(VERSION) --install-location /

all: pkg

clean:
	$(PROJ) clean
	rm -rf ./target

$(TARGET_ROOT): Redwax\ SignText/Redwax\ SignText/*.swift eu.redwax.Redwax.SignText.json
	$(PROJ) install DSTROOT=$(TARGET_ROOT)
	mkdir -p $@/$(FIREFOX_PATH)
	cp -v eu.redwax.Redwax.SignText.json $@/$(FIREFOX_PATH)/eu.redwax.Redwax.SignText.json

$(TARGET_PKG): $(TARGET_ROOT)
	$(PKG_BUILD) --root $< --identifier eu.redwax.Redwax.SignText "$@"

pkg: $(TARGET_PKG)