/* Portability library Imakefile */
XCOMM Portability library Makefile

#if !HasStrcasecmp
XCOMM system doesn't have strcasecmp(), provide it in portlib.
STRSRCS = strcasecmp.c
STROBJS = strcasecmp.o
#endif

DEFINES = \
	-DHAS_SYSCONF=HasSysconf \
	-DHAS_FLOCK=HasFlock \
	-DHAS_FCNTL=HasFcntl \
	-DHAS_SYS_DIR_H=HasSysDirH \
	-DHAS_DIRENT_H=HasDirentH \
	-DHAS_BCOPY=HasBCopy

    LIBSRCS = ato.c dir.c fd.c lock.c mem.c $(STRSRCS)
    LIBOBJS = ato.o dir.o fd.o lock.o mem.o $(STROBJS)

    ATOSRCS = atotest.c
    ATOOBJS = atotest.o
    ATOLIBS = $(PORTLIB)
 DEPATOLIBS = $(DEPPORTLIB)

    DIRSRCS = dirtest.c
    DIROBJS = dirtest.o
    DIRLIBS = $(PORTLIB)
 DEPDIRLIBS = $(DEPPORTLIB)

     FDSRCS = fdtest.c
     FDOBJS = fdtest.o
     FDLIBS = $(PORTLIB)
  DEPFDLIBS = $(DEPPORTLIB)

   LOCKSRCS = locktest.c
   LOCKOBJS = locktest.o
   LOCKLIBS = $(PORTLIB)
DEPLOCKLIBS = $(DEPPORTLIB)

    MEMSRCS = memtest.c
    MEMOBJS = memtest.o
    MEMLIBS = $(PORTLIB)
 DEPMEMLIBS = $(DEPPORTLIB)

       SRCS = $(LIBSRCS) $(ATOSRCS) $(DIRSRCS) $(FDSRCS) $(LOCKSRCS) $(MEMSRCS)

all::

NormalLibraryObjectRule()

BuildNormalLibrary(port,$(LIBSRCS),$(LIBOBJS))
InstallLibrary(port,$(LOCALUSRLIBDIR))

InstallIncludeFile(portlib.h,$(LOCALINCLUDEROOT))

BuildProgram(atotest,$(ATOSRCS),$(ATOOBJS),$(ATOLIBS),$(DEPATOLIBS))
FakeInstallFile(atotest)

BuildProgram(dirtest,$(DIRSRCS),$(DIROBJS),$(DIRLIBS),$(DEPDIRLIBS))
FakeInstallFile(dirtest)

BuildProgram(fdtest,$(FDSRCS),$(FDOBJS),$(FDLIBS),$(DEPFDLIBS))
FakeInstallFile(fdtest)

BuildProgram(locktest,$(LOCKSRCS),$(LOCKOBJS),$(LOCKLIBS),$(DEPLOCKLIBS))
FakeInstallFile(locktest)

BuildProgram(memtest,$(MEMSRCS),$(MEMOBJS),$(MEMLIBS),$(DEPMEMLIBS))
FakeInstallFile(memtest)

ShScriptFromMsubTemplate(porttest,porttest.sh,NullArg)
FakeInstallFile(porttest)

DependTarget()

SimpleWorldTarget($(PROJECTNAME),$(PROJECTRELEASE))

HelpAuxTarget(test-all,test all portlib operations)

test-all:: porttest atotest dirtest fdtest locktest memtest
	./porttest

HelpAuxTarget(test-ato,test string-conversion operations)

test-ato:: porttest atotest
	./porttest ato

HelpAuxTarget(test-dir,test directory-reading operations)

test-dir:: porttest dirtest
	./porttest dir

HelpAuxTarget(test-fd,test file-descriptor operations)

test-fd:: porttest fdtest
	./porttest fd

HelpAuxTarget(test-lock,test file-locking operations)

test-lock:: porttest locktest
	./porttest lock

XCOMM remove test lock file used by locktest
StuffToClean(lock.test)

HelpAuxTarget(test-mem,test memory operations)

test-mem:: porttest memtest
	./porttest mem
