! Project Predefined
!! predefine TopSpeed compilers
!if mod
#declare_compiler mod=
'#set make=%%remake_jpi
 #if %%make #then #rundll TSMOD %%src %%obj #endif
 #pragma link(%%obj)
 #set tsm2=on'
!end
!if pas
#declare_compiler pas=
'#set make=%%remake_jpi
 #if %%make #then #rundll TSPAS %%src %%obj #endif
 #pragma link(%%obj)
 #set tspas=on'
#declare_compiler plg=
'#set make=%%remake_jpi
 #if %%make #then #rundll TSPAS_LG %%src %%obj #endif
 #pragma link(%%obj)
 #set tspas=on'
!end
!if cpp
#declare_compiler cpp=
'#set make=%%remake_jpi
 #if %%make #then
    #rundll TSCPP %%src %%obj
    #if %%system=epoc #then
	#run "ecppfx -s %%obj" no_window no_abort
    #endif
 #endif
 #pragma link_option(decode=>on)
 #pragma link(%%obj)
 #set tsc=on #set tscpp=on'
!! This declaration is overriden by the one below if TopSpeed C is installed
#declare_compiler c=
'#set make=%%remake_jpi
 #if %%make #then #rundll TSCPP %%src %%obj #endif
 #pragma link(%%obj)
 #set tsc=on'
!end
!if c
#declare_compiler c=
'#set make=%%remake_jpi
 #if %%make #then #rundll TSC %%src %%obj #endif
 #pragma link(%%obj)
 #set tsc=on'
!end
!if asm
#declare_compiler a=
'#set make=%%remake_jpi
 #if %%make #then #rundll TSASM %%src %%obj #endif
 #pragma link(%%obj)'
!end
!if masm
#declare_compiler asm=
'#set make=%%remake
 #if %%make #then
  #edit save %%src
  #run "masm %%src,%%obj; >masmtmp.$$$" no_window no_abort
  #file adderrors masmtmp.$$$
  #file delete masmtmp.$$$
 #endif
 #pragma link(%%obj)'
!end

#declare_compiler rc=
'#split %%obj
 #set obj = %%name.res
 #set make=%%remake
 #if %%make #then
  #edit save %%src
  #run "tsrc %%src >rctmp.$$$" no_window no_abort
  #file adderrors rctmp.$$$
  #file delete rctmp.$$$
 #endif
 #pragma link(%%obj)'

#declare_compiler cat=
'#split %%src
 #set make=%%remake
 #if %%make #or %%name.g #older %%name.cat #then
  #run "ctran %%name -c -s -v -l -e..\include\ -x..\include\ -g..\include\" no_window no_abort
  #rundll TSC %%name.c %%name.obj
  #run "ecobj %%name.obj" no_window no_abort
 #endif
 #pragma link(%%name.obj)'

#if %action%=compile #then
!! declarations to allow compilation of include files
!if mod
 #declare_compiler def='#rundll TSMOD %%src %%obj'
!end
!if cpp
 #declare_compiler hpp='#rundll TSCPP %%src %%obj'
 #declare_compiler h='#rundll TSCPP %%src %%obj'
!end
!if C
 #declare_compiler h='#rundll TSC   %%src %%obj'
!end
#endif

!! End of compiler predefinition section
!! =========================================================================
! Project Model
!! The following lines are executed whenever the #model command is used
!! in a project file.

#pragma call(near_call=>on,same_ds=>on,ds_eq_ss=>on,overlay=>off)
#pragma data(far_ext=>off,near_ptr=>on,threshold=>65535,const_in_code=>off,ss_in_dgroup=>on,ds_dynamic=>off)
#pragma define(_fdata=>off,_fcall=>off,_fptr=>off,_mthread=>off)
#pragma link_option(map=>on,case=>on,pack=>on,oldexe=>off)
#pragma define(M_I86SM=>off,M_I86CM=>off,M_I86MM=>off,M_I86LM=>off,M_I86XM=>off,M_I86TM=>off,M_I86MTM=>off,M_I86OM=>off,M_I86DM=>off)

!! PSION SIBO change
#pragma optimize(speed=>off)
#if %system=epoc #then
 #if #not %model=small #then
  #error "ERROR - must use small model for epoc"
 #endif
 #if #not %filetype=img #then
  #if #not %filetype=dyl #then
   #error "ERROR - illegal parameter in #system: %filetype"
  #endif
 #endif
 #if "%epocinit"="" #then
  #set epocinit=iclib
 #endif
#endif
!! end of PSION SIBO change

