SRCS     = $(wildcard *.[sS])

PROGRAMS = $(basename $(SRCS))

LISTINGS = $(addsuffix _listing.txt,$(PROGRAMS))

CFLAGS = -g

LDFLAGS = -g -static


.PHONY: default
default: $(PROGRAMS) $(LISTINGS)

%_listing.txt: %.s
	# "-EB" needed for "ci20" (but not "mips" VM)
	$(AS) -EB -a=$@ -o /dev/null $<

.PHONY: clean
clean:
	rm -f *_listing.txt *.o *~ a.out core

.PHONY: immaculate
immaculate: clean
	rm -f $(PROGRAMS)

.PHONY: untabify
untabify:
	for file in $(SRCS) ;\
	do \
		expand -4 $$file >temp$$$$.s && mv temp$$$$.s $$file ;\
	done

%: %.s %_listing.txt
	$(CC) $(LDFLAGS) -o $@ $<
