include ${MAKETOP}Makefile-common

#
# All library objects contain sccsid strings by default; they may be
# excluded as a space-saving measure.  To produce a library that does
# not contain these strings, delete -DLIBC_SCCS and -DSYSLIBC_SCCS
# from CFLAGS below.  To remove these strings from just the system call
# stubs, remove just -DSYSLIBC_SCCS from CFLAGS.

LIBRARY = libc.a
# CFLAGS+=-DLIBC_SCCS -DSYSLIBC_SCCS

# compat-43 sources
COMPAT43_VPATH = ${cpu}/compat-43:compat-43
COMPAT43_SRCS =	creat.c getwd.c killpg.c setpgrp.c sigcompat.c
COMPAT43_MAN2 =	creat.0 killpg.0 sigblock.0 sigpause.0 sigsetmask.0 sigvec.0

DB_VPATH = db
DB_MAN3 =	db.0

# btree sources
DB_BTREE_VPATH = db/btree
DB_BTREE_SRCS =	big.c btree.c delete.c insert.c lrucache.c lruhash.c lrutils.c\
	search.c seq.c split.c storage.c updutils.c utils.c

# db/hash
DB_HASH_VPATH = db/hash
DB_HASH_SRCS = bigkey.c buf.c dynahash.c hfunc.c hsearch.c log2.c ndbm.c page.c

# gen sources
GEN_VPATH = ${cpu}/gen:gen:gen/regexp
GEN_SRCS = alarm.c clock.c closedir.c crypt.c ctermid.c ctime.c ctype_.c \
	difftime.c disklabel.c errlst.c exec.c fnmatch.c frexp.c fstab.c \
	fts.c getcwd.c getgrent.c getlogin.c getmntinfo.c getpass.c \
	getpwent.c getsubopt.c getttyent.c getusershell.c glob.c initgroups.c \
	isatty.c isctype.c isinf.c mktemp.c nice.c opendir.c \
	pause.c popen.c psignal.c raise.c readdir.c \
	rewinddir.c scandir.c seekdir.c setjmperr.c \
	setmode.c setrgid.c setruid.c siginterrupt.c \
	siglist.c signal.c sigsetops.c sleep.c syslog.c telldir.c \
	termios.c time.c times.c timezone.c ttyname.c ttyslot.c \
	ualarm.c unvis.c usleep.c utime.c valloc.c vis.c wait.c wait3.c \
	waitpid.c

# gen/regexp sources
GEN_REGEXP_SRCS =	regerror.c regexp.c regsub.c

GEN_COMMON_SRCS = _setjmp.s alloca.s fabs.s ldexp.s modf.s setjmp.s nlist.c

HP300_GEN_SRCS = ${GEN_COMMON_SRCS} \
	adddf3.s addsf3.s ashlsi3.s ashrsi3.s cmpdf2.s cmpsf2.s divdf3.s \
	divsf3.s divsi3.s extendsfdf2.s fixdfsi.s fixunsdfsi.s \
	floatsidf.s lshlsi3.s lshrsi3.s modsi3.s muldf3.s mulsf3.s mulsi3.s \
	negdf2.s negsf2.s saveregs.c subdf3.s subsf3.s truncdfsf2.s udivsi3.s \
	umodsi3.s umulsi3.s

I386_GEN_SRCS =  ${GEN_COMMON_SRCS} divsi3.s fixdfsi.s fixunsdfsi.s udivsi3.s

TAHOE_GEN_CFLAGS =-I/sys
TAHOE_GEN_SRCS = ${GEN_COMMON_SRCS} udiv.s urem.s

VAX_GEN_SRCS = ${GEN_COMMON_SRCS} udiv.s urem.s

PMAX_GEN_SRCS = _setjmp.s

PC532_GEN_SRCS = ${GEN_COMMON_SRCS}

