# (GNU) Makefile for Green Card (GHC)

### User serviceable parts  ###
HC      = /path/to/ghc
CC      = gcc
RM      = rm

# Options to compile the sources with.

# For GHC:
SRC_HC_OPTS    += -recomp -O -H12m


# Uncomment this if you're using a 'happy -g' parser.
# (the one shipped with the distribution is not.)
#Parse_HC_OPTS  += -cpp -fglasgow-exts -DBEGIN_GHC_ONLY='-}' -DEND_GHC_ONLY='{-'
Parse_HC_OPTS   += -H12m -Onot
Proc_HC_OPTS    += -H8m
GreenCard_HC_OPTS += -cpp -DBEGIN_GHC_ONLY='-}' -DEND_GHC_ONLY='{-' -DBEGIN_NOT_FOR_GHC='{-' -DEND_NOT_FOR_GHC='-}'

# Needed to work around problem of abstractly importing newtypes
# with 3.02 (and 3.01?)
#FillIn_HC_OPTS += -fno-prune-tydecls

#
# If you're compiling with a system that does support Haskell 98,
# set HASKELL98 to YES.
#
#ifeq "$(HASKELL98)" "YES"
#Process_HC_OPTS  += -cpp -DBEGIN_HASKELL98_SYSTEM='-}' -DEND_HASKELL98_SYSTEM='{-' 
#LexM_HC_OPTS     += -cpp -DBEGIN_HASKELL98_SYSTEM='-}' -DEND_HASKELL98_SYSTEM='{-' 
#endif


# For NHC:
#SRC_HC_OPTS = ???

# You only need to adjust these if you
# should need to change the parser
HAPPY = /path/to/happy

##### End of user serviceable parts  #####

SRCS = \
Casm.lhs DIS.lhs Decl.lhs ErrMonad.lhs FillIn.lhs \
FillInMonad.lhs FiniteMap.lhs GCToken.lhs GetOpt.lhs \
GreenCard.lhs Lex.lhs LexM.lhs ListUtils.lhs MarshallMonad.lhs \
Name.lhs NameSupply.lhs Package.lhs Pretty.lhs \
PrettyUtils.lhs Proc.lhs Process.lhs Target.lhs Type.lhs

BOOT_SRCS = Parse.hs
ALL_SRCS  = $(SRCS) $(BOOT_SRCS) ErrorHook.c
ALL_OBJS  = $(patsubst %, %.o,$(basename $(ALL_SRCS)))

HC_OPTS = $(SRC_HC_OPTS) $(WAY$(_way)_HC_OPTS) $($*_HC_OPTS) $(EXTRA_HC_OPTS)
CC_OPTS = $(SRC_CC_OPTS) $(WAY$(_way)_CC_OPTS) $($*_CC_OPTS) $(EXTRA_CC_OPTS)
HAPPY_OPTS =

# Generating dependcies
MKDEPEND      = $(HC) -M
MKDEPEND_OPTS = -optdep-f -optdep.depend
MKDEPEND_SRCS = $(SRCS) $(BOOT_SRCS)

# Targets
all	:: green-card

show :
	@echo $(ALL_OBJS)

depend ::
	@$(RM) .depend
	@touch .depend
	$(MKDEPEND) $(MKDEPEND_OPTS) $(HC_OPTS) $(MKDEPEND_SRCS)

clean ::
	rm -f *.o green-card

green-card :: $(ALL_OBJS)
	$(HC) $(HC_OPTS) -o green-card $(ALL_OBJS)

# Suffix rules (GNU make.)
%.o : %.lhs	 
	$(HC) $(HC_OPTS) -c $< -o $@

%.o : %.hs
	$(HC) $(HC_OPTS) -c $< -o $@

%.hi : %.o
	@:

%.hs : %.ly
	$(HAPPY) $(HAPPY_OPTS) $<

%.hs : %.lx
	$(LX) $(LX_OPTS) $<

%.o : %.c
	$(CC) $(CC_OPTS) -c $< -o $@

ErrorHook.o : ErrorHook.c
	$(HC) $(CC_OPTS) -c $< -o $@

# Dependencies
-include .depend
