# distributed.net client makefile for VC
# see http://www.distributed.net/
#
# $Id: makefile.vc,v 1.56.2.10 1999/11/15 04:48:55 cyp Exp $
#

!ifndef PROCESSOR_ARCHITECTURE
PROCESSOR_ARCHITECTURE = x86
!endif # default to x86
!if "$(PROCESSOR_ARCHITECTURE)" == "ALPHA"
ALPHA=1
!endif

BASENAME = dnetc
OUTPUTPATH = output
COMMONPATH = common
RC5SRCPATH = rc5
DESSRCPATH = des
OGRSRCPATH = ogr
CSCSRCPATH = csc
CHIPSRCPATH = platforms
PLATSRCPATH = platforms/win32cli

# --------------------------------------------

!ifdef DEBUG
OPTS_CC_DEBUG = -Zi -DDEBUG
OPTS_LINK_DEBUG = /debug /pdb:none /pdbtype:consolidate
!else
OPTS_CC_DEBUG = -DNDEBUG
OPTS_LINK_DEBUG = /release
!endif

!ifdef ALPHA
OPTS_CC_CPU = -DNTALPHA -DKWAN -DDWORZ
OPTS_M_PLAT = ALPHA
OPTS_AS = -Gy -Zi -O1
!else
OPTS_CC_CPU = -DMMX_BITSLICER -DMEGGS -DKWAN -DMMX_RC5
OPTS_M_PLAT = IX86
!endif

# a little blurb about options
#
# -Gs<num> == control stack probes (DevStudio docs)
#          == disable stack checks ("cl -?")
# -Gf == eliminates duplicate strings
# -Gy == enable function-level linking
# -GR- ==disable RTTI
# -GX- ==disable synchronous exception handling
# -GA == optimize code for windows application
#
# -Og == global optimizations
# -Oi == intrinsic functions
# -Os == favor small code
# -Ot == favor fast code
# -Oy == omit frame pointer
# -Oa == assume no aliasing
# -Ob0 == disable inline function expansion
# -Ob1 == only "inline" or "__inline" functions will be expanded
# -Ob2 == any suitable functions will be expanded
#
# -O1 == -Og     -Os -Oy -Ob1 -Gs -Gf -Gy
# -O2 == -Og -Oi -Ot -Oy -Ob1 -Gs -Gf -Gy
# -Ox == -Og -Oi -Ot -Oy -Ob1 -Gs

OPTS_MSVC = -nologo -I$(COMMONPATH) -I$(PLATSRCPATH) \
            -I$(DESSRCPATH) -I$(OGRSRCPATH) -I$(CSCSRCPATH) \
            -DMULTITHREAD -D__WIN32__ -D_CPU_32BIT_ -DBIT_64 -DLURK \
            -DHAVE_DES_CORES -DHAVE_CSC_CORES \
            -W3 -MT -GR- -GX- -GA -GF \
            -D_M_$(OPTS_M_PLAT) $(OPTS_CC_CPU) $(OPTS_CC_DEBUG) 
#           -DHAVE_OGR_CORES 
OPTS_LIBS = advapi32.lib user32.lib kernel32.lib gdi32.lib
OPTS_LINK = /nologo /incremental:no /version:3.10 \
            /machine:$(OPTS_M_PLAT) $(OPTS_LINK_DEBUG)
OPTS_RC   = -d_Windows -d_M_{$(OPTS_M_PLAT)}


# --------------------------------------------

all: $(BASENAME)

# --------------------------------------------

RES_FILE = $(OUTPUTPATH)/$(BASENAME).res
RC_FILE = $(PLATSRCPATH)/w32cons.rc

COMMON_OBJS =                        \
        $(OUTPUTPATH)/autobuff.obj   \
        $(OUTPUTPATH)/base64.obj     \
        $(OUTPUTPATH)/bench.obj      \
	$(OUTPUTPATH)/buffbase.obj   \
        $(OUTPUTPATH)/checkpt.obj    \
        $(OUTPUTPATH)/clicdata.obj   \
        $(OUTPUTPATH)/client.obj     \
        $(OUTPUTPATH)/clievent.obj   \
        $(OUTPUTPATH)/cliident.obj   \
        $(OUTPUTPATH)/clirate.obj    \
        $(OUTPUTPATH)/clirun.obj     \
        $(OUTPUTPATH)/clisrate.obj   \
        $(OUTPUTPATH)/clitime.obj    \
        $(OUTPUTPATH)/cmdline.obj    \
        $(OUTPUTPATH)/confmenu.obj   \
        $(OUTPUTPATH)/confopt.obj    \
        $(OUTPUTPATH)/confrwv.obj    \
        $(OUTPUTPATH)/console.obj    \
        $(OUTPUTPATH)/convdes.obj    \
        $(OUTPUTPATH)/cpucheck.obj   \
        $(OUTPUTPATH)/disphelp.obj   \
        $(OUTPUTPATH)/iniread.obj    \
        $(OUTPUTPATH)/logstuff.obj   \
        $(OUTPUTPATH)/lurk.obj       \
        $(OUTPUTPATH)/mail.obj       \
        $(OUTPUTPATH)/modereq.obj    \
        $(OUTPUTPATH)/netinit.obj    \
        $(OUTPUTPATH)/netres.obj     \
        $(OUTPUTPATH)/network.obj    \
        $(OUTPUTPATH)/pathwork.obj   \
        $(OUTPUTPATH)/pollsys.obj    \
        $(OUTPUTPATH)/probfill.obj   \
        $(OUTPUTPATH)/problem.obj    \
        $(OUTPUTPATH)/probman.obj    \
        $(OUTPUTPATH)/random.obj     \
        $(OUTPUTPATH)/selcore.obj    \
        $(OUTPUTPATH)/selftest.obj   \
        $(OUTPUTPATH)/setprio.obj    \
        $(OUTPUTPATH)/triggers.obj   \
        $(OUTPUTPATH)/util.obj