#if "%system"="" #then
 #error "#model not preceded by #system"
!if smallmodel
#elsif %model=small #then
 #set M=S
 #pragma define(M_I86SM=>on)
!end
!if compactmodel
#elsif %model=compact #then
 #set M=C
 #pragma call(ds_eq_ss=>off)
 #pragma data(near_ptr=>off,threshold=>32767,ss_in_dgroup=>off)
 #pragma define(_fptr=>on)
 #pragma define(M_I86CM=>on)
!end
!if mediummodel
#elsif %model=medium #then
 #set M=M
 #pragma call(near_call=>off)
 #pragma define(_fcall=>on)
 #pragma define(M_I86MM=>on)
!end
!if largemodel
#elsif %model=large #then
 #set M=L
 #pragma call(near_call=>off,ds_eq_ss=>off),data(near_ptr=>off,threshold=>32767,ss_in_dgroup=>off)
 #pragma define(_fcall=>on,_fptr=>on)
 #pragma define(M_I86LM=>on)
!end
!if xlargemodel
#elsif %model=xlarge #then
 #if #not %system=win #then
  #set M=X
  #pragma call(near_call=>off,same_ds=>off,ds_eq_ss=>off),data(far_ext=>on,near_ptr=>off,const_in_code=>on,ss_in_dgroup=>off,ds_dynamic=>on)
  #pragma define(_fcall=>on,  _fdata=>on,_fptr=>on)
  #pragma define(M_I86XM=>on)
 #else
  #error "Extra-large model not available for Windows programs"
 #endif
!end
!if mthreadmodel
#elsif %model=mthread #then
 #if #not %system=win #then
  #set M=T
  #pragma call(near_call=>off,same_ds=>off,ds_eq_ss=>off),data(far_ext=>on,near_ptr=>off,const_in_code=>on,ss_in_dgroup=>off,ds_dynamic=>on)
  #pragma define(_fcall=>on,  _fdata=>on,_fptr=>on,_mthread=>on)
  #pragma define(M_I86TM=>on,M_I86MTM=>on)
 #else
  #error "Multi-thread model not available for Windows programs"
 #endif
!end
!if overlaymodel
#elsif %model=overlay #then
 #if %system=dos #then
  #set M=O
  #pragma call(near_call=>off,same_ds=>off,overlay=>on,ds_eq_ss=>off),data(far_ext=>on,near_ptr=>off,const_in_code=>off,ss_in_dgroup=>off,ds_dynamic=>on)
  #pragma define(_fcall=>on,_fdata=>on,_fptr=>on,_mthread=>on)
  #pragma define(M_I86OM=>on)
 #else
  #error "Overlay model not available for %system programs"
 #endif
!end
!if dynalinkmodel
#elsif %model=dynalink #then
 #if #not %system=win #then
  #set M=D
  #pragma call(near_call=>off,same_ds=>off,ds_eq_ss=>off),data(far_ext=>on,near_ptr=>off,ss_in_dgroup=>off,ds_dynamic=>on)
  #if %system=dos #then
   #pragma call(overlay=>on)
  #else
   #pragma data(const_in_code=>on)
  #endif
  #pragma define(_fcall=>on,_fdata=>on,_fptr=>on,_mthread=>on)
  #pragma define(M_I86DM=>on)
  #pragma link_option(smart_method=>off)
 #else
  #error "Dynalink model not available for Windows programs"
 #endif
!end
#else
 #error "Unrecognized argument %model"
#endif

#if "%jpicall"="" #then #set jpicall=jpi #endif
#if %jpicall=jpi #then
 #pragma call(reg_saved=>(ax,bx,cx,dx,si,di,ds,st1,st2))
 #pragma call(reg_param=>(ax,bx,cx,dx,st0,st6,st5,st4,st3))
 #pragma call(reg_return=>(ax,dx,st0))
 #pragma call(standard_conv=>off,standard_float=>off,opt_var_arg=>on)
 #if %model=overlay #or (%model=dynalink #and %system=dos) #then
  #pragma call(opt_var_arg=>off)
 #endif
 #set C=_
 #pragma define(_jpicall=>on)
#elsif %jpicall=stack #then
 #pragma call(reg_saved=>(si,di,ds,st1,st2))
 #pragma call(reg_param=>())
 #pragma call(reg_return=>(ax,dx))
 #pragma call(standard_conv=>on,standard_float=>on,opt_var_arg=>off)
 #set C=F
 #pragma define(_jpicall=>off)
