@echo off
echo.
echo LADsoft C compiler V 2.02 installation
echo.

if NOT "%1" == "" goto ok

echo.
echo Usage: Install DRIVE:
echo.
goto exit

:ok

echo.
echo This install program installs a version of the LADsoft C compiler
echo that can generate DOS programs.  The directory %1\CC386 will be 
echo created and necessary files will be copied there.
echo.
echo You can read the file 'install.txt' for further information
echo concerning the installation and initial use of the compiler
echo.
echo The following assemblers can be used with this compiler:
echo   NASM  (included)
echo   TASM  (not recommended)
echo.
echo The following linkers can be used with this compiler:
echo   VALX  (included)
echo   TLINK (not recommended)
echo   WLINK
echo.

choice /C:NY /N Do you want to continue with the installation?

if ERRORLEVEL == 2 goto install
echo.
echo Installation canceled
goto exit

:install
echo Now Installing binaries and headers

rem create directory tree and copy files
>nul mkdir %1\cc386
>nul mkdir %1\cc386\bin
>nul mkdir %1\cc386\lib
>nul mkdir %1\cc386\lib\startup
>nul mkdir %1\cc386\include
>nul mkdir %1\cc386\include\sys
>nul mkdir %1\cc386\examples
>nul mkdir %1\cc386\examples\dos
rem >nul mkdir %1\cc386\espanol
>nul mkdir %1\cc386\english

>nul copy *.c %1\cc386\examples
>nul copy keys.c %1\cc386\examples\dos
>nul del  %1\cc386\examples\keys.c
>nul copy mouse.c %1\cc386\examples\dos
>nul del  %1\cc386\examples\mouse.c
>nul copy window.c %1\cc386\examples\dos
>nul del  %1\cc386\examples\window.c
>nul copy stklen.c %1\cc386\examples\dos
>nul del  %1\cc386\examples\stklen.c
>nul copy vga.c %1\cc386\examples\dos
>nul del  %1\cc386\examples\vga.c
>nul copy phone.c %1\cc386\examples\dos
>nul del  %1\cc386\examples\phone.c
>nul copy example.txt %1\cc386\examples
>nul copy example.bat %1\cc386\examples
>nul copy makefile %1\cc386\examples
>nul copy dos.mak %1\cc386\examples\dos
>nul copy dos.bat %1\cc386\examples\dos
>nul copy 4gstub.exe %1\cc386\lib
>nul copy 4gs.exe %1\cc386\lib
>nul copy wdosxle.exe %1\cc386\lib
>nul copy zrdx.exe %1\cc386\lib
>nul copy zrxsetup.exe %1\cc386\lib
>nul copy cwstub.exe %1\cc386\lib
>nul copy 4gsq.exe %1\cc386\lib
>nul copy pmodew.exe %1\cc386\lib
>nul copy *.obj %1\cc386\lib
>nul copy *.lib %1\cc386\lib

>nul copy *.h %1\cc386\include
>nul del  %1\cc386\include\types.h
>nul copy types.h %1\cc386\include\sys
>nul del  %1\cc386\include\locking.h
>nul copy locking.h %1\cc386\include\sys
>nul del  %1\cc386\include\stat.h
>nul copy stat.h %1\cc386\include\sys
>nul del  %1\cc386\include\timeb.h
>nul copy timeb.h %1\cc386\include\sys

>nul copy *.exe %1\cc386\bin
>nul copy valx.hlp %1\cc386\bin

>nul copy valx.hlp %1\cc386\english\valx.doc
>nul copy *.lic %1\cc386
>nul copy *.txt %1\CC386
>nul copy copying %1\cc386
>nul del  %1\cc386\example.txt
>nul copy *.doc %1\cc386\english

>nul copy *.nas %1\cc386\lib\startup
>nul copy *.asm %1\cc386\lib\startup

>nul copy *.mak %1\cc386\bin

>nul copy *.mac %1\cc386\bin

rem >nul copy *.sdc %1\cc386\espanol\*.doc
rem >nul copy *.stx %1\cc386\espanol\*.txt

rem now make the cl386.cfg file
echo Now creating Configuartion files
echo -I%1\CC386\INCLUDE -L%1\CC386\LIB -e /NASM /VALX /C+d  > %1\cc386\bin\cl386.cfg
rem now make the mk386.cfg file
echo -I%1\CC386\INCLUDE -L%1\CC386\LIB -$A=NASM -$L=VALX -$M=IMAKE > %1\cc386\bin\mk386.cfg
rem now make the cc386 .cfg file
echo -I%1\cc386\include > %1\cc386\bin\cc386.cfg
rem now make the valx .cfg file
echo -L:(%1\cc386\lib) > %1\cc386\bin\valx.cfg

