FLEX = /usr/bin/flex
BISON = /usr/bin/bison
FLEXFLAGS = -d
BISONFLAGS = -dvty -Wno-yacc

CXX = clang++-18

TARGETS = stsh-parse-test parser.cc parser.h scanner.cc

# The CFLAGS variable sets compile flags for g: 
#  -g          compile with debug information
#  -Wall       give all diagnostic warnings
#  -pedantic   require compliance with ANSI standard
#  -O0         do not optimize generated code
#  -std=c++0x  use C++ 11 features like range-based for loops
CXXFLAGS = -g -fPIE -Wall -pedantic -O0 -std=c++0x

stsh-parse-test: stsh-parse-test.o stsh-parse.o scanner.cc parser.cc stsh-readline.o
	g++ -o stsh-parse-test stsh-parse-test.o stsh-parse.o scanner.cc parser.cc stsh-readline.o -ll -lreadline

parser.cc: parser.y
	$(BISON) $(BISONFLAGS) -o $@ $^

parser.h: parser.cc
# parser.h is generated by BISON at parser.cc is

scanner.cc: scanner.l parser.h
	$(FLEX) $(FLEXFLAGS) -o $@ scanner.l

stsh-parse.cc: parser.h
# Need to force make to run bison before attempting to compile stsh-parse.cc

# clean up
clean:
	rm -f $(TARGETS) *.o *~ parser.output

spartan: clean
	rm -fr *~
