CWEAVE = cweave -ph +mde -I../
CTANGLE = ctangle -ph

.SUFFIXES:

%.o: %.c
	$(CC) -c $(CPPFLAGS) $(all-C-flags) $<

%.c %.h %type.h: %.w
	$(CTANGLE) $<

%.tex: %.w $(all_derived_headers)
	$(CWEAVE) $<

%.dvi: %.tex
	TEXINPUTS=.:../macros $(TEX) $<

cweb_sources=\
 closure.w coxeter.w decomp.w domchar.w factor.w grpdata.w lr.w plethysm.w\
 sorting.w symg.w tensor.w weyl.w weylloop.w
c_sources=\
 altdom.c branch.c centr.c contragr.c defs.c diagram.c matrix.c orbit.c\
 static3.c

objects= $(cweb_sources:.w=.o) $(c_sources:.c=.o)


derived_headers=\
 coxeter.h decomp.h domchar.h grpdata.h plethysm.h symg.h tensor.h weylloop.h

partent_derived_headers=\
 ../lie.h ../lexer.h ../mem.h ../node.h ../gettype.h ../getvalue.h ../sym.h\
 ../init.h ../main.h ../memtype.h ../nodetype.h

all_derived_headers=$(derived_headers) $(parent_derived_headers)

dvifiles: $(all_derived_headers)
	$(MAKE) $(cweb_sources:.w=.dvi)

# Global organisation (phony targets)

.PHONY: all prepare clean

all:	.last_compiled

prepare: $(derived_headers)

.last_compiled:	$(objects)
	touch .last_compiled

defs.o:		defs.h


# TAGS file with identifier definitions for emacs perusal. The regexp matches
# identifiers directly followed by '(' or '=' (for functions and global
# variables, respectively) which are on unindented lines, with only
# identifiers or '*' preceding them. No '*' should be attached directly to the
# identifier being defined (attach it to the identifier before it instead).
# The reason we not also match identifiers followed by ';' is that this mainly
# leads to many spurious hits in the commentary part of CWEB sections.

TAGS:	$(c_sources) $(cweb_sources)
	etags $(c_sources)\
 --regex='/\([a-zA-Z0-9_\*]+[ \t]+\)*\([a-zA-Z0-9_]+\)[(=]/\2/' $(cweb_sources)

# standard targets

clean:
	rm -f *~ *.o *.log *.dvi *.tex *.toc $(derived_headers)
	rm -f $(cweb_sources:.w=.c) $(cweb_sources:.w=.tex)
	rm -f $(cweb_sources:.w=.toc) .last_compiled


