]> git.lyx.org Git - lyx.git/blob - lib/configure.m4
79d36d2ad5a3885b4a5c7a85f8c59e77d36d6584
[lyx.git] / lib / configure.m4
1 #! /bin/sh
2 dnl Use 'make' to create configure from this m4 script.
3 # This script is a hand-made configure script. It contains a lot of
4 # code stolen from GNU autoconf. I removed all the code that was not
5 # useful for configuring a LyX installation.
6
7
8 dnl ######### Begin M4 macros #########################################
9 dnl This is a template for my stripped-down configure script.
10 dnl First, a few convenient macros.
11 changequote([,])dnl
12 dnl
13 dnl
14 dnl MSG_CHECKING(FEATURE-DESCRIPTION,PREFIX)
15 dnl
16 define(MSG_CHECKING,
17 [echo $ac_n "$2checking $1""... $ac_c"])dnl
18 dnl
19 dnl
20 dnl MSG_RESULT(RESULT-DESCRIPTION)
21 dnl
22 define(MSG_RESULT,
23 [echo "$ac_t""$1"])dnl
24 dnl
25 dnl
26 dnl SEARCH_PROG(FEATURE-DESCRIPTION,VARIABLE-NAME,PROGRAMS-LIST,
27 dnl             ACTION-IF-FOUND,ACTION-IF-NOT-FOUND)
28 dnl
29 define(SEARCH_PROG,[dnl
30 changequote([,])dnl
31 MSG_CHECKING($1)
32 MSG_RESULT(($3))
33 $2=
34 for ac_prog in $3
35 do
36 # Extract the first word of "$ac_prog", so it can be a program name with args.
37 set dummy $ac_prog ; ac_word=$[2]
38 if test -n "$ac_word"; then
39   MSG_CHECKING([for \"$ac_word\"],[+])
40   IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS=":"
41   for ac_dir in $PATH; do
42     test -z "$ac_dir" && ac_dir=.
43     if test -x [$ac_dir/$ac_word]; then
44       $2="$ac_prog"
45       break
46     fi
47   done
48   IFS="$ac_save_ifs"
49
50   if test -n "[$]$2"; then
51     ac_result=yes
52   else
53     ac_result=no
54   fi
55   ifelse($4,,,[$4])
56   MSG_RESULT($ac_result)
57   test -n "[$]$2" && break
58 fi
59 done
60
61 if test -z "[$]$2" ; then
62   $2=none
63 ifelse($5,,,[  $5
64 ])dnl
65 fi
66 changequote(,)dnl
67 ])dnl
68 dnl
69 dnl
70 dnl PROVIDE_DEFAULT_FILE(FILE, DEFAULT-VALUE)
71 dnl
72 define(PROVIDE_DEFAULT_FILE,[dnl
73 # if $1 does not exist (because LaTeX did not run), 
74 # then provide a standard version.
75 if test ! -f $1 ; then
76   cat >$1 <<EOF
77 $2
78 EOF
79 fi])
80 changequote(,)dnl
81 dnl ######### End M4 macros #############################################
82
83
84 ####some configuration variables
85 lyx_check_config=yes
86 lyx_keep_temps=no
87 srcdir=
88
89 #### Parse the command line
90 for ac_option do
91   case "$ac_option" in
92     -help | --help | -h)
93       cat << EOF
94 Usage: configure [options] 
95 Options: 
96   --help                   show this help lines
97   --keep-temps             keep temporary files (for debug. purposes)
98   --without-latex-config   do not run LaTeX to determine configuration
99 EOF
100       exit 0;;
101     --without-latex-config)
102       lyx_check_config=no ;;
103     --keep-temps)
104       lyx_keep_temps=yes ;;
105   esac 
106 done
107
108
109 #### Checking for some echo oddities
110 if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
111   # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu.
112   if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then
113     ac_n= ac_c='
114 ' ac_t='        '
115   else
116     ac_n=-n ac_c= ac_t=
117   fi
118 else
119   ac_n= ac_c='\c' ac_t=
120 fi
121
122
123 #### I do not really know why this is useful, but we might as well keep it.
124 # NLS nuisances.
125 # Only set these to C if already set.  These must not be set unconditionally
126 # because not all systems understand e.g. LANG=C (notably SCO).
127 # Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'!
128 # Non-C LC_CTYPE values break the ctype check.
129 if test "${LANG+set}"   = set; then LANG=C;   export LANG;   fi
130 if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
131 if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
132 if test "${LC_CTYPE+set}"    = set; then LC_CTYPE=C;    export LC_CTYPE;    fi
133
134
135 #### Guess the directory in which configure is located.
136 changequote([,])dnl
137 ac_prog=[$]0
138 changequote(,)dnl
139 srcdir=`echo $ac_prog|sed 's%/[^/][^/]*$%%'` 
140 srcdir=`echo "${srcdir}" | sed 's%\([^/]\)/*$%\1%'`
141 test "x$srcdir" = "x$ac_prog" && srcdir=.
142 if test ! -r ${srcdir}/chkconfig.ltx ; then
143   echo "configure: error: cannot find chkconfig.ltx script"
144   exit 1
145 fi
146
147
148 #### Create the build directories if necessary
149 for dir in bind doc kbd layouts templates reLyX ; do
150   test ! -d $dir && mkdir $dir
151 done
152
153
154 #### Searching some useful programs
155 define(CHECKLATEX2E,[
156 ## Check whether this is really LaTeX2e
157 rm -f chklatex.ltx
158 cat >chklatex.ltx <<EOF
159 \\nonstopmode\\makeatletter
160 \\ifx\\undefined\\documentclass\\else
161   \\message{ThisIsLaTeX2e}
162 \\fi
163 \\@@end
164 EOF
165 if eval ${LATEX} chklatex.ltx </dev/null 2>/dev/null \
166                        | grep 'ThisIsLaTeX2e' >/dev/null; then
167   :
168 else
169   LATEX=
170   ac_result="not useable"
171 fi
172 rm -f chklatex.ltx chklatex.log])dnl
173 dnl
174 # Search LaTeX2e
175 SEARCH_PROG([for a LaTeX2e program],LATEX,latex latex2e,CHECKLATEX2E,dnl
176   [lyx_check_config=no])
177 if test x$lyx_check_config != x ; then
178 SEARCH_PROG([for the pdflatex program],PDFLATEX,pdflatex,CHECKLATEX2E)
179 fi
180
181 # Search for an installed reLyX or a ready-to-install one
182 save_PATH=${PATH}
183 PATH=${PATH}:./reLyX/
184 SEARCH_PROG([for reLyX LaTeX-to-LyX translator],RELYX,reLyX)
185 PATH=${save_PATH}
186
187 # Search something to process a literate document
188 SEARCH_PROG([for a Literate programming processor],LITERATE,"noweave -delay -index")
189 if test "$LITERATE" = "none"; then LITERATE_EXT="none"; else LITERATE_EXT=".nw"; fi
190
191 # Search for a Postscript interpreter
192 SEARCH_PROG([for a Postscript interpreter],GS, gs)
193
194 # Search something to preview postscript
195 SEARCH_PROG([for a Postscript previewer],GHOSTVIEW,gv ghostview)
196
197 # Search a *roff program (used to translate tables in ASCII export)
198 SEARCH_PROG([for a *roff formatter],ROFF,groff nroff)
199 ascii_roff_command=$ROFF
200 test $ROFF = "groff" && ascii_roff_command="groff -t -Tlatin1 \$\$FName"
201 test $ROFF = "nroff" && ascii_roff_command="tbl \$\$FName | nroff"
202
203 # Search the ChkTeX program
204 SEARCH_PROG([for ChkTeX],CHKTEX,chktex)
205 chktex_command=$CHKTEX
206 test $CHKTEX = "chktex" && chktex_command="$CHKTEX -n1 -n3 -n6 -n9 -n22 -n25 -n30 -n38"
207
208 # Search for a spellchecker
209 SEARCH_PROG([for a spell-checker], SPELL,ispell)
210
211 # Search a Fax handling program
212 SEARCH_PROG([for a fax driver], FAX, sendfax faxsend fax)
213 if test $FAX = sendfax ; then
214   fax_command="sendfax -n -h '\$\$Host' -c '\$\$Comment' -x '\$\$Enterprise' -d '\$\$Name'@'\$\$Phone' '\$\$FName'"
215 elif test $FAX = faxsend ; then
216   fax_command="faxsend '\$\$Phone' '\$\$FName'"
217 elif test $FAX = fax ; then
218   fax_command="fax send '\$\$Phone' '\$\$FName'"
219 else
220   fax_command="none"
221 fi
222
223 # Search for LinuxDoc support
224 SEARCH_PROG([for SGML-tools 1.x (LinuxDoc)], LINUXDOC, sgml2lyx)
225 chk_linuxdoc=no
226 if test $LINUXDOC != none; then
227   chk_linuxdoc=yes
228   linuxdoc_cmd="\\def\\haslinuxdoc{yes}"
229 fi
230
231 # Search for DocBook support
232 SEARCH_PROG([for SGML-tools 2.x (DocBook)], DOCBOOK, sgmltools)
233 chk_docbook=no
234 if test $DOCBOOK != none; then
235   chk_docbook=yes
236   docbook_cmd="\\def\\hasdocbook{yes}"
237 fi
238
239
240 # Search for a spool command
241 SEARCH_PROG([for a spool command], LPR, lp lpr)
242 case $LPR in
243   lp) print_spool_command=lp
244       print_spool_printerprefix="-d ";;
245  lpr) print_spool_command=lpr
246       print_spool_printerprefix="-P";;
247    *) :;; # leave to empty values
248 esac
249
250 # Search for a latex to html converter
251 SEARCH_PROG([for an HTML converter], TOHTML, tth latex2html hevea)
252 case $TOHTML in
253         tth) html_command="tth -t < '\$\$FName' > '\$\$OutName'";;
254  latex2html) html_command="latex2html -no_subdir -split 0 -show_section_numbers '\$\$FName'";;
255       hevea) html_command="hevea -s '\$\$FName'";;
256 esac
257
258 #### Explore the LaTeX configuration
259 MSG_CHECKING(LaTeX configuration)
260 # First, remove the files that we want to re-create
261 rm -f textclass.lst packages.lst chkconfig.sed
262 if test ${lyx_check_config} = no ; then
263   MSG_RESULT(default values)
264 else
265   MSG_RESULT(auto)
266   rm -f wrap_chkconfig.ltx chkconfig.vars chkconfig.classes chklayouts.tex
267   cat >wrap_chkconfig.ltx <<EOF
268 \\newcommand\\srcdir{${srcdir}}
269 ${linuxdoc_cmd}
270 ${docbook_cmd}
271 \\input{${srcdir}/chkconfig.ltx}
272 EOF
273   ## Construct the list of classes to test for.
274   # build the list of available layout files and convert it to commands 
275   # for chkconfig.ltx 
276   for file in ./layouts/*.layout ${srcdir}/layouts/*.layout ; do 
277     case $file in
278       */\*.layout) ;;
279       *) echo $file ;;
280     esac
281   done | sed -e 's%^.*layouts/\(.*\)\.layout$%\\TestDocClass{\1}%'\
282              > chklayouts.tex
283 changequote([,])dnl
284   [eval] ${LATEX} wrap_chkconfig.ltx 2>/dev/null | grep '^\+'
285   [eval] `cat chkconfig.vars | sed 's/-/_/g'`
286 changequote(,)dnl
287 fi
288
289 # Do we have all the files we need? Useful if latex did not run
290 changequote([,])dnl
291 echo creating textclass.lst 
292 PROVIDE_DEFAULT_FILE(textclass.lst,dnl
293 [# This file declares layouts and their associated definition files
294 # (include dir. relative to the place where this file is).
295 # It contains only default values, since chkconfig.ltx could not be run 
296 # for some reason. Run ./configure if you need to update it after a
297 # configuration change.  
298 article article article
299 report  report  report
300 book    book    book
301 linuxdoc        linuxdoc        linuxdoc
302 letter  letter  letter])
303
304 PROVIDE_DEFAULT_FILE(chkconfig.sed,[s/@.*@/???/g])
305
306 echo creating packages.lst
307 PROVIDE_DEFAULT_FILE(packages.lst,dnl
308 [# This file should contain the list of LaTeX packages that have been
309 # recognized by LyX. Unfortunately, since configure could not find
310 # your LaTeX2e program, the tests have not been run. Run ./configure
311 # if you need to update it after a configuration change.
312 ])
313 changequote(,)dnl
314
315 echo creating doc/LaTeXConfig.lyx
316 echo "s/@chk_linuxdoc@/$chk_linuxdoc/g" >> chkconfig.sed
317 echo "s/@chk_docbook@/$chk_docbook/g" >> chkconfig.sed
318 sed -f chkconfig.sed ${srcdir}/doc/LaTeXConfig.lyx.in >doc/LaTeXConfig.lyx
319
320 echo creating lyxrc.defaults
321 rm -f lyxrc.defaults
322 cat >lyxrc.defaults <<EOF
323 # This file has been automatically generated by LyX' lib/configure
324 # script. It contains default settings that have been determined by
325 # examining your system. PLEASE DO NOT MODIFY ANYTHING HERE! If you
326 # want to customize LyX, make a copy of the file LYXDIR/lyxrc as
327 # ~/.lyx/lyxrc and edit this file instead. Any setting in lyxrc will
328 # override the values given here.
329 \\latex_command "$LATEX"
330 \\relyx_command "$RELYX"
331 \\literate_command "$LITERATE"
332 \\literate_extension "$LITERATE_EXT"
333 \\ps_command "$GS"
334 \\view_ps_command "$GHOSTVIEW -swap"
335 \\view_pspic_command "$GHOSTVIEW"
336 \\ascii_roff_command "$ascii_roff_command"
337 \\chktex_command "$chktex_command"
338 \\spell_command "$SPELL"
339 \\fax_command "$fax_command"
340 \\html_command "$html_command"
341 \\print_spool_command "$print_spool_command"
342 \\print_spool_printerprefix "$print_spool_printerprefix"
343 \\font_encoding "$chk_fontenc"
344 EOF
345
346 # Remove superfluous files if we are not writing in the main lib
347 # directory 
348 for file in lyxrc.defaults textclass.lst packages.lst \
349             doc/LaTeXConfig.lyx ; do
350   # we rename the file first, so that we avoid comparing a file with itself
351   mv $file $file.new
352   if test -r $srcdir/$file && diff $file.new $srcdir/$file >/dev/null 2>/dev/null ; 
353   then 
354     echo "removing $file, which is identical to the system global version"
355     rm -f $file.new
356   else
357     mv $file.new $file
358   fi
359 done
360
361
362 # Final clean-up
363 if test $lyx_keep_temps = no ; then
364 rm -f chkconfig.sed chkconfig.vars wrap_chkconfig.* chklayouts.tex \
365       missfont.log
366 fi