updated
[latex2e.git] / base / make.bat
blob545aa251ec763ba65329b090fa81bbc4095f2ed9
1 @echo off
3 rem TODO
6 rem Makefile for LaTeX2 "base" files
8   if not [%1] == [] goto init
10 :help
12   echo.
13   echo  make check [show]   - run automated check system
14   echo  make clean          - clean out directory
15   echo  make doc [show]     - typeset all dtx files
16   echo  make localinstall   - locally install package
17   echo  make savetlg ^<name^> - save test log for ^<name^>
18   echo  make checktlg ^<name^> - check one test file ^<name^>
19   echo  make unpack [show]  - extract modules
20   echo  make ctan [show]  - build CTAN distribution
21   echo.
22   echo  The "show" option enables display of the output
23   echo  of the TeX runs in the terminal.
25   goto :EOF
27 :init
29   rem Avoid clobbering anyone else's variables
31   setlocal
33   rem Safety precaution against awkward paths
35   cd /d "%~dp0"
37   rem The name of the module and the bundle it is part of
39   set BUNDLE=latex2e
40   set MODULE=base
42   rem Unpacking information
44 rem  set UNPACK=%MODULE%.ins
46   rem Clean up settings
48   set AUXFILES=aux cmds fpl glo hd idx ilg ind log lvt tlg toc out lof lot bbl tlg-clean
49   set CLEAN=fc gz pdf sty dvi def drv ldf ist fd ps xyc cfg
50   set NOCLEAN=
52   rem Check system set up
54   set CHECKDIR=testfiles
55   set CHECKEXE=etex -interaction=nonstopmode -translate-file ./ascii.tcx -efmt=..\build\latex.fmt -output-format=dvi 
56   set CHECKRUNS=2
58   rem Local installation settings
60   set INSTALLDIR=latex\%BUNDLE%\%MODULE%
61   set INSTALLFILES= *.cfg *.clo *.cls *.def *.dfu  *.fd *.ist *.ltx *.sty *.tex *.err
63   rem Documentation typesetting set up (not using internal format for now, perhaps it should)
65   set TYPESETEXE=pdflatex -interaction=nonstopmode
67   rem Locations for the various support items required
69   set MAINDIR=..
70   set SCRIPTDIR=%MAINDIR%\scripts
71   set VALIDATE=%MAINDIR%\validate
73   set UNPACKDIR=%MAINDIR%\unpacked
74   set BUILDDIR=%MAINDIR%\build
75   set TESTDIR=%MAINDIR%\test
76   set SUPPORTDIR=%MAINDIR%\support
78   set DISTRIBDIR=%MAINDIR%\distrib
81   rem Set up redirection of output
83   set REDIRECT=^> nul
84   if not [%2] == [] (
85     if /i [%2] == [show] (
86       set REDIRECT=
87     )
88   )
90 :main
92   if /i [%1] == [check]        goto check
93   if /i [%1] == [checktlg]     goto checktlg
94   if /i [%1] == [clean]        goto clean
95   if /i [%1] == [cleanall]     goto clean
96   if /i [%1] == [doc]          goto doc
97   if /i [%1] == [localinstall] goto localinstall
98   if /i [%1] == [savetlg]      goto savetlg
99   if /i [%1] == [unpack]       goto unpack
100   if /i [%1] == [ctan]      goto ctan
102   goto help
104 :check-init
106   if not exist %CHECKDIR%\nul goto end
108   rem Check for Perl, and give up if it is not found
110   call :perl
111   if ERRORLEVEL 1 goto :EOF
113   rem Remove any old files, and then copy the test system into place
115   del /q %TESTDIR%\*
117   rem Unpack, allowing for using a 'trace' version or similar
119   call :unpack
121 rem next unpacks are needed if we want to process all test files
122 rem i.e. also those from the required portion, but I guess we really 
123 rem better keep this separate
125 rem   call ..\required\tools\make.bat unpack show
126 rem   call ..\required\graphics\make.bat unpack show
127 rem   call ..\required\cyrillic\make.bat unpack show
129   copy /y %SCRIPTDIR%\log2tlg  %TESTDIR% > nul
130   copy /y %VALIDATE%\test2e.tex %TESTDIR% > nul
131   copy /y %VALIDATE%\test209.tex %TESTDIR% > nul
132   copy /y %VALIDATE%\ascii.tcx  %TESTDIR% > nul
134   if exist %CHECKDIR%\helpers\nul (
135       copy /y %CHECKDIR%\helpers\* %TESTDIR% > nul
136   )
138   goto :EOF
141 :check
143   call :check-init
145   rem Copy all test files for which there is a matching reference log
147   for %%I in (%CHECKDIR%\*.lvt) do (
148     if exist %CHECKDIR%\%%~nI.tlg (
149       copy /y %CHECKDIR%\%%~nI.lvt %TESTDIR% > nul
150       copy /y %CHECKDIR%\%%~nI.tlg %TESTDIR% > nul
151     ) else (
152       echo %CHECKDIR%\%%~nI.tlg missing
153     )
154   )
156   goto check-execute
158 :checktlg
160   if [%2] == [] goto help
161   if not exist %CHECKDIR%\%2.lvt (
162     echo.
163     echo Check file %2.lvt not found!
164     shift
165     goto end
166   )
168   call :check-init
170   rem Copy all test files for which there is a matching reference log
172   for %%I in (%CHECKDIR%\%2.lvt) do (
173     if exist %CHECKDIR%\%%~nI.tlg (
174       copy /y %CHECKDIR%\%%~nI.lvt %TESTDIR% > nul
175       copy /y %CHECKDIR%\%%~nI.tlg %TESTDIR% > nul
176     ) else (
177       echo %CHECKDIR%\%%~nI.tlg missing
178     )
179   )
181  shift
182  goto check-execute
184 :check-execute
186   echo.
187   echo Running checks on
189   SET TEXINPUTS=.;%UNPACKDIR%;%BUILDDIR%
191   pushd %TESTDIR%
193   for %%I in (*.tlg) do (
194     echo   %%~nI
195     for /l %%J in (1,1,%CHECKRUNS%) do (
196         %CHECKEXE% %%~nI.lvt <%SCRIPTDIR%\enter.txt %REDIRECT%
197       )
198     %PERLEXE% log2tlg %%~nI < %%~nI.log > %%~nI.new.log
200 rem    del /q %%~nI.log > nul
201     ren %%~nI.log %%~nI.logfull > nul
202     ren %%~nI.new.log %%~nI.log > nul
204 rem remove empty lines from .tlg file
205     %PERLEXE% -n -e "/^\s*$/ || print" < %%~nI.tlg >%%~nI.clean.tlg
207     fc /n  %%~nI.log %%~nI.clean.tlg > %%~nI.fc
208   )
210   for %%I in (*.fc) do (
211     for /f "skip=1 tokens=1" %%J in (%%~nI.fc) do (
212       if "%%J" == "FC:" (
213         del /q %%I
214       )
215     )
216   )
218   echo.
220   if exist *.fc (
221     set PROBLEM=true
222     echo   Checks fails for
223     for %%I in (*.fc) do (
224       echo   - %%~nI
225     )
226   ) else (
227     echo   All checks passed
228   )
230   for %%I in (*.tlg) do (
231     if exist %%~nI.pdf del /q %%~nI.pdf
232     if exist %%~nI.dvi del /q %%~nI.dvi
233   )
235   popd
237   goto end
239 :clean
242   del /q %DISTRIBDIR%\base\*
243   del /q %DISTRIBDIR%\unpacked\*
245   del /q %TESTDIR%\*
246   del /q %UNPACKDIR%\*
247   del /q %BUILDDIR%\*
250   for %%I in (%NOCLEAN%) do (
251     copy /y %%I %%I.bak > nul
252   )
254   for %%I in (%CLEAN%) do (
255     if exist *.%%I del /q *.%%I
256   )
258   for %%I in (%NOCLEAN%) do (
259     copy /y %%I.bak %%I > nul
260     del /q %%I.bak
261   )
263 :clean-int
265   for %%I in (%AUXFILES%) do (
266     if exist *.%%I del /q *.%%I
267   )
269   if exist log2tlg del /q log2tlg
270   if exist test2e.tex del /q test2e.tex
271   if exist ascii.tcx del /q ascii.tcx
273   goto end
275 :doc
277   echo.
278   echo Typesetting (using normal TeX system on machine)
280   for %%I in (*.dtx) do (
281     if %%~xI == .dtx (
282     echo   %%I
283     %TYPESETEXE% -draftmode %%I %REDIRECT%
284     if ERRORLEVEL 1 (
285       echo   ! Compilation failed
286       set PROBLEM=true
287     ) else (
288       if exist %%~nI.idx (
289         makeindex -q -s l3doc.ist -o %%~nI.ind %%~nI.idx > nul
290       )
291       %TYPESETEXE% %%I %REDIRECT%
292       %TYPESETEXE% %%I %REDIRECT%
293     )
294   ) else echo %%I skipped 
295   )
297   for %%I in (*.fdd) do (
298     if %%~xI == .fdd (
299     echo   %%I
300     %TYPESETEXE% -draftmode %%I %REDIRECT%
301     if ERRORLEVEL 1 (
302       echo   ! Compilation failed
303       set PROBLEM=true
304     ) else (
305       if exist %%~nI.idx (
306         makeindex -q -s l3doc.ist -o %%~nI.ind %%~nI.idx > nul
307       )
308       %TYPESETEXE% %%I %REDIRECT%
309       %TYPESETEXE% %%I %REDIRECT%
310     )
311   ) else echo %%I skipped 
312   )
314   for %%I in (source2e.tex sample2e.tex lppl.tex small2e.tex) do (
315     if %%~xI == .tex (
316     echo   %%I
317     %TYPESETEXE% -draftmode %%I %REDIRECT%
318     if ERRORLEVEL 1 (
319       echo   ! Compilation failed
320       set PROBLEM=true
321     ) else (
322       if exist %%~nI.idx (
323         makeindex -q -s l3doc.ist -o %%~nI.ind %%~nI.idx > nul
324       )
325       %TYPESETEXE% %%I %REDIRECT%
326       %TYPESETEXE% %%I %REDIRECT%
327     )
328   ) else echo %%I skipped 
329   )
331  if "%PROBLEM%" == "true" (
332     echo.
333     echo There have been some problems!
336   goto clean-int
338 :localinstall
340   call :unpack
342   echo.
343   echo Installing files
345   rem Find local root if possible
347   if not defined TEXMFHOME (
348     for /f "delims=" %%I in ('kpsewhich --var-value=TEXMFHOME') do @set TEXMFHOME=%%I
349     if "%TEXMFHOME%" == "" (
350       set TEXMFHOME=%USERPROFILE%\texmf
351     )
352   )
354   set INSTALLROOT=%TEXMFHOME%\tex\%INSTALLDIR%
356   if exist "%INSTALLROOT%\*.*" rmdir /q /s "%INSTALLROOT%"
357   mkdir "%INSTALLROOT%"
360   pushd %UNPACKDIR% 
362   for %%I in (%INSTALLFILES%) do (
363     copy /y %%I "%INSTALLROOT%" > nul
364   )
366   popd
368   goto clean-int
370 :perl
372   set PATHCOPY=%PATH%
374 :perl-loop
376   if defined PERLEXE goto :EOF
378   rem This code is used to find out if Perl is available in the path
380   for /f "delims=; tokens=1,2*" %%I in ("%PATHCOPY%") do (
381     if exist %%I\perl.exe set PERLEXE=perl
382     set PATHCOPY=%%J;%%K
383   )
385   if defined PERLEXE goto :EOF
387   rem No Perl found in the path, so try some standard locations
389   if not "%PATHCOPY%" == ";" goto perl-loop
391   if exist %SYSTEMROOT%\Perl\bin\perl.exe set PERLEXE=%SYSTEMROOT%\Perl\bin\perl
392   if exist %ProgramFiles%\Perl\bin\perl.exe set PERLEXE=%ProgramFiles%\Perl\bin\perl
393   if exist %SYSTEMROOT%\strawberry\Perl\bin\perl.exe set PERLEXE=%SYSTEMROOT%\strawberry\Perl\bin\perl
395   if defined PERLEXE goto :EOF
397   rem Failed to find Perl, give up and kill the entire batch process
399   echo.
400   echo  This procedure requires Perl, but it could not be found.
402   exit /b 1
404   goto :EOF
406 :savetlg
408   if not exist %CHECKDIR%\%2.lvt (
409     echo.
410     echo Check file %2.lvt not found!
411     shift
412     goto end
413   )
415   call :check-init
417   rem Copy the test file 
419   copy /y %CHECKDIR%\%2.lvt %TESTDIR% > nul
421   echo.
422   echo Creating and copying %2.tlg
424   SET TEXINPUTS=.;%UNPACKDIR%;%BUILDDIR%
426   pushd %TESTDIR%
428   for /l %%I in (1,1,%CHECKRUNS%) do (
429       %CHECKEXE% %2.lvt %REDIRECT%
430     )
431   %PERLEXE% log2tlg %2 < %2.log > %2.tlg
433   popd
435   copy /y %TESTDIR%\%2.tlg %CHECKDIR%\%2.tlg > nul
438   shift
440   goto clean-int
443 :ctan
445   del /q %DISTRIBDIR%\base\*
446   del /q %DISTRIBDIR%\unpacked\*
448   for %%I in (*.cls *.dtx latexbug.el *.err *.fdd *.ins ltpatch.ltx README *.tex *.txt) do (
449     copy /y %%I %DISTRIBDIR%\base\%%I >nul
450   )
452   for %%I in (*.cls~ *.dtx~ *atexbug.el~ *.err~ *.fdd~ *.ins~ *tpatch.ltx~ *EADME~ *.tex~ *.txt~) do (
453     echo %%I
454     if exist %DISTRIBDIR%\base\%%I del /q %DISTRIBDIR%\base\%%I >nul
455   )
457   call :unpack
459   copy /y %UNPACKDIR%\* %DISTRIBDIR%\unpacked >nul
461   call :doc
463   pushd %UNPACKDIR%
465   for %%I in (*.pdf) do (
466     copy /y %%I %DISTRIBDIR%\base\%%I >nul
467   )
469   popd
471   
472   goto end
475 :unpack
477   del /q %UNPACKDIR%\*
478   del /q %BUILDDIR%\*
480   echo. 
481   echo ***************************************************
482   echo *** Copying kernel bootstrap sources ...
483   echo ***************************************************
484   echo. 
486   for %%I in (*.dtx *.ins *.fdd ltpatch.ltx *.tex *.cls) do (
487     copy /y %%I %UNPACKDIR%\%%I >nul
488   )
490 rem getting rid of emacs ~ files
492   for %%I in (*.dtx *.ins *.fdd ltpatch.ltx *.tex *.cls) do (
493     if exist %UNPACKDIR%\%%I~ rm %UNPACKDIR%\%%I~
494   )
496 rem remove other files
497   for %%I in (ttcterrata.cls) do (
498     if exist %UNPACKDIR%\%%I del %UNPACKDIR%\%%I
499   )
502 rem unpack the distribution
503 rem Make sure that no external input files are read by setting TEXINPUTS
505   echo. 
506   echo ***************************************************
507   echo *** Generating LaTeX2e kernel bootstrap files...
508   echo ***************************************************
509   echo. 
511   pushd %UNPACKDIR% 
512   SET TEXINPUTS=.;  
513   etex -ini unpack.ins <%SCRIPTDIR%\yes.txt
516   for %%I in (*.dtx *.ins *.fdd ) do (
517     if exist %%I del %%I  >nul
518   )
522   popd
523   pushd %BUILDDIR%
525   echo. 
526   echo ***************************************************
527   echo *** Copying format support files...
528   echo ***************************************************
529   echo. 
530   copy /y %SUPPORTDIR%\*.*
532   echo. 
533   echo ***************************************************
534   echo *** Generating LaTeX2e kernel formats...
535   echo ***************************************************
536   echo. 
538   SET TEXINPUTS=.;%UNPACKDIR%
540   etex -ini -etex latex.ltx <%SCRIPTDIR%\yes.txt   
541   pdfetex -ini -etex -jobname=pdflatex "*pdflatex.ini" latex.ltx <%SCRIPTDIR%\yes.txt   
543   set TEXINPUTS=
544   popd
546   goto end
548 :end
550 rem  echo base: PROBLEM="%PROBLEM%" and GLOBALPROBLEM="%GLOBALPROBLEM%"
552   endlocal & if "%PROBLEM%" == "true" set GLOBALPROBLEM=%PROBLEM%
554   rem If something like "make check show" was used, remove the "show"
556   if /i [%2] == [show] shift
558   shift
559   if not [%1] == [] goto main