SubDir TOP cryptlib ;

# hide variables that cryptlib shouldn't see
OrdinaryFLAGS = $(CCFLAGS) ;
CCFLAGS = -O2 ;
OrdinaryOPTIM = $(OPTIM) ;
OPTIM = "" ;
OrdinaryHDRS = $(HDRS) ;
HDRS = [ FDirName $(TOP) cryptlib ] ;
OrdinaryDEFINES = $(DEFINES) ;
DEFINES = DATA_LITTLEENDIAN NO_THREADS NDEBUG OSVERSION=2
    _REENTRANT __UNIX__ OPENSSL_NO_ASM ;

if $(USE_X86_ASM) {
    DEFINES += USE_ASM ;
}

# There are a few warnings in cryptlib. since we're not going to fix
# them (one of them even is a gcc bug), we disregard them.
CCFLAGS += -w ;

# Comment next line out to build a testable cryptlib. (testlib also
# needs three files to be writable: cryptlib/test/key_dual.p15,
# cryptlib/test/key_ren.p15 and cryptlib/test/key_test.p15).
ORYX_STRIPPED = 1 ;

if $(ORYX_STRIPPED) {
    DEFINES += ORYX_STRIPPED ;
}

# include all the subdirectories
SubInclude TOP cryptlib bn ;
SubInclude TOP cryptlib cert ;
SubInclude TOP cryptlib context ;
SubInclude TOP cryptlib crypt ;
SubInclude TOP cryptlib device ;
SubInclude TOP cryptlib envelope ;
SubInclude TOP cryptlib io ;
SubInclude TOP cryptlib kernel ;
SubInclude TOP cryptlib keyset ;
SubInclude TOP cryptlib mechs ;
SubInclude TOP cryptlib misc ;
SubInclude TOP cryptlib random ;
SubInclude TOP cryptlib session ;
SubInclude TOP cryptlib zlib ;

Build cryptlib : cryptapi.c cryptcfg.c cryptcrt.c cryptctx.c cryptdev.c
    cryptenv.c cryptkey.c cryptlib.c cryptses.c cryptusr.c ;

Depends libcl.a : $(set-cryptlib) ;
Archive libcl.a : $(set-cryptlib) ;
MakeLocate libcl.a : [ FDirName $(TOP) $(BUILD) $(SUBDIR_TOKENS) ] ;


# work around brokenness by including test last, with an extra define
# DEFINES += strnicmp=strncasecmp ;
# SubInclude TOP cryptlib test ;

# we could wrap the above subinclude in the next if, but in that case
# 'jam clean' might not clean in cryptlib/test

# we only build the tests if there's reason to believe they'll work
if ! $(ORYX_STRIPPED) {
    Executable testlib : cryptlib cryptlib-test ;
}
else {
    MakeLocate testlib : [ FDirName $(TOP) bin ] ;
    Clean clean : testlib ;
}

# recover the normal oryx variables
HDRS = $(OrdinaryHDRS) ;
DEFINES = $(OrdinaryDEFINES) ;
CCFLAGS = $(OrdinaryFLAGS) ;
OPTIM = $(OrdinaryOPTIM) ;
