# Makefile for qcl-0.3
#
# This file is part of the Quantum Computation Language QCL.
# 
# (c) Copyright by Bernhard Oemer <oemer@tph.tuwien.ac.at>, 1998
# 
# This program comes without any warranty; without even the implied 
# warranty of merchantability or fitness for any particular purpose.
# 
#      This program is free software under the terms of the 
#      GNU General Public Licence (GPL) version 2 or higher

# Directory for Standard .qcl files

QCLDIR = /usr/local/lib/qcl

# Path for qcl binaries

QCLBIN = /usr/local/bin

# Debugging options

DEBUG = -g -DQCL_DEBUG -DQC_DEBUG
#DEBUG = -O2

# Comment out if you don't have GNU readline on your system

RLOPT = -DQCL_USE_READLINE
RLLIB = -lreadline -lncurses

# Replace with lex and yacc on non GNU systems (untested)

LEX = flex
YACC = bison
INSTALL = install

##### You shouldn't have to edit the stuff below #####

QCDIR = qc
QCLIB = $(QCDIR)/libqc.a
QCLINC = lib

CC = g++
CPP = $(CC) -E
CFLAGS = -c $(DEBUG) $(RLOPT) -I$(QCDIR) -DDEF_INCLUDE_PATH="\"$(QCLDIR)\""
LFLAGS = -L$(QCDIR) $(DEBUG) -lm -lfl -lqc $(RLLIB)

FILESCC = $(wildcard *.cc)
FILESH = $(wildcard *.h)

SOURCE = $(FILESCC) $(FILESH) qcl.lex qcl.y Makefile

OBJECTS = types.o syntax.o typcheck.o symbols.o error.o \
          lex.o yacc.o print.o quheap.o extern.o eval.o exec.o \
          parse.o options.o debug.o

all: do-it-all

ifeq (.depend,$(wildcard .depend))
include .depend
do-it-all: build
else
do-it-all: dep
	make
endif

#### Rules for depend

dep: lex.cc yacc.cc yacc.h $(QCLIB)
	for i in *.cc; do \
	  $(CPP) -I$(QCDIR) -MM $$i; \
	  echo -e '\t$(CC) $(CFLAGS)' $$i '\n'; \
	done > .depend

lex.cc: qcl.lex
	$(LEX) -olex.cc qcl.lex

yacc.cc: qcl.y
	$(YACC) -t -d -o yacc.cc qcl.y

yacc.h: yacc.cc
	mv yacc.cc.h yacc.h

$(QCLIB):
	cd $(QCDIR) && make libqc.a

#### Rules for build

build: qcl $(QCLINC)/default.qcl doc

qcl: $(OBJECTS) qcl.o $(QCLIB)
	$(CC) $(OBJECTS) qcl.o $(LFLAGS) -o qcl

$(QCLINC)/default.qcl: extern.cc
	grep "^//!" extern.cc | cut -c5- > $(QCLINC)/default.qcl

install: build
	$(INSTALL) -m 0755 -d $(QCLBIN) $(QCLDIR)
	$(INSTALL) -m 0755 ./qcl $(QCLBIN)
	$(INSTALL) -m 0644 ./lib/default.qcl $(QCLDIR)
	$(INSTALL) -m 0644 ./lib/dft.qcl $(QCLDIR)
	$(INSTALL) -m 0644 ./lib/expmod.qcl $(QCLDIR)
	$(INSTALL) -m 0644 ./lib/fanout.qcl $(QCLDIR)
	$(INSTALL) -m 0644 ./lib/functions.qcl $(QCLDIR)
	$(INSTALL) -m 0644 ./lib/modarith.qcl $(QCLDIR)
	$(INSTALL) -m 0644 ./lib/qufunct.qcl $(QCLDIR)
	$(INSTALL) -m 0644 ./lib/roulette.qcl $(QCLDIR)
	$(INSTALL) -m 0644 ./lib/shor.qcl $(QCLDIR)
	$(INSTALL) -m 0644 ./lib/swap.qcl $(QCLDIR)

#### Other Functions

SOURCEFILES = `ls $(SOURCE)`

edit:
	nedit -iconic $(SOURCEFILES) &

clean:
	rm -f *.o lex.* yacc.* .depend
	cd $(QCDIR) && make clean

clear: clean
	rm -f qcl qcl/default.qcl
	cd $(QCDIR) && make clear
	cd doc && make clear

#### Dokumentation

docs: 
	cd doc && make qcl.ps

