My commands setup below. Give you the idea on how I did it. (WARNING: Don't use these. Use the safe commands. Go to Step 3.)

SET CONFIG_ARCHITECTURE=x64
call C:\msys64-mamedev\win32\env.bat
cd C:\mamedev\mame
git clean -d -f -X
git pull -f
make TOOLS=1 SEPARATE_BIN=1 PTR64=1 OPTIMIZE=3 SYMBOLS=1 SYMLEVEL=1 STRIP_SYMBOLS=1 REGENIE=1 -j5
DEL /S /Q E:\MAME\chdman.exe; E:\MAME\mame64.exe; E:\MAME\mame64.sym
move "C:\mamedev\mame\build\mingw-gcc\bin\x64\Release\chdman.exe" "E:\MAME"
move "C:\mamedev\mame\build\mingw-gcc\bin\x64\Release\mame64.exe" "E:\MAME"
move "C:\mamedev\mame\build\mingw-gcc\bin\x64\Release\mame64.sym" "E:\MAME"
RD /S /Q E:\MAME\artwork; E:\MAME\bgfx; E:\MAME\docs; E:\MAME\hash; E:\MAME\hlsl; E:\MAME\ini; E:\MAME\language; E:\MAME\nl_examples; E:\MAME\plugins; E:\MAME\samples
robocopy "C:\mamedev\mame\artwork" "E:\MAME\artwork" /mir
robocopy "C:\mamedev\mame\bgfx" "E:\MAME\bgfx" /mir
robocopy "C:\mamedev\mame\docs" "E:\MAME\docs" /mir
robocopy "C:\mamedev\mame\hash" "E:\MAME\hash" /mir
robocopy "C:\mamedev\mame\hlsl" "E:\MAME\hlsl" /mir
robocopy "C:\mamedev\mame\ini" "E:\MAME\ini" /mir
robocopy "C:\mamedev\mame\language" "E:\MAME\language" /mir
robocopy "C:\mamedev\mame\nl_examples" "E:\MAME\nl_examples" /mir
robocopy "C:\mamedev\mame\plugins" "E:\MAME\plugins" /mir
robocopy "C:\mamedev\mame\samples" "E:\MAME\samples" /mir
git clean -d -f -X
pause

============================================= Step 1.

Download the MAME Build Tools. http://mamedev.org/tools/ Please read on what to do.

Unpack it. Make sure it in the C:\ path like this C:\msys64.

============================================= Step 2.

Do these first. Only once. You can change the path.

Click on the autorebase.bat

Click on the win32env.bat. Then type in these commands and then let it get the source and settings. Let it finish. Close the win32env.bat after that.

git config --global core.autocrlf true
mkdir C:\mamedev
cd C:\mamedev
git clone https://github.com/mamedev/mame.git

============================================= Step 3. (Safe to use.)

Copy the win32env.bat from the C:\msys64 path and then paste it into the C:\mamedev path. Right click and then select edit. Copy these commands below and then paste those into the win32env.bat. Make sure there are no other commands. Save it and then close it. Rename the win32env.bat file to Run.bat or what ever.

SET CONFIG_ARCHITECTURE=x64
call C:\msys64\win32\env.bat
git pull -f
RD /S /Q C:\mamedev\mame\build
make TOOLS=1 SEPARATE_BIN=1 PTR64=1 OPTIMIZE=3 SYMBOLS=1 SYMLEVEL=1 STRIP_SYMBOLS=1 REGENIE=1 -j5
DEL /S /Q chdman.exe; mame64.exe; mame64.sym
move "C:\mamedev\mame\build\mingw-gcc\bin\x64\Release\chdman.exe" "C:\mamedev\mame"
move "C:\mamedev\mame\build\mingw-gcc\bin\x64\Release\mame64.exe" "C:\mamedev\mame"
move "C:\mamedev\mame\build\mingw-gcc\bin\x64\Release\mame64.sym" "C:\mamedev\mame"
RD /S /Q C:\mamedev\mame\build
pause

Click on the Run.bat. Wait for a while until it is done.

=============================================

Commads

git clean -d -f -X (Not really needed. This will clean up the source up.) (BEWARE: This will delete the non source files.)

RD /S /Q (Delete a folder. Delete the files in it as well.)

DEL /S /Q (Delete a file.)

SET CONFIG_ARCHITECTURE=x64 (for the x64 computers.)

SET CONFIG_ARCHITECTURE=x86 (for the x86 computers.)

DEBUG=1 (for debug build.)

-j (Number is listed here.) (Core i3 has 2 cores. -j3 // Core i5 has either 2 cores or 4 cores depending on the model. -j3 or -j5 // Core i7 has from 4 cores to 8 cores depending on the model.. -j9 to -j17)

OPTIMIZE=3 (Use it.)

SUBTARGET=arcade (Arcade)

SUBTARGET=mess (Home and Office)

SYMBOLS=1 (for the mame64.sym file.)

STRIP_SYMBOLS=1 (for stripping out.)

TOOLS=1 (for the tools.)

git pull (for the source update.)

-f (Force)

REGENIE=1 (Not really needed. Using this anyway.)

SEPARATE_BIN=1 (Not really needed. Using this anyway.)

PTR64=1 (Not really needed. Using this anyway.)

mkdir (Create a folder.)