4 # This file is part of LyX, the document processor.
5 # Licence details can be found in the file COPYING.
8 # Full author contact details are available in file CREDITS.
10 # This is an experimental version of the configure script, written
13 import sys, os, re, shutil, glob
17 ''' Writing to a Tee object will write to all file objects it keeps.
18 That is to say, writing to Tee(sys.stdout, open(logfile, 'w')) will
19 write to sys.stdout as well as a log file.
21 def __init__(self, *args):
24 def write(self, data):
26 result = f.write(data)
29 def writelines(self, seq):
34 def writeToFile(filename, lines, append = False):
35 " utility function: write or append lines to filename "
37 file = open(filename, 'a')
39 file = open(filename, 'w')
45 ''' utility function: shortcut for appending lines to outfile
46 add newline at the end of lines.
48 if lines.strip() != '':
49 writeToFile(outfile, lines + '\n', append = True)
52 def removeFiles(filenames):
53 '''utility function: 'rm -f'
54 ignore errors when file does not exist, or is a directory.
56 for file in filenames:
64 '''utility function: run a command and get its output as a string
74 ''' I do not really know why this is useful, but we might as well keep it.
76 Only set these to C if already set. These must not be set unconditionally
77 because not all systems understand e.g. LANG=C (notably SCO).
78 Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'!
79 Non-C LC_CTYPE values break the ctype check.
81 os.environ['LANG'] = os.getenv('LANG', 'C')
82 os.environ['LC'] = os.getenv('LC_ALL', 'C')
83 os.environ['LC_MESSAGE'] = os.getenv('LC_MESSAGE', 'C')
84 os.environ['LC_CTYPE'] = os.getenv('LC_CTYPE', 'C')
87 def createDirectories():
88 ''' Create the build directories if necessary '''
89 for dir in ['bind', 'clipart', 'doc', 'examples', 'images', 'kbd', \
90 'layouts', 'scripts', 'templates', 'ui' ]:
91 if not os.path.isdir( dir ):
95 print "Failed to create directory ", dir
100 ''' Determine the path-style needed by the TeX engine on Win32 (Cygwin) '''
101 windows_style_tex_paths = ''
102 if os.name == 'nt' or sys.platform == 'cygwin':
103 from tempfile import mkstemp
104 fd, tmpfname = mkstemp(suffix='.ltx')
106 inpname = tmpfname.replace('\\', '/')
108 inpname = cmdOutput('cygpath -m ' + tmpfname)
109 inpname = inpname.replace('~', '\\string~')
110 os.write(fd, r'\relax')
112 latex_out = cmdOutput(r'latex "\nonstopmode\input{%s}"' % inpname)
113 if 'Error' in latex_out:
114 print "configure: TeX engine needs posix-style paths in latex files"
115 windows_style_tex_paths = 'false'
117 print "configure: TeX engine needs windows-style paths in latex files"
118 windows_style_tex_paths = 'true'
119 removeFiles([tmpfname, 'texput.log'])
120 return windows_style_tex_paths
123 ## Searching some useful programs
124 def checkProg(description, progs, rc_entry = [], path = [], not_found = ''):
126 This function will search a program in $PATH plus given path
127 If found, return directory and program name (not the options).
129 description: description of the program
131 progs: check programs, for each prog, the first word is used
132 for searching but the whole string is used to replace
133 %% for a rc_entry. So, feel free to add '$$i' etc for programs.
135 path: additional pathes
137 rc_entry: entry to outfile, can be
138 1. emtpy: no rc entry will be added
139 2. one pattern: %% will be replaced by the first found program,
140 or '' if no program is found.
141 3. several patterns for each prog and not_found. This is used
142 when different programs have different usages. If you do not
143 want not_found entry to be added to the RC file, you can specify
144 an entry for each prog and use '' for the not_found entry.
146 not_found: the value that should be used instead of '' if no program
150 # one rc entry for each progs plus not_found entry
151 if len(rc_entry) > 1 and len(rc_entry) != len(progs) + 1:
152 print "rc entry should have one item or item for each prog and not_found."
154 print 'checking for ' + description + '...'
155 ## print '(' + ','.join(progs) + ')',
156 for idx in range(len(progs)):
157 # ac_prog may have options, ac_word is the command name
159 ac_word = ac_prog.split(' ')[0]
160 print '+checking for "' + ac_word + '"... ',
161 path = os.environ["PATH"].split(os.pathsep) + path
163 # check both ac_word and ac_word.exe (for windows system)
164 if os.path.isfile( os.path.join(ac_dir, ac_word) ) or \
165 os.path.isfile( os.path.join(ac_dir, ac_word + ".exe") ):
167 # write rc entries for this command
168 if len(rc_entry) == 1:
169 addToRC(rc_entry[0].replace('%%', ac_prog))
170 elif len(rc_entry) > 1:
171 addToRC(rc_entry[idx].replace('%%', ac_prog))
172 return [ac_dir, ac_word]
175 # write rc entries for 'not found'
176 if len(rc_entry) > 0: # the last one.
177 addToRC(rc_entry[-1].replace('%%', not_found))
178 return ['', not_found]
181 def checkViewer(description, progs, rc_entry = [], path = []):
182 ''' The same as checkProg, but for viewers and editors '''
183 return checkProg(description, progs, rc_entry, path, not_found = 'auto')
187 ''' Check latex, return lyx_check_config '''
188 # Find programs! Returned path is not used now
189 if ((os.name == 'nt' or sys.platform == 'cygwin') and
190 checkProg('DVI to DTL converter', ['dv2dt']) != ['', ''] and
191 checkProg('DTL to DVI converter', ['dt2dv']) != ['', '']):
192 # Windows only: DraftDVI
193 converter_entry = r'''\converter latex dvi2 "%%" "latex"
194 \converter dvi2 dvi "python -tt $$s/scripts/clean_dvi.py $$i $$o" ""'''
196 converter_entry = r'\converter latex dvi "%%" "latex"'
197 path, LATEX = checkProg('a Latex2e program', ['pplatex $$i', 'latex $$i', 'latex2e $$i'],
198 rc_entry = [converter_entry])
201 # Check if latex is usable
202 writeToFile('chklatex.ltx', '''
203 \\nonstopmode\\makeatletter
204 \\ifx\\undefined\\documentclass\\else
205 \\message{ThisIsLaTeX2e}
209 # run latex on chklatex.ltx and check result
210 if cmdOutput(LATEX + ' chklatex.ltx').find('ThisIsLaTeX2e') != -1:
214 print "Latex not usable (not LaTeX2e) "
215 # remove temporary files
216 removeFiles(['chklatex.ltx', 'chklatex.log'])
220 def checkFormatEntries():
221 ''' Check all formats (\Format entries) '''
222 checkViewer('a Tgif viewer and editor', ['tgif'],
223 rc_entry = [r'\Format tgif obj Tgif "" "%%" "%%" "vector"'])
225 checkViewer('a FIG viewer and editor', ['xfig'],
226 rc_entry = [r'\Format fig fig FIG "" "%%" "%%" "vector"'])
228 checkViewer('a Grace viewer and editor', ['xmgrace'],
229 rc_entry = [r'\Format agr agr Grace "" "%%" "%%" "vector"'])
231 checkViewer('a FEN viewer and editor', ['xboard -lpf $$i -mode EditPosition'],
232 rc_entry = [r'\Format fen fen FEN "" "%%" "%%" ""'])
234 path, iv = checkViewer('a raster image viewer', ['xv', 'kview', 'gimp'])
235 path, ie = checkViewer('a raster image editor', ['gimp'])
236 addToRC(r'''\Format bmp bmp BMP "" "%s" "%s" ""
237 \Format gif gif GIF "" "%s" "%s" ""
238 \Format jpg jpg JPEG "" "%s" "%s" ""
239 \Format pbm pbm PBM "" "%s" "%s" ""
240 \Format pgm pgm PGM "" "%s" "%s" ""
241 \Format png png PNG "" "%s" "%s" ""
242 \Format ppm ppm PPM "" "%s" "%s" ""
243 \Format tiff tif TIFF "" "%s" "%s" ""
244 \Format xbm xbm XBM "" "%s" "%s" ""
245 \Format xpm xpm XPM "" "%s" "%s" ""''' % \
246 (iv, ie, iv, ie, iv, ie, iv, ie, iv, ie, iv, ie, iv, ie, iv, ie, iv, ie, iv, ie) )
248 checkViewer('a text editor', ['xemacs', 'gvim', 'kedit', 'kwrite', 'kate', \
249 'nedit', 'gedit', 'notepad'],
250 rc_entry = [r'''\Format asciichess asc "Plain text (chess output)" "" "" "%%" ""
251 \Format asciiimage asc "Plain text (image)" "" "" "%%" ""
252 \Format asciixfig asc "Plain text (Xfig output)" "" "" "%%" ""
253 \Format dateout tmp "date (output)" "" "" "%%" ""
254 \Format docbook sgml DocBook B "" "%%" "document"
255 \Format docbook-xml xml "Docbook (XML)" "" "" "%%" "document"
256 \Format literate nw NoWeb N "" "%%" "document"
257 \Format lilypond ly "LilyPond music" "" "" "%%" "vector"
258 \Format latex tex "LaTeX (plain)" L "" "%%" "document"
259 \Format linuxdoc sgml LinuxDoc x "" "%%" "document"
260 \Format pdflatex tex "LaTeX (pdflatex)" "" "" "%%" "document"
261 \Format text txt "Plain text" a "" "%%" "document"
262 \Format text2 txt "Plain text (pstotext)" "" "" "%%" "document"
263 \Format text3 txt "Plain text (ps2ascii)" "" "" "%%" "document"
264 \Format text4 txt "Plain text (catdvi)" "" "" "%%" "document"
265 \Format textparagraph txt "Plain text (paragraphs)" "" "" "%%" "document"''' ])
267 #checkProg('a Postscript interpreter', ['gs'],
268 # rc_entry = [ r'\ps_command "%%"' ])
269 checkViewer('a Postscript previewer', ['gv', 'ghostview -swap', 'kghostview'],
270 rc_entry = [r'''\Format eps eps EPS "" "%%" "" "vector"
271 \Format ps ps Postscript t "%%" "" "document,vector"'''])
273 checkViewer('a PDF previewer', ['acrobat', 'acroread', 'gv', 'ghostview', \
274 'xpdf', 'kpdf', 'kghostview'],
275 rc_entry = [r'''\Format pdf pdf "PDF (ps2pdf)" P "%%" "" "document,vector"
276 \Format pdf2 pdf "PDF (pdflatex)" F "%%" "" "document,vector"
277 \Format pdf3 pdf "PDF (dvipdfm)" m "%%" "" "document,vector"'''])
279 checkViewer('a DVI previewer', ['xdvi', 'kdvi'],
280 rc_entry = [r'\Format dvi dvi DVI D "%%" "" "document,vector"'])
281 if ((os.name == 'nt' or sys.platform == 'cygwin') and
282 checkProg('DVI to DTL converter', ['dv2dt']) != ['', ''] and
283 checkProg('DTL to DVI converter', ['dt2dv']) != ['', '']):
284 # Windows only: DraftDVI
285 addToRC(r'\Format dvi2 dvi DraftDVI "" "" "document,vector"')
287 checkViewer('a HTML previewer', ['mozilla file://$$p$$i', 'netscape'],
288 rc_entry = [r'\Format html html HTML H "%%" "" "document"'])
290 # entried that do not need checkProg
291 addToRC(r'''\Format date "" "date command" "" "" "" ""
292 \Format fax "" Fax "" "" "" "document"
293 \Format lyx lyx LyX "" "" "" ""
294 \Format lyx13x lyx13 "LyX 1.3.x" "" "" "" "document"
295 \Format lyxpreview lyxpreview "LyX Preview" "" "" "" ""
296 \Format pdftex pdftex_t PDFTEX "" "" "" ""
297 \Format program "" Program "" "" "" ""
298 \Format pstex pstex_t PSTEX "" "" "" ""
299 \Format rtf rtf "Rich Text Format" "" "" "" "document,vector"
300 \Format sxw sxw "OpenOffice.Org Writer" O "" "" "document,vector"
301 \Format wmf wmf "Windows Meta File" "" "" "" "vector"
302 \Format word doc "MS Word" W "" "" "document,vector"
303 \Format wordhtml html "MS Word (HTML)" "" "" "" "document"
307 def checkConverterEntries():
308 ''' Check all converters (\converter entries) '''
309 checkProg('the pdflatex program', ['pdflatex $$i'],
310 rc_entry = [ r'\converter pdflatex pdf2 "%%" "latex"' ])
312 ''' If we're running LyX in-place then tex2lyx will be found in
313 ../src/tex2lyx. Add this directory to the PATH temporarily and
315 Use PATH to avoid any problems with paths-with-spaces.
317 path_orig = os.environ["PATH"]
318 os.environ["PATH"] = os.path.join('..', 'src', 'tex2lyx') + \
319 os.pathsep + path_orig
321 checkProg('a LaTeX/Noweb -> LyX converter', ['tex2lyx', 'tex2lyx' + version_suffix],
322 rc_entry = [r'''\converter latex lyx "%% -f $$i $$o" ""
323 \converter literate lyx "%% -n -f $$i $$o" ""'''])
325 os.environ["PATH"] = path_orig
328 checkProg('a Noweb -> LaTeX converter', ['noweave -delay -index $$i > $$o'],
329 rc_entry = [ r'\converter literate latex "%%" ""' ])
331 checkProg('a HTML -> LaTeX converter', ['html2latex $$i'],
332 rc_entry = [ r'\converter html latex "%%" ""' ])
334 checkProg('a MSWord -> LaTeX converter', ['wvCleanLatex $$i $$o'],
335 rc_entry = [ r'\converter word latex "%%" ""' ])
337 checkProg('a LaTeX -> MS Word converter', ["htlatex $$i 'html,word' 'symbol/!' '-cvalidate'"],
338 rc_entry = [ r'\converter latex wordhtml "%%" ""' ])
340 checkProg('an OpenOffice.org -> LaTeX converter', ['w2l -clean $$i'],
341 rc_entry = [ r'\converter sxw latex "%%" ""' ])
343 checkProg('a LaTeX -> OpenOffice.org converter', ['oolatex $$i', 'oolatex.sh $$i'],
344 rc_entry = [ r'\converter latex sxw "%%" "latex"' ])
345 # On windows it is called latex2rt.exe
346 checkProg('a LaTeX -> RTF converter', ['latex2rtf -p -S -o $$o $$i', 'latex2rt -p -S -o $$o $$i'],
347 rc_entry = [ r'\converter latex rtf "%%" "needaux"' ])
349 checkProg('a PS to PDF converter', ['ps2pdf13 $$i $$o'],
350 rc_entry = [ r'\converter ps pdf "%%" ""' ])
352 checkProg('a PS to TXT converter', ['pstotext $$i > $$o'],
353 rc_entry = [ r'\converter ps text2 "%%" ""' ])
355 checkProg('a PS to TXT converter', ['ps2ascii $$i $$o'],
356 rc_entry = [ r'\converter ps text3 "%%" ""' ])
358 checkProg('a DVI to TXT converter', ['catdvi $$i > $$o'],
359 rc_entry = [ r'\converter dvi text4 "%%" ""' ])
361 checkProg('a DVI to PS converter', ['dvips -o $$o $$i'],
362 rc_entry = [ r'\converter dvi ps "%%" ""' ])
364 checkProg('a DVI to PDF converter', ['dvipdfmx -o $$o $$i', 'dvipdfm -o $$o $$i'],
365 rc_entry = [ r'\converter dvi pdf3 "%%" ""' ])
367 path, dvipng = checkProg('dvipng', ['dvipng'])
368 if dvipng == "dvipng":
369 addToRC(r'\converter lyxpreview png "python -tt $$s/scripts/lyxpreview2bitmap.py" ""')
371 addToRC(r'\converter lyxpreview png "" ""')
373 checkProg('a fax program', ['kdeprintfax $$i', 'ksendfax $$i'],
374 rc_entry = [ r'\converter ps fax "%%" ""'])
376 checkProg('a FIG -> EPS/PPM converter', ['fig2dev'],
378 r'''\converter fig eps "fig2dev -L eps $$i $$o" ""
379 \converter fig ppm "fig2dev -L ppm $$i $$o" ""
380 \converter fig png "fig2dev -L png $$i $$o" ""''',
383 checkProg('a TIFF -> PS converter', ['tiff2ps $$i > $$o'],
384 rc_entry = [ r'\converter tiff eps "%%" ""', ''])
386 checkProg('a TGIF -> EPS/PPM converter', ['tgif'],
388 r'''\converter tgif eps "tgif -stdout -print -color -eps $$i > $$o" ""
389 \converter tgif ppm "tgif -stdout -print -color -ppm $$i > $$o" ""
390 \converter tgif png "tgif -stdout -print -color -png $$i > $$o" ""
391 \converter tgif pdf "tgif -stdout -print -color -pdf $$i > $$o" ""''',
394 checkProg('a WMF -> EPS converter', ['wmf2eps -o $$o $$i'],
395 rc_entry = [ r'\converter wmf eps "%%" ""', ''])
397 checkProg('a EPS -> PDF converter', ['epstopdf'],
398 rc_entry = [ r'\converter eps pdf "epstopdf --outfile=$$o $$i" ""', ''])
400 checkProg('a Grace -> Image converter', ['gracebat'],
402 r'''\converter agr eps "gracebat -hardcopy -printfile $$o -hdevice EPS $$i 2>/dev/null" ""
403 \converter agr png "gracebat -hardcopy -printfile $$o -hdevice PNG $$i 2>/dev/null" ""
404 \converter agr jpg "gracebat -hardcopy -printfile $$o -hdevice JPEG $$i 2>/dev/null" ""
405 \converter agr ppm "gracebat -hardcopy -printfile $$o -hdevice PNM $$i 2>/dev/null" ""''',
408 checkProg('a LaTeX -> HTML converter', ['htlatex $$i', 'tth -t -e2 -L$$b < $$i > $$o', \
409 'latex2html -no_subdir -split 0 -show_section_numbers $$i', 'hevea -s $$i'],
410 rc_entry = [ r'\converter latex html "%%" "originaldir,needaux"' ])
412 path, lilypond = checkProg('a LilyPond -> ESP/PDF/PNG converter', ['lilypond'])
414 version_string = cmdOutput("lilypond --version")
415 match = re.match('GNU LilyPond (\S+)', version_string)
417 version_number = match.groups()[0]
418 version = version_number.split('.')
419 if int(version[0]) > 2 or (len(version) > 1 and int(version[0]) == 2 and int(version[1]) >= 6):
420 addToRC(r'''\converter lilypond eps "lilypond -b eps --ps $$i" ""
421 \converter lilypond png "lilypond -b eps --png $$i" ""''')
422 if int(version[0]) > 2 or (len(version) > 1 and int(version[0]) == 2 and int(version[1]) >= 9):
423 addToRC(r'\converter lilypond pdf "lilypond -b eps --pdf $$i" ""')
424 print '+ found LilyPond version %s.' % version_number
426 print '+ found LilyPond, but version %s is too old.' % version_number
428 print '+ found LilyPond, but could not extract version number.'
430 # FIXME: no rc_entry? comment it out
431 # checkProg('Image converter', ['convert $$i $$o'])
433 # Entried that do not need checkProg
434 addToRC(r'''\converter lyxpreview ppm "python -tt $$s/scripts/lyxpreview2bitmap.py" ""
435 \converter date dateout "date +%d-%m-%Y > $$o" ""
436 \converter docbook docbook-xml "cp $$i $$o" "xml"
437 \converter fen asciichess "python -tt $$s/scripts/fen2ascii.py $$i $$o" ""
438 \converter fig pdftex "python -tt $$s/scripts/fig2pdftex.py $$i $$o" ""
439 \converter fig pstex "python -tt $$s/scripts/fig2pstex.py $$i $$o" ""
440 \converter lyx lyx13x "python -tt $$s/lyx2lyx/lyx2lyx -t 221 $$i > $$o" ""
445 ''' Check linuxdoc '''
447 path, LINUXDOC = checkProg('SGML-tools 1.x (LinuxDoc)', ['sgml2lyx'],
449 r'''\converter linuxdoc lyx "sgml2lyx $$i" ""
450 \converter linuxdoc latex "sgml2latex $$i" ""
451 \converter linuxdoc dvi "sgml2latex -o dvi $$i" ""
452 \converter linuxdoc html "sgml2html $$i" ""''',
453 r'''\converter linuxdoc lyx "" ""
454 \converter linuxdoc latex "" ""
455 \converter linuxdoc dvi "" ""
456 \converter linuxdoc html "" ""''' ])
458 return ('yes', 'true', '\\def\\haslinuxdoc{yes}')
460 return ('no', 'false', '')
464 ''' Check docbook '''
465 path, DOCBOOK = checkProg('SGML-tools 2.x (DocBook) or db2x scripts', ['sgmltools', 'db2dvi'],
467 r'''\converter docbook dvi "sgmltools -b dvi $$i" ""
468 \converter docbook html "sgmltools -b html $$i" ""''',
469 r'''\converter docbook dvi "db2dvi $$i" ""
470 \converter docbook html "db2html $$i" ""''',
471 r'''\converter docbook dvi "" ""
472 \converter docbook html "" ""'''])
475 return ('yes', 'true', '\\def\\hasdocbook{yes}')
477 return ('no', 'false', '')
480 def checkOtherEntries():
481 ''' entries other than Format and Converter '''
482 checkProg('a *roff formatter', ['groff', 'nroff'],
484 r'\ascii_roff_command "groff -t -Tlatin1 $$FName"',
485 r'\ascii_roff_command "tbl $$FName | nroff"',
486 r'\ascii_roff_command ""' ])
487 checkProg('ChkTeX', ['chktex -n1 -n3 -n6 -n9 -n22 -n25 -n30 -n38'],
488 rc_entry = [ r'\chktex_command "%%"' ])
489 checkProg('a spellchecker', ['ispell'],
490 rc_entry = [ r'\spell_command "%%"' ])
491 ## FIXME: OCTAVE is not used anywhere
492 # path, OCTAVE = checkProg('Octave', ['octave'])
493 ## FIXME: MAPLE is not used anywhere
494 # path, MAPLE = checkProg('Maple', ['maple'])
495 checkProg('a spool command', ['lp', 'lpr'],
497 r'''\print_spool_printerprefix "-d "
498 \print_spool_command "lp"''',
499 r'''\print_spool_printerprefix "-P",
500 \print_spool_command "lpr"''',
502 # Add the rest of the entries (no checkProg is required)
503 addToRC(r'''\copier fig "python -tt $$s/scripts/fig_copy.py $$i $$o"
504 \copier pstex "python -tt $$s/scripts/tex_copy.py $$i $$o $$l"
505 \copier pdftex "python -tt $$s/scripts/tex_copy.py $$i $$o $$l"
509 def processLayoutFile(file, bool_docbook, bool_linuxdoc):
510 ''' process layout file and get a line of result
512 Declear line are like this: (article.layout, scrbook.layout, svjog.layout)
514 \DeclareLaTeXClass{article}
515 \DeclareLaTeXClass[scrbook]{book (koma-script)}
516 \DeclareLaTeXClass[svjour,svjog.clo]{article (Springer - svjour/jog)}
520 "article" "article" "article" "false"
521 "scrbook" "scrbook" "book (koma-script)" "false"
522 "svjog" "svjour" "article (Springer - svjour/jog)" "false"
524 classname = file.split(os.sep)[-1].split('.')[0]
525 # return ('LaTeX', '[a,b]', 'a', ',b,c', 'article') for \DeclearLaTeXClass[a,b,c]{article}
526 p = re.compile(r'\Declare(LaTeX|DocBook)Class\s*(\[([^,]*)(,.*)*\])*\s*{(.*)}')
527 for line in open(file).readlines():
530 (classtype, optAll, opt, opt1, desc) = res.groups()
531 avai = {'LaTeX':'false', 'DocBook':bool_docbook, 'LinuxDoc':bool_linuxdoc}[classtype]
534 return '"%s" "%s" "%s" "%s"\n' % (classname, opt, desc, avai)
535 print "Layout file without \DeclearXXClass line. "
539 def checkLatexConfig(check_config, bool_docbook, bool_linuxdoc):
540 ''' Explore the LaTeX configuration '''
541 print 'checking LaTeX configuration... ',
542 # First, remove the files that we want to re-create
543 removeFiles(['textclass.lst', 'packages.lst', 'chkconfig.sed'])
546 print ' default values'
547 print '+checking list of textclasses... '
548 tx = open('textclass.lst', 'w')
550 # This file declares layouts and their associated definition files
551 # (include dir. relative to the place where this file is).
552 # It contains only default values, since chkconfig.ltx could not be run
553 # for some reason. Run ./configure.py if you need to update it after a
554 # configuration change.
556 # build the list of available layout files and convert it to commands
559 for file in glob.glob( os.path.join('layouts', '*.layout') ) + \
560 glob.glob( os.path.join(srcdir, 'layouts', '*.layout' ) ) :
562 if not os.path.isfile(file):
564 # get stuff between /xxxx.layout .
565 classname = file.split(os.sep)[-1].split('.')[0]
567 cleanclass = classname.replace(' ', '_')
568 cleanclass = cleanclass.replace('-', '_')
569 # make sure the same class is not considered twice
570 if foundClasses.count(cleanclass) == 0: # not found before
571 foundClasses.append(cleanclass)
572 tx.write(processLayoutFile(file, bool_docbook, bool_linuxdoc))
577 removeFiles(['wrap_chkconfig.ltx', 'chkconfig.vars', \
578 'chkconfig.classes', 'chklayouts.tex'])
580 if not os.path.isfile( 'chkconfig.ltx' ):
581 shutil.copy( os.path.join(srcdir, 'chkconfig.ltx'), 'chkconfig.ltx' )
583 writeToFile('wrap_chkconfig.ltx', '%s\n%s\n\\input{chkconfig.ltx}\n' \
584 % (linuxdoc_cmd, docbook_cmd) )
585 # Construct the list of classes to test for.
586 # build the list of available layout files and convert it to commands
588 p1 = re.compile(r'\Declare(LaTeX|DocBook)Class')
590 for file in glob.glob( os.path.join('layouts', '*.layout') ) + \
591 glob.glob( os.path.join(srcdir, 'layouts', '*.layout' ) ) :
592 if not os.path.isfile(file):
594 classname = file.split(os.sep)[-1].split('.')[0]
595 for line in open(file).readlines():
596 if p1.search(line) == None:
599 print "Wrong input layout file with line '" + line
601 testclasses.append("\\TestDocClass{%s}{%s}" % (classname, line[1:].strip()))
604 cl = open('chklayouts.tex', 'w')
605 for line in testclasses:
606 cl.write(line + '\n')
609 # we have chklayouts.tex, then process it
610 fout = os.popen(LATEX + ' wrap_chkconfig.ltx')
612 line = fout.readline()
615 if re.match('^\+', line):
619 # currently, values in chhkconfig are only used to set
622 for line in open('chkconfig.vars').readlines():
623 key, val = re.sub('-', '_', line).split('=')
625 values[key] = val.strip("'")
626 # chk_fontenc may not exist
628 addToRC(r'\font_encoding "%s"' % values["chk_fontenc"])
631 if rmcopy: # remove the copied file
632 removeFiles( [ 'chkconfig.ltx' ] )
635 def createLaTeXConfig():
636 ''' create LaTeXConfig.lyx '''
637 # if chkconfig.sed does not exist (because LaTeX did not run),
638 # then provide a standard version.
639 if not os.path.isfile('chkconfig.sed'):
640 writeToFile('chkconfig.sed', 's!@.*@!???!g\n')
641 print "creating packages.lst"
642 # if packages.lst does not exist (because LaTeX did not run),
643 # then provide a standard version.
644 if not os.path.isfile('packages.lst'):
645 writeToFile('packages.lst', '''
646 ### This file should contain the list of LaTeX packages that have been
647 ### recognized by LyX. Unfortunately, since configure could not find
648 ### your LaTeX2e program, the tests have not been run. Run ./configure.py
649 ### if you need to update it after a configuration change.
651 print 'creating doc/LaTeXConfig.lyx'
653 # This is originally done by sed, using a
654 # tex-generated file chkconfig.sed
655 ##sed -f chkconfig.sed ${srcdir}/doc/LaTeXConfig.lyx.in
656 ## >doc/LaTeXConfig.lyx
657 # Now, we have to do it by hand (python).
659 # add to chekconfig.sed
660 writeToFile('chkconfig.sed', '''s!@chk_linuxdoc@!%s!g
662 ''' % (chk_linuxdoc, chk_docbook) , append=True)
663 # process this sed file!!!!
664 lyxin = open( os.path.join(srcdir, 'doc', 'LaTeXConfig.lyx.in')).readlines()
666 p = re.compile(r's!(.*)!(.*)!g')
667 # process each sed replace.
668 for sed in open('chkconfig.sed').readlines():
669 if sed.strip() == '':
672 fr, to = p.match(sed).groups()
673 # if latex did not run, change all @name@ to '???'
675 for line in range(len(lyxin)):
676 lyxin[line] = re.sub('@.*@', to, lyxin[line])
678 for line in range(len(lyxin)):
679 lyxin[line] = lyxin[line].replace(fr, to)
680 except: # wrong sed entry?
681 print "Wrong sed entry in chkconfig.sed: '" + sed + "'"
684 writeToFile( os.path.join('doc', 'LaTeXConfig.lyx'),
688 def checkTeXAllowSpaces():
689 ''' Let's check whether spaces are allowed in TeX file names '''
690 tex_allows_spaces = 'false'
692 print "Checking whether TeX allows spaces in file names... ",
693 writeToFile('a b.tex', r'\message{working^^J}' )
695 latex_out = cmdOutput(LATEX + r""" "\nonstopmode\input{\"a b\"}" """)
697 latex_out = cmdOutput(LATEX + r""" '\nonstopmode\input{"a b"}' """)
698 if 'working' in latex_out:
700 tex_allows_spaces = 'true'
703 tex_allows_spaces = 'false'
704 addToRC(r'\tex_allows_spaces ' + tex_allows_spaces)
705 removeFiles( [ 'a b.tex', 'a b.log', 'texput.log' ])
708 def removeTempFiles():
710 if not lyx_keep_temps:
711 removeFiles(['chkconfig.sed', 'chkconfig.vars', \
712 'wrap_chkconfig.ltx', 'wrap_chkconfig.log', \
713 'chklayouts.tex', 'missfont.log',
714 'chklatex.ltx', 'chklatex.log'])
717 if __name__ == '__main__':
718 lyx_check_config = True
719 outfile = 'lyxrc.defaults'
721 lyx_keep_temps = False
723 logfile = 'configure.log'
724 ## Parse the command line
725 for op in sys.argv[1:]: # default shell/for list is $*, the options
726 if op in [ '-help', '--help', '-h' ]:
727 print '''Usage: configure [options]
729 --help show this help lines
730 --keep-temps keep temporary files (for debug. purposes)
731 --without-latex-config do not run LaTeX to determine configuration
732 --with-version-suffix=suffix suffix of binary installed files
735 elif op == '--without-latex-config':
736 lyx_check_config = False
737 elif op == '--keep-temps':
738 lyx_keep_temps = True
739 elif op[0:22] == '--with-version-suffix=': # never mind if op is not long enough
740 version_suffix = op[22:]
742 print "Unknown option", op
745 # set up log file for stdout and stderr
746 log = open(logfile, 'w')
747 sys.stdout = Tee(sys.stdout, log)
748 sys.stderr = Tee(sys.stderr, log)
749 # check if we run from the right directory
750 srcdir = os.path.dirname(sys.argv[0])
753 if not os.path.isfile( os.path.join(srcdir, 'chkconfig.ltx') ):
754 print "configure: error: cannot find chkconfig.ltx script"
758 windows_style_tex_paths = checkTeXPaths()
759 ## Write the first part of outfile
760 writeToFile(outfile, '''# This file has been automatically generated by LyX' lib/configure.py
761 # script. It contains default settings that have been determined by
762 # examining your system. PLEASE DO NOT MODIFY ANYTHING HERE! If you
763 # want to customize LyX, use LyX' Preferences dialog or modify directly
764 # the "preferences" file instead. Any setting in that file will
765 # override the values given here.
770 checkConverterEntries()
771 (chk_linuxdoc, bool_linuxdoc, linuxdoc_cmd) = checkLinuxDoc()
772 (chk_docbook, bool_docbook, docbook_cmd) = checkDocBook()
773 checkTeXAllowSpaces()
774 if windows_style_tex_paths != '':
775 addToRC(r'\tex_expects_windows_paths %s' % windows_style_tex_paths)
777 # --without-latex-config can disable lyx_check_config
778 checkLatexConfig( lyx_check_config and LATEX != '', bool_docbook, bool_linuxdoc)