#else
 #error "Unrecognized argument %jpicall"
#endif

#if %system=win #then
 #set O=W
 #pragma link_option(pack=>off,windows=>on),call(windows=>on)
#elsif %system=dos #then
 #set O=R
 #pragma link_option(oldexe=>on,pack=>off),call(windows=>off)
 #pragma optimize(cpu=>86)
#elsif %system=os2 #then
 #set O=P
 #pragma optimize(cpu=>286),call(windows=>off)
!! PSION SIBO change
#elsif %system=epoc #then
 #set O=R
 #pragma link_option(case=>on,oldexe=>on,pack=>off)
 #pragma optimize(cpu=>86)
 #pragma data(no_far_data=>on)
 #pragma define(EPOC=>1)
 #if "%epocinit"="iclib" #then
  #pragma data(stack_size=>8192)
 #elsif "%epocinit"="iclib4" #then
  #pragma data(stack_size=>4096)
 #elsif "%epocinit"="iclib2" #then
  #pragma data(stack_size=>2048)
 #elsif "%epocinit"="iplib8" #then
  #pragma data(stack_size=>8192)
 #elsif "%epocinit"="iplib" #then
  #pragma data(stack_size=>4096)
 #elsif "%epocinit"="iplib2" #then
  #pragma data(stack_size=>2048)
 #else
  #error "Unknown epocinit: %epocinit"
 #endif
!! end of PSION SIBO change
#else
 #error "Unknown argument to #system: %system"
#endif

!! defines used by library source files
!! you may wish to disable these in order to share OS2/DOS object files
!! _DLL may not be disabled
#pragma define(_ENV=>off,_WINDOWS=>off,_DLL=>off,_WINDLL=>off,_OVL=>off,_OS2=>off,__OS2__=>off,__MSDOS__=>off)
#if %system=os2 #then #pragma define(__OS2__=>on,_OS2=>on) #endif
#if %system=dos #then #pragma define(__MSDOS__=>on) #endif
#if %system=win #then #pragma define(_WINDOWS=>on) #endif
#if %model=overlay  #then #pragma define(_OVL=>on) #endif
#if %model=dynalink #then #pragma define(_DLL=>on) #endif

!! End of Project model section
!! =========================================================================
! Project Link
!! The following lines are executed whenever a #link command is executed in
!! a project file

#autocompile

!! Calculate lfiletype - the type of file being made for this #link only
!! Default is the filetype specified by #system (%filetype)

#if "%filetype"="" #then
!! PSION SIBO change
 #if %system=epoc #then
  #set filetype=img
 #else
  #set filetype=exe
 #endif
!! end of PSION SIBO change
#endif

#split %link_arg
#if "%ext"="" #then
 #set lfiletype_=%filetype
 #set ext=%filetype
#elsif (%ext=exe) #or (%ext=dll) #or (%ext=lib) #then
 #set lfiletype_=%ext
#else
 #set lfiletype_=%filetype
#endif

!! PSION SIBO change
#if %system=epoc #then
 #if %filetype=img #then
  #set epoctype=t1
 #elsif %filetype=dyl #then
  #set epoctype=t4
 #endif
#endif
!! end of PSION SIBO change

!! Calculate any additional libraries or object files that need to be linked

#if #not %lfiletype_=lib #then
 #if %system=win #then
  #if %lfiletype_=dll #then
   #compile initwdll.a
   #pragma linkfirst(initwdll.obj)
  #elsif %filetype=exe #then
   #if "%tsm2" #or "%tspas" #then
    #compile initmwin.a
    #pragma linkfirst(initmwin.obj)
   #else
    #compile initwin.a
    #pragma linkfirst(initwin.obj)
   #endif
  #else
   #error "Unknown argument to #system: %filetype"
  #endif
 #else
  #if %lfiletype_=dll #then
    #pragma linkfirst(initdll.obj)
  #elsif %lfiletype_=exe #then
   #if (#not ("%tsc" #or "%tscpp")) #and (%system = dos)
      #and (("%model"=xlarge) #or ("%model"=mthread)) #then
     #pragma linkfirst(initnew.obj)
   #elsif "%pm_api" #and (%system=os2) #then
     #pragma link_option(pm=>on,non_pm=>off)
     #pragma linkfirst(initpm.obj)
!! PSION SIBO change
   #elsif %system=epoc #then
    #if %filetype=img #then
     #pragma linkfirst(%epocinit.obj)
    #else
     #pragma linkfirst(icat.obj)
    #endif
