1#! /bin/sh
2
3cd image
4
5# Space-optimized version: strip comments, drop precision to 3
6# figures, eliminate duplicates.
7# update(creinig): precision reduction is now done in data2ps and comments
8# (except for % bound) now are also ommitted from the start
9
10echo 'image.ps: image-unop.ps'
11#echo '	grep -v "^%" < $< | sed -e "s/\.\([0-9][0-9]\)[0-9]\+/.\1/g" -e "s/\(^\| \|-\)\([0-9][0-9][0-9]\)[0-9][0-9]\.[0-9][0-9]/\1\200/g" -e "s/\(^\| \|-\)\([0-9][0-9][0-9]\)[0-9]\.[0-9][0-9]/\1\20/g" -e "s/\(^\| \|-\)\([0-9][0-9][0-9]\)\.[0-9][0-9]/\1\2/g" -e "s/\(^\| \|-\)\([0-9][0-9]\)\.\([0-9]\)[0-9]/\1\2.\30/g" | awk "\$$0 ~ /lineto/ { if ( LASTLINE == \$$0 ) next; } { LASTLINE=\$$0; print; }" > $@'
12echo '	grep -v "^% bound" < $< > $@'
13# Need last comment (bounding box)
14echo '	tail -1 $< >> $@'
15echo '	ls -l image.ps image-unop.ps'
16
17echo 'image-unop.ps: outline.ps ring1.ps ring2.ps ring3.ps ring4.ps'
18echo '	cat ring[1234].ps > $@'
19# Bounding box is at bottom now.  Next two won't change it.
20echo '	tail -1 $@ > bounding-box'
21echo '	cat outline.ps >> $@'
22echo '	cat ../tux.ps >> $@'
23echo '	cat bounding-box >> $@ && rm bounding-box'
24
25# Finished rings are precious!
26echo .SECONDARY: ring1.ps ring2.ps ring3.ps ring4.ps
27
28# Rings 1 and 4 are all thrown together.
29echo RING1_DEPS:=`find $RING1 -name '*.c.*' | sed 's/\.c.*/-all.ps/' | sort | uniq`
30echo RING4_DEPS:=`find $RING4 -name '*.c.*' | sed 's/\.c.*/-all.ps/' | sort | uniq`
31
32# Other rings are divided into dirs.
33echo RING2_DEPS:=`for d in $RING2; do echo $d-ring2.ps; done`
34echo RING3_DEPS:=`for d in $RING3; do echo $d-ring3.ps; done`
35echo
36
37# First ring starts at inner radius.
38echo 'ring1.ps: $(RING1_DEPS)'
39echo "	@echo Making Ring 1"
40echo "	@echo /angle 0 def > \$@"
41echo "	@../draw_arrangement $FILE_SCRUNCH 0 360 $INNER_RADIUS \$(RING1_DEPS) >> \$@"
42echo "	@echo Done Ring 1"
43
44# Second ring starts at end of above ring (assume it's circular, so
45# grab any bound).
46echo 'ring2.ps: ring1.ps $(RING2_DEPS)'
47echo "	@echo Making Ring 2"
48echo "	@echo /angle 0 def > \$@"
49echo "	@../rotary_arrange.sh $DIR_SPACING" `for f in $RING2; do echo $f-ring2.ps $f-ring2.angle; done` '>> $@'
50echo "	@echo Done Ring 2"
51
52# Third ring starts at end of second ring.
53echo 'ring3.ps: ring2.ps $(RING3_DEPS)'
54echo "	@echo Making Ring 3"
55echo "	@echo /angle 0 def > \$@"
56echo "	@../rotary_arrange.sh $DIR_SPACING" `for f in $RING3; do echo $f-ring3.ps $f-ring3.angle; done` '>> $@'
57echo "	@echo Done Ring 3"
58
59# Outer ring starts at end of fourth ring.
60# And it's just a big ring of drivers.
61echo 'ring4.ps: $(RING4_DEPS) ring3.radius'
62echo "	@echo Making Ring 4"
63echo "	@echo /angle 0 def > \$@"
64echo "	@../draw_arrangement $FILE_SCRUNCH 0 360 \`cat ring3.radius\` \$(RING4_DEPS) >> \$@"
65echo "	@echo Done Ring 4"
66echo
67
68# How to make directory picture: angle file contains start and end angle.
69# Second ring starts at end of above ring (assume it's circular, so
70# grab any bound).
71echo "%-ring2.ps: %-ring2.angle ring1.radius"
72echo "	@echo Rendering \$@"
73echo "	@../draw_arrangement $FILE_SCRUNCH 0 \`cat \$<\` \`cat ring1.radius\` \`find \$* -name '*-all.ps'\` > \$@"
74
75echo "%-ring3.ps: %-ring3.angle ring2.radius"
76echo "	@echo Rendering \$@"
77echo "	@../draw_arrangement $FILE_SCRUNCH 0 \`cat \$<\` \`cat ring2.radius\` \`find \$* -name '*-all.ps'\` > \$@"
78
79# How to extract radii
80echo "%.radius: %.ps"
81echo '	@echo scale=2\; `tail -1 $< | sed "s/^.* //"` + '$RING_SPACING' | bc > $@'
82echo
83
84# How to make angle.  Need total angle for that directory, and weight.
85echo "%-ring2.angle: %-ring2.weight ring2.weight"
86echo '	@echo "scale=2; ( 360 - ' `echo $RING2 | wc -w` ' * ' $DIR_SPACING ') * `cat $<` / `cat ring2.weight`" | bc > $@'
87
88echo "%-ring3.angle: %-ring3.weight ring3.weight"
89echo '	@echo "scale=2; ( 360 - ' `echo $RING3 | wc -w` ' * ' $DIR_SPACING ') * `cat $<` / `cat ring3.weight`" | bc > $@'
90
91# How to make ring weights (sum directory totals).
92echo "ring2.weight:" `for d in $RING2; do echo $d-ring2.weight; done`
93echo '	@cat $^ | ../tally > $@'
94echo "ring3.weight:" `for d in $RING3; do echo $d-ring3.weight; done`
95echo '	@cat $^ | ../tally > $@'
96
97# How to make a wieght.
98echo "%-ring2.weight:" `find $RING2 -name '*.c.*' | sed 's/\.c.*/-all.ps/' | sort | uniq`
99echo '	@../total_area.pl `find $* -name \*-all.ps` > $@'
100echo "%-ring3.weight:" `find $RING3 -name '*.c.*' | sed 's/\.c.*/-all.ps/' | sort | uniq`
101echo '	@../total_area.pl `find $* -name \*-all.ps` > $@'
102echo
103
104# Now rule to make the graphs of a function.
105#echo %.ps::%
106#echo '	@../function2ps `echo $< | sed '\''s/^.*\.\([^.]*\)\.\+.*$$/\1/'\''` > $@ $<'
107## Need the space.
108##echo '	@rm -f $<'
109#echo
110
111# Rule to make all from constituent parts.
112echo %-all.ps:
113echo "	@echo Rendering \$*.c"
114echo "	@../conglomerate_functions.pl $FUNCTION_SCRUNCH $BOX_SCRUNCH \$^ > \$@"
115# Need the space.
116#echo '	@rm -f $^'
117echo
118
119# Generating outline, requires all the angles.
120echo outline.ps: ../make-outline.sh ring1.ps ring2.ps ring3.ps ring4.ps `for f in $RING2; do echo $f-ring2.angle; done` `for f in $RING3; do echo $f-ring3.angle; done`
121echo "	../make-outline.sh $INNER_RADIUS $DIR_SPACING $RING_SPACING \"$RING1\" > \$@"
122echo
123
124# Now all the rules to make each function.
125for d in `find . -type d`; do
126    for f in `cd $d; ls *+.ps 2>/dev/null | sed 's/\.c\..*$//' | uniq`; do
127	echo $d/$f-all.ps: `cd $d; ls $f.c.* | sed -e "s?^?$d/?"`
128    done
129done
130