#  C->Haskell Compiler: makefile for the marshaling library
#
#  Author : Manuel M. T. Chakravarty
#  Derived: 19 March 1999
#
#  Version $Revision: 1.18 $ from $Date: 2004/05/15 08:34:50 $
#
#  Copyright (c) [1999..2003] Manuel M. T. Chakravarty
#
#  This file is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This file is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  = DOCU =====================================================================
#
#  * Originally, derived from `c2hs/gen/Makefile'.
#
#  * The files in this part are not linked into `c2hs', but instead contain
#    routines used at runtime by the code generated by `c2hs'.
#

#  ***************************************
#  !!! This makefile requires GNU make !!!
#  ***************************************

# info for this part: its package, name, sources and objects files (must be 
# before the include due to conditionals etc in `common.mk')
#
PACKAGE = c2hs
PART    = lib
SRCS	= C2HS.hs C2HSBase.hs C2HSMarsh.hs
OBJS	= $(patsubst %.hs,%.o,$(filter %.hs,$(SRCS)))

# C->Haskell specific configuration
#
-include ../mk/config.mk
include  ../../mk/common.mk
-include $(DEPEND)

# The code in this part is independent from the compiler code; so forget about
# all the other directories
#
VPATH =
HIDIRS=.

# We have our own dependcy computations here, as the library modules are 
# independent from the c2hs compiler modules.
#
.PHONY: depend
depend:
	$(MKDEPENDHS) -optdep-f -optdep$(DEPEND) $(HCFLAGS)\
	  $(EXTRAMKDEPENDOPTS) $(SRCS)

# Extra flags for the Haskell compiler
#
# * The following enables the use of the FFI; if we are building a package, 
#   one more extra option is needed.
#
EXTRAHCFLAGS = -ffi $(LIB_HCFLAGS)

# make all object files
#
objs: $(OBJS)

# target for building the archive of the marshaling library
#
libc2hs: libc2hs.a
libc2hs.a: $(OBJS)
	-$(RM) $@
	$(AR) -crs $@ $(OBJS)

# make all
#
all: libc2hs
default: all

# misc targets
#
.PHONY: clean cleanhi

clean:
	-$(RM) *.o libc2hs.a
cleanhi:
	-$(RM) *.hi
