<commit_before>REPO        ?= precursors_server

.PHONY: rel deps

all: compile

compile: deps
	./rebar compile

deps:
	./rebar get-deps

clean: testclean
	./rebar clean

distclean: clean relclean
	./rebar delete-deps


TEST_LOG_FILE := eunit.log
testclean:
	@rm -f $(TEST_LOG_FILE)

eunit: clean deps compile
	./rebar eunit skip_deps=true

test: deps compile testclean
	./rebar eunit skip_deps=true

script: compile
	./rebar escriptize skip_deps=true

rel: compile
	./rebar generate skip_deps=true

relclean:
	rm -rf rel/$(REPO)

devrel: rel
	rm -rf rel/$(REPO)/lib/$(REPO)*; ln -sf $(abspath .) rel/$(REPO)/lib/$(REPO)-1;<commit_msg>Reworked Makefile to add help, build certs, build devrel less hackishly, create dev-precursors_server script to replace devboot, correctly use .PHONY, etc.<commit_after># Variables
REPO ?= precursors_server
PRIVDIR ?= priv
RELDIR ?= $(REPO)
DEVRELDIR ?= dev


# The default target
all: compile


# Targets that don't correspond to the name of a file
.PHONY: all help deps compile script cert rel devrel
.PHONY: clean-deps clean-cert clean-rel clean-test clean distclean


.DEFAULT:
	$(error "Unrecognized target '$@'! Try 'make help'.")


# Help!
help:
	@echo "Targets:"
	@echo "    all            same as 'compile', below"
	@echo "    help           display this help message"
	@echo
	@echo "    deps           fetch all dependencies"
	@echo "    compile        compile the project"
	@echo "    script         run 'escriptize' to generate an executable script for the project"
	@echo "    devcert        generate an SSL certificate for development"
	@echo "    rel            generate a production release"
	@echo "    devrel         generate a development release"
	@echo
	@echo "    clean          clean up after 'compile' and 'test'"
	@echo "    clean-deps     clean up after 'deps'"
	@echo "    clean-devcert  clean up after 'devcert'"
	@echo "    clean-rel      clean up after 'rel'"
	@echo "    clean-devrel   clean up after 'devrel'"
	@echo "    clean-test     clean up after 'test'"
	@echo "    distclean      clean up everything possible"


# Building
deps:
	./rebar get-deps

compile: deps
	./rebar compile

script: compile
	./rebar escriptize skip_deps=true


# SSL certificates
SSL_CERT ?= $(PRIVDIR)/precursors.crt
SSL_CSR ?= $(PRIVDIR)/precursors.csr
SSL_KEY ?= $(PRIVDIR)/key
SSL_PUBKEY ?= $(SSL_KEY).pub
SSL_CSR_SUBJECT ?= "/C=US/ST=Texas/L=Lubbock/O=Skewed Aspect/CN=$(shell hostname).$(shell dnsdomainname)"

$(SSL_KEY):
	@echo "Generating RSA key..."
	openssl genpkey -algorithm rsa -pass pass: -out $@

$(SSL_CSR): $(SSL_KEY)
	@echo "Generating Certificate Signing Request..."
	openssl req -new -subj $(SSL_CSR_SUBJECT) -key $< -out $@

$(SSL_CERT): $(SSL_CSR) $(SSL_KEY)
	@echo "Generating self-signed for a year..."
	openssl x509 -req -days 365 -in $< -signkey $(SSL_KEY) -out $@

devcert: $(SSL_CERT)


# Building releases
rel/$(RELDIR) rel/$(DEVRELDIR): compile
	./rebar generate target_dir=$(@F) skip_deps=true

rel: rel/$(RELDIR)

dev-$(REPO):
	@echo "#!/bin/bash" > dev-$(REPO)
	@echo 'exec $(abspath rel/$(DEVRELDIR)/bin/$(REPO)) "$$@"' >> dev-$(REPO)
	chmod +x dev-$(REPO)

devrel: rel/$(DEVRELDIR) dev-$(REPO)
	-rm -rf rel/$(DEVRELDIR)/lib/$(REPO)*
	ln -sf $(abspath .) rel/$(DEVRELDIR)/lib/$(REPO)-1


# Testing
#FIXME: Why are these two identical, with slightly different deps?
eunit: clean deps compile
	./rebar eunit skip_deps=true

test: deps compile testclean
	./rebar eunit skip_deps=true


# Cleanup
clean-deps: clean
	./rebar delete-deps

clean-devcert:
	-rm -f $(SSL_CERT) $(SSL_CSR) $(SSL_KEY) $(SSL_PUBKEY)

clean-rel:
	-rm -rf rel/$(RELDIR)

clean-devrel:
	-rm -f dev-$(REPO)
	-rm -rf rel/$(DEVRELDIR)

TEST_LOG_FILE := eunit.log
clean-test:
	-rm -f $(TEST_LOG_FILE)

clean: clean-test
	./rebar clean

distclean: clean clean-deps clean-devcert clean-rel clean-devrel
{'fraction_non_alphanumeric': 0.13680104031209364, 'fraction_numerical': 0.002080624187256177, 'mean_word_length': 3.472093023255814, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2413387', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1425, 'n_words': 408}