# Makefile for hacked MiNTlib for Heat-n-Serve/Sozobon C, version 1.33i
# and above.  This makefile works with the make provided with 1.40 and
# up, and less well with the make provided with 1.33i

# Where to install libraries.
# LIBDIR = c:\sozobon\lib
LIBDIR = u:\lib

# You might want any or all of these; Sozobon's make predefines most of them.
AR = ar
#CP = cp
#RM = rm -f
MAKE = make

# A trick to build a v1.40-compatible library with a v2.00 or higher
# compiler -- either uncomment this line or build the target
# "short_names".  This isn't necessary unless you're building an old
# library with a new compiler (and hopefully by the next release it
# won't be necessary at all).
#SHORTNAMES = -8
AFLAGS = $(SHORTNAMES)


# To build the .cpp files, you'll need my stand-alone preprocessor,
# which should be available where you got this archive.
CPP = cpp
CPPFLAGS = -P -Wno-bad-chars -D__SOZOBON__ -D__MSHORT__

# 1.33i's top apparently takes about 30 minutes on doprnt.c; if you don't
# want to wait that long, use the alternate definition of NOOPT. 
# Unfortunately, there is an optimizer bug in 1.40 that bites here; if
# you're using that version, you must use the non-optimizing version.
CFLAGS = -O -D__NO_FLOAT__ -DNDEBUG $(SHORTNAMES)
#NOOPT = -D__NO_FLOAT__ -DNDEBUG $(SHORTNAMES)	# without optimizing
NOOPT = $(CFLAGS)				# with optimizing

# If you prefer more "standard" Unix-like names for your library files, use
# the alternate definitions of CRT0 and LIBC -- assuming, of course, that
# you have a cc that recognizes those names!
# CRT0 = crt0.o
# LIBC = libc.a
CRT0 = dstart.o
LIBC = dlibs.a
LIBS = $(CRT0) $(LIBC) libtermcap.a

all : $(LIBS)

# These are in alphabetical order to make it easy to find one.
OBJECTS = \
	a64l.o abort.o abs.o access.o alarm.o alloca.o alphasor.o \
	atexit.o atoi.o atol.o \
	bcmp.o bcopy.o binmode.o bsearch.o buffindf.o bzero.o \
	calloc.o cfgetisp.o cfgetosp.o cfsetisp.o cfsetosp.o chdir.o \
	chmod.o chown.o clock.o close.o closedir.o console.o crtinit.o \
	ctermid.o ctime.o ctype.o cuserid.o \
	defmode.o difftime.o div.o div.o do_lock.o do_stat.o doprnt.o \
	dup.o dup2.o \
	enoent.o eprintf.o execl.o execle.o execp.o execv.o execve.o \
	fclose.o fcntl.o fdopen.o fflush.o ffs.o fgetc.o fgetpos.o \
	fgets.o filbuf.o findfile.o flock.o fopen.o fopen_i.o fopenp.o \
	fork.o fprintf.o fputc.o fputs.o fread.o freopen.o frwbin.o \
	fscanf.o fseek.o fsetpos.o fstat.o ftell.o ftw.o fungetc.o \
	fwrite.o \
	getbuf.o getcwd.o getdtabl.o getegid.o getenv.o geteuid.o \
	getgid.o getgroup.o gethostn.o getlogin.o getopt.o getpages.o \
	getpass.o getpid.o getppid.o getpw.o getrusag.o gets.o getuid.o \
	getw.o getwd.o grp.o \
	heapbase.o \
	ic.o ident.o ig.o il.o inistack.o initsig.o inode.o ioctl.o ip.o \
	isatty.o isctty.o iw.o \
	kill.o killpg.o \
	l64a.o labs.o ldiv.o linea.o link.o lmalloc.o localtim.o lockf.o \
	lseek.o lstat.o ltoa.o \
	main.o malloc.o memccpy.o memchr.o memcmp.o memset.o mkdir.o \
	mkfifo.o mknod.o mktemp.o \
	nice.o nlist.o \
	obstack.o open.o opendir.o osbind.o \
	pause.o perror.o pgrp.o pipe.o popen.o printf.o psignal.o putenv.o \
	putpwent.o puts.o \
	qsort.o \
	raise.o rand.o random.o read.o readdir.o realloc.o regexp.o \
	regsup.o rename.o rewind.o rewinddi.o rmdir.o \
	sbrk.o scandir.o scanf.o seekdir.o select.o setbuf.o setegid.o \
	seteuid.o setgid.o setjmp.o setlocal.o setregid.o setreuid.o \
	setrlimi.o setuid.o setvbuf.o sgtty.o sigactio.o sigblock.o \
	siglist.o signal.o sleep.o sozolong.o sozulong.o spawn.o \
	spawnve.o spawnvp.o sprintf.o sscanf.o stat.o statfs.o stksiz.o \
	strcat.o strchr.o strcmp.o strcoll.o strcpy.o strcspn.o strdup.o \
	strerror.o strftime.o stricmp.o strlen.o strlwr.o strncat.o \
	strncmp.o strncpy.o strnicmp.o strpbrk.o strrchr.o strrev.o \
	strspn.o strstr.o strtok.o strtol.o strtoul.o strupr.o symlink.o \
	sync.o sysconf.o system.o sysvar.o \
	tcattr.o tcbreak.o tcdrain.o tcflow.o tcflush.o tcpgrp.o \
	telldir.o textio.o thread.o time.o timeoday.o times.o tmpfile.o \
	tmpnam.o toxxx.o truncate.o ttyname.o \
	uidgid.o uname.o unlink.o unx2dos.o utime.o utmp.o \
	vfork.o vfprintf.o vfscanf.o vprintf.o vscanf.o \
	wait.o wait3.o waitpid.o wcmb.o wcscat.o wcscmp.o wcscpy.o \
	wcslen.o wnull.o write.o wtmp.o