GEN_MAN3 =	alarm.0 clock.0 crypt.0 ctermid.0 ctime.0 ctype.0 directory.0 \
	exec.0 fnmatch.0 frexp.0 fts.0 getcwd.0 getdiskbyname.0 getfsent.0 \
	getgrent.0 getmntinfo.0 getpass.0 getpwent.0 getsubopt.0 \
	getttyent.0 getusershell.0 glob.0 initgroups.0 isalnum.0 \
	isalpha.0 isascii.0 iscntrl.0 isdigit.0 isgraph.0 isinf.0 \
	islower.0 isprint.0 ispunct.0 isspace.0 isupper.0 isxdigit.0 \
	ldexp.0 modf.0 nice.0 nlist.0 pause.0 popen.0 psignal.0 \
	raise.0 regexp.0 scandir.0 setjmp.0 setmode.0 setuid.0 \
	siginterrupt.0 signal.0 sigsetops.0 sleep.0 syslog.0 time.0 \
	times.0 timezone.0 tolower.0 toupper.0 ttyname.0 tzset.0 \
	ualarm.0 unvis.0 usleep.0 utime.0 valloc.0 vis.0

#MLINKS=	crypt.3 encrypt.3 crypt.3 setkey.3
#MLINKS+=ctime.3 asctime.3 ctime.3 difftime.3 ctime.3 gmtime.3 \
#	ctime.3 localtime.3 ctime.3 mktime.3
#MLINKS+=directory.3 closedir.3 directory.3 dirfd.3 directory.3 opendir.3 \
#	directory.3 readdir.3 directory.3 rewinddir.3 directory.3 seekdir.3 \
#	directory.3 telldir.3
#MLINKS+=exec.3 execl.3 exec.3 execle.3 exec.3 execlp.3 exec.3 execv.3 \
#	exec.3 execvp.3
#MLINKS+=isinf.3 isnan.3
#MLINKS+=getcwd.3 getwd.3
#MLINKS+=getfsent.3 endfsent.3 getfsent.3 getfsfile.3 getfsent.3 getfsspec.3 \
#	getfsent.3 getfstype.3 getfsent.3 setfsent.3
#MLINKS+=getgrent.3 endgrent.3 getgrent.3 setgroupent.3 getgrent.3 getgrgid.3 \
#	getgrent.3 getgrnam.3 getgrent.3 setgrent.3 getgrent.3 setgrfile.3
#MLINKS+=getpwent.3 endpwent.3 getpwent.3 setpassent.3 getpwent.3 getpwnam.3 \
#	getpwent.3 getpwuid.3 getpwent.3 setpwent.3 getpwent.3 setpwfile.3
#MLINKS+=getttyent.3 endttyent.3 getttyent.3 getttynam.3 getttyent.3 \
#	setttyent.3
#MLINKS+=getusershell.3 endusershell.3 getusershell.3 setusershell.3
#MLINKS+=glob.3 globfree.3
#MLINKS+=popen.3 pclose.3
#MLINKS+=psignal.3 sys_siglist.3
#MLINKS+=regexp.3 regcomp.3 regexp.3 regexec.3 regexp.3 regsub.3 \
#	regexp.3 regerror.3
#MLINKS+=scandir.3 alphasort.3
#MLINKS+=setjmp.3 _longjmp.3 setjmp.3 _setjmp.3 setjmp.3 longjmp.3 \
#	setjmp.3 longjmperr.3 setjmp.3 longjmperror.3
#MLINKS+=setmode.3 getmode.3
#MLINKS+=setuid.3 setegid.3 setuid.3 seteuid.3 setuid.3 setgid.3 \
#	setuid.3 setrgid.3 setuid.3 setruid.3
#MLINKS+=sigsetops.3 sigemptyset.3 sigsetops.3 sigfillset.3 \
#	sigsetops.3 sigaddset.3 sigsetops.3 sigdelset.3 \
#	sigsetops.3 sigismember.3
#MLINKS+=syslog.3 closelog.3 syslog.3 openlog.3 syslog.3 setlogmask.3 \
#	syslog.3 vsyslog.3
#MLINKS+=ttyname.3 isatty.3 ttyname.3 ttyslot.3
#MLINKS+=tzset.3 tzsetwall.3