!! end of PSION SIBO change
   #else
     #pragma linkfirst(initexe.obj)
   #endif
   #if (%system=os2) #then
    #if "%pm_compat" #then
     #pragma link_option(pm=>on,non_pm=>on)
    #elsif "%pm_noncompat" #then
     #pragma link_option(pm=>off,non_pm=>on)
    #endif
   #endif
  #else
 !! PSION SIBO change
   #if %system=epoc #then
    #if %filetype=img #then
     #pragma linkfirst(%epocinit.obj)
    #else
     #pragma linkfirst(icat.obj)
    #endif
   #else
    #error "Unknown argument to #system: %filetype"
   #endif
!! end of PSION SIBO change
  #endif
 #endif

!! calculate jpilib_

 #set prefix_="%O%%M%%C%"
 #if (%lfiletype_=dll) #and (%system=win) #then
   #set jpilib_="%prefix_%comd.lib"
 #else
   #set jpilib_="%prefix_%com.lib"
 #endif
 #if "%tsc" #then
  #set jpilib_="%jpilib_,%prefix_%clib.lib"
 #endif

 #if "%tscpp" #then
  #if %model=dynalink #then
    #set CPPprefix_="%O%%M%%C%"
  #else
    #set CPPprefix_="C%M%%C%"
  #endif
  #set jpilib_="%jpilib_,%CPPprefix_%slib.lib"
  #if "%usertool" #then
    #set jpilib_="%jpilib_,%CPPprefix_%rtool.lib"
  #endif
  #if "%usermath" #then
    #set jpilib_="%jpilib_,%CPPprefix_%rmath.lib"
  #endif
 #endif

 #if "%tsm2" #then
  #set jpilib_="%jpilib_,%prefix_%m2.lib"
  #if "%tsc" #then
   #set jpilib_="%jpilib_, %prefix_%mlibc.lib"
   #if "%cwindow"=jpi #then
    #set jpilib_="%jpilib_, %prefix_%wind.lib"
   #endif
  #else
   #set jpilib_="%jpilib_, %prefix_%mlib.lib"
  #endif
 #endif

 #if "%tspas" #then
  #if %model=dynalink #then
   #if %tsc #then
    #set jpilib_="%jpilib_,%prefix_%pasc.lib"
   #elsif %tsm2 #then
    #set jpilib_="%jpilib_,%prefix_%pasm.lib"
   #else
    #set jpilib_="%jpilib_,%prefix_%pas.lib"
   #endif
  #else
   #set jpilib_="%jpilib_,%prefix_%pas.lib"
  #endif
  #if "%tsc" #then
   #set jpilib_="%jpilib_,%prefix_%mlibc.lib"
   #if "%cwindow"=jpi #then
     #set jpilib_="%jpilib_,%prefix_%wind.lib"
   #endif
  #elsif "%tsm2" #then
   #set jpilib_="%jpilib_,%prefix_%mlib.lib"
  #else
   #set jpilib_="%jpilib_,%prefix_%plib.lib"
  #endif
  #pragma link_option(case=>off)
 #endif

 #if "%cgraph"=jpi #then
  #set jpilib_="%jpilib_,%prefix_%graph.lib"
 #elsif "%cgraph"=borland #then
  #set jpilib_="%jpilib_,graphics.lib"
 #endif

 #if ("%cwindow"=jpi) #and #not(("%tsm2") #or("%tspas")) #then
  #set jpilib_="%jpilib_,%prefix_%wind.lib"
 #elsif "%cwindow"=borland #then
  #set jpilib_="%jpilib_,%prefix_%borw.lib"
 #endif

 #if "%system"=os2 #then
  #if "%pm_api" #then
   #set jpilib_="%jpilib_,pmjpi.lib,os2jpi.lib"
  #else
   #set jpilib_="%jpilib_,os2jpi.lib"
  #endif
 #elsif (%model=overlay) #or (%model=dynalink) #then
  #set jpilib_="%jpilib_,loader.lib"
 #endif

!! PSION SIBO change
 #if %system=epoc #then
  #if "%epocinit"="iclib" #or "%epocinit"="iclib4" #or "%epocinit"="iclib2" #then
   #if %filetype=img #then
    #pragma link(clib.lib)
   #endif
  #endif
  #set jpilib_="plib.lib"
 #endif
!! end of PSION SIBO change

 #pragma link(%jpilib_)
!! PSION SIBO change
 #if %system=epoc #then
  #pragma link(wlib.lib)
  #pragma link(rlib.lib)
 #endif
!! end of PSION SIBO change
#endif

