2005-03-03 04:38:40 -05:00
|
|
|
@echo off
|
|
|
|
:: usage: ifchange target temporary
|
|
|
|
|
2008-10-17 06:46:23 -04:00
|
|
|
set timestamp=
|
2009-03-15 23:30:01 -04:00
|
|
|
:optloop
|
|
|
|
for %%I in (%1) do set opt=%%~I
|
|
|
|
if "%opt%" == "--timestamp" (
|
|
|
|
set timestamp=.
|
|
|
|
shift
|
|
|
|
goto :optloop
|
|
|
|
) else if "%opt:~0,12%" == "--timestamp=" (
|
|
|
|
set timestamp=%opt:~12%
|
2008-10-17 06:46:23 -04:00
|
|
|
shift
|
2009-03-15 23:30:01 -04:00
|
|
|
goto :optloop
|
2008-10-17 06:46:23 -04:00
|
|
|
)
|
2009-03-15 23:30:01 -04:00
|
|
|
if "%opt%" == "" goto :end
|
|
|
|
|
2008-01-25 04:27:30 -05:00
|
|
|
set dest=%1
|
|
|
|
set src=%2
|
|
|
|
set dest=%dest:/=\%
|
|
|
|
set src=%src:/=\%
|
|
|
|
if not "%dest%" == "" if not "%dest%" == "%%dest:/=\%%" goto :nt
|
|
|
|
|
|
|
|
if not exist %2 goto :end
|
|
|
|
|
2005-03-03 04:38:40 -05:00
|
|
|
:: check if fc.exe works.
|
2008-01-25 04:27:30 -05:00
|
|
|
echo foo > conftst1.tmp
|
|
|
|
echo bar > conftst2.tmp
|
|
|
|
fc.exe conftst1.tmp conftst2.tmp > nul
|
2005-03-03 04:38:40 -05:00
|
|
|
if not errorlevel 1 goto :brokenfc
|
2008-01-25 04:27:30 -05:00
|
|
|
del conftst1.tmp > nul
|
|
|
|
del conftst2.tmp > nul
|
2005-03-03 04:38:40 -05:00
|
|
|
|
|
|
|
:: target does not exist or new file differs from it.
|
|
|
|
if not exist %1 goto :update
|
|
|
|
fc.exe %1 %2 > nul
|
|
|
|
if errorlevel 1 goto :update
|
|
|
|
|
|
|
|
:unchange
|
|
|
|
echo %1 unchanged.
|
|
|
|
del %2
|
|
|
|
goto :end
|
|
|
|
|
|
|
|
:brokenfc
|
|
|
|
del conftest1.tmp > nul
|
|
|
|
del conftest2.tmp > nul
|
|
|
|
echo FC.EXE does not work properly.
|
|
|
|
echo assuming %1 should be changed.
|
|
|
|
|
|
|
|
:update
|
|
|
|
echo %1 updated.
|
2008-01-25 04:27:30 -05:00
|
|
|
:: if exist %1 del %1
|
|
|
|
dir /b %2
|
|
|
|
copy %2 %1
|
|
|
|
del %2
|
|
|
|
goto :end
|
|
|
|
|
|
|
|
:nt
|
|
|
|
if not exist %src% goto :end
|
|
|
|
if exist %dest% (
|
|
|
|
fc.exe %dest% %src% > nul && (
|
2008-10-17 06:46:23 -04:00
|
|
|
echo %1 unchanged.
|
2008-01-25 04:27:30 -05:00
|
|
|
del %src%
|
2008-10-17 06:46:23 -04:00
|
|
|
goto :nt_end
|
2008-01-25 04:27:30 -05:00
|
|
|
)
|
|
|
|
)
|
2008-10-17 06:46:23 -04:00
|
|
|
echo %1 updated.
|
2008-01-25 04:27:30 -05:00
|
|
|
copy %src% %dest% > nul
|
|
|
|
del %src%
|
|
|
|
|
2008-10-17 06:46:23 -04:00
|
|
|
:nt_end
|
|
|
|
if "%timestamp%" == "" goto :end
|
2009-03-15 23:30:01 -04:00
|
|
|
if "%timestamp%" == "." (
|
|
|
|
for %%I in ("%dest%") do set timestamp=%%~dpI.time.%%~nxI
|
|
|
|
)
|
|
|
|
goto :end > "%timestamp%"
|
2005-03-03 04:38:40 -05:00
|
|
|
:end
|