errlst.o errlst.po: errlst.c
	${CC} -S ${CFLAGS} $<
	VPATH="${VPATH}"; export VPATH;\
	   ed - < `wh -q -p VPATH ${cpu}/:errfix` errlst.s
	${AS} -o $@ errlst.s
	rm -f errlst.s

# locale sources
LOCALE_VPATH = ${cpu}/locale:locale

LOCALE_SRCS =	lconv.c localeconv.c setlocale.c

# net sources
NET_VPATH = ${cpu}/net:net

NET_SRCS =	gethostnamadr.c getnetbyaddr.c getnetbyname.c getnetent.c \
	getproto.c getprotoent.c getprotoname.c getservbyname.c \
	getservbyport.c getservent.c herror.c inet_addr.c inet_lnaof.c \
	inet_makeaddr.c inet_netof.c inet_network.c inet_ntoa.c \
	iso_addr.c linkaddr.c ns_addr.c ns_ntoa.c rcmd.c recv.c res_comp.c \
	res_debug.c res_init.c res_mkquery.c res_query.c res_send.c \
	send.c sethostent.c

HP300_NET_SRCS = htonl.s htons.s ntohl.s ntohs.s
I386_NET_SRCS  = htonl.s htons.s ntohl.s ntohs.s
TAHOE_NET_SRCS = htonl.s htons.s ntohl.s ntohs.s
VAX_NET_SRCS   = htonl.s htons.s ntohl.s ntohs.s
PMAX_NET_SRCS  = htons.c
PC532_NET_SRCS = ntoh.s

NET_MAN3 = byteorder.0 gethostbyname.0 getnetent.0 getprotoent.0 getservent.0 \
	inet.0 ns.0 rcmd.0 resolver.0 \

#MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \
#	byteorder.3 ntohs.3
#MLINKS+=gethostbyname.3 endhostent.3 gethostbyname.3 gethostbyaddr.3 \
#	gethostbyname.3 sethostent.3 gethostbyname.3 gethostent.3 \
#	gethostbyname.3 herror.3
#MLINKS+=getnetent.3 endnetent.3 getnetent.3 getnetbyaddr.3 \
#	getnetent.3 getnetbyname.3 getnetent.3 setnetent.3
#MLINKS+=getprotoent.3 endprotoent.3 getprotoent.3 getprotobyname.3 \
#	getprotoent.3 getprotobynumber.3 getprotoent.3 setprotoent.3
#MLINKS+=getservent.3 endservent.3 getservent.3 getservbyname.3 \
#	getservent.3 getservbyport.3 getservent.3 setservent.3
#MLINKS+=inet.3 addr.3 inet.3 inet_addr.3 inet.3 inet_lnaof.3 \
#	inet.3 inet_makeaddr.3 inet.3 inet_netof.3 inet.3 inet_network.3 \
#	inet.3 inet_ntoa.3 inet.3 network.3 inet.3 ntoa.3
#MLINKS+=ns.3 ns_addr.3 ns.3 ns_ntoa.3
#MLINKS+=rcmd.3 rresvport.3 rcmd.3 ruserok.3
#MLINKS+=resolver.3 dn_comp.3 resolver.3 dn_expand.3 resolver.3 res_init.3 \
#	resolver.3 res_mkquery.3 resolver.3 res_send.3 resolver.3 res_query.3 \
#	resolver.3 res_search.3

# stdio sources
STDIO_VPATH = stdio

STDIO_SRCS =	clrerr.c fclose.c fdopen.c feof.c ferror.c fflush.c fgetc.c \
	fgetline.c fgetpos.c fgets.c fileno.c findfp.c flags.c fopen.c \
	fprintf.c fpurge.c fputc.c fputs.c fread.c freopen.c fscanf.c \
	fseek.c fsetpos.c ftell.c funopen.c fvwrite.c fwalk.c fwrite.c \
	getc.c getchar.c gets.c getw.c makebuf.c perror.c printf.c putc.c \
	putchar.c puts.c putw.c refill.c remove.c rewind.c rget.c scanf.c \
	setbuf.c setbuffer.c setvbuf.c snprintf.c sprintf.c sscanf.c \
	stdio.c strerror.c tempnam.c tmpfile.c tmpnam.c ungetc.c vfprintf.c \
	vfscanf.c vprintf.c vscanf.c vsnprintf.c vsprintf.c vsscanf.c \
	wbuf.c wsetup.c