!! Now do the link
#if (%ext=dll) #then
 #pragma link_option(smart_method=>off)
 #if (%system=dos) #then
  #if #not ((%model=overlay) #or (%model=dynalink)) #then
   #error "DOS DLLs must use overlay or dynalink model"
  #endif
 #elsif (%system=os2) #then
  #if #not ((%model=xlarge) #or (%model=mthread) #or (%model=dynalink)) #then
   #error "OS2 DLLs must use xlarge, mthread or dynalink model"
  #endif
 #endif
#endif

#if "%ext%"=lib #then
 #dolink %name%.%ext%
#elsif ("%model"=overlay) #or ((%system=dos) #and ("%model"=dynalink)) #then
 #if "%ext%"=dll #then
  #if #not "%manual_export" #then
   #if #exists %name%.exp #then
    #implib %name%.lib %name%.exp
   #else
    #implib %name%.lib
   #endif
  #endif
 #else
  #pragma link_option(stub=>ovlload.exe)
 #endif
 #pragma link_option(map=>on,oldexe=>off,overlay=>on,pack=>off)
 #dolink %name%.%ext%
 #message "link complete"
 #set ovrexe_=%name%.%ext%
 #set ovrmap_=%name%.map
 #if #exists %name%.exp #then
  #set ovrexp_=%name%.exp
 #else
  #set ovrexp_=overlay.exp
 #endif
 #if %make #or %ovrexe_ #older %ovrexp_ #then
  #message "Patching EXE header"
  #exemod %ovrexe_ %ovrexp_ %ovrmap_
 #endif
#elsif (%system=os2) #and ("%ext%"=dll) #then
 #if #not "%manual_export" #then
  #if #exists %name%.exp #then
   #implib %name%.lib %name%.exp
  #else
   #implib %name%.lib
  #endif
 #endif
 #pragma link_option(map=>on,oldexe=>off)
 #dolink %name%.%ext%
 #message "link complete"
#elsif %system = win #then
 #set link_arg=%name%.%ext%
 #set winexp_=%name%.exp
 #set winexe_=%name%.%ext%
 #set winlib_=%name%.lib
 #set winmap_=%name%.map
 #implib %winlib_ %winexp_
 #pragma link_option(map=>on,oldexe=>off,windows=>on,export=>on)
 #pragma link(windows.lib)
 #if "%winmath" = chip #then
   #pragma link(noemul.obj)
 #elsif "%winmath" = emu #then
   #pragma link(winfloat.obj)
   #pragma link(win87em.lib)
 #elsif "%winmath" = none #then
   #pragma link(nofloat.obj)
 #else
   #error "Please set project system macro 'winmath' to 'chip', 'emu' or 'none'"
 #endif
 #dolink %link_arg
 #message "link complete"
 #if "%make" #then
  #exemod %winexe_ %winexp_ %winmap_
 #endif
!! PSION SIBO change
#elsif %system=epoc #then
 #dolink %name%.exe
!! end of PSION SIBO change
#else
 #dolink %name%.%ext%
#endif

!! PSION SIBO change
!! convert the .exe file to a .img or .dyl file
#if %system=epoc #then
 #if %name%.%filetype% #older %name%.exe #then
  #set afl=""
  #set dfl=""
  #if "%version"="" #then #set version=0x100f #endif
  #message "Making %name%.%filetype%"
  #if %filetype=img #then
   #if #exists %name%.afl #then #set afl="-a%name%.afl" #endif
   #if #exists %name%.dfl #then #set dfl="-d%name%.dfl" #endif
   #if "%priority"="" #then #set priority=0x80 #endif
   #if "%heapsize"="" #then #set heapsize=0x80 #endif
  #else
   #set priority=""
   #set heapsize=""
  #endif
  #run "emake >make.$$$ -b %afl% %dfl% -o%name% -s -v%version% -p%priority% -h%heapsize% -%epoctype% %name%.exe" no_window no_abort
  #file adderrors make.$$$
  #file delete make.$$$
 #endif
#endif
!!   #run "emake >make.$$$ -b -o%name% -s -v%version% -%epoctype% %name%" no_window no_abort
!! end of PSION SIBO change

!! Reset macros indicating what libraries are required

#set tsc=off
#set tscpp=off
#set tspas=off
#set tsm2=off
#set cwindow=""
#set cgraph=""
#set pm_api=""
#set pm_compat=""
#set pm_noncompat=""
#set manual_export=""

!! End of Project Link section
! Project End
!! =========================================================================

