# defines
VENDOR := jcomeau.com
APPNAME := minimo
DESCRIPTION := MiniMozilla
LONGDESCRIPTION := $(DESCRIPTION)
ABSBINDIR := bin
MOZILLA := /cygdrive/c/builds/wince/arm_ppc/dist/bin
WINMOZILLA := $(shell cygpath -w $(MOZILLA))
INSTALLER := $(APPNAME)setup.exe
export
# rules
$(ABSBINDIR)/$(INSTALLER): $(APPNAME).CAB readme.txt license.txt $(APPNAME).ini
	ezsetup -l english -i $(APPNAME).ini -r readme.txt -e license.txt -o $@
$(APPNAME).inf: $(MOZILLA) $(APPNAME).inf.template Makefile
	DIRS= && DIR=1 && \
	for dir in $$(find $< -type d); do \
	 DIRS=$$(printf "%s\n%s = ,\"%s\",,%s " \
	 "$$DIRS" $$DIR "$$(basename $$dir) $$DIR" "$$(cygpath -w $$dir)"); \
	 DIR=$$((DIR + 1)); \
	done; \
	FILES= && DIR=1 && \
	for dir in $$(cd $< && find . -type d); do \
	 for file in $$(find $</$$dir -maxdepth 1 -type f); do \
	  FILES=$$(printf "%s\n%s = $$DIR" "$$FILES" "$$(basename $$file)"); \
	 done; DIR=$$((DIR + 1)); \
	done; \
	COPYFILES= && DESTDIRS= && DIR=1 && \
	for dir in $$(cd $< && find . -type d); do \
	 if [ "$$COPYFILES" ]; then COPYFILES="$$COPYFILES, "; fi; \
	 COPYFILES="$$COPYFILES\"$$(basename $$dir | sed s/\\./root/)$$DIR\""; \
	 DESTDIRS=$$(printf "%s\n\"%s\" = 0, %%InstallDir%%\%s" \
	  "$$DESTDIRS" "$$(basename $$dir | sed s/\\./root/)$$DIR" \
	 "$$(cygpath -w $$dir)"); \
	 DIR=$$((DIR + 1)); \
	done; \
	DESTFILES= && DIR=1 && \
	for dir in $$(cd $< && find . -type d); do \
	 DESTFILES=$$(printf "%s\n[%s]\n" \
	  "$$DESTFILES" "$$(basename $$dir | sed s/\\./root/)$$DIR"); \
	 for file in $$(find $</$$dir -maxdepth 1 -type f); do \
	  DESTFILES=$$(printf "%s\n\"%s\"" \
	   "$$DESTFILES" "$$(basename $$file)"); \
	 done; DIR=$$((DIR + 1)); \
	done; \
	template=$$(< $@.template) && \
	 eval "echo \"$$template\"" > $@
	unix2dos $@
# might be necessary to use /cpu HPCPRO_ARM which generates app.HPCPRO_ARM.cab
%.CAB: %.inf
	cabwiz $<
readme.txt: /usr/src/mozilla/README.txt
	unix2dos < $< > $@
license.txt: /usr/src/mozilla/LICENSE
	unix2dos < $< > $@
%: %.template
	template=$$(< $<) && \
	 eval "echo \"$$template\"" > $@
checkenv:
	set
ppcinstall: $(ABSBINDIR)/$(INSTALLER)
	$(ABSBINDIR)/$(INSTALLER)
clean:
	rm -f *.ini *.inf *.exe *.list