STDIO_MAN3 = fclose.0 ferror.0 fflush.0 fgetline.0 fgets.0 fopen.0 fputs.0 \
	fread.0 fseek.0 funopen.0 getc.0 mktemp.0 printf.0 putc.0 remove.0 \
	scanf.0 setbuf.0 stdio.0 strerror.0 tmpnam.0 ungetc.0

#MLINKS+=ferror.3 clearerr.3 ferror.3 feof.3 ferror.3 fileno.3
#MLINKS+=fflush.3 fpurge.3
#MLINKS+=fgets.3 gets.3
#MLINKS+=fopen.3 fdopen.3 fopen.3 freopen.3
#MLINKS+=fputs.3 puts.3
#MLINKS+=fread.3 fwrite.3
#MLINKS+=fseek.3 fgetpos.3 fseek.3 fsetpos.3 fseek.3 ftell.3 fseek.3 rewind.3
#MLINKS+=funopen.3 fropen.3 funopen.3 fwopen.3
#MLINKS+=getc.3 fgetc.3 getc.3 getchar.3 getc.3 getw.3
#MLINKS+=mktemp.3 mkstemp.3
#MLINKS+=printf.3 fprintf.3 printf.3 snprintf.3 printf.3 sprintf.3 \
#	printf.3 vfprintf.3 printf.3 vprintf.3 printf.3 vsnprintf.3 \
#	printf.3 vsprintf.3 
#MLINKS+=putc.3 fputc.3 putc.3 putchar.3 putc.3 putw.3
#MLINKS+=scanf.3 fscanf.3 scanf.3 sscanf.3 scanf.3 vfscanf.3 scanf.3 vscanf.3 \
#	scanf.3 vsscanf.3
#MLINKS+=setbuf.3 setbuffer.3 setbuf.3 setlinebuf.3 setbuf.3 setvbuf.3
#MLINKS+=strerror.3 perror.3
#MLINKS+=tmpnam.3 tempnam.3 tmpnam.3 tmpfile.3

# stdlib sources
STDLIB_VPATH = ${cpu}/stdlib:stdlib

STDLIB_SRCS = abort.c atexit.c atoi.c atol.c bsearch.c calloc.c div.c exit.c \
	getenv.c getopt.c heapsort.c labs.c ldiv.c malloc.c multibyte.c \
	putenv.c qsort.c radixsort.c rand.c random.c setenv.c strtol.c \
	strtoul.c system.c

HP300_STDLIB_SRCS =	abs.s atof.c
I386_STDLIB_SRCS =	abs.s atof.c
TAHOE_STDLIB_SRCS =	abs.s atof.s
VAX_STDLIB_SRCS =	abs.s atof.s
PMAX_STDLIB_SRCS =
PC532_STDLIB_SRCS =	abs.s atof.c

STDLIB_MAN3 = abort.0 abs.0 alloca.0 atexit.0 atof.0 atoi.0 atol.0 bsearch.0 \
	calloc.0 div.0 exit.0 free.0 getenv.0 getopt.0 labs.0 ldiv.0 \
	malloc.0 memory.0 qsort.0 radixsort.0 rand.0 random.0 realloc.0 \
	strtod.0 strtol.0 strtoul.0 system.0

#MLINKS+=getenv.3 setenv.3 getenv.3 unsetenv.3 getenv.3 putenv.3
#MLINKS+=qsort.3 heapsort.3
#MLINKS+=rand.3 srand.3
#MLINKS+=random.3 initstate.3 random.3 setstate.3 random.3 srandom.3

# string sources
STRING_VPATH = ${cpu}/string:string

STRING_SRCS =	memccpy.c strcasecmp.c strcoll.c strdup.c \
	strftime.c strmode.c strtok.c strxfrm.c swab.c

