###############################################################################
#
# Makefile to build
#
#     - sys.a (single and multithread)
#     - rsxnt.dll
#
# This makefile will be called from the directories st,mt and dll
#
# (c) Copyright 1997 Rainer Schnitker
#
###############################################################################

ifndef recursive

.PHONY rsxnt: st mt dll

st:
        $(MAKE) -C st -f ..\makefile recursive=1

mt:
        $(MAKE) -C mt -f ..\makefile recursive=1 multi=1

dll:
        $(MAKE) -C dll -f ..\makefile recursive=1 dll=1 rsxnt.dll

endif

###############################################################################

S=\rsxnt\source\rsxnt
I=\rsxnt\source\rsxnt\include
ES=\emx\src\lib\str

ifdef multi
MT = -Zmt
LIB = \rsxnt\lib\mt\sys.a
LIBC_A = \emx\lib\mt\c.a
else
MT =
LIB = \rsxnt\lib\st\sys.a
LIBC_A = \emx\lib\st\c.a
endif

ifdef dll
DEFINES=
else
DEFINES=-DEMX_SYS_LIB
endif

CC     = gcc -Zwin32 $(MT)
CFLAGS = -O2 -Wall -I$(I) $(DEFINES)
AFLAGS = -x assembler-with-cpp $(DEFINES)

VPATH=$(S)\sys;$(S)\helper;$(ES);$(ES)\386

.c.o:
        $(CC) -c $(CFLAGS) $<

.s.o:
        $(CC) -c $(AFLAGS) $<

SYSOBJS =  \
        accept.o \
        alarm.o \
        bind.o \
        brk.o \
        cgets.o \
        chdir.o \
        chdrive.o \
        chmod.o \
        chsize.o \
        clock.o \
        close.o \
        connect.o \
        dup.o \
        dup2.o \
        endthrea.o \
        execname.o \
        exit.o \
        fcntl.o \
        filefind.o \
        filesys.o \
        fstat.o \
        fsync.o \
        ftime.o \
        ftruncat.o \
        getcwd.o \
        getdrive.o \
        gethosti.o \
        gethostn.o \
        getpeern.o \
        getpid.o \
        getppid.o \
        getsockh.o \
        getsockn.o \
        getsocko.o \
        ghostbya.o \
        ghostbyn.o \
        gnetbyad.o \
        gnetbyna.o \
        gportbna.o \
        gportbnu.o \
        gservbyn.o \
        gservbyp.o \
        imphandl.o \
        impsockh.o \
        initthre.o \
        ioctl1.o \
        ioctl2.o \
        kill.o \
        listen.o \
        lseek.o \
        memacces.o \
        memavail.o \
        mkdir.o \
        newthrea.o \
        nls_ctyp.o \
        nls_memu.o \
        open.o \
        os_ver.o \
        pause.o \
        pipe.o \
        portacce.o \
        ptrace.o \
        raise.o \
        read.o \
        read_kbd.o \
        recv.o \
        recvfrom.o \
        remove.o \
        rename.o \
        rmdir.o \
        sbrk.o \
        scrsize.o \
        select.o \
        send.o \
        sendto.o \
        setsocko.o \
        setsyser.o \
        settime.o \
        shutdown.o \
        sigactio.o \
        signal.o \
        sigpendi.o \
        sigprocm.o \
        sigsuspe.o \
        sleep.o \
        sleep2.o \
        socket.o \
        spawnve.o \
        stat.o \
        swchar.o \
        syserrno.o \
        ttyname.o \
        uflags.o \
        ulimit.o \
        umask.o \
        utimes.o \
        wait.o \
        waitpid.o \
        write.o \
        emx_ver.o \
        fork.o \
        fork1.o \
        unwind.o

RSXNTOBJS = \
        checkcon.o \
        checkdir.o \
        checkpip.o \
        dofork.o \
        doptrace.o \
        error.o \
        exceptio.o \
        ft2stat.o \
        gethtype.o \
        gmt2st.o \
        heap.o \
        heapsize.o \
        init.o \
        initfile.o \
        initsock.o \
        newfile.o \
        ntansi.o \
        st2gmt.o \
        statino.o \
        termio.o \
        truncate.o \
        dll.o \
        argvenv.o \
        sysinit.o

