1 #LyX 1.6.2 created this file. For more info see http://www.lyx.org/
5 \textclass literate-article
9 \use_default_options true
17 \font_typewriter default
18 \font_default_family default
25 \paperfontsize default
34 \paperorientation portrait
37 \paragraph_separation skip
39 \quotes_language english
43 \tracking_changes false
56 Sam Liddicott <sam@liddicott.com>
63 \begin_layout Standard
64 \begin_inset CommandInset toc
65 LatexCommand tableofcontents
72 \begin_layout Section*
76 \begin_layout aphorism
77 noweb 2.11b and lyx 2.6.2 nearly play together nicely.
80 \begin_layout Standard
81 This document talks about finishing the job.
82 To run these examples you will need Lyx 2.6.2 and noweb 2.11b, and a copy
83 of notanglefix in the same folder as this document noweb-lyx.lyx
87 \begin_inset CommandInset label
96 \begin_layout Standard
97 According to the Extended Lyx Features
98 \begin_inset CommandInset citation
104 which you should read, we use notangle to derive the
108 , and Lyx automatically uses noweave to generate the
115 \begin_layout Standard
116 There are, sadly, some serious problems with noweb and Lyx.
119 \begin_layout Section
121 \begin_inset space \hspace*{}
128 \begin_layout Standard
129 notangle complains when a double chevron <
130 \begin_inset space \hspace*{}
134 < occurs in non code chunk portions of the input document.
135 These are supposed to be escaped with @, requiring me to enter @
136 \begin_inset space \hspace*{}
141 \begin_inset space \hspace*{}
145 <, however the @ is not being removed by noweave when it generates the output
150 \begin_layout Standard
151 To solve this problem and have more normal looking lyx at edit time, I tried
152 inserting a zero-width space between the chevrons, looking somewhat like
153 this in Lyx: <␣<, but being represented as <
155 hspace*{0in}< internally.
158 \begin_layout Standard
159 Sadly this does not work in the Lyx-Code environment, where the zero width
160 space is presented a literal space character, and so < < is emitted in
161 the document with a space between the chevrons.
164 \begin_layout Standard
169 noweave attempts to remove the extra @, detecting the
171 textcompwordmark{} that noweave inserts between the chevrons:
176 \begin_inset Newline newline
183 textcompwordmark{}</<
187 textcompwordmark{}</g;'
188 \begin_inset Newline newline
194 \begin_layout Standard
196 \begin_inset space \hspace*{}
201 \begin_inset space \hspace*{}
205 > is used in the Lyx-Code environment to demonstrate a code chunk as in
207 \begin_inset CommandInset ref
209 reference "lyx:example-scrap"
213 , no special behaviour is needed -- in fact a real noweb code chunk is being
214 declared, and so as long as the chunk name does not conflict it is acceptable.
215 Although notangle sees a real code chunk, noweave does not -- no doubt
216 because noweave only detects chunks in a Lyx Scrap.
217 In any case the sed on the previous line permits @
218 \begin_inset space \hspace*{}
223 \begin_inset space \hspace*{}
227 < to be used in the Lyx-Code environment.
230 \begin_layout Section
232 \begin_inset space \hspace*{}
239 \begin_layout Standard
240 When a double chrevron occurs within a code chunk it us usually must also
241 be escaped with @, but it is shown in the generated document as a double
246 \begin_layout Plain Layout
254 If it is not escaped with @, then it shows in the document as the angle
259 \begin_layout Standard
260 This seems to be a noweave bug which should replace non-special <
261 \begin_inset space \hspace*{}
265 < in noweb chunks with <
270 \begin_layout Standard
271 The following sed must run
275 noweave and prevents <
276 \begin_inset space \hspace*{}
281 \begin_inset space \hspace*{}
285 > from being interpreted as
289 \begin_layout Plain Layout
299 \begin_layout Standard
300 First we detect when begincode environment starts or ends by coping those
301 lines to the hold space with the sed h command.
305 <<fix-noweave-chevron>>=
306 \begin_inset Newline newline
318 \begin_inset Newline newline
330 \begin_inset Newline newline
336 \begin_layout Standard
341 ] is required to prevent the literal
343 nwendcode in this code chunk from triggering the nwbegincode and nwendcode
344 detectors when this document is processed.
345 It doesn't work by merely avoiding nwbegincode preceded by two slashes
350 it appears that way in this code chunk.
353 \begin_layout Standard
354 It is because noweave is escaping back-slashes with another back-slash anyway
355 so a double backslash signifies a literal document backslash, and it is
356 these that we wish to avoid.
357 In fact the noweave output of this chunk looks like this now: [^
376 \begin_layout Standard
377 Then, for lines that contain <
378 \begin_inset space \hspace*{}
383 \begin_inset space \hspace*{}
387 > we check that the line in the hold space contains
391 , by using the sed x command to exchange the current line in pattern space
392 with the saved line in hold space and then doing a match.
396 \begin_layout Standard
397 If there is a match, then we know that we are in the begincode environment,
398 and we do a replace to insert
402 textcompwordmark between them.
403 The sed /g makes sure we do this for all occurances on the line.
407 <<fix-noweave-chevron>>=
408 \begin_inset Newline newline
411 /<</{x;/begincode/{x;s/<</<
415 textcompwordmark</g;x};x};
416 \begin_inset Newline newline
419 />>/{x;/begincode/{x;s/>>/>
423 textcompwordmark>/g;x};x}'
424 \begin_inset Newline newline
430 \begin_layout Section
431 Underscore in chunk names
434 \begin_layout Standard
435 Underscores cannot be expressed in the fragment name; e.g.
438 \begin_layout LyX-Code
440 \begin_inset Newline newline
446 \begin_layout Standard
447 otherwise the document refuses to generate.
448 I believe this is a noweave bug, it should escape any _ in the <
449 \begin_inset space \hspace*{}
454 \begin_inset space \hspace*{}
463 \begin_layout Standard
464 The following sed must be run
472 <<fix-noweave-underscore>>=
473 \begin_inset Newline newline
477 \begin_inset space \hspace*{}
486 \begin_inset Newline newline
492 \begin_layout Standard
493 This makes the noweave output conversion filter set in Tools\SpecialChar \menuseparator
494 Preferences\SpecialChar \menuseparator
496 Handling\SpecialChar \menuseparator
497 Converters\SpecialChar \menuseparator
498 NoWeb -> Latex something like this
499 \begin_inset Note Note
502 \begin_layout Plain Layout
503 I would have used @<<fix-noweave-underscore>> but I wanted the entire code
504 to output in the document.
505 I wish there was a @<<>> variant that showed the included text in the output
516 \begin_inset Newline newline
524 \begin_inset Newline newline
527 noweave -delay -index - |
528 \begin_inset Newline newline
535 textcompwordmark{}</<
539 textcompwordmark{}</g;' |
540 \begin_inset Newline newline
552 \begin_inset Newline newline
564 \begin_inset Newline newline
567 /<</{x;/begincode/{x;s/<</<
571 textcompwordmark</g;x};x};
572 \begin_inset Newline newline
575 />>/{x;/begincode/{x;s/>>/>
579 textcompwordmark>/g;x};x}' > $$o
580 \begin_inset Newline newline
586 \begin_layout Section
587 \begin_inset CommandInset label
589 name "sub:notangle--L-breaks"
593 notangle -L breaks indentation
596 \begin_layout Standard
597 Normally we would generate the source using someting like:
600 \begin_layout LyX-Code
601 notangle -L'#line %L "%F"%N' -Rexample-print-loop noweb-lyx.lyx
604 \begin_layout Standard
605 Although -L'#line %L "%F"%N' is required to aid tracing compile errors back
606 to the lyx document, it also spoils the indentation of the C output.
609 \begin_layout Standard
610 Normally the indent before the chunk include is applied to each line of
611 the included chunk; e.g.
614 \begin_layout LyX-Code
615 \begin_inset CommandInset label
617 name "lyx:example-scrap"
624 \begin_layout LyX-Code
626 \begin_inset Quotes eld
632 \begin_inset Quotes erd
638 \begin_layout LyX-Code
642 \begin_layout LyX-Code
646 \begin_layout LyX-Code
647 \begin_inset CommandInset label
649 name "lyx:example-print-loop"
653 @<<example-print-loop>>=
656 \begin_layout LyX-Code
660 \begin_layout LyX-Code
664 \begin_layout LyX-Code
665 ␣␣for(a=0; a<5; a++) {
668 \begin_layout LyX-Code
669 ␣␣␣␣@<<example-print>>
672 \begin_layout LyX-Code
676 \begin_layout LyX-Code
680 \begin_layout LyX-Code
684 \begin_layout Standard
685 Would generate something like this if the -L argument were not used
689 \begin_layout Plain Layout
690 although the output looks only
694 like this on account of other notangle problems, see section
695 \begin_inset CommandInset ref
697 reference "sub:Generally-mangled-notangle"
709 \begin_layout LyX-Code
713 \begin_layout LyX-Code
717 \begin_layout LyX-Code
718 ␣␣for(a=0; a<5; a++) {
721 \begin_layout LyX-Code
725 \begin_layout LyX-Code
727 \begin_inset Quotes eld
733 \begin_inset Quotes erd
739 \begin_layout LyX-Code
743 \begin_layout LyX-Code
747 \begin_layout Standard
748 Here is an extract of the C it generates when the argument -L'#line %L "%F"%N'
752 \begin_layout LyX-Code
753 #line 509 "noweb-lyx.lyx"
756 \begin_layout LyX-Code
760 \begin_layout LyX-Code
764 \begin_layout LyX-Code
765 ␣␣for(a=0; a<5; a++) {
768 \begin_layout LyX-Code
772 \begin_layout LyX-Code
773 #line 491 "noweb-lyx.lyx"
776 \begin_layout LyX-Code
780 \begin_layout LyX-Code
786 \begin_layout LyX-Code
787 #line 525 "noweb-lyx.lyx"
790 \begin_layout LyX-Code
794 \begin_layout LyX-Code
798 \begin_layout Standard
799 We see that the correct indent is emitted on the line before the #line statement
800 , but the rest of the block is not indented.
801 We must fix this by storing any non-newline white space before a line matching
802 /^#line/ and inserting it before each line.
805 \begin_layout Standard
806 We do this in section
807 \begin_inset CommandInset ref
809 reference "notanglefix-leading-space"
816 \begin_layout Section
817 \begin_inset CommandInset label
819 name "sub:Generally-mangled-notangle"
823 Generally mangled notangle output
826 \begin_layout Standard
827 There also is serious problem with either noweb or Lyx's Scrap handling.
828 For instance, when the code block
833 \begin_inset CommandInset ref
835 reference "lyx:example-print-loop"
839 ) is untangled we see mangled output like this:
842 \begin_layout LyX-Code
845 begin_inset Newline newline
848 \begin_layout LyX-Code
854 \begin_layout LyX-Code
858 \begin_layout LyX-Code
862 \begin_layout LyX-Code
865 begin_inset Newline newline
868 \begin_layout LyX-Code
874 \begin_layout LyX-Code
878 \begin_layout LyX-Code
882 \begin_layout LyX-Code
885 begin_inset Newline newline
888 \begin_layout LyX-Code
894 \begin_layout LyX-Code
898 \begin_layout LyX-Code
902 \begin_layout LyX-Code
908 \begin_layout LyX-Code
914 \begin_layout LyX-Code
918 \begin_layout LyX-Code
924 \begin_layout LyX-Code
928 \begin_layout LyX-Code
934 \begin_layout LyX-Code
940 \begin_layout Standard
941 Line-breaks occur freely, and backslash characters come out as
943 backslash on a new line, sometimes with a blank line following.
944 In fact the output has not been properly un-lyx-ified.
947 \begin_layout Standard
954 backslash with an actual backslash and to remove newline characters altogether,
955 and instead insert newlines where
959 begin_inset Newline newline
962 (I also note that the promised [[ ]] for quoting code doesn't work).
965 \begin_layout Standard
970 because it fixes the output from notangle.
973 \begin_layout Standard
974 Note the space after #! which makes the first four characters #! /, and
975 aids BSD systems which use the first four characters of a file as the magic
976 number for script handling.
981 \begin_inset Newline newline
985 \begin_inset Newline newline
991 \begin_layout Standard
992 emit_buffer simply outputs the newline-less buffer of accumulated text.
993 AWK's print adds a newline on the end automatically.
994 The buffer is then cleared ready for more data.
999 \begin_inset Newline newline
1002 function emit_buffer() {
1003 \begin_inset Newline newline
1006 print indent buffer;
1007 \begin_inset Newline newline
1011 \begin_inset Newline newline
1015 \begin_inset Newline newline
1021 \begin_layout Standard
1022 The BEGIN block is used to initialize the buffer, although this isn't required
1024 The indent is used to fixup indenting when the -L argument has been used
1025 for notangle as mentioned in section
1026 \begin_inset CommandInset ref
1028 reference "sub:notangle--L-breaks"
1037 \begin_inset Newline newline
1041 \begin_inset Newline newline
1045 \begin_inset Newline newline
1049 \begin_inset Newline newline
1053 \begin_inset Newline newline
1059 \begin_layout Standard
1060 As notanges -L output the indent once only before the #line, we need to
1061 store this indent when we see #line.
1062 We also match a digit after the token #line in order to avoid wrongly detecting
1063 files (like Makefile.inc in section
1064 \begin_inset CommandInset ref
1066 reference "sub:Keeping-extracted-files"
1070 ) which might specify -L'#line %L "%F"%N'
1075 \begin_inset Newline newline
1079 \begin_inset Newline newline
1083 \begin_inset Newline newline
1087 \begin_inset Newline newline
1091 \begin_inset Newline newline
1097 \begin_layout Standard
1098 \begin_inset CommandInset label
1100 name "notanglefix-leading-space"
1104 We want to trim leading white-space on each line -- unless we haven't accumulate
1106 This permits us to preserve notangles indent at the start of each proper
1107 line, without caring when lyx starts a new line for things like
1110 Because we preserve the first chunk of white space, the #line matching
1111 code is able to take this and store it when -L mode is used.
1116 \begin_inset Newline newline
1120 \begin_inset Newline newline
1123 if (length(buffer) > 0) gsub("^ *", "");
1124 \begin_inset Newline newline
1128 \begin_inset Newline newline
1134 \begin_layout Standard
1136 \begin_inset Quotes eld
1140 \begin_inset Quotes erd
1143 was determined to be emitted by notangle everywhere ctrl+enter was used
1144 in the lyx Scrap style, so we use this pattern to emit the buffer (with
1145 a trailing newline).
1146 We avoid doing this on the first line of the document in order to prevent
1147 all generate files starting with a blank line.
1148 This would otherwise occur, because I press ctrl+enter after the
1151 \begin_inset space \hspace*{}
1156 \begin_inset space \hspace*{}
1162 line before typing code in a code chunk in order to get a common indent
1166 \begin_layout Plain Layout
1167 Sadly if the first line of a chunk includes another chunk then we still
1168 get blank lines at the top of the document.
1169 The fix is probably to remove any Newline insets immediately after the
1181 \begin_inset Newline newline
1188 begin_inset Newline newline$/ {
1189 \begin_inset Newline newline
1192 if (NR > 1) emit_buffer();
1193 \begin_inset Newline newline
1197 \begin_inset Newline newline
1203 \begin_layout Standard
1204 A line containing only
1206 backslash is emitted by lyx where an actual backslash was present in the
1207 chunk, so we convert this back into a literal backslash.
1208 No other special character treatment has been observed as yet.
1213 \begin_inset Newline newline
1221 \begin_inset Newline newline
1229 \begin_inset Newline newline
1233 \begin_inset Newline newline
1237 \begin_inset Newline newline
1243 \begin_layout Standard
1244 Other lines observed that contain sections with a backslash don't seem relevant
1245 to the Scrap and so are removed.
1250 \begin_inset Newline newline
1258 \begin_inset Newline newline
1270 \begin_inset Newline newline
1274 \begin_inset Newline newline
1280 \begin_layout Standard
1281 The default action is to append the line to the buffer.
1282 In AWK (unlike PERL's $_) the trailing newline is not part of $0 so we
1283 don't need to explicitly strip the newline at the end of $0.
1284 This also means that blank lines in the input are ignored.
1289 \begin_inset Newline newline
1293 \begin_inset Newline newline
1297 \begin_inset Newline newline
1301 \begin_inset Newline newline
1307 \begin_layout Standard
1308 At the end of the file we emit_buffer, but only if it is not empty.
1309 This stops a blank line being emitted at the end of the output file.
1310 It also means that if the final line of the Lyx Scrap was didn't have a
1311 newline, that a newline will still be appended by emit_buffer.
1312 This is not considered a bug.
1317 \begin_inset Newline newline
1321 \begin_inset Newline newline
1324 if (length(buffer) > 0) emit_buffer();
1325 \begin_inset Newline newline
1329 \begin_inset Newline newline
1335 \begin_layout Standard
1336 The irony is in getting notanglefix out of this noweb document, as notanglefix
1337 is also required in order to get notanglefix out of this document.
1340 \begin_layout Standard
1341 A shorter (but perhaps not faster) variation could be based on this older
1342 but more confusing version, by defining the record separator as the same
1343 as the Lyx line separator, and otherwise treating embedded newlines as
1345 This example is not complete.
1350 \begin_inset Newline newline
1354 \begin_inset Newline newline
1358 \begin_inset Newline newline
1362 \begin_inset Newline newline
1373 begin_inset Newline newline[
1386 \begin_inset Newline newline
1390 \begin_inset Newline newline
1394 \begin_inset Newline newline
1398 \begin_inset Newline newline
1402 \begin_inset Newline newline
1418 \begin_inset Newline newline
1424 \begin_inset Newline newline
1428 \begin_inset Newline newline
1432 \begin_inset Newline newline
1438 \begin_layout Standard
1439 Finally, to extract a C source file, we use this command, where $1 is the
1440 lyx filename and $2 is the root fragment to extract:
1444 <<fix-notangle-extract>>=
1445 \begin_inset Newline newline
1448 notangle -L'#line %L "%F"%N' ${2+-R"$2"} "$1"
1451 \begin_inset Newline newline
1454 | awk -f notangle-fix
1455 \begin_inset Newline newline
1465 \begin_layout Section
1466 A word about Make with Noweb and Lyx
1469 \begin_layout Standard
1470 Whitespace formatting is very important in a Makefile.
1471 The first character of each command line must be a TAB.
1474 \begin_layout LyX-Code
1475 target: pre-requisite
1476 \begin_inset Newline newline
1480 \begin_inset Newline newline
1486 \begin_layout Standard
1487 But a TAB is pretty hard to enter in a Lyx scrap.
1488 An alternative is to use a semi-colon after the pre-requisite, and a backslash
1489 at the end of each line (except the last).
1492 \begin_layout LyX-Code
1493 target: pre-requisite ;
1496 \begin_inset Newline newline
1502 \begin_inset Newline newline
1508 \begin_layout Standard
1509 This is the style that we use and it works pretty well for GNU make at least.
1512 \begin_layout Standard
1513 We also adopt a convention that code chunks whose names beginning with ./
1514 should always be automatically extracted from the document.
1515 Code chunks whose names do not begin with ./ are for internal reference.
1516 (This doesn't prevent such chunks from being extracted directly).
1519 \begin_layout Section
1520 Boot-strapping the extraction
1523 \begin_layout Standard
1524 It seems convenient to have the makefile extract or update the C source
1525 files as part of it's operation.
1526 It also seems convenient to have the makefile itself extracted from this
1530 \begin_layout Standard
1531 It would also be convenient to have the code to extract the makefile from
1532 this document to also be part of this document, however we have to start
1533 somewhere and this unfortunately requires us to type at least a few words
1534 by hand to start things off.
1537 \begin_layout Standard
1538 Therefore we will have a minimal root fragment, which, when extracted, can
1539 cope with extracting the rest of the source.
1540 This, along fix notanglefix will need to be extracted manually somehow
1541 first, perhaps with this shell script, which could be called
1550 \begin_inset Newline newline
1554 \begin_inset Newline newline
1558 \begin_inset Newline newline
1561 notangle -R./Makefile.inc "${1:-noweb-lyx.lyx}"
1564 \begin_inset Newline newline
1567 | awk -f notanglefix > ./Makefile.inc
1568 \begin_inset Newline newline
1572 \begin_inset Newline newline
1575 make -f ./Makefile.inc tangle_source
1576 \begin_inset Newline newline
1582 \begin_layout Standard
1583 The general Makefile can be invoked with
1587 and can also be included into any automake file to automatically re-generate
1591 \begin_layout Standard
1596 can be extracted with this command:
1599 \begin_layout LyX-Code
1600 notangle noweb-lyx.lyx | awk -f notanglefix > ./autoboot
1603 \begin_layout Standard
1604 This looks simple enough, but as mentioned, notanglefix has to be had from
1605 somewhere before it can be extracted.
1608 \begin_layout Section
1609 \begin_inset CommandInset label
1611 name "sub:Keeping-extracted-files"
1615 Keeping extracted files up to date
1618 \begin_layout Standard
1619 Makefile.inc will cope with extracting all the other source files from this
1620 document and keeping them up to date.
1621 It make may also be included by Makefile.am.
1624 \begin_layout Standard
1625 We first define NOWEB_SOURCE to hold the name of this Lyx file.
1630 \begin_inset Newline newline
1633 NOWEB_SOURCE=noweb-lyx.lyx
1634 \begin_inset Newline newline
1640 \begin_layout Standard
1641 The Lyx document can result in any number of source documents, but not all
1642 of these will be changed each time the Lyx document is updated.
1643 We certainly don't want to update the timestamps of these files and cause
1644 the whole source tree to be recompiled just because the Lyx document was
1646 To solve this problem we use a stamp file which is always updated each
1647 time the sources are extracted from the Lyx document.
1648 If the stamp file is older than the Lyx document then we can make an attempt
1649 to re-extract the sources.
1654 \begin_inset Newline newline
1657 NOWEB_SOURCE_STAMP=$(NOWEB_SOURCE).stamp
1658 \begin_inset Newline newline
1664 \begin_layout Standard
1665 We also must compute NOWEB_SOURCES to hold the names of all the source files
1666 defined in this document.
1667 We compute this only once, by means of := in assignent.
1668 The sed deletes the <
1669 \begin_inset space \hspace*{}
1674 \begin_inset space \hspace*{}
1678 > which surround the output of the noroots command, and removes the root
1679 called * as that is not a valid filename.
1683 \begin_layout Standard
1684 As we use chunk names beginning with ./ to denote top level fragments that
1685 should be extracted, we also filter out all fragments that do not begin
1691 \begin_inset Newline newline
1694 NOWEB_SOURCES:=$(shell noroots $(NOWEB_SOURCE) |
1697 \begin_inset Newline newline
1700 sed -e 's/^@<<//;s/@>>$$//;/^
1707 \begin_inset Newline newline
1711 \begin_inset Newline newline
1714 echo_noweb_sources: ; @echo $(NOWEB_SOURCES)
1715 \begin_inset Newline newline
1721 \begin_layout Standard
1722 We define a convenient target called noweb_sources to re-extract the source
1723 if the Lyx file has been updated.
1728 \begin_inset Newline newline
1731 noweb_sources: $(NOWEB_SOURCE_STAMP)
1732 \begin_inset Newline newline
1738 \begin_layout Standard
1739 And also a convenient target to remove extracted sources.
1744 \begin_inset Newline newline
1747 clean_noweb_sources: ; rm $(NOWEB_SOURCESTAMP) $(NOWEB_SOURCES)
1748 \begin_inset Newline newline
1754 \begin_layout Standard
1755 We now define the pattern for extracting a file.
1756 The files are written using noweb's
1760 so that the file timestamp will not be touched if the contents haven't
1762 This avoids the need to rebuild the entire project because of a typographical
1763 change in the documentation, or if only a few C source files have changed.
1768 \begin_inset Newline newline
1771 noweb_extract = mkdir -p $(dir $(1)) &&
1774 \begin_inset Newline newline
1777 notangle $(call notangle_args,$(1))
1780 \begin_inset Newline newline
1786 \begin_inset Newline newline
1789 | awk -f notanglefix | cpif "$(1)"
1790 \begin_inset Newline newline
1796 \begin_layout Standard
1797 For some source files like C files, we want to turn on source tracing by
1798 passing additional -L arguments to notangle so that C compile errors will
1799 refer to the line number in this document.
1800 We do this using the makefile macro tangle_line to generate these arguments
1801 for certain file extensions: C_EXTENSIONS.
1806 \begin_inset Newline newline
1810 \begin_inset Newline newline
1813 C_SOURCE_TRACING=-L'
1816 \begin_inset Newline newline
1819 notangle_args = $(if $(findstring $(suffix $(1)),
1822 \begin_inset Newline newline
1825 $(C_EXTENSIONS)),$(C_SOURCE_TRACING))
1826 \begin_inset Newline newline
1832 \begin_layout Standard
1833 Source tracing can be turned off with:
1836 \begin_layout LyX-Code
1837 make notangle_sources C_SOURCE_TRACING=
1840 \begin_layout Standard
1841 We define a target which will extract or update all sources.
1842 Sadly in this first attempt the targets are all extracted in one big command
1848 <<Makefile.inc-sources-big>>=
1849 \begin_inset Newline newline
1852 $(NOWEB_SOURCE_STAMP): $(NOWEB_SOURCE);
1855 \begin_inset Newline newline
1858 $(foreach source,$(NOWEB_SOURCES),
1861 \begin_inset Newline newline
1864 $(call noweb_extract,$(source),$(NOWEB_SOURCE)) &&
1867 \begin_inset Newline newline
1870 ) touch $(NOWEB_SOURCE_STAMP)
1871 \begin_inset Newline newline
1877 \begin_layout Standard
1878 This better alternative defines a target for each extractable source file
1883 extract them individually.
1884 To do this we first defined a makefile template that can do this for any
1889 <<Makefile.inc-sources>>=
1890 \begin_inset Newline newline
1893 define NOTANGLE_template
1894 \begin_inset Newline newline
1900 \begin_inset Newline newline
1903 $(call noweb_extract,$(1),$(2))
1904 \begin_inset Newline newline
1908 \begin_inset Newline newline
1912 \begin_inset Newline newline
1918 \begin_layout Standard
1919 We then enumerate the discovered NOTANGLE_SOURCES to generate a makefile
1920 rule for each one using the makefile template we defined above.
1924 <<Makefile.inc-sources>>=
1925 \begin_inset Newline newline
1928 $(foreach source,$(NOWEB_SOURCES),
1931 \begin_inset Newline newline
1934 $(eval $(call NOTANGLE_template,$(source),$(NOWEB_SOURCE)))
1937 \begin_inset Newline newline
1941 \begin_inset Newline newline
1947 \begin_layout Standard
1948 And finally declare the rule to build them all:
1952 <<Makefile.inc-sources>>=
1953 \begin_inset Newline newline
1956 $(NOWEB_SOURCE_STAMP): $(NOWEB_SOURCE) $(NOWEB_TARGETS);
1959 \begin_inset Newline newline
1962 touch $(NOWEB_SOURCE_STAMP)
1965 \begin_inset Newline newline
1971 \begin_layout Standard
1972 The Makefile.inc is then defined as
1977 \begin_inset Newline newline
1981 \begin_inset Newline newline
1984 <<Makefile.inc-sources>>
1985 \begin_inset Newline newline
1991 \begin_layout Standard
1992 We may as well have notanglefix from section
1993 \begin_inset CommandInset ref
1995 reference "sub:Generally-mangled-notangle"
1999 extracted automatically too, but it will sadly begin with a blank line.
2003 <<./notanglefix.awk>>=
2004 \begin_inset Newline newline
2008 \begin_inset Newline newline
2014 \begin_layout Standard
2015 If Makefile.inc is included into Makefile, then extracted files can be updated
2019 \begin_layout LyX-Code
2023 \begin_layout Standard
2027 \begin_layout LyX-Code
2028 make -f Makefile.inc noweb_sources
2031 \begin_layout Bibliography
2032 \begin_inset CommandInset bibitem
2033 LatexCommand bibitem
2034 label "Extended Lyx Features"
2039 http://nuclear.gla.ac.uk/computing/LyX_doc/Extended.html#tth_sEc6.5