HP300_STRING_SRCS = \
	bcmp.s bcopy.s bzero.s ffs.s index.s memchr.c memcmp.c memset.c \
	rindex.s strcat.c strcmp.s strcpy.s strcspn.c strlen.s \
	strncat.c strncmp.s strncpy.s strpbrk.c strsep.c \
	strspn.c strstr.c

HP300_STRING_OBJS = memmove.o memcpy.o strchr.o strrchr.o
HP300_MEMMOVE = memmove
HP300_MEMCPY = memcpy
HP300_STRCHR = strchr
HP300_STRRCHR = strrchr

I386_STRING_SRCS = \
	bcmp.c bcopy.c bzero.s ffs.c index.c memchr.c memcmp.c memset.c \
	rindex.c strcat.c strcmp.c strcpy.c strcspn.c strlen.c \
	strncat.c strncmp.c strncpy.c strpbrk.c strsep.c \
	strspn.c strstr.c

I386_STRING_OBJS = memmove.o memcpy.o strchr.o strrchr.o
I386_MEMMOVE = memmove
I386_MEMCPY = memcpy
I386_STRCHR = strchr
I386_STRRCHR = strrchr

TAHOE_STRING_SRCS = \
	bcmp.s bcopy.s bzero.s ffs.s index.c memchr.c memcmp.s memset.c \
	rindex.c strcat.s strcmp.s strcpy.s strcspn.c strlen.s \
	strncat.s strncmp.s strncpy.s strpbrk.c strsep.c \
	strspn.c strstr.c \
	memmove.s

TAHOE_STRING_OBJS = memcpy.o strchr.o strrchr.o
TAHOE_MEMMOVE = no-memmove
TAHOE_MEMCPY = memcpy
TAHOE_STRCHR = strchr
TAHOE_STRRCHR = strrchr

VAX_STRING_SRCS = \
	bcmp.s bcopy.s bzero.s ffs.s index.c memchr.s memcmp.s memset.s \
	rindex.s strcat.s strcmp.s strcpy.s strcspn.s strlen.s \
	strncat.s strncmp.s strncpy.s strpbrk.s strsep.s \
	strspn.s strstr.s \
	memmove.s strchr.s strrchr.s

VAX_STRING_OBJS = memcpy.o
VAX_MEMMOVE = no-memmove
VAX_MEMCPY = memcpy
VAX_STRCHR = no-strchr
VAX_STRRCHR = no-strrchr

PMAX_STRING_SRCS = bcopy.s \
	bcmp.c bcopy.c bzero.s ffs.c index.c memchr.c memcmp.c memset.c \
	rindex.c strcat.c strcmp.c strcpy.c strcspn.c strlen.c \
	strncat.c strncmp.c strncpy.c strpbrk.c strsep.c \
	strspn.c strstr.c

PMAX_STRING_OBJS = memmove.o memcpy.o strchr.o strrchr.o
PMAX_MEMMOVE = memmove
PMAX_MEMCPY = memcpy
PMAX_STRCHR = strchr
PMAX_STRRCHR = strrchr

PC532_STRING_SRCS = bcopy.s \
	bcmp.c bcopy.c bzero.s ffs.c index.c memchr.c memcmp.c memset.c \
	rindex.c strcat.c strcmp.c strcpy.c strcspn.c strlen.c \
	strncat.c strncmp.c strncpy.c strpbrk.c strsep.c \
	strspn.c strstr.c

PC532_STRING_OBJS = memmove.o memcpy.o strchr.o strrchr.o
PC532_MEMMOVE = memmove
PC532_MEMCPY = memcpy
PC532_STRCHR = strchr
PC532_STRRCHR = strrchr

# if no machine specific memmove(3), build one out of bcopy(3).
${${TARGET_MACHINE}_MEMMOVE}.o: bcopy.c
	${CC} -DMEMMOVE ${CFLAGS} -c $> -o $@
	@${LD} -x -r $@
	@mv a.out $@

${${TARGET_MACHINE}_MEMMOVE}.po: bcopy.c
	${CC} -DMEMMOVE ${CFLAGS} -c -p $> -o $@
	@${LD} -X -r $@
	@mv a.out $@

