############################################################################
#                                                                          #
#  Make file for compiling the Nonpareil compiler                          #
#  Jeffrey H. Kingston                                                     #
#                                                                          #
#     make              Compile the Nonpareil compiler                     #
#     make npc          Ditto                                              #
#     make clean        Undo the effect of "make npc".                     #
#                                                                          #
#  Mail jeff@it.usyd.edu.au if you have any problems.                      #
#                                                                          #
############################################################################

############################################################################
#                                                                          #
#  NPC_LIB_DIR                                                             #
#                                                                          #
#  The full path name of the compiler's library directory.  This is        #
#  ordinarily directory lib in this directory; if this makefile is         #
#  run in this directory, the value below will be right.                   #
#                                                                          #
#  Various files needed by the Nonpareil compiler are stored in the lib    #
#  directory; for full information about them, see lib/README.  The        #
#  name has to be a full path name because otherwise the directory         #
#  will not be locatable when the compiler is run in other directories,    #
#  as it usually is.                                                       #
#                                                                          #
#  You can move this directory to somewhere else if you like, as long      #
#  as you give the full path name below.  But there doesn't seem to be     #
#  any point in moving it.                                                 #
#                                                                          #
############################################################################

NPC_LIB_DIR = $(CURDIR)/lib


############################################################################
#                                                                          #
#  NPC_DIR_SEP                                                             #
#                                                                          #
#  The string used to separate directories within path names.              #
#                                                                          #
############################################################################

NPC_DIR_SEP = /


############################################################################
#                                                                          #
#  NPC_C_COMPILER                                                          #
#                                                                          #
#  The compiler called by npc to compile the C code that it generates,     #
#  with any applicable flags.                                              #
#                                                                          #
############################################################################

NPC_C_COMPILER = gcc -g -ansi -pedantic -Wall


############################################################################
#                                                                          #
#  Dependencies                                                            #
#                                                                          #
#  It has not been thought worthwhile to track the dependencies between    #
#  files in full detail.  Instead, a coarse classification into three      #
#  groups has been made, and dependencies worked out for each group:       #
#                                                                          #
#  (1) $(LOBJS) are library modules conceived independently of the         #
#      Nonpareil compiler but used freely throughout it.  To emphasise     #
#      their separate reusability, they have their own header files, and   #
#      separate dependency lists below, not including externs.h.           #
#                                                                          #
#  (2) $(EOBJS), representing the different kinds of expressions, are a    #
#      distinguished group.  The compiler in general is only aware of the  #
#      existence of the EXPR type and operations on EXPR types generally,  #
#      as defined in externs.h, whereas the $(EOBJS) files know about and  #
#      implement these functions for particular expression types, defined  #
#      in expr.h, so they depend on expr.h as well as externs.h.           #
#                                                                          #
#  (3) $(OBJS), the remaining files, depend on externs.h but not expr.h.   #
#      They are classified into $(FOBJS) (front-end function classes),     #
#      $(BOBJS) (back-end function classes), and $(OOBS) (other); but      #
#      the dependencies are the same in each case.                         #
#                                                                          #
############################################################################

CC	= gcc

CFLAGS	= -g -ansi -pedantic -Wall 					\
	    -DNPC_LIB_DIR="\"$(NPC_LIB_DIR)"\"				\
	    -DNPC_DIR_SEP="\"$(NPC_DIR_SEP)\""				\
	    -DNPC_C_COMPILER="\"$(NPC_C_COMPILER)\""

LHEADS	= memory.h boolean.h array.h trie.h iset.h utypes.h astring.h	\
	  asymtab.h uchar.h ustring.h usymtab.h ustring_pool.h codegen.h

LOBJS	= array.o trie.o iset.o astring.o asymtab.o uchar.o ustring.o	\
	  usymtab.o ustring_pool.o codegen_c.o

EOBJS	= expr.o expr_lit.o expr_paren.o expr_tuple.o expr_list.o	\
	  expr_array.o expr_call.o expr_let.o expr_if.o expr_case.o	\
	  expr_fnhead.o expr_precond.o expr_default.o

FOBJS	= fefn.o fefn_creation.o fefn_credft.o fefn_feature.o		\
	  fefn_precond.o fefn_builtin.o fefn_letdef.o fefn_downdef.o	\
	  fefn_param.o fefn_invariant.o

BOBJS	= befn.o befn_creation.o befn_credft.o befn_feature.o		\
	  befn_precond.o befn_builtin.o befn_letdef.o befn_downdef.o	\
	  befn_param.o befn_invariant.o befn_class_init.o		\
	  befn_enum_init.o befn_system_init.o

OOBJS	= lexer.o name.o context.o type.o coercion.o class.o		\
	  class_view.o system.o system_view.o auto.o np_back.o main.o

OBJS	= $(FOBJS) $(BOBJS) $(OOBJS)


############################################################################
#                                                                          #
#  Rules                                                                   #
#                                                                          #
############################################################################

npc:	$(LOBJS) $(OBJS) $(EOBJS)
	$(CC) -o npc $(CFLAGS) $(LOBJS) $(OBJS) $(EOBJS) -lm
	chmod a+x npc

clean:	
	-rm -f npc *.o

uchar.o:	boolean.h utypes.h uchar.h ustring.h ustring_pool.h

astring.o:	boolean.h utypes.h astring.h

ustring.o:	boolean.h utypes.h uchar.h ustring.h

ustring_pool.o:	boolean.h utypes.h ustring.h ustring_pool.h

trie.o:		boolean.h array.h trie.h

array.o:	boolean.h array.h

iset.o:		boolean.h array.h iset.h

symtab.o:	boolean.h ustring.h array.h symtab.h

asymtab.o:	boolean.h astring.h array.h asymtab.h

codegen_c.o:	boolean.h astring.h ustring.h

$(EOBJS):	$(LHEADS) expr.h externs.h

$(OBJS):	$(LHEADS) externs.h