PLAT_OBJS =                          \
        $(OUTPUTPATH)/w32cons.obj    \
        $(OUTPUTPATH)/w32pre.obj     \
        $(OUTPUTPATH)/w32ras.obj     \
        $(OUTPUTPATH)/w32sock.obj    \
        $(OUTPUTPATH)/w32ss.obj      \
        $(OUTPUTPATH)/w32svc.obj     \
        $(OUTPUTPATH)/w32util.obj

SCR_OBJS =                           \
        $(OUTPUTPATH)/w32ss.obj      \
        $(OUTPUTPATH)/w32ssb.obj     \
        $(OUTPUTPATH)/w32util.obj

CUI_OBJS =                           \
        $(OUTPUTPATH)/w32cuis.obj

# -------

!ifdef ALPHA
CHIP_OBJS =
!else
CHIP_OBJS = $(OUTPUTPATH)/x86ident.obj
!endif

# -------

!ifdef ALPHA
RC5_OBJS_CHIP =                      \
        $(OUTPUTPATH)/rc5-alpha-nt.obj
!else
RC5_OBJS_CHIP =                      \
        $(OUTPUTPATH)/brfp5.obj      \
        $(OUTPUTPATH)/rc5-rgk5.obj   \
        $(OUTPUTPATH)/rc5-rgk6.obj   \
        $(OUTPUTPATH)/rc5-rgp6.obj   \
        $(OUTPUTPATH)/rc5mmx.obj     \
        $(OUTPUTPATH)/rg486.obj      \
        $(OUTPUTPATH)/rg6x86.obj
!endif

# -------

!ifdef ALPHA
DES_OBJS_CHIP =                              \
        $(OUTPUTPATH)/des-slice-dworz.obj    \
        $(OUTPUTPATH)/deseval-dworz3.obj
!else                                
DES_OBJS_CHIP =                              \
        $(OUTPUTPATH)/bbdeslow.obj           \
        $(OUTPUTPATH)/bdeslow.obj            \
        $(OUTPUTPATH)/des-slice.obj          \
        $(OUTPUTPATH)/des-slice-meggs.obj    \
        $(OUTPUTPATH)/des-x86.obj            \
        $(OUTPUTPATH)/deseval.obj            \
#       $(OUTPUTPATH)/deseval-meggs3-mmx.gcc \
        $(OUTPUTPATH)/deseval-mmx.obj        \
        $(OUTPUTPATH)/p1bdespro.obj          \
        $(OUTPUTPATH)/p2bdespro.obj          \
        $(OUTPUTPATH)/sboxes-kwan4.obj       \
#       $(OUTPUTPATH)/sboxes-mmx.obj
!endif

# -------

!ifdef ALPHA
CSC_OBJS =                           \
        $(OUTPUTPATH)/convcsc.obj    \
        $(OUTPUTPATH)/csc-1k.obj     \
        $(OUTPUTPATH)/csc-1k-i.obj   \
        $(OUTPUTPATH)/csc-6b.obj     \
        $(OUTPUTPATH)/csc-6b-i.obj   \
        $(OUTPUTPATH)/csc-common.obj
!else                                
CSC_OBJS =                           \
        $(OUTPUTPATH)/convcsc.obj    \
        $(OUTPUTPATH)/csc-1k.obj     \
        $(OUTPUTPATH)/csc-1k-i.obj   \
        $(OUTPUTPATH)/csc-6b.obj     \
        $(OUTPUTPATH)/csc-6b-i.obj   \
        $(OUTPUTPATH)/csc-comm.obj
!endif

# -------

OGR_OBJS =
#OGR isn't ready yet
#OGR_OBJS =                           \
#        $(OUTPUTPATH)/choosedat.obj  \
#        $(OUTPUTPATH)/crc32.obj      \
#        $(OUTPUTPATH)/ogr.obj

