@echo off
echo.
echo ========================================================================
echo === MAKE Script for NX-DOS Distribution                             ====
echo === BUILD Utility                                  Type /? for HELP ====
echo ========================================================================
echo.
if exist C:\TASM\TASM.EXE goto setdefs
set TASM=D:\TASM\
set NXDOS=D:\NXDOS\
set UTILS=D:\UTILS\
goto contmake
:setdefs
set TASM=C:\TASM\
set NXDOS=C:\NXDOS\
set UTILS=C:\UTILS\
:contmake
if "%1"=="/?" goto helptext
if "%1"=="/BUILD" goto Build
if "%1"=="/Build" goto Build
if "%1"=="/build" goto Build
if "%1"=="/archives" goto archive
if "%1"=="/ARCHIVES" goto archive
if "%1"=="/Archives" goto archive
if "%1"=="/mirror" goto update_mirror
if "%1"=="/MIRROR" goto update_mirror
if "%1"=="/Mirror" goto update_mirror
if "%1"=="/reset" goto reset
if "%1"=="/Reset" goto reset
if "%1"=="/RESET" goto reset
if "%1"=="/METAKERN" goto Metakern
if "%1"=="/Metakern" goto Metakern
if "%1"=="/metakern" goto Metakern
if "%1"=="/tmake" goto tasmmake
if "%1"=="/TASM" goto tasmmake
if "%1"=="/Tasm" goto tasmmake
if "%1"=="/tasm" goto tasmmake
goto makeproject
:makeproject
call %0 /reset %1
echo Files are listed in order of newest first. > WHATSNEW.TXT
echo. >> WHATSNEW.TXT
dir *.* /B /O:-D >> WHATSNEW.TXT
%NXDOS%bin\maketime.exe
%NXDOS%bin\dumpasm %NXDOS%src\boot\nxdos.bss %NXDOS%src\boot\nxdos.inc
:: /zi /z
for %%v in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do %TASM%tasm /la /z /zi %%v > %%v.err
for %%v in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do %TASM%tlink /3 %%v  >> %%v.err
for %%v in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do %UTILS%exe2bin %%v >> %%v.err
for %%v in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do copy /b %%v.bin %%v.com
for %%v in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do move %%v.sys %NXDOS%bin\%%v.sys
for %%v in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do move %%v.com %NXDOS%bin\%%v.com
for %%v in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do move %%v.exe %NXDOS%bin\%%v.exe
for %%v in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do move %%v.bss %NXDOS%bin\%%v.bss
for %%v in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do del %%v.bin
for %%v in (1 2 3) do %NXDOS%bin\delay.com
%NXDOS%bin\dumpasm\dumpasm %NXDOS%src\boot\metakern.bin %NXDOS%src\boot\metakern.inc
if not exist %NXDOS%src\kernel\nxbio.sys echo *** SRC NXBIO.SYS not found!
if not exist %NXDOS%bin\nxbio.sys echo *** BIN NXBIO.SYS not found!
:: if not exist \nxdos\src\kernel\nxbio.sys goto exit
copy %NXDOS%src\kernel\nxbio.bin \nxdos\src\kernel\nxbio.sys
copy %NXDOS%src\kernel\nxbio.sys \nxdos\bin\nxbio.sys
copy %NXDOS%src\boot\metakern.bin c:\
copy %NXDOS%src\boot\nxdos.bss c:\
copy %NXDOS%src\kernel\nxbio.sys c:\
if exist %1.err type %1.err
goto exit
:makefloppy
if not exist a:\nul goto exit
echo.
echo Insert a blank formatted floppy diskette into drive A: 
pause > nul
echo.
echo Making floppy disk...
echo.
copy %NXDOS%bin\nxbio.sys a:\
copy %NXDOS%bin\command.com a:\
copy %NXDOS%bin\*.* a:\ 
if NOT exist %NXDOS%src\boot\syslinux.com goto no_syslinux
if NOT exist %NXDOS%src\boot\syslinux.cfg goto no_syslinux
if NOT exist %NXDOS%src\boot\syslinux\dos\syslinux.com goto no_syslinux
copy %NXDOS%src\boot\syslinux.com a:\
copy %NXDOS%src\boot\syslinux.cfg a:\
%NXDOS%src\boot\syslinux\dos\syslinux.com -sf a:
:no_syslinux
a:
writeb
c:
:: fc \nxdos\bin\floppy\nxbio.sys a:\nxbio.sys > nul
:: if not errorlevel 0 goto builddisk
goto exit
:reset
shift
echo.
echo    *******************
echo    *** Cleaning up ***
echo    *******************
for %%v in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do del %%v.err
for %%v in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do del %%v.map
for %%v in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do del %%v.obj
for %%v in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do del %%v.bin
for %%v in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do del %%v.exe
for %%v in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do del %%v.com
for %%v in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do del %%v.sys
for %%v in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do del %%v.ov?
goto exit
:sys
if exist \src\nul goto dontrun
cd %NXDOS%src
copy /b apps\sys.com+boot\boot.bin+kernel\nxbio.bin+apps\command.com $$$sys$$.bin
del oldsys.com
ren $$$sys$$.bin oldsys.com
copy /b boot\boot.bin+kernel\nxbio.sys system.bin
echo w 0100 0 0 1 > make.scr
echo q >> make.scr
debug system.bin < make.scr
del make.scr
goto exit
:tasmmake
%TASM%tasm /zi /z %1
%TASM%tlink /3 %1
%TASM%tlink /tdc %1
%UTILS%exe2bin %1
goto exit
:dontrun
echo.
echo =============================================================================
echo ===                    Can't run on the development disk!                ====
echo =============================================================================
goto exit
:helptext
echo.
echo MAKE [/switch] [file]
echo.
echo      /build    make the whole damn thing 
echo      /archives make distribution zips
echo      /reset    deletes left over linking files
echo      METAKERN  build the BSS files
echo      BUILD     [file], "defaults to nxbio.asm"
echo.
echo It sho ask for answers to fit into build.equ then run build.bat
echo.
goto exit
:archive
:: -saroseisaroseisarose
D:
cd dos
cd nxdos
pkzip -r -p srcnxdos src\*.asm src\*.inc src\*.equ src\*.lst
pkzip -r -p srcnxdos src\*.c src\*.h src\*.cpp src\*.hpp src\*.bpb
pkzip -r -p srcnxdos src\*.pas src\*.bas src\*.scr src\*.cmd
pkzip -r -p srcnxdos src\*.bat src\*.cfg src\*.dev src\*.sh
pkzip -r -p srcnxdos src\*.ans src\*.asc src\*.gif src\*.jpg src\*.bmp src\*.png
pkzip -r -p srcnxdos src\*.lsm src\*.diz src\*.txt src\*.doc
::
pkzip -r -p binnxdos \nxdos\*.sys \nxdos\*.com \nxdos\*.exe \nxdos\*.ov? \nxdos\*.bin
pkzip -r -p binnxdos \nxdos\*.bat \nxdos\*.scr \nxdos\*.ini \nxdos\*.cfg \nxdos\*.bss
pkzip -r -p binnxdos \nxdos\*.ans \nxdos\*.asc \nxdos\*.gif \nxdos\*.jpg \nxdos\*.bmp \nxdos\*.png
pkzip -r -p binnxdos \nxdos\*.lsm \nxdos\*.diz \nxdos\*.txt \nxdos\*.doc src\*.sh
::
pkzip -r -p bsenxdos bin\*.*
pkzip -r -p bsenxdos src\utils\command\*.com src\utils\command\*.exe src\utils\command\*.ov?
pkzip -r -p bsenxdos src\utils\sys.com 
pkzip -r -p bsenxdos src\utils\format\format.com 
pkzip -r -p bsenxdos src\utils\fdisk\fdisk.exe 
pkzip -r -p bsenxdos src\boot\tools\*.com
pkzip -r -p bsenxdos src\boot\*.bss
pkzip -r -p bsenxdos src\*.cfg src\*.lsm src\*.diz
pkzip -r -p bsenxdos src\*.ans src\*.asc src\*.gif src\*.jpg src\*.bmp src\*.png
::
:: if NOT exist x:\pub\dmsoft\nxdos\place.txt goto no_deletearchs
:: copy /b *.ZIP x:\pub\dmsoft\nxdos
:: del *.ZIP
:: md h:\nxdos
:: xcopy \nxdos\*.* x:\data\nxdos\ /s /e /v /y
:no_deletearchs
goto exit
:Build
D:
cd dos
shift
cd nxdos\src\kernel
if "%1"=="" goto nochangeapp
cd nxdos\src\%1 
:nochangeapp
:: update build.equ
call nxdos\src\make %1 \nxdos\src\kernel\nxbio
:buildall
if NOT "%1"=="" goto buildbins
cd nxdos\src\boot
call nxdos\src\make /METAKERN FLOPPY
cd \nxdos\src\boot
call nxdos\src\make /METAKERN FIXED
::
cd nxdos\src\utils\command
call nxdos\src\make command
cd nxdos\src\utils\sys
call nxdos\src\make sys
cd nxdos\src\utils\format
call nxdos\src\make format
cd nxdos\src\utils\setup
call nxdos\src\make setup
cd nxdos\src\utils\label
call nxdos\src\make label
:buildbins
echo    ***********************
echo    *** Building Floppy ***
echo    ***********************
copy \nxdos\src\kernel\nxbio.com \nxdos\src\kernel\nxbio.sys
copy \nxdos\src\kernel\nxbio.sys \nxdos\bin
copy \nxdos\src\utils\command\*.com \nxdos\bin
copy \nxdos\src\boot\tools\writeb.com \nxdos\bin
copy \nxdos\src\boot\tools\readb.com \nxdos\bin
copy \nxdos\src\boot\*.bss \nxdos\bin
::
copy \nxdos\src\utils\sys\*.com \nxdos\bin
copy \nxdos\src\utils\sys\*.exe \nxdos\bin
copy \nxdos\src\utils\format\*.com \nxdos\bin
copy \nxdos\src\utils\format\*.exe \nxdos\bin
copy \nxdos\src\utils\fdisk\*.exe \nxdos\bin
copy \nxdos\src\utils\move\*.com \nxdos\bin
copy \nxdos\src\utils\grab\*.com \nxdos\bin
copy \nxdos\src\utils\setup\*.exe \nxdos\bin
copy \nxdos\src\utils\setup\lha.exe \nxdos\bin
::
echo setup.exe > \nxdos\bin\autoexec.bat
:update_mirror
goto no_update
find "**Error**" nxbio.err
if NOT errorlevel 0 goto no_update
if NOT exist x:\pub\dmsoft\nxdos\bin\place.txt goto no_update
echo Updating binaries...
copy /b c:\nxdos\bin\*.* x:\pub\dmsoft\nxdos\bin
if NOT exist x:\pub\dmsoft\nxdos\src\place.txt goto no_update
echo Updating sources...
xcopy c:\nxdos\src\*.* x:\pub\dmsoft\nxdos\src\ /s /e /v /y
:no_update
goto exit
:Metakern
echo ***************************************
echo ** Metakern Boot sector make utility **
echo ***************************************
shift
cd\nxdos\src\boot
if "%1"=="" goto help
if "%1"=="MAKE" goto make_all
if "%1"=="M" goto link_MBSS
if "%1"=="FIXED" echo FIXEDDISK EQU 1 > metakern.EQU
if "%1"=="FIXED" goto chk_bootable
   echo FIXEDDISK EQU 0 > metakern.EQU
