# Type `make' for native code
# Type `make byte' for byte code instead of native code

VERSION = 1.3.0
export VERSION

SOURCES = \
  version.ml lexer.mli lexer.mll \
  parser_directive.mly directive.ml main.ml
RESULT = camlmix

.PHONY: default native byte all opt install www version force clean veryclean

default: native
native: version nc
byte: version bc

ifndef PREFIX
  PREFIX := $(shell dirname `which ocaml`)/..
endif
export PREFIX

all: byte
opt: native
install:
	install -m 0755 $(addsuffix $(EXE), \
			$(sort $(BCRESULT) $(NCRESULT))) $(PREFIX)/bin/

www: all test install archive

version:
	contents='let version = "$(VERSION)"'; \
	  if test "`cat version.ml`" != "$$contents"; then \
	    echo "$$contents" > version.ml;\
	  fi

.PHONY: examples
examples:
	cd examples && $(MAKE)

force:
	$(MAKE) clean
	$(MAKE)
	$(MAKE) archive

ARCHIVE_FILES = \
  $(SOURCES) OCamlMakefile Makefile \
  LICENSE INSTALL \
  examples/

archive:
	$(MAKE) && $(MAKE) examples
	cp examples/test.html version.ml LICENSE $$WWW/camlmix/
	rm -rf /tmp/camlmix-$(VERSION) && mkdir -p /tmp/camlmix-$(VERSION) && \
          cp -r $(ARCHIVE_FILES) /tmp/camlmix-$(VERSION) && \
	  (cd /tmp/camlmix-$(VERSION) && $(MAKE) veryclean) && \
          cd /tmp && tar czf camlmix-$(VERSION).tar.gz camlmix-$(VERSION) && \
          cd /tmp && tar cjf camlmix-$(VERSION).tar.bz2 camlmix-$(VERSION)
	mv /tmp/camlmix-$(VERSION).tar.gz /tmp/camlmix-$(VERSION).tar.bz2 \
		$$WWW/camlmix/

TRASH = META.mlx.ml langmix.* camlmix.exe
MORETRASH = *~

clean::
	cd examples && $(MAKE) clean

veryclean: clean
	rm -f $(MORETRASH)

LIBS = unix

OCAMLMAKEFILE = OCamlMakefile
include $(OCAMLMAKEFILE)
