.PHONY: test testv clean

SRC = word.c syntax.c char.c exec.c
CC = gcc
OBJ = $(SRC:.c=.o)
LIBS=
CFLAGS = -g -Wall -ansi -pedantic
STATICFLAGS = -Os -static -s

main: main.c $(OBJ)
	$(CC) $(CFLAGS) $^ $(LIBS) -o $@

static: main.c $(OBJ)
	$(CC) $(CFLAGS) $(STATICFLAGS) $^ -o shell

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

test: main
	@cd test/; bash run_tests

testv: main
	@cd test/; bash -x run_tests

clean:
	rm -f *.o main deps.mk


ifneq ($(SRC),)

ifneq (clean, $(MAKECMDGOALS))
-include deps.mk
endif

deps.mk: $(wildcard *.c)
	$(CC) -MM $^ > $@

endif
