HEADER_FILES=openFile/openFile.h parser/parser.h readCharacter/readCharacter.h struct.h error_codes.h
C_FILES=main.c parser/parser.c openFile/openFile.c readCharacter/readCharacter.c

OBJS=$(C_FILES:.c=.o)
CFLAGS=-pedantic -Wall -Werror -std=c99



#
#
PROG=swc


AUTOSAVES=$(OBJS:.c=.c~) $(HEADER_FILES:.h=.h~) 


%.o:%.c
	gcc -c $(CFLAGS) $< -o $@

$(PROG): $(OBJS)
	gcc $(OBJS) -o $@ -lm

$(OBJS): $(HEADER_FILES)

bb:
	@echo Performing black box tests
# stdin
	@echo " -- stdin ---"
	@echo -n "$(PROG) -l: ";    export COUNT=$$(seq 1 10 | $(PROG) -l); if [ $$COUNT -ne 10 ] ; then echo " failure" ; exit 1 ; else echo "ok" ; fi
	@echo -n "$(PROG) -c: ";    export COUNT=$$(seq 1 10 | $(PROG) -c); if [ $$COUNT -ne 21 ] ; then echo " failure" ; exit 1 ; else echo "ok" ; fi
	@echo -n "$(PROG) -l -: ";    export COUNT=$$(seq 1 10 | $(PROG) -l - | awk '{ print $$1}'); if [ $$COUNT -ne 10 ] ; then echo " failure" ; exit 1 ; else echo "ok" ; fi
	@echo -n "$(PROG) -c - : ";    export COUNT=$$(seq 1 10 | $(PROG) -c - | awk '{ print $$1}'); if [ $$COUNT -ne 21 ] ; then echo " failure" ; exit 1 ; else echo "ok" ; fi
	@echo -n "$(PROG) -c: ";    export COUNT=$$(cat test-data/words.txt | $(PROG) -c | awk '{ print $$1}'); if [ $$COUNT -ne 56 ] ; then echo "Count $$COUNT != 56" ; exit 1 ; else echo "ok"; fi
	@echo -n "$(PROG) -l: ";   export COUNT=$$(cat test-data/words.txt | $(PROG) -l - | awk '{ print $$1}'); if [ $$COUNT -ne 3 ] ; then echo "Count $$COUNT != 56" ; exit 1 ; else echo "ok"; fi
# file
	@echo " -- file ---"
	@echo -n "$(PROG) -c: "; export COUNT=$$( $(PROG) -c test-data/words.txt | awk '{ print $$1}'); if [ $$COUNT -ne 56 ] ; then echo "Count $$COUNT != 56" ; exit 1 ; else echo "ok"; fi
	@echo -n "$(PROG) -c: "; export COUNT=$$( $(PROG) -l test-data/words.txt | awk '{ print $$1}'); if [ $$COUNT -ne 3 ] ; then echo "Count $$COUNT != 56" ; exit 1 ; else echo "ok"; fi

clean:
	-rm -f $(OBJS) swc a.out *~ *.o
	-rm -f $(AUTOSAVES)
