## -*- mode: Makefile -*-
##
## Copyright (c) 2000 University of Utah and the Flux Group.
## All rights reserved.
## 
## This file is part of the Knit component composition software.
## 
## Permission to use, copy, modify, distribute, and sell this software and
## its documentation is hereby granted without fee, provided that the above
## copyright notice and this permission/disclaimer notice is retained in all
## copies or modified versions, and that both notices appear in supporting
## documentation.  THE COPYRIGHT HOLDERS PROVIDE THIS SOFTWARE "AS IS" AND
## WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION,
## THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
## PURPOSE.  THE COPYRIGHT HOLDERS DISCLAIM ANY LIABILITY OF ANY KIND FOR
## ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
## 
## Users are requested, but not required, to send to csl-dist@cs.utah.edu any
## improvements that they make and grant Univ. of Utah redistribution rights.
##

###############################################################################
#
# This Makefile builds the programs that don't depend on which Haskell compiler
# you use.
#
# This Makefile is generally invoked indirectly through one of the Makefiles
# ``below us'' in the tree: i.e., either `compiler/ghc/GNUmakerules' or
# `compiler/hugs/GNUmakerules'.  This is because we aren't yet being so clever
# as to figure out whether the user wants GHC-based Knit or Hugs-based Knit.
#
# So, the user chooses by invoking `make' in one of the subdirectories, and
# those Makefiles ``recurse'' back up to here.
#
# Eventually, we'll sort things out so that *this* file invokes *those* files,
# not the other way 'round!
#
###############################################################################

BUILD_DIR=$(TOP_OBJDIR)/bin

vpath % $(SRCDIR)

# This goes first to make it the default.
.PHONY: all
all		::

.PHONY: install
install		::

.PHONY: clean
clean		::

.PHONY: veryclean
veryclean	:: clean

###############################################################################
# mk_unit
###############################################################################

all     :: $(BUILD_DIR)/mk_unit

$(BUILD_DIR)/mk_unit: mk_unit
	$(CP) $< $@

veryclean ::
	$(RM) $(BUILD_DIR)/mk_unit

###############################################################################
# knit_smartmv
###############################################################################

all     :: $(BUILD_DIR)/knit_smartmv

$(BUILD_DIR)/knit_smartmv: knit_smartmv
	$(CP) $< $@

veryclean ::
	$(RM) $(BUILD_DIR)/knit_smartmv

###############################################################################
# Object file renaming tool
###############################################################################

all     :: $(BUILD_DIR)/rename_dot_o_files

$(BUILD_DIR)/rename_dot_o_files: rename_dot_o_files.c
	$(CC) -o $@ $(CPPFLAGS) $(DEFS) $(CFLAGS) $(LDFLAGS) $^ $(LIBS)

veryclean ::
	$(RM) $(BUILD_DIR)/rename_dot_o_files

###############################################################################
# C parsing support
###############################################################################

YFLAGS	= -dv
LFLAGS	=

SRC	= gram.y scan.l main.c sexpr.c
OBJ	= gram.o scan.o main.o sexpr.o

all :: $(BUILD_DIR)/knit_c_parser

$(BUILD_DIR)/knit_c_parser: $(OBJ)
	$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBS)

veryclean ::
	$(RM) $(BUILD_DIR)/knit_c_parser

gram.o	: sexpr.h
gram.o  : gram.c
	$(CC) -c -I. -I$(SRCDIR)/.. $(CPPFLAGS) $(DEFS) $(CFLAGS) $<
scan.o	: y.tab.h
scan.o	: scan.c
	$(CC) -c -I. -I$(SRCDIR)/.. $(CPPFLAGS) $(DEFS) $(CFLAGS) $<

y.tab.h y.output gram.c : gram.y
# Should say: .INTERMEDIATE: y.tab.h gram.c

clean	::
	$(RM) y.tab.h y.output gram.c *.o *.so
	$(RM) xxx yyy zzz foo.c script.sh

###############################################################################
# Installation rules
###############################################################################

###############################################################################
# End of Makefile
###############################################################################

