# ================================================================
# NOTE: This makefile is not intended to be used in a packaging system --
# rather, Miller uses autconfig for that. This makefile is intended for users
# who prefer (for whatever reason) to bypass autoconfig.  Please also see
# http://johnkerl.org/miller/doc/build.html#Without_using_autoconfig
# ================================================================

CC=gcc

CFLAGS=-I.. -O3
#CFLAGS=-I.. -g

# ----------------------------------------------------------------
top: filter_dsl_lexer.o filter_dsl_parse.o filter_dsl_wrapper.o put_dsl_lexer.o put_dsl_parse.o put_dsl_wrapper.o

# ----------------------------------------------------------------
put_dsl_wrapper.o: put_dsl_wrapper.c put_dsl_wrapper.h put_dsl_parse.h
	$(CC) -Wall $(CFLAGS) -c -std=gnu99 put_dsl_wrapper.c

put_dsl_parse.o: put_dsl_parse.c put_dsl_parse.h
	$(CC) $(CFLAGS) -c -std=gnu99 put_dsl_parse.c
put_dsl_parse.c put_dsl_parse.h: put_dsl_parse.y lemon
	./lemon put_dsl_parse.y
	mv put_dsl_parse.c put_dsl_parse.c.tmp
	sed \
			-e 's/ParseTrace/put_dsl_ParseTrace/g' \
			-e 's/ParseTokenName/put_dsl_ParseTokenName/g' \
			-e 's/lemon_parser_alloc/put_dsl_lemon_parser_alloc/g' \
			-e 's/lemon_parser_free/put_dsl_lemon_parser_free/g' \
			-e 's/lemon_parser_parse_token/put_dsl_lemon_parser_parse_token/g' \
			-e 's/yy_destructor/put_dsl_yy_destructor/g' \
		put_dsl_parse.c.tmp > put_dsl_parse.c
	rm -f put_dsl_parse.c.tmp

# muldef:
#   ParseTrace
#   ParseTokenName
#   lemon_parser_alloc
#   lemon_parser_free
#   lemon_parser_parse_token
#   yy_destructor

put_dsl_lexer.o: put_dsl_lexer.c put_dsl_lexer.h put_dsl_parse.h
	$(CC) $(CFLAGS) -c -std=gnu99 put_dsl_lexer.c
put_dsl_lexer.c put_dsl_lexer.h: put_dsl_lexer.l
	flex --prefix=put_dsl_lexer_ --outfile=put_dsl_lexer.c --header-file=put_dsl_lexer.h put_dsl_lexer.l

# ----------------------------------------------------------------
filter_dsl_wrapper.o: filter_dsl_wrapper.c filter_dsl_wrapper.h filter_dsl_parse.h
	$(CC) -Wall $(CFLAGS) -c -std=gnu99 filter_dsl_wrapper.c

filter_dsl_parse.o: filter_dsl_parse.c filter_dsl_parse.h
	$(CC) $(CFLAGS) -c -std=gnu99 filter_dsl_parse.c
filter_dsl_parse.c filter_dsl_parse.h: filter_dsl_parse.y lemon
	./lemon filter_dsl_parse.y
	mv filter_dsl_parse.c filter_dsl_parse.c.tmp
	sed \
			-e 's/ParseTrace/filter_dsl_ParseTrace/g' \
			-e 's/ParseTokenName/filter_dsl_ParseTokenName/g' \
			-e 's/lemon_parser_alloc/filter_dsl_lemon_parser_alloc/g' \
			-e 's/lemon_parser_free/filter_dsl_lemon_parser_free/g' \
			-e 's/lemon_parser_parse_token/filter_dsl_lemon_parser_parse_token/g' \
			-e 's/yy_destructor/filter_dsl_yy_destructor/g' \
		filter_dsl_parse.c.tmp > filter_dsl_parse.c
	rm -f filter_dsl_parse.c.tmp

filter_dsl_lexer.o: filter_dsl_lexer.c filter_dsl_lexer.h filter_dsl_parse.h
	$(CC) $(CFLAGS) -c -std=gnu99 filter_dsl_lexer.c
filter_dsl_lexer.c filter_dsl_lexer.h: filter_dsl_lexer.l
	flex --prefix=filter_dsl_lexer_ --outfile=filter_dsl_lexer.c --header-file=filter_dsl_lexer.h filter_dsl_lexer.l

# ----------------------------------------------------------------
lemon: lemon.c lempar.c
	$(CC) -o lemon lemon.c

# ----------------------------------------------------------------
clean:
	rm -f *.o
	rm -f put_dsl_parse.c put_dsl_parse.h put_dsl_parse.out
	rm -f put_dsl_lexer.c put_dsl_lexer.h
	rm -f filter_dsl_parse.c filter_dsl_parse.h filter_dsl_parse.out
	rm -f filter_dsl_lexer.c filter_dsl_lexer.h
	rm -f lemon

.always:
	@/bin/true
