# make file for ccna32.c

cc=gcc
cflags= -std=c89 -fno-asm -ffreestanding -g
objects = vars.o ctype.o codegen.o declarations.o diagnostics.o driver.o error.o \
		  expression.o lex.o parse.o preprocess.o stdlib.o string.o main.o
objdir = build
name = scc
src = main.c
srcdir = src
options = -I include/

$(name) : $(objects) $(objdir)
	$(cc) $(cflags) $(options) -o $(name) $(objdir)/*.o

vars.o : $(srcdir)/vars.c
	$(cc) $(cflags) $(options) -c $< -o $(objdir)/$@

ctype.o : $(srcdir)/ctype.c
	$(cc) $(cflags) $(options) -c $< -o $(objdir)/$@

codegen.o : $(srcdir)/codegen.c
	$(cc) $(cflags) $(options) -c $< -o $(objdir)/$@

declarations.o : $(srcdir)/declarations.c
	$(cc) $(cflags) $(options) -c $< -o $(objdir)/$@

diagnostics.o : $(srcdir)/diagnostics.c
	$(cc) $(cflags) $(options) -c $< -o $(objdir)/$@

driver.o : $(srcdir)/driver.c
	$(cc) $(cflags) $(options) -c $< -o $(objdir)/$@

error.o : $(srcdir)/error.c
	$(cc) $(cflags) $(options) -c $< -o $(objdir)/$@

expression.o : $(srcdir)/expression.c
	$(cc) $(cflags) $(options) -c $< -o $(objdir)/$@

lex.o: $(srcdir)/lex.c
	$(cc) $(cflags) $(options) -c $< -o $(objdir)/$@

parse.o : $(srcdir)/parse.c
	$(cc) $(cflags) $(options) -c $< -o $(objdir)/$@

preprocess.o : $(srcdir)/preprocess.c
	$(cc) $(cflags) $(options) -c $< -o $(objdir)/$@

stdlib.o : $(srcdir)/stdlib.c
	$(cc) $(cflags) $(options) -c $< -o $(objdir)/$@

string.o : $(srcdir)/string.c
	$(cc) $(cflags) $(options) -c $< -o $(objdir)/$@

main.o : $(srcdir)/main.c
	$(cc) $(cflags) $(options) -c $< -o $(objdir)/$@

ifeq ($(wildcard $(objdir)/),)
$(shell mkdir -p $(objdir))
endif

.PHONY: tst1
tst1:
	nasm -@ tst1.mak
	$(cc) -g driver.c tst1.o -o $@

# This is GNU makefile extension to notify that roughly means: 'clean' does
# not depend on any files in order to call it.
.PHONY: clean
clean:
	rm -rf $(name) $(objdir) mytst.txt tst1 tst1err.txt tst1.lst tst1.nsm tst1.o

# -eof-