#!/usr/bin/env bash
# Makefile.nativeEnv

LIBXML20_CFLAGS += `pkg-config libxml-2.0 --cflags`
LIBXML20_LDFLAGS += `pkg-config libxml-2.0 --libs`

JSONC_CFLAGS += `pkg-config json-c --cflags`
JSONC_LDFLAGS += `pkg-config json-c --libs`

ZLIB_CFLAGS += `pkg-config zlib --cflags`
ZLIB_LDFLAGS += `pkg-config zlib --libs`

all: fastXmlLint

fastXmlLint: fastXmlLint.c
	gcc -O3 -Wall -pedantic -Wextra $(JSONC_CFLAGS) $(ZLIB_CFLAGS) $(LIBXML20_CFLAGS) \
		-c fastXmlLint.c\
		-o fastXmlLint_.o
	gcc -O3 -Wall -pedantic -Wextra -std=gnu1x fastXmlLint_.o  $(JSONC_LDFLAGS) $(ZLIB_LDFLAGS) $(LIBXML20_LDFLAGS)\
		-o fastXmlLint

# TODO automate this test one fine day
test:
	@echo "by executing fastXmlLint's main function we run all the contained tests"
	@echo "----------------------------------------------------------------------------------------"
	./fastXmlLint
	@echo "----------------------------------------------------------------------------------------"


# tests below show that our schema and html input files are in sync to the libxml2 implementation.
# we wrote these tests to have some documents to work with while developing fastXmlLint
html-rng-test:
	@echo "--------------------- test test_success1 ---------------------"
	xmllint --relaxng html5-rng/xhtml.rng test_success1.html
	@echo "--------------------- test test_fail1 ---------------------"
	xmllint --relaxng html5-rng/xhtml.rng test_fail1.html

libreoffice-rng-test:
	@echo "--------------------- test test_success1 ---------------------"
	xmllint --relaxng libreoffice-relax-ng-example/OpenDocument-schema-v1.1-errata01-complete.rng libreoffice-relax-ng-example/example1_success/content.xml
	xmllint --relaxng libreoffice-relax-ng-example/OpenDocument-schema-v1.1-errata01-complete.rng success_example3.xml

closure:
	closure_compiler/jcc rngLoader.js schemainfoCreator.js
	@echo "schemainfoCreator.js: 100% coverage, well done"

# use a virtual display for tests, see
# http://coreygoldberg.blogspot.de/2011/06/python-headless-selenium-webdriver.html
# from pyvirtualdisplay import Display
# from selenium import webdriver
schemainfo-test: closure
	@echo "WARNING: only tested with selenium >= 2.53, 2.44 won't work, see https://github.com/NixOS/nixpkgs/pull/15982"
	nix-shell -I nixpkgs=./nixpkgs -p python35Packages.selenium firefox-bin --command "python3 selenium_test.py"
	@echo "schemaInfo generating is working, very good"

clean:
	rm -rf fastXmlLint fastXmlLint_.o
