#
#    Proteus Parallel Architecture Simulator
#    Eric A. Brewer  and  Chris N. Dellarocas
#    Laboratory for Computer Science
#    Massachusetts Institute of Technology
#
#    Module:  Makefile for cycle-counted version of libc.a
#
#    Last Modified:      11-25-92 (eab)
#

OBJS = alarm.o atoi.o atol.o crypt.o ctype_.o \
       gcvt.o getenv.o malloc.o mktemp.o  \
       qsort.o random.o regex.o setenv.o \
       strcasecmp.o string.o swab.o safe_malloc.o \
       time.o valloc.o userdebug.o memcpy.o

CC = $(INIT_CC)
CLIB = $(INIT_LIBDIR)/libc.a

CFLAGS = -O
AFLAGS = -p
AUG = ../augment

# printf modules from printf directory
PRINTF = printf/print_.o printf/fprint_.o printf/sprint_.o printf/vprint_.o \
	 printf/vfprint_.o printf/vsprint_.o printf/wrappers.o

.c.o:
	@ echo File $*.c
	@ $(CC) $(CFLAGS) -S $*.c
	@ $(AUG) $(AFLAGS) $*.s -o aug-$*.s
	@ $(CC) $(CFLAGS) -c aug-$*.s -o $*.o

libcyc.a: $(OBJS) printf/print_.o
	ar cru libcyc.a $(OBJS) $(PRINTF)
	ar ts libcyc.a
	./list-procs libcyc.a | comm -23 - not_augmented | \
		sed -e 's/cyc_//' | sort > cyc.lib
	/bin/rm -f *.s

printf/print_.o:
	printf/INSTALL_PRINTF

malloc.o: malloc.c
	$(CC) -c -O malloc.c

safe_malloc.o: safe_malloc.c
	$(CC) -c -O safe_malloc.c

userdebug.o: userdebug.c
	$(CC) -c -O userdebug.c

clean:
	/bin/rm -f *.s *~

reset:
	/bin/rm -f *.o *.s

superreset: clean reset
	/bin/rm -f *.a missing* counted* c.lib
	printf/INSTALL_PRINTF superreset

# include files for augment

c.lib: $(CLIB)
	./list-procs $(CLIB) | sort > c.lib 

missing: cyc.lib c.lib
	comm -23 c.lib cyc.lib > missing
	comm -12 c.lib cyc.lib > counted
	sed -e 's/.*/    InsertSymbol("&", SYM_NOCYC);/' < missing > missing.h
	sed -e 's/.*/    InsertSymbol("&", SYM_LIB);/' < counted > counted.h
