home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume39 / dist-3.0 / part02 < prev    next >
Encoding:
Text File  |  1993-08-18  |  54.8 KB  |  1,392 lines

  1. Newsgroups: comp.sources.misc
  2. From: Raphael Manfredi <ram@acri.fr>
  3. Subject: v39i006:  dist-3.0 - Configure script generator and related tools, Part02/28
  4. Message-ID: <1993Aug18.183629.16541@sparky.sterling.com>
  5. X-Md4-Signature: 13b9e49772320088498e01669a7e684b
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Advanced Computer Research Institute, Lyon, France.
  8. Date: Wed, 18 Aug 1993 18:36:29 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: Raphael Manfredi <ram@acri.fr>
  12. Posting-number: Volume 39, Issue 6
  13. Archive-name: dist-3.0/part02
  14. Environment: UNIX, Perl, RCS
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then feed it
  18. # into a shell via "sh file" or similar.  To overwrite existing files,
  19. # type "sh file -c".
  20. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  21. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  22. # Contents:  mcon/U/d_access.U mcon/man/mconfig.SH.01
  23. # Wrapped by ram@soft208 on Wed Aug 18 14:42:18 1993
  24. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  25. echo If this archive is complete, you will see the following message:
  26. echo '          "shar: End of archive 2 (of 28)."'
  27. if test -f 'mcon/U/d_access.U' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'mcon/U/d_access.U'\"
  29. else
  30.   echo shar: Extracting \"'mcon/U/d_access.U'\" \(2215 characters\)
  31.   sed "s/^X//" >'mcon/U/d_access.U' <<'END_OF_FILE'
  32. X?RCS: $Id: d_access.U,v 3.0 1993/08/18 12:05:42 ram Exp $
  33. X?RCS:
  34. X?RCS: Copyright (c) 1991-1993, Raphael Manfredi
  35. X?RCS: 
  36. X?RCS: You may redistribute only under the terms of the Artistic Licence,
  37. X?RCS: as specified in the README file that comes with the distribution.
  38. X?RCS: You may reuse parts of this distribution only within the terms of
  39. X?RCS: that same Artistic Licence; a copy of which may be found at the root
  40. X?RCS: of the source tree for dist 3.0.
  41. X?RCS:
  42. X?RCS: $Log: d_access.U,v $
  43. X?RCS: Revision 3.0  1993/08/18  12:05:42  ram
  44. X?RCS: Baseline for dist 3.0 netwide release.
  45. X?RCS:
  46. X?MAKE:d_access: test +cc cat +cppflags h_fcntl h_sysfile rm Inlibc Findhdr
  47. X?MAKE:    -pick add $@ %<
  48. X?S:d_access:
  49. X?S:    This variable conditionally defines HAS_ACCESS if the access() system
  50. X?S:    call is available to check for access permissions using real IDs.
  51. X?S:.
  52. X?C:HAS_ACCESS:
  53. X?C:    This manifest constant lets the C program know that the access()
  54. X?C:    system call is available to check for accessibility using real UID/GID.
  55. X?C:    (always present on UNIX.)
  56. X?C:.
  57. X?H:#$d_access HAS_ACCESS        /**/
  58. X?H:.
  59. X?W:%<:R_OK W_OK X_OK F_OK
  60. X?LINT:set d_access
  61. X?LINT:change h_fcntl h_sysfile
  62. X: access call always available on UNIX
  63. Xset access d_access
  64. Xeval $inlibc
  65. X
  66. X: locate the flags for 'access()'
  67. Xcase "$d_access" in
  68. X"$define")
  69. X    echo " "
  70. X    $cat >access.c <<'EOCP'
  71. X#include <sys/types.h>
  72. X#ifdef I_FCNTL
  73. X#include <fcntl.h>
  74. X#endif
  75. X#ifdef I_SYS_FILE
  76. X#include <sys/file.h>
  77. X#endif
  78. X#ifdef I_UNISTD
  79. X#include <unistd.h>
  80. X#endif
  81. Xmain() {
  82. X    exit(R_OK);
  83. X}
  84. XEOCP
  85. X    : check sys/file.h first, no particular reason here
  86. X    if $test `./findhdr sys/file.h` && \
  87. X        $cc $cppflags -DI_SYS_FILE access.c -o access >/dev/null 2>&1 ; then
  88. X        h_sysfile=true;
  89. X        echo "<sys/file.h> defines the *_OK access constants." >&4
  90. X    elif $test `./findhdr fcntl.h` && \
  91. X        $cc $cppflags -DI_FCNTL access.c -o access >/dev/null 2>&1 ; then
  92. X        h_fcntl=true;
  93. X        echo "<fcntl.h> defines the *_OK access constants." >&4
  94. X@if I_UNISTD
  95. X    elif $test `./findhdr unistd.h` && \
  96. X        $cc $cppflags -DI_UNISTD access.c -o access >/dev/null 2>&1 ; then
  97. X        echo "<unistd.h> defines the *_OK access constants." >&4
  98. X@end
  99. X    else
  100. X        echo "I can't find the four *_OK access constants--I'll use mine." >&4
  101. X    fi
  102. X    ;;
  103. Xesac
  104. X$rm -f access*
  105. X
  106. END_OF_FILE
  107.   if test 2215 -ne `wc -c <'mcon/U/d_access.U'`; then
  108.     echo shar: \"'mcon/U/d_access.U'\" unpacked with wrong size!
  109.   fi
  110.   # end of 'mcon/U/d_access.U'
  111. fi
  112. if test -f 'mcon/man/mconfig.SH.01' -a "${1}" != "-c" ; then 
  113.   echo shar: Will not clobber existing file \"'mcon/man/mconfig.SH.01'\"
  114. else
  115.   echo shar: Extracting \"'mcon/man/mconfig.SH.01'\" \(49943 characters\)
  116.   sed "s/^X//" >'mcon/man/mconfig.SH.01' <<'END_OF_FILE'
  117. Xcase $CONFIG in
  118. X'')
  119. X    if test -f config.sh; then TOP=.;
  120. X    elif test -f ../config.sh; then TOP=..;
  121. X    elif test -f ../../config.sh; then TOP=../..;
  122. X    elif test -f ../../../config.sh; then TOP=../../..;
  123. X    elif test -f ../../../../config.sh; then TOP=../../../..;
  124. X    else
  125. X        (echo "Can't find config.sh."; exit 1)
  126. X    fi
  127. X    . $TOP/config.sh
  128. X    ;;
  129. Xesac
  130. Xcase "$0" in
  131. X*/*) cd `expr X$0 : 'X\(.*\)/'` ;;
  132. Xesac
  133. Xecho "Extracting mcon/man/metaconfig.$manext (with variable substitutions)"
  134. X$rm -f metaconfig.$manext
  135. X$spitshell >metaconfig.$manext <<!GROK!THIS!
  136. X.TH METACONFIG $manext "Version $VERSION PL$PATCHLEVEL"
  137. X''' @(#) Manual page for metaconfig
  138. X'''
  139. X''' $Id: mconfig.SH,v 3.0 1993/08/18 12:10:14 ram Exp $
  140. X'''
  141. X'''  Copyright (c) 1991-1993, Raphael Manfredi
  142. X'''  
  143. X'''  You may redistribute only under the terms of the Artistic Licence,
  144. X'''  as specified in the README file that comes with the distribution.
  145. X'''  You may reuse parts of this distribution only within the terms of
  146. X'''  that same Artistic Licence; a copy of which may be found at the root
  147. X'''  of the source tree for dist 3.0.
  148. X'''
  149. X''' $Log: mconfig.SH,v $
  150. X''' Revision 3.0  1993/08/18  12:10:14  ram
  151. X''' Baseline for dist 3.0 netwide release.
  152. X'''
  153. X'''
  154. X.de Ex        \" Start of Example
  155. X.sp
  156. X.in +5
  157. X.nf
  158. X..
  159. X.de Ef        \" End of Example
  160. X.sp
  161. X.in -5
  162. X.fi
  163. X..
  164. X.SH NAME
  165. Xmetaconfig \- a Configure script generator
  166. X.SH SYNOPSIS
  167. X.B metaconfig
  168. X[ \-\fBdhkmostvwV\fR ]
  169. X.SH DESCRIPTION
  170. X.I Metaconfig
  171. Xis a program that generates Configure scripts. If you don't know what a
  172. XConfigure script is, please skip to the \fBTUTORIAL\fR section of this
  173. Xmanual page. If you want a full (formal) description of the way to
  174. Xuse \fImetaconfig\fR and its units, please look at the \fBREFERENCE\fR
  175. Xsection. The following is a quick introduction and reference for
  176. Xknowledgeable users.
  177. X.PP
  178. X.B Metaconfig
  179. Xoperates from set of
  180. X.I units
  181. Xwhich define everything that metaconfig knows about portability.
  182. XEach unit is self-contained, and does not have to be registered anywhere
  183. Xother than by inclusion in either the public U directory or your private
  184. XU directory.
  185. XIf the dist package (of which metaconfig is a part) is installed in LIB,
  186. Xthen the public U directory is LIB/dist/mcon/U. On this machine, the
  187. XLIB directory is $privlibexp.
  188. XYour private U directory, if you have one,
  189. Xis in the top level directory of your package.
  190. XBefore you can run \fImetaconfig\fR you must do a several things:
  191. X.IP \(bu 5
  192. XCreate a .package file in the package's top level directory by running
  193. X\fIpackinit\fR.
  194. XThis program will ask you about your package and remember what you tell
  195. Xit so that all the dist programs can be smart.
  196. X.IP \(bu
  197. XConsult the Glossary (in LIB/dist/mcon) and write your shell scripts and
  198. XC programs in terms of the symbols that metaconfig knows how to define.
  199. XYou don't need to tell metaconfig which symbols you used, since metaconfig
  200. Xwill figure that out for you.
  201. X.IP \(bu
  202. XGenerate any .SH scripts needed to write Makefiles or shell scripts that
  203. Xwill depend on values defined by Configure.
  204. XThere is a program called \fImakeSH\fR that will help you convert a plain
  205. Xscript into a script.SH template; some editing will still need to be performed
  206. Xon the resulting .SH file to move the variable configuration part in the
  207. Xtop part of the script (see inline comments generated by \fImakeSH\fR within
  208. Xyour .SH file).
  209. X.IP \(bu
  210. XCreate a MANIFEST.new file in your top level directory that lists all the
  211. Xfiles in your package. This file will remain private and will not be
  212. Xpart of the final distribution.
  213. XThe filename should be the first field on each line.
  214. XAfter some whitespace you can add a short comment describing your file.
  215. XOnly source files should be listed in there. The special file
  216. X\fIpatchlevel.h\fR (which is handled and maintained by the patching tools --
  217. Xsee \fIpat\fR(1)) should not be part of the MANIFEST.new file. As a rule of
  218. Xthumb, only files maintained by RCS should be listed in there.
  219. X.IP \(bu
  220. XOptionally, you may wish to create a MANIFEST file, which will be an
  221. Xexported version of your MANIFEST.new. That file must be made part of
  222. Xthe release, i.e. listed in both your MANIFEST.new and MANIFEST itself.
  223. XOne of the \fImetaconfig\fR units knows about this file and will force
  224. XConfigure to perform a release check, ensuring all the files listed
  225. Xthere are part of the distribution. The MANIFEST and MANIFEST.new
  226. Xfiles should be distinct, not links.
  227. X.IP \(bu
  228. XCopy any .U files that you want to modify to your private U directory.
  229. XAny .U files in your private U directory will be used in preference to
  230. Xthe one in the public U directory.
  231. XFor example, one way to force inclusion of any unit is to copy the End.U
  232. Xfile to your .U directory and add the name of the unit you want as
  233. Xa dependency on the end of the ?MAKE: line.
  234. XCertain units can ONLY be forced in this way, namely those of the form
  235. XWarn_*.U and Chk_*.U.
  236. XYou can also customize certain default Configure variables by copying
  237. XMyinit.U to your package's private U directory and setting the variables in
  238. Xthat unit.
  239. X.PP
  240. XNow you are ready to run \fImetaconfig\fR. That will create a \fIConfigure\fR
  241. Xfile, and optionally a \fIconfig_h.SH\fR file (if your sources make any use
  242. Xof C symbols).
  243. XThe generated files will automatically be added to your MANIFEST.new
  244. Xif necessary. Do not forget to update your MANIFEST file though.
  245. X.PP
  246. XIn order to create new units, do the following:
  247. X.IP \(bu 5
  248. XCopy a similar unit to a new .U file.
  249. XThe name you choose should be the name of a variable generated by the unit,
  250. Xalthough this is only a convenience for you, not a requirement.
  251. XIt should be 12 or less characters to prevent filename chopping.
  252. XActually, it should probably be 10 or less so that those who want to use RCS
  253. Xcan have a .U,v on the end without chopping.
  254. XMetaconfig uses the case of the first letter to determine if any variable is
  255. Xactually produced by this unit, so don't Capitalize your unit
  256. Xname if it is supposed to produce a shell variable.
  257. X.IP \(bu
  258. XEdit the new .U file to do what you want.
  259. XThe first ?MAKE: line indicates the dependencies; before the final list
  260. Xcolon all the variables this unit defines, and after the final colon
  261. Xall the variables (or other units) on which this unit depends.
  262. XIt is very important that these lists be accurate. If a dependency is
  263. Xoptional and a default value can be used, you should prefix the dependency
  264. Xwith a '+' sign. The corresponding unit will not be loaded to compute the
  265. Xsymbol, unless really required by another unit.
  266. X.IP \(bu
  267. XTo the extent possible, parameterize your unit based on shell
  268. Xvariable defined on ?INIT: lines.
  269. XThis will move the variable definitions up to the Init.U unit,
  270. Xwhere they can be overridden by definitions in Myinit.U, which is
  271. Xincluded after Init.U.
  272. X.IP \(bu
  273. XAdd the definition of any C symbols desired as ?H: lines.
  274. XA line beginning with ?H:?%<: in the .U file will be added to the eventual
  275. Xconfig.h file if and only if metaconfig decides that this unit is needed.
  276. XThe %< stands for the unit's name, which happens to be the name of
  277. Xthe file too (without .U) if you followed the convention.
  278. XAlways put a comment on each ?H: line in case one of the variable
  279. Xsubstitutions earlier on the line starts a comment without finishing it.
  280. XAny shell variable starting with d_ may do this, so beware.
  281. XIf you ommit the ?%<:, then metaconfig will try to intuit the symbol whose
  282. Xdefinition is needed prior any inclusion in config.h.
  283. X.IP \(bu
  284. XAdd glossary definitions as ?S: lines for shell variables and ?C:
  285. Xlines for C preprocessor variables.
  286. XSee a current unit for examples.
  287. XIt is VERY important to start each entry with a left justified symbol
  288. Xname, and end each entry with a ?C:. or ?S:. line.  The algorithm
  289. Xthat translates C preprocessor symbol entries for the Glossary into
  290. Xcomments for config.h depends on this.
  291. X.IP \(bu
  292. XMake sure the order of all your ? lines is right.  The correct order is:
  293. X.sp
  294. X.RS +10
  295. X.PD 0
  296. X.TP 15
  297. X?RCS: and ?X:
  298. Xbasically just comments
  299. X.TP
  300. X?MAKE:
  301. Xmetaconfig dependencies
  302. X.TP
  303. X?S:
  304. Xglossary shell definitions
  305. X.TP
  306. X?C:
  307. Xglossary C definitions
  308. X.TP
  309. X?H:
  310. Xconfig.h definitions
  311. X.TP
  312. X?W:
  313. Xwanted symbols
  314. X.TP
  315. X?V:
  316. Xvisible symbols
  317. X.TP
  318. X?T:
  319. Xtemporary shell symbols used
  320. X.TP
  321. X?D:
  322. Xoptional dependencies default value
  323. X.TP
  324. X?O:
  325. Xused to mark obsolete units
  326. X.TP
  327. X?LINT:
  328. Xmetalint hints
  329. X.TP
  330. X?INIT:
  331. Xshell symbols initializations
  332. X.PD
  333. X.RE
  334. X.PP
  335. XHere is an example to show the ordering of the lines and the various
  336. Xformats allowed:
  337. X.Ex
  338. X?RCS: \$RCS-Id\$
  339. X?RCS: Copyright information
  340. X?RCS: \$RCS-Log\$
  341. X?X:
  342. X?X: A contrived example
  343. X?X:
  344. X?MAKE:d_one two: three +four Five
  345. X?MAKE:    -pick add \$@ %<
  346. X?S:d_one:
  347. X?S:    First shell symbol, conditionally defines ONE.
  348. X?S:.
  349. X?S:two:
  350. X?S:    Second shell symbol, value for TWO.
  351. X?S:.
  352. X?C:ONE:
  353. X?C:    First C symbol.
  354. X?C:.
  355. X?C:TWO:
  356. X?C:    Second C symbol.
  357. X?C:.
  358. X?H:#\$d_one ONE    /**/
  359. X?H:#define TWO "\$two"
  360. X?H:#\$d_one ONE_TWO "\$two"
  361. X?H:.
  362. X?W:%<:one_two
  363. X?V:p_one p_two:p_three
  364. X?T:tmp var
  365. X?D:two='undef'
  366. X?LINT:change three
  367. X?INIT:two_init='2'
  368. X: shell code implementing the unit follows
  369. Xp_one='one'
  370. Xp_two='two'
  371. Xp_three="$three"
  372. X.Ef
  373. XLet me state it one more time: the above unit definition is a \fIfake\fR
  374. Xone to only show the different possibilities. Such a unit would serve
  375. Xlittle purpose anyway... Some more advanced features are not described
  376. Xhere. Please refer to the \fBREFERENCE\fR section for more complete
  377. Xinformation.
  378. X.IP \(bu
  379. XPut the unit into the public or private U directory as appropriate.
  380. X.IP \(bu
  381. XRerun \fImetaconfig\fR.
  382. X.IP \(bu
  383. XSend your unit to ram@acri.fr (Raphael Manfredi) for inclusion
  384. Xin the master copy, if you think it's of general interest.
  385. X.PP
  386. XIn order to add a new program to be located:
  387. X.IP \(bu
  388. XEdit Loc.U, and add the name of the program both to the ?MAKE: line
  389. X(between the two colons) and to either loclist or trylist (depending
  390. Xon whether the program is mandatory or not).
  391. X.IP \(bu
  392. XRerun metaconfig.
  393. X.IP \(bu
  394. XSend your unit to me for inclusion in the master copy, if you think it's
  395. Xof general interest.
  396. X.PP
  397. XNotes for writing .U files:
  398. X.IP * 5
  399. XAlways use "rm -f" because there are systems where rm is interactive by
  400. Xdefault.
  401. X.IP *
  402. XDo not use "set -- ..." because '--' does not work with every shell. Use
  403. X"set x ...; shift".
  404. X.IP *
  405. XAlways use echo " " (with a space) because of Eunice systems.
  406. X.IP *
  407. XUse only programs that came with V7, so that you know everyone has them.
  408. X.IP *
  409. XUse \$\&contains when you want to grep conditionally, since not all
  410. Xgreps return a reasonable status.
  411. XBe sure to redirect the output to /dev/null, by using '>/dev/null 2>&1'.
  412. X.IP *
  413. XUse "if test" rather than "if [...]" since not every sh knows the
  414. Xlatter construct.
  415. X.IP *
  416. XUse the myread script for inputs so that they can do shell escapes
  417. Xand default evaluation.  The general form is
  418. X.Ex
  419. Xcase "$grimble" in
  420. X'') dflt=452;;
  421. X*) dflt="$grimble";;
  422. Xesac
  423. Xrp='How many grimbles do you have?'
  424. X. myread
  425. Xgrimble="$ans"
  426. X.Ef
  427. X.IP *
  428. XUse the getfile script when asking for a file pathname in order to
  429. Xhave optional ~name expansion and sanity checks. See the Getfile.U
  430. Xunit for a full decription.
  431. X.IP *
  432. XIssue important messages on file descriptor #4, by using '>&4' to redirect
  433. Xoutput. Only those messages will appear when the \fB\-s\fR switch is
  434. Xgiven to \fIConfigure\fR on the command line (silent mode).
  435. X.IP *
  436. XAlways try to determine whether a feature is present in the most
  437. Xspecific way--don't say "if bsd" when you can grep libc.  There
  438. Xare many hybrid systems out there, and each feature should stand
  439. Xor fall by itself.
  440. X.IP *
  441. XAlways try to determine whether a feature is present in the most
  442. Xgeneral way, so that other packages can use your unit.
  443. X.IP *
  444. XWhen in doubt, set a default and ask.  Don't assume anything.
  445. X.IP *
  446. XIf you think the user is wrong, allow for the fact that he may be right.
  447. XFor instance, he could be running Configure on a different system than
  448. Xhe is going to use the final product on.
  449. X.PP
  450. XMetaconfig reserves the following names in your directory, and if you use such
  451. Xa name it may get clobbered or have other unforeseen effects:
  452. X.Ex
  453. X.MT/*
  454. XConfigure
  455. XWanted
  456. XObsolete
  457. Xconfig_h.SH
  458. XU/*
  459. XMANIFEST.new
  460. X.Ef
  461. XAdditionally, Configure may clobber these names in the directory it is run in:
  462. X.Ex
  463. XUU/*
  464. Xconfig.sh
  465. Xconfig.h
  466. X.Ef
  467. X'''
  468. X''' O p t i o n s
  469. X'''
  470. X.SH OPTIONS
  471. XThe following options are recognized by \fImetaconfig\fR:
  472. X.TP 15
  473. X.B \-d
  474. XTurn on debug mode. Not really useful unless you are debugging \fImetaconfig\fR
  475. Xitself.
  476. X.TP
  477. X.B \-h
  478. XPrint help message and exit.
  479. X.TP
  480. X.B \-k
  481. XKeep temporary directory, so that you may examine the working files used
  482. Xby \fImetaconfig\fR to build your \fIConfigure\fR script. Useful only when
  483. Xdebugging the units.
  484. X.TP
  485. X.B \-m
  486. XAssume lots of memory and swap space. This will speed up symbol lookup in
  487. Xsource files by a significant amount of time, at the expense of memory
  488. Xconsumption...
  489. X.TP
  490. X.B \-o
  491. XMap obsolete symbols on new ones. Use this switch if you still have some
  492. Xobsolete symbols in your source code and do not want (or cannot) remove
  493. Xthem for now. The obsolete symbols are otherwise ignored, although that
  494. Xwill give you a warning from \fImetaconfig\fR.
  495. X.TP
  496. X.B \-s
  497. XTurn silent mode on.
  498. X.TP
  499. X.B \-t
  500. XTrace symbols as they are found.
  501. X.TP
  502. X.B \-v
  503. XTurn verbose mode on.
  504. X.TP
  505. X.B \-w
  506. XAssume Wanted file is up-to-date. This will skip the time and memory
  507. Xconsuming phase of source code scanning, looking for known symbols.
  508. XUse it only when you know your source file have not changed with respect
  509. Xto the pool of \fImetaconfig\fR symbols used.
  510. X.TP
  511. X.B \-V
  512. XPrint version number and exit.
  513. X'''
  514. X''' T u t o r i a l
  515. X'''
  516. X.SH TUTORIAL
  517. XThis (long) section is an introduction to \fImetaconfig\fR, in which we will
  518. Xlearn all the basics. If you already know how to use \fImetaconfig\fR, you
  519. Xmay safely skip to the next section.
  520. X'''
  521. X.SS Overview
  522. X.PP
  523. XUsually when you want to get some source package to compile on a given
  524. Xplatform you have to edit the main Makefile (assuming there is one!),
  525. Xchoose a C compiler, make sure you have the proper libraries, and then
  526. Xfire the \fImake\fR command. If the package is reasonably well written, it
  527. Xwill compile (without a warning being an option :-). In itself, the last
  528. Xsentence is a real performance, since given the variety of UNIX platforms
  529. Xavailable today and the diversity of flavours, that means the author of the
  530. Xpackage has gone into deep trouble to figure out the right choices given
  531. Xsome standard trial, guessing and messing around with system includes and
  532. Xtypes.
  533. X.PP
  534. XHowever, despite all his talent, the author cannot possibly know that
  535. Xsome system has a broken system call, or that some sytem structure lacks
  536. Xone otherwise standard field, or simply wheter a given include file exists
  537. Xor not. And I'm not considering the implicit assumptions, like the type
  538. Xreturned by the \fImalloc()\fR function or the presence of the \fIrename()\fR
  539. Xsystem call to name a few. But that knowledge is necessary to achieve real
  540. Xportability.
  541. X.PP
  542. XNow let's not abuse ourselves. Using that information requires greater
  543. Xskills, yet it can lead to more portable programs since it is then
  544. Xwritten in a system-independant fashion and relies only on the fact that
  545. Xsome assumption is true or false on a particular system, each assumption
  546. Xbeing unrelated with each other. That is to say, we do not say: We're on
  547. Xa BSD system or we are on a USG system. That's too fuzzy anyway nowadays.
  548. XNo, we want to say to the source code: this system does not have the
  549. X\fIrename()\fR system call and \fImalloc()\fR returns a \f(Ivoid *)\fR
  550. Xvalue.
  551. X.PP
  552. XMetaconfig is a tool that will let you do just that, with the additional
  553. Xbenefit of not having to hand-edit the Makefile if all goes well. By
  554. Xrunning \fImetaconfig\fR, you create a shell script named \fIConfigure\fR.
  555. XLots of efforts have been devoted to the Configure script internals to ensure
  556. Xit will run on 99% of the existing shells available as of this writing.
  557. XConfigure will probe the target system, asking questions when in doubt and
  558. Xgather all the answers in one single shell file, which in turn can be used
  559. Xto automatically generate configured Makefiles and C include files.
  560. X.PP
  561. XThere is only a limited (but quite large) set of symbols available for your
  562. Xshell scripts and C programs. They are all documented in the Glossary file.
  563. XAll you need to do is learn about them and start using them to address
  564. Xportability and configuration problems. Then, by running \fImetaconfig\fR,
  565. Xa suitable Configure script will be generated for your package.
  566. X.PP
  567. XThe Configure script is built out several units (more than 300), each
  568. Xunit being responsible for defining a small number of shell and/or C
  569. Xsymbols. Units are assembled together at the final stage, honoring
  570. Xthe dependency graph (one unit may need the result of several other
  571. Xunits which are then placed before in the script).
  572. X'''
  573. X.SS Symbols
  574. X.PP
  575. XSymbols are the most important thing in the \fImetaconfig\fR world. They
  576. Xare the smallest recognized entity, usually a word, and can be granted
  577. Xa value at the end of the Configure execution. For instance, the C
  578. Xpre-processor symbol \fIHAS_RENAME\fR is a \fImetaconfig\fR symbol that is
  579. Xguranteed to be defined if, and only if, the \fIrename()\fR system call
  580. Xis present. Likewise, the \fI\$\&ranlib\fR shell variable will be set to
  581. Xeither ':' or 'ranlib' depending on whether the call to the \fIranlib\fR
  582. Xprogram is needed to order a library file. How this works is not important
  583. Xfor now, what is important is to understand that those symbols are given
  584. Xa \fIlife\fR (i.e. a value) upon \fIConfigure\fR execution.
  585. X.PP
  586. XUsing symbols is relatively straightforward. In a C source file, you simply
  587. Xuse the symbol value, as a pre-processor directive (for instance an: \fI#ifdef
  588. XHAS_RENAME\fR) or, if the symbol value is a string, directly as you would use
  589. Xa macro in C. And in a shell file or a Makefile, you may reference a shell
  590. Xsymbol directly.
  591. X.PP
  592. XActually, I'm lying, because that's not completely as magic as the previous
  593. Xparagraph could sound. In a C file, you need to include the Configure-produced
  594. X\fIconfig.h\fR file, and you must wrap your shell script or Makefile in a .SH
  595. Xfile and you may reference the shell symbol only in the variable
  596. Xsubstitution part of that .SH file. More on this later.
  597. X'''
  598. X.SS Source Files
  599. X.PP
  600. XSymbols may only appear in a limited set of source files, because
  601. X\fImetaconfig\fR will only scan those when looking for known symbols, trying
  602. Xto figure out which units it will need. You may use C symbols in C source
  603. Xfiles, i.e. files with a \fI.c\fR, \fI.h\fR, \fI.y\fR or \fI.l\fR extension,
  604. Xand shell symbols are looked for only in .SH files.
  605. X.PP
  606. XIn order to get the value of a symbol, a C file needs to include the special
  607. X\fIconfig.h\fR file, which is produced by \fIConfigure\fR when C symbols
  608. Xare present. And .SH files are run through a shell, producing a new file.
  609. XHowever, in the top section of the .SH file, the special \fIconfig.sh\fR
  610. Xfile (also produced by running \fIConfigure\fR) is sourced, and variable
  611. Xsubstitutions apply. Actually, \fIconfig.h\fR is produced by running the
  612. X\fImetaconfig\fR-produced \fIconfig_h.SH\fR file, again using variable
  613. Xsubstitution. So we're going to look at that a little more closely since
  614. Xthis is the heart of the whole \fIconfiguration\fR scheme...
  615. X'''
  616. X.SS Variable Substitution
  617. X.PP
  618. XThere is shell construct called \fIhere document\fR which enables a
  619. Xcommand to take an input specified within the script itself. That
  620. Xinput is interpreted by the shell as a double-quoted string or a
  621. Xsingle quoted string depending on the form of the here document
  622. Xspecification.
  623. X.PP
  624. XTo specify a here document, the '<<' token is used, followed by a single
  625. Xidentifier. From then on, the remaining script lines form the input for
  626. Xthe command, until the here document is found on a line by itself.
  627. XShell substitution (including shell variable substitutions) is done
  628. Xunless the identifier is surrounded by single quotes. For instance:
  629. X.Ex
  630. Xvar='first'
  631. Xtar='second'
  632. Xecho "--> first here document:"
  633. Xcat <<EOM
  634. Xvar='\$var'
  635. Xtar='\$\&tar'
  636. XEOM
  637. Xecho "--> second here document:"
  638. Xcat <<'EOM'
  639. Xecho \$var
  640. Xecho \$\&tar
  641. XEOM
  642. Xecho "--> end."
  643. X.Ef
  644. Xwill produce, when run through a shell:
  645. X.Ex
  646. X--> first here document:
  647. Xvar='first'
  648. Xtar='second'
  649. X--> second here document:
  650. Xecho \$var
  651. Xecho \$\&tar
  652. X--> end.
  653. X.Ef
  654. XThe first here document has its content interpreted whilst the second
  655. Xone is output as-is. Both are useful in a .SH script, as we are about to see.
  656. X'''
  657. X.SS Using .SH Scripts
  658. X.PP
  659. XA .SH script is usually produced by running the \fIMakeSH\fR script other
  660. Xan existing file, transforming \fIfile\fR into a \fIfile.SH\fR. Let's take
  661. Xa single example. Here is a little script (let's call it \fIintsize\fR)
  662. Xwhich prints a single message, the size of the \fBint\fR datatype in C.
  663. XUnfortunately, it has the value hardwired in it, thusly:
  664. X.Ex
  665. X#!/bin/sh
  666. Xintsize='4'
  667. Xecho "On this machine, the int type is \$\&intsize bytes"
  668. X.Ef
  669. XLet's run \fImakeSH\fR on it by typing '\fImakeSH intsize\fR'. We get a single
  670. X\fIintsize.SH\fR file that looks like this:
  671. X.Ex
  672. Xcase \$CONFIG in
  673. X'')
  674. X    if test -f config.sh; then TOP=.;
  675. X    elif test -f ../config.sh; then TOP=..;
  676. X    elif test -f ../../config.sh; then TOP=../..;
  677. X    elif test -f ../../../config.sh; then TOP=../../..;
  678. X    elif test -f ../../../../config.sh; then TOP=../../../..;
  679. X    else
  680. X        (echo "Can't find config.sh."; exit 1)
  681. X    fi
  682. X    . \$TOP/config.sh
  683. X    ;;
  684. Xesac
  685. X: This forces SH files to create target in same directory as SH file.
  686. X: This is so that make depend always knows where to find SH derivatives.
  687. Xcase "\$0" in
  688. X*/*) cd \`expr X\$0 : 'X\\\\(.*\\\\)/'\` ;;
  689. Xesac
  690. Xecho "Extracting intsize (with variable substitutions)"
  691. X: This section of the file will have variable substitutions done on it.
  692. X: Move anything that needs config subs from !NO!SUBS! section to !GROK!THIS!.
  693. X: Protect any dollar signs and backticks that you do not want interpreted
  694. X: by putting a backslash in front.  You may delete these comments.
  695. X\$spitshell >intsize <<!GROK!THIS!
  696. X\$startsh
  697. X\&!GROK!THIS!
  698. X
  699. X: In the following dollars and backticks do not need the extra backslash.
  700. X\$spitshell >>intsize <<'!NO!SUBS!'
  701. Xintsize='4'
  702. Xecho "On this machine, the int type is \$\&intsize bytes"
  703. X\&!NO!SUBS!
  704. Xchmod 755 intsize
  705. X\$\&eunicefix intsize
  706. X.Ef
  707. XThe first part of this script (in the \fIcase\fR statement) is trying to
  708. Xlocate the \fIconfig.sh\fR file, in order to source it. The \fI\$CONFIG\fR
  709. Xvariable is false by default, by true when \fIconfig.sh\fR has been sourced
  710. Xalready (which would be the case if this file was executed from within
  711. X\fIConfigure\fR itself, but let's not confuse the issue here).
  712. X.PP
  713. XOnce the \fIconfig.sh\fR file has been sources, all the shell symbols
  714. Xdefined by \fIConfigure\fR are set. We know reach a second case statement,
  715. Xused to change the current directory should a path be used to
  716. Xreach this program (for instance if we said '\fIsh ../scripts/intsize.SH\fR',
  717. Xwe would first run '\fIcd ../scripts\fR' before continuing). If you do not
  718. Xunderstand this, don't worry about it.
  719. X.PP
  720. XHere comes the intersting stuff. This script uses the \fI\$spitshell\fR
  721. Xvariable, and it's not something we know about...yet. If you look through
  722. Xthe Glossary file, you will see that this is a variable known by
  723. X\fImetaconfig\fR. If you make this file part of your distribution (by including
  724. Xit in the MANIFEST.new file, we'll come back to that later on) and run
  725. X\fImetaconfig\fR, then the \fIConfigure\fR script will determine a suitable
  726. Xvalue for this variable and it will be set in \fIconfig.sh\fR. Same goes for
  727. X\fI\$startsh\fR and the mysterious \fI\$\&eunicefix\fR at the end. On a
  728. Xreasonable system, the relevant part of \fIconfig.sh\fR would look like this:
  729. X.Ex
  730. Xspitshell='cat'
  731. Xstartsh='#!/bin/sh'
  732. Xeunicefix=':'
  733. X.Ef
  734. XAh! We're getting there. Now it looks familiar. We're facing a single
  735. X\fIcat\fR command whose input comes from a variable-interpolated here
  736. Xdocument and whose output is redirected to \fIintsize\fR. The value
  737. Xwill be that of \fI\$startsh\fR, i.e. '#!/bin/sh'. Fine so far.
  738. X.PP
  739. XThen we reach the second here document expansion, to get the remaining of
  740. Xthe script. This time, the here document symbol is surrounded by single
  741. Xquotes so the contents will be appended verbatim to the \fIintsize\fR file.
  742. XSo, by running '\fIsh intsize.SH\fR', we get the following output:
  743. X.Ex
  744. XExtracting intsize (with variable substitutions)
  745. X.Ef
  746. Xand by looking at the produced intsize file, we see:
  747. X.Ex
  748. X#!/bin/sh
  749. Xintsize='4'
  750. Xecho "On this machine, the int type is \$\&intsize bytes"
  751. X.Ef
  752. Xwhich is exactly what we had at the beginning. So far, it's a no-operation
  753. Xprocedure... But, how marvelous! It so happens (pure coincidence, trust me!),
  754. Xthat \fImetaconfig\fR knows about the \fI$\&intsize\fR shell symbol. By moving
  755. Xthe initialization of intsize to the variable-interpolated area of the .SH
  756. Xscript and initializing it with the \fIConfigure\fR-computed value,
  757. Xand removing the now useless comments added by \fImakeSH\fR, we get:
  758. X.Ex
  759. Xcase \$CONFIG in
  760. X'')
  761. X    if test -f config.sh; then TOP=.;
  762. X    elif test -f ../config.sh; then TOP=..;
  763. X    elif test -f ../../config.sh; then TOP=../..;
  764. X    elif test -f ../../../config.sh; then TOP=../../..;
  765. X    elif test -f ../../../../config.sh; then TOP=../../../..;
  766. X    else
  767. X        (echo "Can't find config.sh."; exit 1)
  768. X    fi
  769. X    . \$TOP/config.sh
  770. X    ;;
  771. Xesac
  772. Xcase "\$0" in
  773. X*/*) cd \`expr X\$0 : 'X\\\\(.*\\\\)/'\` ;;
  774. Xesac
  775. Xecho "Extracting intsize (with variable substitutions)"
  776. X\$\&spitshell >intsize <<!GROK!THIS!
  777. X\$\&startsh
  778. Xintsize='\$\&intsize'
  779. X\&!GROK!THIS!
  780. X
  781. X\$\&spitshell >>intsize <<'!NO!SUBS!'
  782. Xecho "On this machine, the int type is \$\&intsize bytes"
  783. X\&!NO!SUBS!
  784. Xchmod 755 intsize
  785. X\$\&eunicefix intsize
  786. X.Ef
  787. XOf course, running this script through a shell will again output the same
  788. Xscript. But if we run \fIConfigure\fR on a machine where an \fBint\fR is
  789. Xstored as a 64 bits quantity, \fIconfig.sh\fR will set \fIintsize\fR to
  790. X8 and the \fIintsize\fR script will bear the right value and print:
  791. X.Ex
  792. XOn this machine, the int type is 8 bytes
  793. X.Ef
  794. Xwhich is correct. Congratulations! We have just configured a shell script!!
  795. X'''
  796. X.SS Producing config.h
  797. X.PP
  798. XWe can now have a look at the way \fIconfig.h\fR is produced out of
  799. X\fIconfig_h.SH\fR. We know that running \fIConfigure\fR produces a
  800. X\fIconfig.sh\fR script (how exactly this is done is not strictly
  801. Xrelevant here, but for the curious, it's another here document
  802. Xsubstitution within \fIConfigure\fR itself). The \fIconfig_h.SH\fR
  803. Xitself is built by \fImetaconfig\fR at the same time \fIConfigure\fR
  804. Xis, provided you make use of at least one C symbol within your sources.
  805. X.PP
  806. XLet's have a look at some random \fIconfig_h.SH\fR file to see what
  807. Xreally happens:
  808. X.Ex
  809. Xcase \$CONFIG in
  810. X'')
  811. X    if test -f config.sh; then TOP=.;
  812. X    elif test -f ../config.sh; then TOP=..;
  813. X    elif test -f ../../config.sh; then TOP=../..;
  814. X    elif test -f ../../../config.sh; then TOP=../../..;
  815. X    elif test -f ../../../../config.sh; then TOP=../../../..;
  816. X    else
  817. X        (echo "Can't find config.sh."; exit 1)
  818. X    fi
  819. X    . \$TOP/config.sh
  820. X    ;;
  821. Xesac
  822. Xcase "\$0" in
  823. X*/*) cd \`expr X\$0 : 'X\\\\(.*\\\\)/'\` ;;
  824. Xesac
  825. Xecho "Extracting config.h (with variable substitutions)"
  826. Xsed <<!GROK!THIS! >config.h -e 's!^#undef!/\*#define!' -e 's!^#un-def!#undef!'
  827. X/*
  828. X * This file was produced by running the config_h.SH script, which
  829. X * gets its values from config.sh, which is generally produced by
  830. X * running Configure.
  831. X *
  832. X * Feel free to modify any of this as the need arises.  Note, however,
  833. X * that running config.h.SH again will wipe out any changes you've made.
  834. X * For a more permanent change edit config.sh and rerun config.h.SH.
  835. X */
  836. X
  837. X/* Configuration time: \$\&cf_time
  838. X * Configured by: \$\&cf_by
  839. X * Target system: \$myuname
  840. X */
  841. X
  842. X#ifndef _config_h_
  843. X#define _config_h_
  844. X
  845. X/* bcopy:
  846. X *    This symbol is maped to memcpy if the bcopy() routine is not
  847. X *    available to copy strings.
  848. X */
  849. X/* HAS_BCOPY:
  850. X *    This symbol is defined if the bcopy() routine is available to
  851. X *    copy blocks of memory. You should not use this symbol under
  852. X *    normal circumstances and use bcopy() directly instead, which
  853. X *    will get mapped to memcpy() if bcopy is not available.
  854. X */
  855. X#\$\&d_bcopy HAS_BCOPY    /**/
  856. X#ifndef HAS_BCOPY
  857. X#ifdef bcopy
  858. X#un-def bcopy
  859. X#endif
  860. X#define bcopy(s,d,l) memcpy((d),(s),(l))        /* mapped to memcpy */
  861. X#endif
  862. X
  863. X/* HAS_DUP2:
  864. X *    This symbol, if defined, indicates that the dup2 routine is
  865. X *    available to duplicate file descriptors.
  866. X */
  867. X#\$\&d_dup2 HAS_DUP2    /**/
  868. X
  869. X/* I_STRING:
  870. X *    This symbol, if defined, indicates to the C program that it should
  871. X *    include <string.h> (USG systems) instead of <strings.h> (BSD systems).
  872. X */
  873. X#\$\&i_string I_STRING        /**/
  874. X
  875. X#endif
  876. X\&!GROK!THIS!
  877. X.Ef
  878. XAt the top of the file, we recognize the standard .SH construct that we
  879. Xhave already studied in detail. Next comes the extraction of the file
  880. Xitself, via a here document with variable substitutions. However, here
  881. Xwe do not use a plain \fIcat\fR but a \fIsed\fR instead, since we need
  882. Xto do some further editing on-the-fly. We'll see why later on, so let's
  883. Xforget about it right now.
  884. X.PP
  885. XWe now reach the leading comment, and the file is tagged with the
  886. Xconfiguration time, the target system, etc... (those variables coming
  887. Xfrom the sourced \fIconfig.sh\fR file have been set up by \fIConfigure\fR).
  888. XThat comment header is followed by a '#ifndef' protection to guard against
  889. Xmultiple inclusions of this file. Then comes the heart of the file...
  890. X.PP
  891. XIt helps to know that \fI\$d_*\fR and \fI\$i_*\fR variables are set to
  892. Xeither '\fIdefine\fR' or '\fIundef\fR' by \fIConfigure\fR, depending on
  893. Xwether a function or an include file is present on the system or not.
  894. XThat means the:
  895. X.Ex
  896. X#\$\&d_bcopy HAS_BCOPY /**/
  897. X.Ef
  898. Xline will be expanded to either:
  899. X.Ex
  900. X#define HAS_BCOPY /**/
  901. X.Ef
  902. Xif the \$\&d_bcopy variable is set to 'define' or:
  903. X.Ex
  904. X#undef HAS_BCOPY /**/
  905. X.Ef
  906. Xif \$\&d_bcopy was set to 'undef', because the feature was not there. However,
  907. Xthat's not what gets written in the \fIconfig.h\fR file because of the
  908. X\fIsed\fR filter we have already seen, which will transform the second form
  909. Xinto:
  910. X.Ex
  911. X/*#define HAS_BCOPY /**/
  912. X.Ef
  913. XThat's a handy form for later editing of \fIconfig.h\fR because you only need
  914. Xto remove the leading '/*' if you want to override \fIConfigure\fR's choice.
  915. XLikewise, you may add a single '/*' at the beginning of a '#define' line
  916. Xto avoid the definition of a particular symbol. This is why each symbol
  917. Xdefinition is protected by a trailing '/**/', to close the leading
  918. Xcomment opened by '/*' (comments are not nested in C).
  919. X.PP
  920. XNow transforming '#undef' into '/*#define' is nice, but if we want to actually
  921. Xwrite a '#undef', we're stuck... unless we write it as '#un-def' and let
  922. X\fIsed\fR fix that to '#undef' while producing \fIconfig.h\fR, which is what
  923. Xis actually done here.
  924. X.PP
  925. XThe same kind of reasoning applies to those two lines:
  926. X.Ex
  927. X#\$\&d_dup2 HAS_DUP2   /**/
  928. X#\$\&i_string I_STRING      /**/
  929. X.Ef
  930. Xand assuming \fIconfig.sh\fR defines:
  931. X.Ex
  932. Xd_dup2='define'
  933. Xi_string='undef'
  934. X.Ef
  935. Xwe'll get in the produced \fIconfig.h\fR:
  936. X.Ex
  937. X#define HAS_DUP2   /**/
  938. X/*#define I_STRING      /**/
  939. X.Ef
  940. XClear as running water? Good!
  941. X.PP
  942. XNow it should be obvious that by including \fIconfig.h\fR in all your
  943. XC source files, you get to know what \fIConfigure\fR has guessed on
  944. Xyour system. In effect, by using those symbols, you are writing
  945. Xconfigured C code, since \fImetaconfig\fR will know that you need
  946. Xthose symbols and will generate a suitable \fIconfig_h.SH\fR file as
  947. Xwell as all the necessary code in \fIConfigure\fR to compute a
  948. Xproper value for them (by assigning values to associated shell variables).
  949. X'''
  950. X.SS Running Metaconfig
  951. X.PP
  952. XLet's focus on the \fImetaconfig\fR program for a while to understand how
  953. Xit uses its units and your source code to produce all the needed configuration
  954. Xfiles. If you intend to write new units, you should have a good understanding
  955. Xof the whole scheme.
  956. X.PP
  957. XAssuming your MANIFEST.new file is properly set and lists all the source
  958. Xfiles you wish to configure, and that you have run \fIpackint\fR in your
  959. Xroot source directory to create a \fI.package\fR file, you may run
  960. X\fImetaconfig\fR and you'll get the following:
  961. X.Ex
  962. X\$ metaconfig
  963. XLocating units...
  964. XExtracting dependency lists from 312 units...
  965. XExtracting filenames (*.[chyl] and *.SH) from MANIFEST.new...
  966. XBuilding a Wanted file...
  967. X.in +2
  968. XScanning .[chyl] files for symbols...
  969. XScanning .SH files for symbols...
  970. X.in -2
  971. XComputing optimal dependency graph...
  972. X.in +2
  973. XBuilding private make file...
  974. XDetermining loadable units...
  975. XUpdating make file...
  976. X.in -2
  977. XDetermining the correct order for the units...
  978. XCreating Configure...
  979. XDone.
  980. X.Ef
  981. XThe first phase looks for all the units files (ending with .U) in the public
  982. Xdirectory first, then in your private one. If you copy a public file in your
  983. Xprivate U directory (i.e. a directory named U at the top level of your package),
  984. Xit will override the public version. Once it has a list of all the available
  985. Xunits, it parses them and extracts all the ?MAKE: lines to know about the
  986. Xdependencies and the known shell symbols. It also focuses on the ?H: lines to
  987. Xlearn about the C symbols and which shell symbols needs to be computed to get
  988. Xa proper value for that C symbol (so we have another level of dependencies
  989. Xhere).
  990. X.PP
  991. XNext, the proper filenames are extracted from the MANIFEST.new files and a
  992. X\fIWanted\fR file is built: that file lists all the C symbols and the shell
  993. Xsymbols needed for that package. We first scan the C-type files for C symbols,
  994. Xthen propagate the dependencies to their associated shell symbols (gathered
  995. Xfrom ?H: lines). Next .SH files are scanned and finally all the shell symbols
  996. Xare known.
  997. X.PP
  998. XA temporary Makefile is built and metaconfig tries to \fImake\fR all the shell
  999. Xsymbols to see what commands (listed on the second ?MAKE: lines) are
  1000. Xexecuted, and thus which units are really needed. Optional units not otherwise
  1001. Xrequired are removed and a second Makefile is generated. This time, we know
  1002. Xabout all the units and their respective orders, optional units having been
  1003. Xremoved and default values computed for their shell symbols. The \fIConfigure\fR
  1004. Xscript can then be generated, along with \fIconfig_h.SH\fR. We're done.
  1005. X'''
  1006. X.SS Conventions
  1007. X.PP
  1008. XProper conventions needs to be followed to make the whole process sound.
  1009. XThere is a case convention for units and a variable naming convention.
  1010. X.PP
  1011. XAll units should have their first letter lower-cased, unless they are
  1012. Xspecial units. By special, we mean they do not really define new
  1013. Xshell variables that can be used by the user in his .SH files, but rather
  1014. Xunits producing scripts or shell variables that are to be used internally
  1015. Xby the \fIConfigure\fR script. Typical examples are the \fIInit.U\fR
  1016. Xfile which is the main variable initialization, or \fIMyread.U\fR which
  1017. Xproduces the \fImyread\fR script used almost everywhere in \fIConfigure\fR
  1018. Xwhen a question is to be asked to the user.
  1019. X.PP
  1020. XNon-special units then subdivise in two distinct groups: units defining
  1021. Xvariables associated to a C symbol and units defining shell variables of
  1022. Xtheir own. The first group is further divided in variables related to
  1023. Xinclude files (their name begin with \fIi_\fR) and variables related to
  1024. Xother definitions (name starting with \fId_\fR). The second group have
  1025. Xnames standing for itself, for instance \fIcc.U\fR defines the \fI\$\&cc\fR
  1026. Xshell variable whose value is the C compiler to be used.
  1027. X.PP
  1028. XSpecial units sometimes reserve themselves some pre-defined variable and
  1029. Xreturn "results" in other well-known variables. For instance, the \fImyread\fR
  1030. Xscript produced by Myread.U expects the prompt in \fI$rp\fR, the default
  1031. Xanswer in \fI\$dflt\fR and places the user answer in \fI$ans\fR. This is
  1032. Xnot documented in this manual page: you have to go and look at the unit
  1033. Xitself to understand which variables are used and how the unit is to be
  1034. Xused.
  1035. X'''
  1036. X.SS Using The Glossary
  1037. X.PP
  1038. XThe Glossary file is automatically produced by the \fImakegloss\fR script,
  1039. Xwhich extracts the information from ?S:, ?C: and ?MAKE: lines and reformats
  1040. Xthem into an alphabetically sorted glossary.
  1041. XIt is important to read the Glossary to know about the symbols you are
  1042. Xallowed to use. However, the Glossary will not tell you how to use them.
  1043. XUsually, that's up to you.
  1044. X.PP
  1045. XOne day, you will probably write your own units and you will know enough
  1046. Xabout \fImetaconfig\fR to do so quickly and efficiently. However, never
  1047. Xforget to properly document your work in the ?S: and ?C: lines, or other
  1048. Xpeople will not be able to reuse it. Remember about the time where you
  1049. Xhad only the Glossary and this manual page to get started.
  1050. X'''
  1051. X.SS Conclusion
  1052. X.PP
  1053. XNow that you know the \fImetaconfig\fR basics, you should read the
  1054. X\fIDESCRIPTION\fR section, then skip to the \fIREFERENCE\fR section
  1055. Xto learn about all the gory details such as the allowed syntax for
  1056. Xunit control lines (lines starting with a '?') or the distinct MAKE
  1057. Xcommands you are allowed to use.
  1058. X.SH REFERENCE
  1059. XThis section documents the internals of \fImetaconfig\fR, basically the
  1060. Xunit syntax, the special units you should know about and the hint files.
  1061. X'''
  1062. X.SS General Unit Syntax
  1063. X.PP
  1064. XA metaconfig unit is divided into two distinct parts. The header section
  1065. X(lines starting with '?') and a shell section (code to be included in
  1066. Xthe \fIConfigure\fR script). It is possible to add '?X:' comments anywhere
  1067. Xwithin the unit, but the other '?' lines (also called \fIcontrol lines\fR)
  1068. Xhave a strict ordering policy.
  1069. X.PP
  1070. XIf a control line is too long, it
  1071. Xis possible to use a continuation by escaping the final new-line with a
  1072. Xbackslash and continuing on the next line (which should then be indented by
  1073. Xspaces or tabs).
  1074. X.PP
  1075. XThe following is a formal description of each of the control lines. Unless
  1076. Xstated otherwise, the order of this presentation is the order to be used
  1077. Xwithin the unit.
  1078. X.TP 5
  1079. X?RCS: \fIfree_text\fR
  1080. XTo be used for RCS comments, at the top of the unit.
  1081. X.TP
  1082. X?X: \fIany text\fR
  1083. XGeneral purpose comments. May appear anywhere in the unit but must be left
  1084. Xjustfied. For RCS comments, please use the ?RCS: comment form.
  1085. X.TP
  1086. X?MAKE:\fIsymbol list\fR:\fIdependency list\fR [\fI+optional\fR]
  1087. XThis is the first dependency line. The first \fIsymbol list\fR should list
  1088. Xall the symbols built by this unit (i.e. whose value is computed by the
  1089. Xshell section of the unit). Symbols should be space separated.
  1090. XThe second part of the list (after the middle ':') is the unit dependency.
  1091. XIt should list all the needed special units, as well as all the symbols
  1092. Xused by the shell implementation. If a symbol is nedded but its configuration
  1093. Xvalue is not critical, it can be preceded by a '+', in which case it is
  1094. Xcalled a conditional dependency: its corresponding unit will be loaded if,
  1095. Xand only if, that symbol is otherwise really wanted; otherwise the default
  1096. Xvalue will be used.
  1097. X.TP
  1098. X?MAKE:\fItab\fR \fIcommand\fR
  1099. XThere can be one or more command lines following the initial dependency lines.
  1100. XThose commands will be executed when the unit is wanted to load them into
  1101. X\fIConfigure\fR. See the paragraph about make commands for more information.
  1102. XNote that the leading \fItab\fR character is required before the \fIcommand\fR.
  1103. X.TP
  1104. X?S:\fIsymbol_name\fR [(\fIobsolete symbol list\fR)]:
  1105. XIntroduces a shell symbol. This first line names the symbol, optionally
  1106. Xfollowed by a list enclosed between parenthesis and giving the obsolete
  1107. Xequivalent. Those obsolete symbols will be remapped to the new
  1108. X\fIsymbol_name\fR if the \fB\-o\fR option is given to \fImetaconfig\fR.
  1109. X.TP
  1110. X?S:\fIany text, for Glossary\fR
  1111. XBasically a comment describing the shell symbol, which will be extracted
  1112. Xby \fImakegloss\fR into the Glossary file.
  1113. X.TP
  1114. X?S:.
  1115. XCloses the shell symbol comment.
  1116. X.TP
  1117. X?C:\fIsymbol_name\fR [~ \fIalias\fR] [(\fIobsolete symbol list\fR)]:
  1118. XIntroduces a new C symbol. The \fIalias\fR name is the name under which
  1119. Xthe C symbol will be controlled, i.e. if the \fIalias\fR symbol is wanted,
  1120. Xthen that C symbol will be written in the \fIconfig_h.SH\fR file. Usually,
  1121. Xthe alias is just '%<' (stands for the unit's name) and there is also
  1122. Xa ?W: line mapping a C symbol to the \fIalias\fR. Also the relevant parts
  1123. Xof the ?H: lines are explicitely protected by a '?%<' condition. See
  1124. Xthe symbol aliasing paragraph for more details.
  1125. XThe remaining of the line is the optional \fIobsolete symbol list\fR,
  1126. Xwhich lists old equivalents for the new \fIsymbol_name\fR.
  1127. X.TP
  1128. X?C:\fIany text, for Glossary and config_h.SH\fR
  1129. XBasically a comment describing the C symbol, which will be extracted
  1130. Xby \fImakegloss\fR into the Glossary file and by \fImetaconfig\fR into
  1131. Xthe \fIconfig_h.SH\fR file if the symbol is wanted (or if its alias is
  1132. Xwanted when symbol aliasing is used).
  1133. X.TP
  1134. X?C:.
  1135. XCloses the C symbol comment.
  1136. X.TP
  1137. X?H:?\fIsymbol\fR:\fIconfig_h.SH stuff\fR
  1138. XThis is the general inclusion request into \fIconfig_h.SH\fR. The line is
  1139. Xonly written when the guarding \fIsymbol\fR is really wanted. This general
  1140. Xform is needed when C symbol aliasing was used. Otherwise, if you use one
  1141. Xof the other "standard" forms, the guarding is automatically done by
  1142. X\fImetaconfig\fR itself.
  1143. X.TP
  1144. X?H:#\fI\$d_var VAR\fR "\fI\$var\fR"
  1145. XConditionally defines the \fIVAR\fR C symbol into \fI\$var\fR when \fI$d_var\fR
  1146. Xis set to '\fIdefine\fR'. Implies a '?\fIVAR\fR:' guarding condition, and
  1147. X\fImetaconfig\fR automatically links \fIVAR\fR to its two shell variable
  1148. Xdependencies (i.e. both \fI\$d_var\fR and \fI\$var\fR will be flagged as
  1149. X\fIwanted\fR if \fIVAR\fR is used in C sources).
  1150. X.TP
  1151. X?H:#define \fIVAR\fR [\fIoptional text\fR]
  1152. XAlways defines the \fIVAR\fR C symbol to some value. Implies a '?\fIVAR\fR:'
  1153. Xguarding condition. An automatic shell dependency is made to the unit itself.
  1154. X.TP
  1155. X?H:#\fI\$d_var VAR\fR
  1156. XConditionally defines \fIVAR\fR if \fI\$d_var\fR is set to '\fIdefine\fR'.
  1157. XImplies a '?\fIVAR\fR:' guarding condition. An automatic shell dependency is
  1158. Xgenerated towards \fI\$d_war\fR.
  1159. X.TP
  1160. X?H:#define \fIVAR\fR "\fI\$var\fR"
  1161. XAssigns a configured value to the \fIVAR\fR C symbol. Implies a '?\fIVAR\fR:'
  1162. Xgurading condition. An automatic shell dependency is generated to link
  1163. X\fIVAR\fR and \fI\$var\fR.
  1164. X.TP
  1165. X?H:.
  1166. XCloses the \fIconfig_h.SH\fR inclusion requests.
  1167. X.TP
  1168. X?W:\fIshell symbol list\fR:\fIC symbol list\fR
  1169. XTies up the destiny of the shell symbols with that of the C symbols: if any
  1170. Xof the C symbols listed is wanted, then all the shell symbols are marked
  1171. Xas wanted. Useful to force inclusion of a unit (shell symbol list set to
  1172. X'%<') when the presence of some C symbol is detected. The shell symbol list
  1173. Xmay be left empty, to benefit from the side effect of C symbol location
  1174. Xwithin the builtin pre-processor (symbol being \fIdefined\fR for that
  1175. Xpre-processor if located in the source). To look for patterns with a space
  1176. Xin them, you need to quote the C symbols within simple quotes, as in
  1177. X'struct timezone'.
  1178. X.TP
  1179. X?V:\fIread-only symbols\fR:\fIread-write symbols\fR
  1180. XThis is a \fImetalint\fR hint and should be used only in special units
  1181. Xexporting some shell variables. The variables before the middle ':'
  1182. Xare exported read-only (changing them will issue a warning), while
  1183. Xother symbols may be freely read and changed.
  1184. X.TP
  1185. X?T:\fIshell temporaries\fR
  1186. XAnother \fImetalint\fR hint. This line lists all the shell variables used
  1187. Xas temporaries within the shell section of this unit.
  1188. X.TP
  1189. X?D:\fIsymbol\fR='\fIvalue\fR'
  1190. XInitialization value for symbols used as conditional dependencies. If no
  1191. X?D: line is found, then a null value is used instead. The \fImetalint\fR
  1192. Xprogram will warn you if a symbol is used at least once as a conditional
  1193. Xdependency and does not have a proper ?D: initialization. It's a good
  1194. Xpractice to add those lines even for a null initialization since it
  1195. Xemphasizes on the possibly optional nature of a symbol.
  1196. X.TP
  1197. X?O:\fIany message you want\fR
  1198. XThis directive indicates that this unit is obsolete as a whole. Whenever
  1199. Xusage of any of its symbols is made (or indirect usage via dependencies),
  1200. Xthe message is output on the screen (on stderr). You can put one ore more
  1201. Xlines, in which case each line will be printed, in order.
  1202. X.TP
  1203. X?LINT:\fImetalint hints\fR
  1204. XSee the \fImetalint\fR manual page for an explaination of the distinct
  1205. Xhints that can be used.
  1206. X.TP
  1207. X?INIT:\fIinitialization code\fR
  1208. XThe initialization code specified by this line will be loaded at the top
  1209. Xof the \fIConfigure\fR script provided the unit is needed.
  1210. X'''
  1211. X.SS C Symbol Aliasing
  1212. X.PP
  1213. XSometimes it is not possible to rely on \fImetaconfig\fR's own default
  1214. Xselection for \fIconfig_h.SH\fR comments and C symbol definition. That's
  1215. Xwhere aliasing comes into play. Since it's rather tricky to explain, we'll
  1216. Xstudy an example to understand the underlying mechanism.
  1217. X.PP
  1218. XThe d_const.U unit tries to determine whether or not your C compiler
  1219. Xknown about the \fIconst\fR keyword. If it doesn't we want to remap
  1220. Xthat keyword to a null string, in order to let the program compile.
  1221. XMoreover, we want to automatically trigger the test when the \fIconst\fR
  1222. Xword is used.
  1223. X.PP
  1224. XHere are the relevant parts of the d_const.U unit:
  1225. X.Ex
  1226. X?MAKE:d_const: cat cc ccflags Setvar
  1227. X?MAKE:    -pick add $@ %<
  1228. X?S:d_const:
  1229. X?S:    This variable conditionally defines the HASCONST symbol, which
  1230. X?S:    indicates to the C program that this C compiler knows about the
  1231. X?S:    const type.
  1232. X?S:.
  1233. X?C:HASCONST ~ %<:
  1234. X?C:    This symbol, if defined, indicates that this C compiler knows about
  1235. X?C:    the const type. There is no need to actually test for that symbol
  1236. X?C:    within your programs. The mere use of the "const" keyword will
  1237. X?C:    trigger the necessary tests.
  1238. X?C:.
  1239. X?H:?%<:#$\&d_const HASCONST    /**/
  1240. X?H:?%<:#ifndef HASCONST
  1241. X?H:?%<:#define const
  1242. X?H:?%<:#endif
  1243. X?H:.
  1244. X?W:%<:const
  1245. X?LINT:set d_const
  1246. X?LINT:known const
  1247. X: check for const keyword
  1248. Xecho " "
  1249. Xecho 'Checking to see if your C compiler knows about "const"...' >&4
  1250. X$cat >const.c <<'EOCP'
  1251. Xmain()
  1252. X{
  1253. X    const char *foo;
  1254. X}
  1255. XEOCP
  1256. Xif $\&cc -c $\&ccflags const.c >/dev/null 2>&1 ; then
  1257. X    val="$\&define"
  1258. X    echo "Yup, it does."
  1259. Xelse
  1260. X    val="$\&undef"
  1261. X    echo "Nope, it doesn't."
  1262. Xfi
  1263. Xset d_const
  1264. Xeval $\&setvar
  1265. X.Ef
  1266. XFirst we notice the use of a ?W: line, which basically says: "This unit
  1267. Xis wanted when the \fIconst\fR keyword is used in a C file.". In order
  1268. Xto conditionally remap \fIconst\fR to a null string in \fIconfig.h\fR,
  1269. XI chose to conditionally define \fIHASCONST\fR via \fI\$\&d_const\fR.
  1270. X.PP
  1271. XHowever, this raises a problem, because the \fIHASCONST\fR symbol is not
  1272. Xgoing to be used in the sources, only the \fIconst\fR token is. And the
  1273. X?H: line defining \fIHASCONST\fR is implicitely guarded by '?HASCONST'.
  1274. XTherefore, we must add the explicit '?%<' constraint to tell \fImetaconfig\fR
  1275. Xthat those lines should be included in \fIconfig_h.SH\fR whenever the
  1276. X'%<' symbol gets wanted (%< refers to the unit's name, here \fId_const\fR).
  1277. X.PP
  1278. XThat's almost perfect, because the ?W: line will want \fId_const\fR whenever
  1279. X\fIconst\fR is used, then the ?H: lines will get included in the
  1280. X\fIconfig_h.SH\fR file. However, the leading comment (?C: lines) attached to
  1281. X\fIHASCONST\fR is itself also guarded via \fIHASCONST\fR, i.e. it has an
  1282. Ximplicit '?HASCONST' constraint. Hence the need for \fIaliasing\fR the
  1283. X\fIHASCONST\fR symbol to '%<'.
  1284. X.PP
  1285. XThe remaining part of the unit (the shell part) is really straightforward.
  1286. XIt simply tries to compile a sample C program using the \fIconst\fR keyword.
  1287. XIf it can, then it will define \fI\$\&d_const\fR via the \fI\$\&setvar\fR
  1288. Xfonction (defined by the \fISetvar.U\fR unit). See the paragraph about
  1289. Xspecial units for more details.
  1290. X'''
  1291. X.SS Make Commands
  1292. X.PP
  1293. XOn the ?MAKE: command line, you may write a shell command to be executed as-is
  1294. Xor a special \fI-pick\fR command which is trapped by \fImetaconfig\fR and
  1295. Xparsed to see what should be done. The leading '-' is only there to prevent
  1296. X\fImake\fR from failing when the command returns a non-zero status -- it's
  1297. Xnot really needed since we use '\fImake -n\fR' to resolve the dependencies,
  1298. Xbut I advise you to keep it in case it becomes mandatory in future versions.
  1299. XThe syntax of the \fIpick\fR command is:
  1300. X.Ex
  1301. X-pick \fIcmd\fR \$@ \fItarget_file\fR
  1302. X.Ef
  1303. Xwhere \fI\$@\fR is the standard macro within Makefiles standing for the current
  1304. Xtarget (the name of the unit being built, with the final .U extension stripped).
  1305. XThe \fIcmd\fR part is the actual \fImetaconfig\fR command to be run, and the
  1306. X\fItarget_file\fR is yet another parameter, whose interpretation depends on
  1307. Xthe \fIcmd\fR itself. It also has its final .U extension stripped and normally
  1308. Xrefers to a unit file, unless it start with './' in which case it references
  1309. Xone of the \fImetaconfig\fR control files in the '\fI.MT\fR directory.
  1310. X.PP
  1311. XThe available commands are:
  1312. X.TP 10
  1313. Xadd
  1314. XAdds the \fItarget_file\fR to \fIConfigure\fR.
  1315. X.TP
  1316. Xadd.Config_sh
  1317. XFills in that part of \fIConfigure\fR producing the \fIconfig.sh\fR file.
  1318. XOnly used variables are added, conditional ones (from conditional dependencies)
  1319. Xare skipped.
  1320. X.TP
  1321. Xadd.Null
  1322. XAdds the section initializing all the shell variables used to an empty string.
  1323. X.TP
  1324. Xc_h_weed
  1325. XProduces the \fIconfig_h.SH\fR file. Only the necessary lines are printed.
  1326. X.TP
  1327. Xclose.Config_sh
  1328. XAdds the final 'EOT' symbol on a line by itself to end the here document
  1329. Xconstruct producing the \fIconfig.sh\fR file.
  1330. X.TP
  1331. Xprepend
  1332. XPrepends the content of the target to the \fItarget_file\fR if that file is
  1333. Xnot empty.
  1334. X.TP
  1335. Xweed
  1336. XAdds the unit to \fIConfigure\fR like the \fIadd\fR command, but make some
  1337. Xadditional tests to remove the '?\fIsymbol\fR' and '%\fIsymbol\fR' lines
  1338. Xfrom the \fItarget_file\fR if the symbol is not wanted or conditionally
  1339. Xwanted. The '%' form is only used internally by \fImetaconfig\fR while
  1340. Xproducing its own .U files in the '\fI.MT\fR' directory.
  1341. X.TP
  1342. Xwipe
  1343. XSame as \fIadd\fR really, but performs an additional macro substitution.
  1344. XThe available macros are described in the \fIHardwired Macros\fR paragraph.
  1345. X.PP
  1346. XAs a side note, \fImetaconfig\fR generates a \fI-cond\fR command internally
  1347. Xto deal with conditional dependencies. You should not use it by yourself,
  1348. Xbut you will see it if scanning the generated \fIMakefile\fR in the \fI.MT\fR
  1349. Xdirectory.
  1350. X'''
  1351. X.SS Hardwired Macros
  1352. X.PP
  1353. XThe following macros are recognized by the \fIwipe\fR command and subsituted
  1354. Xbefore inclusion in \fIConfigure\fR:
  1355. X.TP 10
  1356. X<BASEREV>
  1357. XThe base revision number of the package, derived from \fI.package\fR.
  1358. X.TP
  1359. X<DATE>
  1360. XThe current date.
  1361. X.TP
  1362. X<MAINTLOC>
  1363. XThe e-mail address of the maintainer of this package, derived from
  1364. Xyour \fI.package\fR.
  1365. X.TP
  1366. X<PACKAGENAME>
  1367. END_OF_FILE
  1368.   if test 49943 -ne `wc -c <'mcon/man/mconfig.SH.01'`; then
  1369.     echo shar: \"'mcon/man/mconfig.SH.01'\" unpacked with wrong size!
  1370.   fi
  1371.   # end of 'mcon/man/mconfig.SH.01'
  1372. fi
  1373. echo shar: End of archive 2 \(of 28\).
  1374. cp /dev/null ark2isdone
  1375. MISSING=""
  1376. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ; do
  1377.     if test ! -f ark${I}isdone ; then
  1378.     MISSING="${MISSING} ${I}"
  1379.     fi
  1380. done
  1381. if test "${MISSING}" = "" ; then
  1382.     echo You have unpacked all 28 archives.
  1383.     echo "Please run PACKNOTES through sh, read REAMDE and then type Configure."
  1384.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1385. else
  1386.     echo You still must unpack the following archives:
  1387.     echo "        " ${MISSING}
  1388. fi
  1389. exit 0
  1390.  
  1391. exit 0 # Just in case...
  1392.