LIBC =  memcpy.o memchr.o memcmp.o memset.o strchr.o strcmp.o strncmp.o

DLLOBJS = dll0w32.o \
          doscall.o \
          emxcall.o \
          win32s.o \
          rsxnt.def

DIFOBJS = sysinit.o  \
          dll.o      \
          error.o    \
          init.o     \
          initsock.o \
          brk.o      \
          kill.o     \
          memacces.o \
          pause.o    \
          raise.o    \
          read.o     \
          read_kbd.o \
          sigactio.o \
          signal.o   \
          sigprocm.o \
          sleep.o    \
          sleep2.o   \
          spawnve.o  \
          wait.o     \
          waitpid.o  \
          write.o

$(LIB): $(SYSOBJS) $(RSXNTOBJS) $(LIBC)
        -del $(LIB)
        ar r $(LIB) \rsxnt\source\lib\IMPORT#1 $(SYSOBJS) $(RSXNTOBJS) $(LIBC)

rsxnt.dll: $(DLLOBJS) $(DIFOBJS) rsxnt.res
        -del rsxnt.dll
        $(CC) -nostartfiles -s -Zdll -Zno-rte -o rsxnt.dll $(DLLOBJS) $(DIFOBJS) -lsys -v
        rsrc rsxnt.dll rsxnt.res

$(SYSOBJS): $(I)\rsxnt.h
$(RSXNTOBJS): $(I)\rsxnt.h
$(DLLOBJS): $(I)\rsxnt.h
$(DIFOBJS): $(I)\rsxnt.h

__getsockhandle.o: $(I)\rsxntso.h
__socket.o: $(I)\rsxntso.h
__bind.o: $(I)\rsxntso.h
__listen.o: $(I)\rsxntso.h
__recv.o: $(I)\rsxntso.h
__send.o: $(I)\rsxntso.h
__accept.o: $(I)\rsxntso.h
__connect.o: $(I)\rsxntso.h
__getsockopt.o: $(I)\rsxntso.h
__setsockopt.o: $(I)\rsxntso.h
__getsockname.o: $(I)\rsxntso.h
__getpeername.o: $(I)\rsxntso.h
__gethostbyname.o: $(I)\rsxntso.h
__gethostbyaddr.o: $(I)\rsxntso.h
__getservbyname.o: $(I)\rsxntso.h
__getservbyport.o: $(I)\rsxntso.h
__getprotobyname.o: $(I)\rsxntso.h
__getprotobynumber.o: $(I)\rsxntso.h
__getnetbyname.o: $(I)\rsxntso.h
__getnetbyaddr.o: $(I)\rsxntso.h
__gethostname.o: $(I)\rsxntso.h
__gethostid.o: $(I)\rsxntso.h
__shutdown.o: $(I)\rsxntso.h
__recvfrom.o: $(I)\rsxntso.h
__sendto.o: $(I)\rsxntso.h
__impsockhandle.o: $(I)\rsxntso.h
#__recvmsg.o: $(I)\rsxntso.h
#__sendmsg.o: $(I)\rsxntso.h

memcpy.o: $(LIBC_A)
        ar x $(LIBC_A) memcpy.o
memchr.o: $(LIBC_A)
        ar x $(LIBC_A) memchr.o
memcmp.o: $(LIBC_A)
        ar x $(LIBC_A) memcmp.o
memset.o: $(LIBC_A)
        ar x $(LIBC_A) memset.o
strchr.o: $(LIBC_A)
        ar x $(LIBC_A) strchr.o
strcmp.o: $(LIBC_A)
        ar x $(LIBC_A) strcmp.o
strncmp.o: $(LIBC_A)
        ar x $(LIBC_A) strncmp.o

rsxnt.res: $(S)/buildide/rsxnt.rc
        rc -I$(S)/builddll /forsxnt.res $(S)/builddll/rsxnt.rc
