#
# DMakeFile for asyncio library. Both shared library and normal library models.
#
#
# Does not generate all flavors; only the basic ones:
#   Normal arguments, smalldata
#   Registered arguments, smalldata
#
# Should be easy to modify below to generate other flavors, if needed.
#

SRC = CloseAsync.c OpenAsync.c OpenAsyncFH.c OpenAsyncFromFH.c ReadAsync.c \
      ReadCharAsync.c RecordAsyncFailure.c RequeuePacket.c SeekAsync.c SendPacket.c \
      WaitPacket.c WriteAsync.c WriteCharAsync.c

OBJ = $(SRC:*.?:*.o)

PRAGMA = /include/pragmas/asyncio_pragmas.h
FD     = /include/fd/asyncio_lib.fd

# Generate all "normal" flavors

All : /libs/asyncio.library $(PRAGMA) \
      /dlib/asynciolibs.lib /dlib/asynciolibsr.lib /dlib/asyncios.lib /dlib/asynciosr.lib \
      /lib/asyncio.lib /lib/asyncior.lib


# The only difference when making the shared library is that Lib.c is included
# (MUST be first), and that SHARED_LIB is defined. It only affects another define
# in the (private) include file async.h

/libs/asyncio.library : Lib.o $(OBJ)
	Sc LINK TO %(left) %(right)

Lib.o $(OBJ) : Lib.c $(SRC)
	Sc DEF ASIO_SHARED_LIB UTILLIB OBJNAME %(left) %(right)


/lib/asyncio.lib : $(SRC:*.c:*l.o) AsyncLib.o
	Sc OBJLIB %(left) %(right)

$(SRC:*.c:*l.o) : $(SRC)
	Sc PARAMS STACK OBJNAME %(left) %(right)

/lib/asyncior.lib : $(SRC:*.c:*lr.o) AsyncLib.o
	Sc OBJLIB %(left) %(right)

$(SRC:*.c:*lr.o) AsyncLib.o : $(SRC) AsyncLib.c
	Sc DEF ASIO_REGARGS OBJNAME %(left) %(right)


# Does this dependancy look odd to you? Well, it is a bit odd, but it need to
# be written like this in order to avoid a bug in DMake. If "$(SRC) : async.h"
# was used instead, DMake would recompile the files that _didn't_ need it, and
# ignore the ones that _did_ need it. ;)

$(OBJ) : async.h


# Keep the pragma file up to date

$(PRAGMA) : $(FD)
	FDTOPragma -o%(left) %(right)


# Link libraries for use with the shared version of the library. Only needed if
# the -mi option isn't used, or you use the autoinit stuff.

/lib/asynciolibs.lib : $(FD)
	FDToLib -o%(left) %(right) -auto asyncio.library

/lib/asynciolibsr.lib : $(FD)
	FDToLib -o%(left) %(right) -mr -hasynciolibsr.h -auto asyncio.library

# Large data models of the above two libraries. Not generated per default.

/lib/asynciolibs.lib : $(FD)
	FDToLib -o%(left) %(right) -auto asyncio.library -md

/lib/asynciolibsr.lib : $(FD)
	FDToLib -o%(left) %(right) -mr -hasynciolibsr.h -auto asyncio.library -md


# Here the normal link library versions are generated. See lib.def for more information.

/lib/asyncios.lib :
	LbMake asyncio s

/lib/asynciosr.lib :
	LbMake asyncio s r

# Other flavours, not generated per default

/lib/asynciol.lib :
	LbMake asyncio l

/lib/asynciorl.lib :
	LbMake asyncio l r

/lib/asyncioes.lib :
	LbMake asyncio s e

/lib/asyncioesr.lib :
	LbMake asyncio s r e

/lib/asyncioel.lib :
	LbMake asyncio l e

/lib/asyncioelr.lib :
	LbMake asyncio l r e

/lib/asynciolp.lib :
	LbMake asyncio l p

/lib/asynciolrp.lib :
	LbMake asyncio l r p

/lib/asyncioesp.lib :
	LbMake asyncio s p e

/lib/asyncioesrp.lib :
	LbMake asyncio s r p e

/lib/asyncioelp.lib :
	LbMake asyncio l p e

/lib/asyncioelrp.lib :
	LbMake asyncio l r p e

/lib/asynciosp.lib :
	LbMake asyncio s p

/lib/asynciosrp.lib :
	LbMake asyncio s r p


# SAS versions of some of the above

/lib/asyncioer.lib : $(SRC:*.c:*ler.o) AsyncLib.o
	Sc OBJLIB %(left) %(right)

$(SRC:*.c:*ler.o) : $(SRC)
	Sc DEF ASIO_REGARGS OBJNAME %(left) %(right)

/lib/asyncioe.lib : $(SRC:*.c:*le.o) AsyncLib.o
	Sc PARAMS STACK DEF ASIO_NO_EXTERNALS OBJLIB %(left) %(right)

$(SRC:*.c:*le.o) : $(SRC)
	Sc PARAMS STACK DEF ASIO_NO_EXTERNALS,ASIO_REGARGS OBJNAME %(left) %(right)