# --------------------------------------------

!ifdef ALPHA
{$(RC5SRCPATH)/alpha}.s{$(OUTPUTPATH)}.obj:
        asaxp $(OPTS_AS) -Fo$@ $<

{$(DESSRCPATH)/alpha-asm}.s{$(OUTPUTPATH)}.obj:
        asaxp $(OPTS_AS) -Fo$@ $<

{$(DESSRCPATH)/alpha-asm}.cpp{$(OUTPUTPATH)}.obj::
        cl -c $(OPTS_MSVC) -Ox -Fo$(OUTPUTPATH)\ $<

{$(CSCSRCPATH)}.cpp{$(OUTPUTPATH)}.obj::
        cl -c $(OPTS_MSVC) -Ox -Fo$(OUTPUTPATH)\ $<
!else
{$(CHIPSRCPATH)}.asm{$(OUTPUTPATH)}.obj:
        tasm32 /t /m /ml /dmodelnum=2 $(**:/=\), $(@:/=\)

{$(RC5SRCPATH)/x86/nasm}.asm{$(OUTPUTPATH)}.obj:
        nasmw -o $(@:/=\) -f win32 -i $(RC5SRCPATH:/=\)\x86\nasm\ $(**:/=\)

{$(DESSRCPATH)/brydmasm}.asm{$(OUTPUTPATH)}.obj:
        tasm32 /t /m /ml /dmodelnum=2 /i$(DESSRCPATH:/=\)\brydmasm $(**:/=\), $(@:/=\)

{$(DESSRCPATH)/nasm}.asm{$(OUTPUTPATH)}.obj:
        nasmw -o $(@:/=\) -f win32 -i $(DESSRCPATH:/=\)\nasm\ $(**:/=\)

{$(DESSRCPATH)/mmx-bitslice}.asm{$(OUTPUTPATH)}.obj:
        nasmw -o $(@:/=\) -f win32 -i $(DESSRCPATH:/=\)\mmx-bitslice\ $(**:/=\)

{$(CSCSRCPATH)/x86}.asm{$(OUTPUTPATH)}.obj:
        nasmw -o $(@:/=\) -f win32 -i $(CSCSRCPATH:/=\)\x86\ $(**:/=\)
!endif

{$(DESSRCPATH)}.cpp{$(OUTPUTPATH)}.obj::
        cl -c $(OPTS_MSVC) -Ox -Fo$(OUTPUTPATH)\ $<

{$(OGRSRCPATH)}.cpp{$(OUTPUTPATH)}.obj::
        cl -c $(OPTS_MSVC) -Ox -Fo$(OUTPUTPATH)\ $<

{$(PLATSRCPATH)}.cpp{$(OUTPUTPATH)}.obj::
        cl -c $(OPTS_MSVC) -O1 -Fo$(OUTPUTPATH)\ $<

{$(PLATSRCPATH)}.c{$(OUTPUTPATH)}.obj::
        cl -c -Zl -O1 -Fo$(OUTPUTPATH)\ $<

{$(COMMONPATH)}.cpp{$(OUTPUTPATH)}.obj::
        cl -c $(OPTS_MSVC) -O2 -Fo$(OUTPUTPATH)\ $<

#$(RC_FILE):
#       echo 1 ICON $(PLATSRCPATH)\w32cons.ico > $(@:/=\)

$(RES_FILE):    $(RC_FILE)
        rc  -i $(OPTS_RC) -I$(COMMONPATH) -fo$@ $(**:/=\)

# --------------------------------------------

$(BASENAME): $(PLAT_OBJS) $(COMMON_OBJS) $(CHIP_OBJS) $(RC5_OBJS_CHIP) $(DES_OBJS_CHIP) $(OGR_OBJS) $(CSC_OBJS) $(SCR_OBJS) $(CUI_OBJS) $(RES_FILE)
        link $(OPTS_LINK) /SUBSYSTEM:WINDOWS /OUT:$(BASENAME).scr /version:4.0 $(OPTS_LIBS) $(SCR_OBJS) $(RES_FILE) 
        link $(OPTS_LINK) /SUBSYSTEM:CONSOLE /OUT:$(BASENAME).com $(OPTS_LIBS) $(CUI_OBJS)
        link $(OPTS_LINK) /SUBSYSTEM:WINDOWS /OUT:$(BASENAME).exe $(OPTS_LIBS) $(PLAT_OBJS) $(COMMON_OBJS) $(CHIP_OBJS) $(RC5_OBJS_CHIP) $(DES_OBJS_CHIP) $(OGR_OBJS) $(CSC_OBJS) $(RES_FILE)

clean:
        -del $(OUTPUTPATH:/=\)\*.obj $(RES_FILE:/=\)

superclean: clean
        -del $(BASENAME).exe $(BASENAME).scr $(BASENAME).com $(BASENAME).ini buff-in.* buff-out.*

rebuild: clean all

# --------------------------------------------