# if no machine specific memcpy(3), build one out of bcopy(3).
${${TARGET_MACHINE}_MEMCPY}.o: bcopy.c
	${CC} -DMEMCOPY ${CFLAGS} -c $> -o $@
	@${LD} -x -r $@
	@mv a.out $@

${${TARGET_MACHINE}_MEMCPY}.po: bcopy.c
	${CC} -DMEMCOPY ${CFLAGS} -c -p $> -o $@
	@${LD} -X -r $@
	@mv a.out $@

# if no machine specific strchr(3), build one out of index(3).
${${TARGET_MACHINE}_STRCHR}.o: index.c
	${CC} -DSTRCHR ${CFLAGS} -c $> -o $@
	@${LD} -x -r $@
	@mv a.out $@

${${TARGET_MACHINE}_STRCHR}r.po: index.c
	${CC} -DSTRCHR ${CFLAGS} -c -p $> -o $@
	@${LD} -X -r $@
	@mv a.out $@

# if no machine specific strrchr(3), build one out of rindex(3).
${${TARGET_MACHINE}_STRRCHR}.o: rindex.c
	${CC} -DSTRRCHR ${CFLAGS} -c $> -o $@
	@${LD} -x -r $@
	@mv a.out $@

${${TARGET_MACHINE}_STRRCHR}.po: rindex.c
	${CC} -DSTRRCHR ${CFLAGS} -c -p $> -o $@
	@${LD} -X -r $@
	@mv a.out $@

STRING_MAN3 = \
	bcmp.0 bcopy.0 bstring.0 bzero.0 ffs.0 index.0 memccpy.0 memchr.0 \
	memcmp.0 memcpy.0 memmove.0 memset.0 rindex.0 strcasecmp.0 strcat.0 \
	strchr.0 strcmp.0 strcoll.0 strcpy.0 strcspn.0 strftime.0 string.0 \
	strlen.0 strmode.0 strdup.0 strpbrk.0 strrchr.0 strsep.0 strspn.0 \
	strstr.0 strtok.0 strxfrm.0 swab.0

#MLINKS+=strcasecmp.3 strncasecmp.3
#MLINKS+=strcat.3 strncat.3
#MLINKS+=strcmp.3 strncmp.3
#MLINKS+=strcpy.3 strncpy.3

# sys sources
SYS_VPATH = ${cpu}/sys:sys

# modules with non-default implementations on at least one architecture:
SYS_SRCS = Ovfork.s brk.s cerror.s exect.s fork.s pipe.s ptrace.s reboot.s \
	sbrk.s setlogin.s sigpending.s sigprocmask.s sigreturn.s \
	sigsuspend.s syscall.s

# modules with default implementations on all architectures:
SYS_ASM = accept.o access.o acct.o adjtime.o async_daemon.o bind.o chdir.o \
	chflags.o chmod.o chown.o chroot.o close.o connect.o dup.o dup2.o \
	execve.o fchdir.o fchflags.o fchmod.o fchown.o fcntl.o flock.o \
	fstat.o fstatfs.o fsync.o ftruncate.o getdirentries.o \
	getdtablesize.o getegid.o geteuid.o getfh.o getfsstat.o getgid.o \
	getgroups.o gethostid.o gethostname.o getitimer.o getkerninfo.o \
	getpagesize.o getpeername.o getpgrp.o getpid.o getppid.o \
	getpriority.o getrlimit.o getrusage.o getsockname.o getsockopt.o \
	gettimeofday.o getuid.o ioctl.o kill.o ktrace.o link.o listen.o \
	lseek.o lstat.o madvise.o mincore.o mkdir.o mkfifo.o mknod.o \
	mmap.o mount.o mprotect.o msync.o munmap.o nfssvc.o open.o \
	profil.o quotactl.o read.o readlink.o readv.o recvfrom.o recvmsg.o \
	rename.o revoke.o rmdir.o select.o sendmsg.o sendto.o setegid.o \
	seteuid.o setgid.o setgroups.o sethostid.o sethostname.o \
	setitimer.o setpgid.o setpriority.o setregid.o setreuid.o \
	setrlimit.o setsid.o setsockopt.o settimeofday.o setuid.o \
	shutdown.o sigaction.o sigstack.o socket.o socketpair.o stat.o \
	statfs.o swapon.o symlink.o sync.o truncate.o umask.o unlink.o \
	unmount.o utimes.o vadvise.o wait4.o write.o writev.o

