# ReloadME makefile
# Requirements: GNU Make, JRE 3 to 8

# Common vars

SRCDIR := src
OUTDIR := out
SHELL = '/bin/bash'
OUTNAME := out.jar
CC = javac -Xlint:-options
CLDC_VER := $(shell cat "${SRCDIR}/Manifest.mf" | grep MicroEdition-Configuration | cut -d ':' -f 2 | cut -d '-' -f 2 | tr -d ' ')
MIDP_VER := $(shell cat "${SRCDIR}/Manifest.mf" | grep MicroEdition-Profile | cut -d ':' -f 2 | cut -d '-' -f 2 | tr -d ' ')
CLASSPATH := .:lib/cldc_${CLDC_VER}.jar:lib/midp_${MIDP_VER}.jar:$(shell find lib -type f -name "jsr*.jar" | tr '\n' ':')
SRCLIST := $(shell find ${SRCDIR} -type f -name "*.java" | tr '\n' ' ')

all: build

pre-build:
	mkdir -p ${OUTDIR}
	cp ${SRCDIR}/Manifest.mf ${OUTDIR}/

build: pre-build
	$(CC) -source 1.3 -target 1.3 -cp "${CLASSPATH}" -d "${OUTDIR}" -sourcepath "${SRCDIR}" ${SRCLIST}
	cd ${OUTDIR} && jar cvfm ../${OUTNAME} Manifest.mf $$(find . -type f -name "*.class" | tr '\n' ' ')

clean:
	rm -rf ${OUTDIR} ${OUTNAME}