rem now make the standard build file
echo Now creating Build.bat (freeware tools build)
echo @echo off > %1\cc386\bin\build.bat
echo cc386 /C+N /A- -I%1\CC386\INCLUDE %%1.c >> %1\cc386\bin\build.bat
echo if NOT ERRORLEVEL = 0 goto exit >> %1\cc386\bin\build.bat
echo NASM -fobj %%1.asm >> %1\cc386\bin\build.bat
echo if NOT ERRORLEVEL=0 goto exit >> %1\cc386\bin\build.bat
echo valx -nci -use32 %1\CC386\LIB\c0dos.obj %%1.obj,%%1,%%1,%1\CC386\LIB\CLDOS.LIB >> %1\cc386\bin\build.bat
echo :exit >> %1\cc386\bin\build.bat

rem now make the pmb.bat file
echo Now creating pmb.bat (BORLAND) build file
echo REM > %1\cc386\bin\pmb.bat
echo REM WARNING!!! >> %1\cc386\bin\pmb.bat
echo REM >> %1\cc386\bin\pmb.bat
echo REM Borland tools may add bugs to your code >> %1\cc386\bin\pmb.bat
echo REM Use them at your own risk >> %1\cc386\bin\pmb.bat
echo REM >> %1\cc386\bin\pmb.bat
echo @echo off >> %1\cc386\bin\pmb.bat
echo cc386 -A- -I%1\CC386\INCLUDE %%1.c >> %1\cc386\bin\pmb.bat
echo if NOT ERRORLEVEL = 0 goto exit >> %1\cc386\bin\pmb.bat
echo TASM /ml /m2 %%1.asm >> %1\cc386\bin\pmb.bat
echo if NOT ERRORLEVEL=0 goto exit >> %1\cc386\bin\pmb.bat
echo TLINK /3/c %1\CC386\LIB\c0dos.obj %%1.obj,%%1,%%1,%1\CC386\LIB\CLDOS.LIB >> %1\cc386\bin\pmb.bat
echo :exit >> %1\cc386\bin\pmb.bat

rem now make the pmw.bat file
echo Now creating pmw.bat and pmw.lnk (WATCOM) build files
echo @echo off	> %1\cc386\bin\pmw.bat
echo cc386 /A- /I%1\CC386\INCLUDE %%1.c >> %1\cc386\bin\pmw.bat
echo if NOT ERRORLEVEL == 0 goto exit >> %1\cc386\bin\pmw.bat
echo NASM -fobj %%1.asm >> %1\cc386\bin\pmw.bat
echo if NOT ERRORLEVEL==0 goto exit >> %1\cc386\bin\pmw.bat
echo WLINK debug @%1\cc386\bin\pmw.lnk NAME %%1 FILE %%1 >> %1\cc386\bin\pmw.bat
echo :exit >> %1\cc386\bin\pmw.bat

rem now make the pmw.lnk linker file
echo option osname='CC386'> %1\cc386\bin\pmw.lnk
echo op stub=%1\cc386\lib\pmodew.exe >> %1\cc386\bin\pmw.lnk
echo op symf >> %1\cc386\bin\pmw.lnk
echo op nod >> %1\cc386\bin\pmw.lnk
echo format os2 le >> %1\cc386\bin\pmw.lnk
echo file %1\cc386\lib\c0dosw.obj >> %1\cc386\bin\pmw.lnk
echo library %1\cc386\lib\cldos.lib >> %1\cc386\bin\pmw.lnk

echo.
echo %1\CC386\BIN must be added to the path.
echo.
choice /C:NY /N Do you want install to modify your autoexec.bat?

if ERRORLEVEL == 2 goto dobat
echo.
echo This package is NOT completely installed.  You MUST add the following
echo commands to AUTOEXEC.BAT
echo.
echo SET PATH=%%PATH%%;%1\CC386\BIN
echo SET CCINCL=%1\CC386\INCLUDE
echo.
goto nobat

:dobat
echo.
echo Modifying AUTOEXEC.BAT
echo.
echo.  >> C:\autoexec.bat
echo SET PATH=%%PATH%%;%1\CC386\BIN >> C:\autoexec.bat
echo SET CCINCL=%1\CC386\INCLUDE >> C:\AUTOEXEC.BAT

:nobat
echo.
echo Adding components to environment
echo.
SET PATH=%PATH%;%1\CC386\BIN
SET CCINCL=%1\CC386\INCLUDE
echo.
echo Installation complete
echo.
echo Read the file %1\CC386\README.TXT for general information on how to
echo get started.
echo. 

:exit