1 #! /usr/bin/env python -tt
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
16 def writeToFile(filename, lines, append = False):
17 " utility function: write or append lines to filename "
19 file = open(filename, 'a')
21 file = open(filename, 'w')
27 ''' utility function: shortcut for appending lines to outfile
28 add newline at the end of lines.
30 if lines.strip() != '':
31 writeToFile(outfile, lines + '\n', append = True)
34 def removeFiles(filenames):
35 '''utility function: 'rm -f'
36 ignore errors when file does not exist, or is a directory.
38 for file in filenames:
46 '''utility function: run a command and get its output as a string
56 ''' I do not really know why this is useful, but we might as well keep it.
58 Only set these to C if already set. These must not be set unconditionally
59 because not all systems understand e.g. LANG=C (notably SCO).
60 Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'!
61 Non-C LC_CTYPE values break the ctype check.
63 os.environ['LANG'] = os.getenv('LANG', 'C')
64 os.environ['LC'] = os.getenv('LC_ALL', 'C')
65 os.environ['LC_MESSAGE'] = os.getenv('LC_MESSAGE', 'C')
66 os.environ['LC_CTYPE'] = os.getenv('LC_CTYPE', 'C')
69 def createDirectories():
70 ''' Create the build directories if necessary '''
71 for dir in ['bind', 'clipart', 'doc', 'examples', 'images', 'kbd', \
72 'layouts', 'scripts', 'templates', 'ui' ]:
73 if not os.path.isdir( dir ):
77 print "Failed to create directory ", dir
82 ''' Determine the path-style needed by the TeX engine on Win32 (Cygwin) '''
83 windows_style_tex_paths = ''
84 if os.name == 'nt' or sys.platform == 'cygwin':
85 from tempfile import mkstemp
86 fd, tmpfname = mkstemp(suffix='.ltx')
88 inpname = tmpfname.replace('\\', '/')
90 inpname = cmdOutput('cygpath -m ' + tmpfname)
91 inpname = inpname.replace('~', '\\string~')
92 os.write(fd, r'\relax')
94 latex_out = cmdOutput(r'latex "\nonstopmode\input{%s}"' % inpname)
95 if 'Error' in latex_out:
96 print "configure: TeX engine needs posix-style paths in latex files"
97 windows_style_tex_paths = 'false'
99 print "configure: TeX engine needs windows-style paths in latex files"
100 windows_style_tex_paths = 'true'
101 removeFiles([tmpfname, 'texput.log'])
102 return windows_style_tex_paths
105 ## Searching some useful programs
106 def checkProg(description, progs, rc_entry = [], path = [], not_found = ''):
108 This function will search a program in $PATH plus given path
109 If found, return directory and program name (not the options).
111 description: description of the program
113 progs: check programs, for each prog, the first word is used
114 for searching but the whole string is used to replace
115 %% for a rc_entry. So, feel free to add '$$i' etc for programs.
117 path: additional pathes
119 rc_entry: entry to outfile, can be
120 1. emtpy: no rc entry will be added
121 2. one pattern: %% will be replaced by the first found program,
122 or '' if no program is found.
123 3. several patterns for each prog and not_found. This is used
124 when different programs have different usages. If you do not
125 want not_found entry to be added to the RC file, you can specify
126 an entry for each prog and use '' for the not_found entry.
128 not_found: the value that should be used instead of '' if no program
132 # one rc entry for each progs plus not_found entry
133 if len(rc_entry) > 1 and len(rc_entry) != len(progs) + 1:
134 print "rc entry should have one item or item for each prog and not_found."
136 print 'checking for ' + description + '...'
137 ## print '(' + ','.join(progs) + ')',
138 for idx in range(len(progs)):
139 # ac_prog may have options, ac_word is the command name
141 ac_word = ac_prog.split(' ')[0]
142 print '+checking for "' + ac_word + '"... ',
143 path = os.environ["PATH"].split(os.pathsep) + path
145 # check both ac_word and ac_word.exe (for windows system)
146 if os.path.isfile( os.path.join(ac_dir, ac_word) ) or \
147 os.path.isfile( os.path.join(ac_dir, ac_word + ".exe") ):
149 # write rc entries for this command
150 if len(rc_entry) == 1:
151 addToRC(rc_entry[0].replace('%%', ac_prog))
152 elif len(rc_entry) > 1:
153 addToRC(rc_entry[idx].replace('%%', ac_prog))
154 return [ac_dir, ac_word]
157 # write rc entries for 'not found'
158 if len(rc_entry) > 0: # the last one.
159 addToRC(rc_entry[-1].replace('%%', not_found))
160 return ['', not_found]
163 def checkViewer(description, progs, rc_entry = [], path = []):
164 ''' The same as checkProg, but for viewers and editors '''
165 return checkProg(description, progs, rc_entry, path, not_found = 'auto')
169 ''' Check latex, return lyx_check_config '''
170 # Find programs! Returned path is not used now
171 if ((os.name == 'nt' or sys.platform == 'cygwin') and
172 checkProg('DVI to DTL converter', ['dv2dt']) != ['', ''] and
173 checkProg('DTL to DVI converter', ['dt2dv']) != ['', '']):
174 # Windows only: DraftDVI
175 converter_entry = r'''\converter latex dvi2 "%%" "latex"
176 \converter dvi2 dvi "python -tt $$s/scripts/clean_dvi.py $$i $$o" ""'''
178 converter_entry = r'\converter latex dvi "%%" "latex"'
179 path, LATEX = checkProg('a Latex2e program', ['pplatex $$i', 'latex $$i', 'latex2e $$i'],
180 rc_entry = [converter_entry])
183 # Check if latex is usable
184 writeToFile('chklatex.ltx', '''
185 \\nonstopmode\\makeatletter
186 \\ifx\\undefined\\documentclass\\else
187 \\message{ThisIsLaTeX2e}
191 # run latex on chklatex.ltx and check result
192 if cmdOutput(LATEX + ' chklatex.ltx').find('ThisIsLaTeX2e') != -1:
196 print "Latex not usable (not LaTeX2e) "
197 # remove temporary files
198 removeFiles(['chklatex.ltx', 'chklatex.log'])
202 def checkFormatEntries():
203 ''' Check all formats (\Format entries) '''
204 checkViewer('a Tgif viewer and editor', ['tgif'],
205 rc_entry = [r'\Format tgif obj Tgif "" "%%" "%%" ""'])
207 checkViewer('a FIG viewer and editor', ['xfig'],
208 rc_entry = [r'\Format fig fig FIG "" "%%" "%%" ""'])
210 checkViewer('a Grace viewer and editor', ['xmgrace'],
211 rc_entry = [r'\Format agr agr Grace "" "%%" "%%" ""'])
213 checkViewer('a FEN viewer and editor', ['xboard -lpf $$i -mode EditPosition'],
214 rc_entry = [r'\Format fen fen FEN "" "%%" "%%" ""'])
216 path, iv = checkViewer('a raster image viewer', ['xv', 'kview', 'gimp'])
217 path, ie = checkViewer('a raster image editor', ['gimp'])
218 addToRC(r'''\Format bmp bmp BMP "" "%s" "%s" ""
219 \Format gif gif GIF "" "%s" "%s" ""
220 \Format jpg jpg JPEG "" "%s" "%s" ""
221 \Format pbm pbm PBM "" "%s" "%s" ""
222 \Format pgm pgm PGM "" "%s" "%s" ""
223 \Format png png PNG "" "%s" "%s" ""
224 \Format ppm ppm PPM "" "%s" "%s" ""
225 \Format tiff tif TIFF "" "%s" "%s" ""
226 \Format xbm xbm XBM "" "%s" "%s" ""
227 \Format xpm xpm XPM "" "%s" "%s" ""''' % \
228 (iv, ie, iv, ie, iv, ie, iv, ie, iv, ie, iv, ie, iv, ie, iv, ie, iv, ie, iv, ie) )
230 checkViewer('a text editor', ['xemacs', 'gvim', 'kedit', 'kwrite', 'kate', \
231 'nedit', 'gedit', 'notepad'],
232 rc_entry = [r'''\Format asciichess asc "Plain text (chess output)" "" "" "%%" ""
233 \Format asciiimage asc "Plain text (image)" "" "" "%%" ""
234 \Format asciixfig asc "Plain text (Xfig output)" "" "" "%%" ""
235 \Format dateout tmp "date (output)" "" "" "%%" ""
236 \Format docbook sgml DocBook B "" "%%" "document"
237 \Format docbook-xml xml "Docbook (XML)" "" "" "%%" "document"
238 \Format literate nw NoWeb N "" "%%" "document"
239 \Format latex tex "LaTeX (plain)" L "" "%%" "document"
240 \Format linuxdoc sgml LinuxDoc x "" "%%" "document"
241 \Format pdflatex tex "LaTeX (pdflatex)" "" "" "%%" "document"
242 \Format text txt "Plain text" a "" "%%" "document"
243 \Format textparagraph txt "Plain text (paragraphs)" "" "" "%%" "document"''' ])
245 #checkProg('a Postscript interpreter', ['gs'],
246 # rc_entry = [ r'\ps_command "%%"' ])
247 checkViewer('a Postscript previewer', ['gv', 'ghostview -swap', 'kghostview'],
248 rc_entry = [r'''\Format eps eps EPS "" "%%" "" ""
249 \Format ps ps Postscript t "%%" "" "document"'''])
251 checkViewer('a PDF previewer', ['acrobat', 'acroread', 'gv', 'ghostview', \
252 'xpdf', 'kpdf', 'kghostview'],
253 rc_entry = [r'''\Format pdf pdf "PDF (ps2pdf)" P "%%" "" "document"
254 \Format pdf2 pdf "PDF (pdflatex)" F "%%" "" "document"
255 \Format pdf3 pdf "PDF (dvipdfm)" m "%%" "" "document"'''])
257 checkViewer('a DVI previewer', ['xdvi', 'kdvi'],
258 rc_entry = [r'\Format dvi dvi DVI D "%%" "" "document"'])
259 if ((os.name == 'nt' or sys.platform == 'cygwin') and
260 checkProg('DVI to DTL converter', ['dv2dt']) != ['', ''] and
261 checkProg('DTL to DVI converter', ['dt2dv']) != ['', '']):
262 # Windows only: DraftDVI
263 addToRC(r'\Format dvi2 dvi DraftDVI "" "" "document"')
265 checkViewer('a HTML previewer', ['mozilla file://$$p$$i', 'netscape'],
266 rc_entry = [r'\Format html html HTML H "%%" "" "document"'])
268 # entried that do not need checkProg
269 addToRC(r'''\Format date "" "date command" "" "" "" ""
270 \Format fax "" Fax "" "" "" "document"
271 \Format lyx lyx LyX "" "" "" ""
272 \Format lyx13x lyx13 "LyX 1.3.x" "" "" "" "document"
273 \Format lyxpreview lyxpreview "LyX Preview" "" "" "" ""
274 \Format pdftex pdftex_t PDFTEX "" "" "" ""
275 \Format program "" Program "" "" "" ""
276 \Format pstex pstex_t PSTEX "" "" "" ""
277 \Format sxw sxw "OpenOffice.Org Writer" O "" "" "document"
278 \Format word doc "MS Word" W "" "" "document"
279 \Format wordhtml html "MS Word (HTML)" "" "" "" "document"
283 def checkConverterEntries():
284 ''' Check all converters (\converter entries) '''
285 checkProg('the pdflatex program', ['pdflatex $$i'],
286 rc_entry = [ r'\converter pdflatex pdf2 "%%" "latex"' ])
288 ''' If we're running LyX in-place then tex2lyx will be found in
289 ../src/tex2lyx. Add this directory to the PATH temporarily and
291 Use PATH to avoid any problems with paths-with-spaces.
293 path_orig = os.environ["PATH"]
294 os.environ["PATH"] = os.path.join('..', 'src', 'tex2lyx') + \
295 os.pathsep + path_orig
297 checkProg('a LaTeX -> LyX converter', ['tex2lyx -f $$i $$o', \
298 'tex2lyx' + version_suffix + ' -f $$i $$o' ],
299 rc_entry = [ r'\converter latex lyx "%%" ""' ])
301 os.environ["PATH"] = path_orig
304 checkProg('a Noweb -> LyX converter', ['noweb2lyx' + version_suffix + ' $$i $$o'], path = ['./reLyX'],
305 rc_entry = [ r'\converter literate lyx "%%" ""' ])
307 checkProg('a Noweb -> LaTeX converter', ['noweave -delay -index $$i > $$o'],
308 rc_entry = [ r'\converter literate latex "%%" ""' ])
310 checkProg('a HTML -> LaTeX converter', ['html2latex $$i'],
311 rc_entry = [ r'\converter html latex "%%" ""' ])
313 checkProg('a MSWord -> LaTeX converter', ['wvCleanLatex $$i $$o'],
314 rc_entry = [ r'\converter word latex "%%" ""' ])
316 checkProg('a LaTeX -> MS Word converter', ["htlatex $$i 'html,word' 'symbol/!' '-cvalidate'"],
317 rc_entry = [ r'\converter latex wordhtml "%%" ""' ])
319 checkProg('an OpenOffice.org -> LaTeX converter', ['w2l -clean $$i'],
320 rc_entry = [ r'\converter sxw latex "%%" ""' ])
322 checkProg('an LaTeX -> OpenOffice.org LaTeX converter', ['oolatex $$i', 'oolatex.sh $$i'],
323 rc_entry = [ r'\converter latex sxw "%%" "latex"' ])
325 checkProg('a PS to PDF converter', ['ps2pdf13 $$i $$o'],
326 rc_entry = [ r'\converter ps pdf "%%" ""' ])
328 checkProg('a DVI to PS converter', ['dvips -o $$o $$i'],
329 rc_entry = [ r'\converter dvi ps "%%" ""' ])
331 checkProg('a DVI to PDF converter', ['dvipdfmx -o $$o $$i', 'dvipdfm -o $$o $$i'],
332 rc_entry = [ r'\converter dvi pdf3 "%%" ""' ])
334 path, dvipng = checkProg('dvipng', ['dvipng'])
335 if dvipng == "dvipng":
336 addToRC(r'\converter lyxpreview png "python -tt $$s/scripts/lyxpreview2bitmap.py" ""')
338 addToRC(r'\converter lyxpreview png "" ""')
340 checkProg('a fax program', ['kdeprintfax $$i', 'ksendfax $$i'],
341 rc_entry = [ r'\converter ps fax "%%" ""'])
343 checkProg('a FIG -> EPS/PPM converter', ['fig2dev'],
345 r'''\converter fig eps "fig2dev -L eps $$i $$o" ""
346 \converter fig ppm "fig2dev -L ppm $$i $$o" ""
347 \converter fig png "fig2dev -L png $$i $$o" ""''',
350 checkProg('a TIFF -> PS converter', ['tiff2ps $$i > $$o'],
351 rc_entry = [ r'\converter tiff eps "%%" ""', ''])
353 checkProg('a TGIF -> EPS/PPM converter', ['tgif'],
355 r'''\converter tgif eps "tgif -stdout -print -color -eps $$i > $$o" ""
356 \converter tgif ppm "tgif -stdout -print -color -ppm $$i > $$o" ""
357 \converter tgif png "tgif -stdout -print -color -png $$i > $$o" ""
358 \converter tgif pdf "tgif -stdout -print -color -pdf $$i > $$o" ""''',
361 checkProg('a EPS -> PDF converter', ['epstopdf'],
362 rc_entry = [ r'\converter eps pdf "epstopdf --outfile=$$o $$i" ""', ''])
364 checkProg('a Grace -> Image converter', ['gracebat'],
366 r'''\converter agr eps "gracebat -hardcopy -printfile $$o -hdevice EPS $$i 2>/dev/null" ""
367 \converter agr png "gracebat -hardcopy -printfile $$o -hdevice PNG $$i 2>/dev/null" ""
368 \converter agr jpg "gracebat -hardcopy -printfile $$o -hdevice JPEG $$i 2>/dev/null" ""
369 \converter agr ppm "gracebat -hardcopy -printfile $$o -hdevice PNM $$i 2>/dev/null" ""''',
372 checkProg('a LaTeX -> HTML converter', ['htlatex $$i', 'tth -t -e2 -L$$b < $$i > $$o', \
373 'latex2html -no_subdir -split 0 -show_section_numbers $$i', 'hevea -s $$i'],
374 rc_entry = [ r'\converter latex html "%%" "originaldir,needaux"' ])
376 # FIXME: no rc_entry? comment it out
377 # checkProg('Image converter', ['convert $$i $$o'])
379 # Entried that do not need checkProg
380 addToRC(r'''\converter lyxpreview ppm "python -tt $$s/scripts/lyxpreview2bitmap.py" ""
381 \converter date dateout "date +%d-%m-%Y > $$o" ""
382 \converter docbook docbook-xml "cp $$i $$o" "xml"
383 \converter fen asciichess "python -tt $$s/scripts/fen2ascii.py $$i $$o" ""
384 \converter fig pdftex "python -tt $$s/scripts/fig2pdftex.py $$i $$o" ""
385 \converter fig pstex "python -tt $$s/scripts/fig2pstex.py $$i $$o" ""
386 \converter lyx lyx13x "python -tt $$s/lyx2lyx/lyx2lyx -t 221 $$i > $$o" ""
391 ''' Check linuxdoc '''
393 path, LINUXDOC = checkProg('SGML-tools 1.x (LinuxDoc)', ['sgml2lyx'],
395 r'''\converter linuxdoc lyx "sgml2lyx $$i" ""
396 \converter linuxdoc latex "sgml2latex $$i" ""
397 \converter linuxdoc dvi "sgml2latex -o dvi $$i" ""
398 \converter linuxdoc html "sgml2html $$i" ""''',
399 r'''\converter linuxdoc lyx "" ""
400 \converter linuxdoc latex "" ""
401 \converter linuxdoc dvi "" ""
402 \converter linuxdoc html "" ""''' ])
404 return ('yes', 'true', '\\def\\haslinuxdoc{yes}')
406 return ('no', 'false', '')
410 ''' Check docbook '''
411 path, DOCBOOK = checkProg('SGML-tools 2.x (DocBook) or db2x scripts', ['sgmltools', 'db2dvi'],
413 r'''\converter docbook dvi "sgmltools -b dvi $$i" ""
414 \converter docbook html "sgmltools -b html $$i" ""''',
415 r'''\converter docbook dvi "db2dvi $$i" ""
416 \converter docbook html "db2html $$i" ""''',
417 r'''\converter docbook dvi "" ""
418 \converter docbook html "" ""'''])
421 return ('yes', 'true', '\\def\\hasdocbook{yes}')
423 return ('no', 'false', '')
426 def checkOtherEntries():
427 ''' entries other than Format and Converter '''
428 checkProg('a *roff formatter', ['groff', 'nroff'],
430 r'\ascii_roff_command "groff -t -Tlatin1 $$FName"',
431 r'\ascii_roff_command "tbl $$FName | nroff"',
432 r'\ascii_roff_command ""' ])
433 checkProg('ChkTeX', ['chktex -n1 -n3 -n6 -n9 -n22 -n25 -n30 -n38'],
434 rc_entry = [ r'\chktex_command "%%"' ])
435 checkProg('a spellchecker', ['ispell'],
436 rc_entry = [ r'\spell_command "%%"' ])
437 ## FIXME: OCTAVE is not used anywhere
438 # path, OCTAVE = checkProg('Octave', ['octave'])
439 ## FIXME: MAPLE is not used anywhere
440 # path, MAPLE = checkProg('Maple', ['maple'])
441 checkProg('a spool command', ['lp', 'lpr'],
443 r'''\print_spool_printerprefix "-d "
444 \print_spool_command "lp"''',
445 r'''\print_spool_printerprefix "-P",
446 \print_spool_command "lpr"''',
448 # Add the rest of the entries (no checkProg is required)
449 addToRC(r'''\copier fig "python -tt $$s/scripts/fig_copy.py $$i $$o"
450 \copier pstex "python -tt $$s/scripts/tex_copy.py $$i $$o $$l"
451 \copier pdftex "python -tt $$s/scripts/tex_copy.py $$i $$o $$l"
455 def processLayoutFile(file, bool_docbook, bool_linuxdoc):
456 ''' process layout file and get a line of result
458 Declear line are like this: (article.layout, scrbook.layout, svjog.layout)
460 \DeclareLaTeXClass{article}
461 \DeclareLaTeXClass[scrbook]{book (koma-script)}
462 \DeclareLaTeXClass[svjour,svjog.clo]{article (Springer - svjour/jog)}
466 "article" "article" "article" "false"
467 "scrbook" "scrbook" "book (koma-script)" "false"
468 "svjog" "svjour" "article (Springer - svjour/jog)" "false"
470 classname = file.split(os.sep)[-1].split('.')[0]
471 # return ('LaTeX', '[a,b]', 'a', ',b,c', 'article') for \DeclearLaTeXClass[a,b,c]{article}
472 p = re.compile(r'\Declare(LaTeX|DocBook|LinuxDoc)Class\s*(\[([^,]*)(,.*)*\])*\s*{(.*)}')
473 for line in open(file).readlines():
476 (classtype, optAll, opt, opt1, desc) = res.groups()
477 avai = {'LaTeX':'false', 'DocBook':bool_docbook, 'LinuxDoc':bool_linuxdoc}[classtype]
480 return '"%s" "%s" "%s" "%s"\n' % (classname, opt, desc, avai)
481 print "Layout file without \DeclearXXClass line. "
485 def checkLatexConfig(check_config, bool_docbook, bool_linuxdoc):
486 ''' Explore the LaTeX configuration '''
487 print 'checking LaTeX configuration... ',
488 # First, remove the files that we want to re-create
489 removeFiles(['textclass.lst', 'packages.lst', 'chkconfig.sed'])
492 print ' default values'
493 print '+checking list of textclasses... '
494 tx = open('textclass.lst', 'w')
496 # This file declares layouts and their associated definition files
497 # (include dir. relative to the place where this file is).
498 # It contains only default values, since chkconfig.ltx could not be run
499 # for some reason. Run ./configure if you need to update it after a
500 # configuration change.
502 # build the list of available layout files and convert it to commands
505 for file in glob.glob( os.path.join('layouts', '*.layout') ) + \
506 glob.glob( os.path.join(srcdir, 'layouts', '*.layout' ) ) :
508 if not os.path.isfile(file):
510 # get stuff between /xxxx.layout .
511 classname = file.split(os.sep)[-1].split('.')[0]
513 cleanclass = classname.replace(' ', '_')
514 cleanclass = cleanclass.replace('-', '_')
515 # make sure the same class is not considered twice
516 if foundClasses.count(cleanclass) == 0: # not found before
517 foundClasses.append(cleanclass)
518 tx.write(processLayoutFile(file, bool_docbook, bool_linuxdoc))
523 removeFiles(['wrap_chkconfig.ltx', 'chkconfig.vars', \
524 'chkconfig.classes', 'chklayouts.tex'])
526 if not os.path.isfile( 'chkconfig.ltx' ):
527 shutil.copy( os.path.join(srcdir, 'chkconfig.ltx'), 'chkconfig.ltx' )
529 writeToFile('wrap_chkconfig.ltx', '%s\n%s\n\\input{chkconfig.ltx}\n' \
530 % (linuxdoc_cmd, docbook_cmd) )
531 # Construct the list of classes to test for.
532 # build the list of available layout files and convert it to commands
534 p1 = re.compile(r'\Declare(LaTeX|DocBook|LinuxDoc)Class')
536 for file in glob.glob( os.path.join('layouts', '*.layout') ) + \
537 glob.glob( os.path.join(srcdir, 'layouts', '*.layout' ) ) :
538 if not os.path.isfile(file):
540 classname = file.split(os.sep)[-1].split('.')[0]
541 for line in open(file).readlines():
542 if p1.search(line) == None:
545 print "Wrong input layout file with line '" + line
547 testclasses.append("\\TestDocClass{%s}{%s}" % (classname, line[1:].strip()))
550 cl = open('chklayouts.tex', 'w')
551 for line in testclasses:
552 cl.write(line + '\n')
555 # we have chklayouts.tex, then process it
556 for line in cmdOutput(LATEX + ' wrap_chkconfig.ltx').splitlines():
557 if re.match('^\+', line):
560 # currently, values in chhkconfig are only used to set
563 for line in open('chkconfig.vars').readlines():
564 key, val = re.sub('-', '_', line).split('=')
566 values[key] = val.strip("'")
567 # chk_fontenc may not exist
569 addToRC(r'\font_encoding "%s"' % values["chk_fontenc"])
572 if rmcopy: # remove the copied file
573 removeFiles( [ 'chkconfig.ltx' ] )
576 def createLaTeXConfig():
577 ''' create LaTeXConfig.lyx '''
578 # if chkconfig.sed does not exist (because LaTeX did not run),
579 # then provide a standard version.
580 if not os.path.isfile('chkconfig.sed'):
581 writeToFile('chkconfig.sed', 's!@.*@!???!g\n')
582 print "creating packages.lst"
583 # if packages.lst does not exist (because LaTeX did not run),
584 # then provide a standard version.
585 if not os.path.isfile('packages.lst'):
586 writeToFile('packages.lst', '''
587 ### This file should contain the list of LaTeX packages that have been
588 ### recognized by LyX. Unfortunately, since configure could not find
589 ### your LaTeX2e program, the tests have not been run. Run ./configure
590 ### if you need to update it after a configuration change.
592 print 'creating doc/LaTeXConfig.lyx'
594 # This is originally done by sed, using a
595 # tex-generated file chkconfig.sed
596 ##sed -f chkconfig.sed ${srcdir}/doc/LaTeXConfig.lyx.in
597 ## >doc/LaTeXConfig.lyx
598 # Now, we have to do it by hand (python).
600 # add to chekconfig.sed
601 writeToFile('chkconfig.sed', '''s!@chk_linuxdoc@!%s!g
603 ''' % (chk_linuxdoc, chk_docbook) , append=True)
604 # process this sed file!!!!
605 lyxin = open( os.path.join(srcdir, 'doc', 'LaTeXConfig.lyx.in')).readlines()
607 p = re.compile(r's!(.*)!(.*)!g')
608 # process each sed replace.
609 for sed in open('chkconfig.sed').readlines():
610 if sed.strip() == '':
613 fr, to = p.match(sed).groups()
614 # if latex did not run, change all @name@ to '???'
616 for line in range(len(lyxin)):
617 lyxin[line] = re.sub('@.*@', to, lyxin[line])
619 for line in range(len(lyxin)):
620 lyxin[line] = lyxin[line].replace(fr, to)
621 except: # wrong sed entry?
622 print "Wrong sed entry in chkconfig.sed: '" + sed + "'"
625 writeToFile( os.path.join('doc', 'LaTeXConfig.lyx'),
629 def checkTeXAllowSpaces():
630 ''' Let's check whether spaces are allowed in TeX file names '''
631 tex_allows_spaces = 'false'
633 print "Checking whether TeX allows spaces in file names... ",
634 writeToFile('a b.tex', r'\message{working^^J}' )
636 latex_out = cmdOutput(LATEX + r""" "\nonstopmode\input{\"a b\"}" """)
638 latex_out = cmdOutput(LATEX + r""" '\nonstopmode\input{"a b"}' """)
639 if 'working' in latex_out:
641 tex_allows_spaces = 'true'
644 tex_allows_spaces = 'false'
645 addToRC(r'\tex_allows_spaces ' + tex_allows_spaces)
646 removeFiles( [ 'a b.tex', 'a b.log', 'texput.log' ])
649 def removeTempFiles():
651 if not lyx_keep_temps:
652 removeFiles(['chkconfig.sed', 'chkconfig.vars', \
653 'wrap_chkconfig.ltx', 'wrap_chkconfig.log', \
654 'chklayouts.tex', 'missfont.log',
655 'chklatex.ltx', 'chklatex.log'])
658 if __name__ == '__main__':
659 lyx_check_config = True
660 outfile = 'lyxrc.defaults'
662 lyx_keep_temps = False
664 ## Parse the command line
665 for op in sys.argv[1:]: # default shell/for list is $*, the options
666 if op in [ '-help', '--help', '-h' ]:
667 print '''Usage: configure [options]
669 --help show this help lines
670 --keep-temps keep temporary files (for debug. purposes)
671 --without-latex-config do not run LaTeX to determine configuration
672 --with-version-suffix=suffix suffix of binary installed files
675 elif op == '--without-latex-config':
676 lyx_check_config = False
677 elif op == '--keep-temps':
678 lyx_keep_temps = True
679 elif op[0:22] == '--with-version-suffix=': # never mind if op is not long enough
680 version_suffix = op[22:]
682 print "Unknown option", op
685 # check if we run from the right directory
686 srcdir = os.path.dirname(sys.argv[0])
689 if not os.path.isfile( os.path.join(srcdir, 'chkconfig.ltx') ):
690 print "configure: error: cannot find chkconfig.ltx script"
694 windows_style_tex_paths = checkTeXPaths()
695 ## Write the first part of outfile
696 writeToFile(outfile, '''# This file has been automatically generated by LyX' lib/configure.py
697 # script. It contains default settings that have been determined by
698 # examining your system. PLEASE DO NOT MODIFY ANYTHING HERE! If you
699 # want to customize LyX, make a copy of the file LYXDIR/lyxrc as
700 # ~/.lyx/lyxrc and edit this file instead. Any setting in lyxrc will
701 # override the values given here.
706 checkConverterEntries()
707 (chk_linuxdoc, bool_linuxdoc, linuxdoc_cmd) = checkLinuxDoc()
708 (chk_docbook, bool_docbook, docbook_cmd) = checkDocBook()
709 checkTeXAllowSpaces()
710 if windows_style_tex_paths != '':
711 addToRC(r'\tex_expects_windows_paths %s' % windows_style_tex_paths)
713 # --without-latex-config can disable lyx_check_config
714 checkLatexConfig( lyx_check_config and LATEX != '', bool_docbook, bool_linuxdoc)