SYS_PSEUDO = _exit.o _getlogin.o

SYS_OBJS = ${SYS_ASM} ${SYS_PSEUDO}
SYS_POBJS = ${ASM/\.o/.po} ${PSEUDO/\.o/.po}
SYS_CLEANFILES = ${SYS_ASM} ${SYS_PSEUDO} ${SYS_POBJS} 

.SUFFIXES: .rs .xs

%.rs:
	printf '#include <syscall.h>\n#include "SYS.h"\nRSYSCALL($*)\n' > %.rs

${SYS_ASM}: ${SYS_ASM/\.o/.rs/}
	@echo creating $@ $*.po
	${ASCPP} -MD -DASSEMBLER ${DEFS} ${INCS} $*.rs > $*.as
	${AS} ${ASFLAGS}  -o $*.o $*.as
	${RM} $*.as
	ld -x -r $@
	${MV} a.out $@
	${ASCPP} -DPROF -MD -DASSEMBLER ${DEFS} ${INCS} $*.rs > $*.as
	${AS} ${ASFLAGS} -o $*.po $*.as
	${RM} $*.as
	ld -x -r $*.po
	${MV} a.out $*.po

%.xs:
	printf '#include <syscall.h>\n#include "SYS.h"\nPSEUDO($*,${*/_//})\n' > %.xs

${SYS_PSEUDO}: ${SYS_PSEUDO/\.o/.xs/}
	${ASCPP} -MD -DASSEMBLER ${DEFS} ${INCS} $*.xs > $*.as
	${AS} ${ASFLAGS} -o $*.o $*.as
	${RM} $*.as
	ld -x -r $@
	${MV} a.out $@
	${ASCPP} -DPROF -MD -DASSEMBLER ${DEFS} ${INCS} $*.xs > $*.as
	${AS} ${ASFLAGS} -o $*.po $*.as
	${RM} $*.as
	ld -x -r $*.po
	${MV} a.out $*.po

SYS_MAN2 = accept.0 access.0 acct.0 adjtime.0 async_daemon.0 bind.0 brk.0 \
	chdir.0 chflags.0 chmod.0 chown.0 chroot.0 close.0 connect.0 \
	dup.0 execve.0 _exit.0 fcntl.0 flock.0 fork.0 fsync.0 \
	getdirentries.0 getdtablesize.0 getfh.0 getfsstat.0 getgid.0 \
	getgroups.0 gethostid.0 gethostname.0 getitimer.0 getlogin.0 \
	getpagesize.0 getpeername.0 getpgrp.0 getpid.0 getpriority.0 \
	getrlimit.0 getrusage.0 getsockname.0 getsockopt.0 \
	gettimeofday.0 getuid.0 intro.0 ioctl.0 kill.0 link.0 listen.0 \
	lseek.0 mkdir.0 mkfifo.0 mknod.0 madvise.0 mincore.0 mmap.0 mount.0 \
	mprotect.0 msync.0 munmap.0 nfssvc.0 open.0 pipe.0 \
	quotactl.0 read.0 readlink.0 reboot.0 recv.0 rename.0 \
	rmdir.0 select.0 send.0 setgroups.0 setpgid.0 setregid.0 setreuid.0 \
	shutdown.0 sigaction.0 sigprocmask.0 sigreturn.0 sigstack.0 \
	sigsuspend.0 socket.0 socketpair.0 stat.0 statfs.0 swapon.0 \
	symlink.0 sync.0 syscall.0 truncate.0 umask.0 unlink.0 utimes.0 \
	vfork.0 wait.0 write.0