:chk_bootable
if "%2"=="NXDOS" echo NXDOS EQU 1 >> metakern.EQU
if "%2"=="NXDOS" goto chk_nonboot
   echo NXDOS EQU 0 >> metakern.EQU
if "%2"=="MBR" echo MBR EQU 1 >> metakern.EQU
if "%2"=="MBR" goto chk_nonboot
   echo MBR EQU 0 >> metakern.EQU
if "%2"=="CHECKIT" echo CHECKIT EQU 1 >> metakern.EQU
if "%2"=="CHECKIT" goto chk_nonboot
   echo CHECKIT EQU 0 >> metakern.EQU
:chk_nonboot
if "%2"=="NONBOOT" echo BOOTABLE EQU 0 >> metakern.EQU
if "%2"=="NONBOOT" goto chk_extras
   echo BOOTABLE EQU 1 >> metakern.EQU
   goto chk_extas2
:chk_extras
SET BOOTF=%2
shift
goto chk_extas3
:chk_extas2
SET BOOTF=%2
:chk_extas3
echo UMBBSS EQU 0 >> metakern.EQU
if "%2"=="DFOS" echo DFOS EQU 1 >> metakern.EQU
if NOT "%2"=="DFOS" echo DFOS EQU 0 >> metakern.EQU
if "%2"=="CREOS" echo CREOS  EQU 1 >> metakern.EQU
if NOT "%2"=="CREOS" echo CREOS EQU 0 >> metakern.EQU
if "%2"=="MINI" echo MINI EQU 1 >> metakern.EQU
if NOT "%2"=="MINI" echo MINI EQU 0 >> metakern.EQU
if "%2"=="HELLO" echo HELLO EQU 1 >> metakern.EQU
if NOT "%2"=="HELLO" echo HELLO EQU 0 >> metakern.EQU
if "%2"=="" goto no_extras
if "%2"=="CHECKIT" goto no_extras
if NOT "%2"=="CREOS" goto add_extrasflag
if NOT "%2"=="MINI"  goto add_extrasflag
if NOT "%2"=="HELLO" goto add_extrasflag
if "%2"=="" goto no_extras
echo %2 EQU 1 >> metakern.EQU
goto add_extrasflag
:no_extras
echo EXTRAS EQU 0 >> metakern.EQU
goto makebss
:add_extrasflag
echo 1 > extras.001
set EXTRAS=1
:: set EXTRAS=TRUE
echo EXTRAS EQU 1 >> metakern.EQU
goto makebss
:link_MBSS
del m.bss
:makebss
if exist metakern.exe del metakern.exe
if exist metakern.bin del metakern.bin
if exist metakern.com del metakern.com
call \nxdos\src\make metakern
if "%2"=="MBR" goto fixupmetakern
if exist extras.001 goto fixupmetakern
if "%1"=="NONBOOT" goto fixupmetakern
if "%1"=="FIXED" goto fixed_fixup
if NOT "%2"=="" goto fixupmetakern
if exist metakern.bss del metakern.bss
ren metakern.bin metakern.bss
\nxdos\src\utils\dumpasm\dumpasm metakern.bss metakern.inc
if NOT "%1"=="M" goto no_MBSS
:prep_MBSS
copy metakern.bss m.bss
copy m.bss nxdos.bss
:no_MBSS
goto phase2
:fixed_fixup
if "%2"=="" SET BOOTF=NXDOS
goto fixupmetakern
:fixupmetakern
if exist %BOOTF%.bss del %BOOTF%.bss
ren metakern.bin %BOOTF%.bss
\nxdos\src\utils\dumpasm\dumpasm %BOOTF%.bss %BOOTF%.inc
goto phase2
:phase2
if exist metakern.exe del metakern.exe
if exist metakern.bin del metakern.bin
if exist metakern.com del metakern.com
goto end
:make_all
del  metakern.err
call \nxdos\src\make METAKERN FIXED
call \nxdos\src\make METAKERN FIXED MBR
call \nxdos\src\make METAKERN FLOPPY 
call \nxdos\src\make METAKERN FLOPPY NONBOOT
call \nxdos\src\make METAKERN FLOPPY HELLO
call \nxdos\src\make METAKERN FLOPPY MINI
call \nxdos\src\make METAKERN FLOPPY CREOS
call \nxdos\src\make METAKERN FLOPPY CHECKIT
call \nxdos\src\make METAKERN FIXED CHECKIT
crc -e *.BSS > FILELIST.TXT
goto end
:help
echo metakern [FIXED/FLOPPY] [NONBOOT/MBR] [DFOS/CREOS/MINI/HELLO/CHECKIT]
:end
if exist extras.001 del extras.001
SET BOOTF=
:exit
set TASM=
echo. 
:end