# Rule to handle .cpp files
.SUFFIXES: .cpp

.cpp.s:
	$(CPP) $(CPPFLAGS) $< $*.i
	mit2mot $*.i
	$(RM) $*.i

.cpp.o:
	$(CPP) $(CPPFLAGS) $< $*.i
	mit2mot $*.i
	$(RM) $*.i
	$(AS) $(AFLAGS) $*.s

# Make sure the targets get built if necessary
alloca.o: alloca.cpp
bcopy.o: bcopy.cpp
crt0.o: crt0.cpp
osbind.o: osbind.cpp
setjmp.o: setjmp.cpp
vfork.o: vfork.cpp

# bzero.cpp contains both bzero() and memset().
bzero.o: bzero.cpp
	$(CPP) $(CPPFLAGS) -DLbzero bzero.cpp bzero.i
	mit2mot bzero.i
	$(RM) bzero.i
	$(AS) $(AFLAGS) bzero.s

memset.o: bzero.cpp
	$(CPP) $(CPPFLAGS) -DLmemset bzero.cpp memset.i
	mit2mot memset.i
	$(RM) memset.i
	$(AS) $(AFLAGS) memset.s

# If you're using 1.33i's make or ar, this command will fail spectacularly
# for the first build; you'll have to build it by hand, a few files
# at a time.  After that, if you only change a few files at a time,
# you shouldn't have problems.  Later versions are compiled with ARGV
# and have no problems.
$(LIBC) : $(OBJECTS)
	$(AR) rv $@ $?

doprnt.o: doprnt.c
	$(CC) $(NOOPT) -c $?

libtermcap.a : termcap.o
	$(AR) rv $@ $?

# this is ugly, but I can't think of a way around it without risking the TOS
# "copy file to itself" bug.  If you have CRT0 = crt0.o, this rule will
# never be used anyway.
dstart.o : crt0.o
	$(CP) $? $@

# The trick described above -- force v2.00+ compilers to generate short
# identifiers compatible with v1.40 and before.
short_names:
	$(MAKE) SHORTNAMES=-8

clean :
	$(RM) *.o

realclean : clean
	$(RM) $(LIBS)

install : $(LIBS)
	$(CP) $(LIBC) $(LIBDIR)
	$(CP) $(CRT0) $(LIBDIR)
	$(CP) libtermcap.a $(LIBDIR)