#MLINKS+=brk.2 sbrk.2
#MLINKS+=dup.2 dup2.2
#MLINKS+=chdir.2 fchdir.2
#MLINKS+=chflags.2 fchflags.2
#MLINKS+=chmod.2 fchmod.2
#MLINKS+=chown.2 fchown.2
#MLINKS+=getgid.2 getegid.2
#MLINKS+=gethostid.2 sethostid.2
#MLINKS+=gethostname.2 sethostname.2
#MLINKS+=getitimer.2 setitimer.2
#MLINKS+=getlogin.2 setlogin.2
#MLINKS+=getpid.2 getppid.2
#MLINKS+=getpriority.2 setpriority.2
#MLINKS+=getrlimit.2 setrlimit.2
#MLINKS+=getsockopt.2 setsockopt.2
#MLINKS+=gettimeofday.2 settimeofday.2
#MLINKS+=getuid.2 geteuid.2
#MLINKS+=intro.2 errno.2
#MLINKS+=lseek.2 seek.2
#MLINKS+=mount.2 unmount.2
#MLINKS+=read.2 readv.2
#MLINKS+=recv.2 recvfrom.2 recv.2 recvmsg.2
#MLINKS+=send.2 sendmsg.2 send.2 sendto.2
#MLINKS+=stat.2 fstat.2 stat.2 lstat.2
#MLINKS+=statfs.2 fstatfs.2
#MLINKS+=truncate.2 ftruncate.2
#MLINKS+=wait.2 wait3.2 wait.2 wait4.2 wait.2 waitpid.2
#MLINKS+=write.2 writev.2

HP300_SRCS = ${HP300_GEN_SRCS} ${HP300_NET_SRCS} ${HP300_STDLIB_SRCS} \
	${HP300_STRING_SRCS} 

I386_SRCS = ${I386_GEN_SRCS} ${I386_NET_SRCS} ${I386_STDLIB_SRCS} \
	${I386_STRING_SRCS} 

TAHOE_SRCS = ${TAHOE_GEN_SRCS} ${TAHOE_NET_SRCS} ${TAHOE_STDLIB_SRCS} \
	${TAHOE_STRING_SRCS}

VAX_SRCS = ${VAX_GEN_SRCS} ${VAX_NET_SRCS} ${VAX_STDLIB_SRCS} \
	${VAX_STRING_SRCS} 

PMAX_SRCS = ${PMAX_GEN_SRCS} ${PMAX_NET_SRCS} ${PMAX_STDLIB_SRCS} \
	${PMAX_STRING_SRCS} 

PC532_SRCS = ${PC532_GEN_SRCS} ${PC532_NET_SRCS} ${PC532_STDLIB_SRCS} \
	${PC532_STRING_SRCS} 

VPATH = ${cpu}:${COMPAT43_VPATH}:${DB_VPATH}:${DB_BTREE_VPATH}:${DB_HASH_VPATH}:${GEN_VPATH}:${LOCALE_VPATH}:${NET_VPATH}:${STDIO_VPATH}:${STDLIB_VPATH}:${STRING_VPATH}:${SYS_VPATH} 

SRCS = ${COMPAT43_SRCS} ${DB_BTREE_SRCS} ${DB_HASH_SRCS} ${GEN_SRCS} \
	${GEN_REGEXP_SRCS} ${LOCALE_SRCS} ${NET_SRCS} ${STDIO_SRCS} \
	${STDLIB_SRCS} ${STRING_SRCS} ${SYS_SRCS} ${${TARGET_MACHINE}_SRCS}

OBJECTS = ${SRCS/(.*)\.[^.]*/\1.o/} \
	${SYS_OBJS} ${${TARGET_MACHINE}_STRING_OBJS}

MAN2PAGES = ${COMPAT43_MAN2} ${SYS_MAN2} 

MAN3PAGES = ${DB_MAN3} ${GEN_MAN3} ${NET_MAN3} ${STDIO_MAN3} ${STDLIB_MAN3} \
	${STRING_MAN3} 

include ${MAKETOP}Makefile-lib
-include Makedep
