@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 that
echo can generate DOS and WIN32 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\include\win32
>nul mkdir %1\cc386\examples
>nul mkdir %1\cc386\espanol
>nul mkdir %1\cc386\english

>nul copy *.c %1\cc386\examples
>nul copy example.txt %1\cc386\examples
>nul copy example.bat %1\cc386\examples
>nul copy example.mak %1\cc386\examples
>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\asciifun.h
>nul copy asciifun.h %1\cc386\include\win32
>nul del  %1\cc386\include\base.h
>nul copy base.h %1\cc386\include\win32
>nul del  %1\cc386\include\commonfu.h
>nul copy commonfu.h %1\cc386\include\win32
>nul del  %1\cc386\include\defines.h
>nul copy defines.h %1\cc386\include\win32
>nul del  %1\cc386\include\errors.h
>nul copy errors.h %1\cc386\include\win32
>nul del  %1\cc386\include\function.h
>nul copy function.h %1\cc386\include\win32
>nul del  %1\cc386\include\messages.h
>nul copy messages.h %1\cc386\include\win32
>nul del  %1\cc386\include\sockets.h
>nul copy sockets.h %1\cc386\include\win32
>nul del  %1\cc386\include\structur.h
>nul copy structur.h %1\cc386\include\win32
>nul del  %1\cc386\include\unicodef.h
>nul copy unicodef.h %1\cc386\include\win32

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

>nul copy valx.hlp %1\cc386\valx.doc
>nul copy *.lic %1\cc386
>nul copy *.txt %1\CC386
>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

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

rem now make the cl386.cfg file
echo Now creating CL386 configuration file
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 Now creating MK386 configuration 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 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