
# Makefile for popcorn applications
# January 1999
# Dan Grossman

POPCORN   = popcorn
TALC      = talc
CC        = cl /nologo
COMPFLAGS = --TALC

TARGETDIR = build

# directory structure for applications (add directories as necessary)
SRC_DIRS = util talx86 scheme

# .pop files in each directory (add as necessary)
UTIL_BASE   = core id set dict list var_string 
TAL_BASE    = tal talpp
SCHEME_BASE = sast slex sparse sil scomp smain

# .c file
SCHEME_RUNTIME = sclib

# should run unmodified as you add files to the directores
# add new variables for new directories in obvious fashion
UTIL_TAL   = $(addprefix util/,   $(addsuffix .tal, $(UTIL_BASE)))
UTIL_OBJ   = $(addprefix util/,   $(addsuffix .obj, $(UTIL_BASE)))
TAL_TAL    = $(addprefix talx86/, $(addsuffix .tal, $(TAL_BASE)))
TAL_OBJ    = $(addprefix talx86/, $(addsuffix .obj, $(TAL_BASE)))
SCHEME_TAL = $(addprefix scheme/, $(addsuffix .tal, $(SCHEME_BASE)))
SCHEME_OBJ = $(addprefix scheme/, $(addsuffix .obj, $(SCHEME_BASE) \
                                                    $(SCHEME_RUNTIME)))

ALL_OBJ = $(UTIL_OBJ) $(TAL_OBJ) $(SCHEME_OBJ)
ALL_TAL = $(UTIL_TAL) $(TAL_TAL) $(SCHEME_TAL)

SCHEME_FILES=$(TAL_FILES) $(SCHEME_RUNTIME).obj

all: scheme util talx86

scheme_linkcheck: $(UTIL_TAL) $(TAL_TAL) $(SCHEME_TAL)
	$(TALC) --verify-link --TALC $^ --std-lib stdlib \
		--std-lib pop_runtime scheme/$(SCHEME_RUNTIME).obj \
		-o $(TARGETDIR)/scheme.exe

scheme: $(UTIL_OBJ) $(TAL_OBJ) $(SCHEME_OBJ)
	$(POPCORN) -o $(TARGETDIR)/$@.exe $(COMPFLAGS) $^

util: $(UTIL_OBJ)

talx86: $(TAL_OBJ)

#templates
%.tal %.obj: %.pop
	$(POPCORN) $(COMPFLAGS) -c $<

%.obj: %.c
	$(CC) /Fo$@ /c $<

# clean currently doesn't clean up the scheme/tests directory
clean:
	for i in $(SRC_DIRS); do \
	  (cd $$i; rm -f *~ $(addprefix *., tal tali obj)) \
	done
	rm -f *~
	rm -f $(TARGETDIR)/*.exe

