summaryrefslogtreecommitdiff
path: root/autoconf/scripts/makemake.sh
blob: 3eca6c62a8a68686409cdff1920b486cdde51ada (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/sh
#
# Generate Makefile dependencies inclusion and module target file "depend.mk~"
# by scanning the directory "src" for files ending in ".c" and ".d", and for
# subdirectories not starting with "_".
#
# Modules live inside subdirectories called [^_]* - i.e. a directory "foo" will
# have a rule created which links all code inside it to "foo.o".
#
# The directory "src/include" is never scanned; neither are CVS or SVN
# directories.
#

outlist=$1
outlink=$2

FIND=find
GREP=grep
which gfind 2>/dev/null | grep /gfind >/dev/null && FIND=gfind
which ggrep 2>/dev/null | grep /ggrep >/dev/null && GREP=ggrep

echo '# Automatically generated file listings' > $outlist
echo '#' >> $outlist
echo "# Creation time: `date`" >> $outlist
echo >> $outlist

echo '# Automatically generated module linking rules' > $outlink
echo '#' >> $outlink
echo "# Creation time: `date`" >> $outlink
echo >> $outlink

echo -n "Scanning for source files: "

allsrc=`$FIND src -type f -name "*.c" -print`
allobj=`echo $allsrc | tr ' ' '\n' | sed 's/\.c$/.o/'`
alldep=`echo $allsrc | tr ' ' '\n' | sed 's/\.c$/.d/'`

echo `echo $allsrc | wc -w | tr -d ' '` found

echo -n "Scanning for modules: "

modules=`$FIND src -type d -print \
         | $GREP -v '^src$' \
         | $GREP -v '/_' \
         | $GREP -v '^src/include' \
         | $GREP -v 'CVS' \
         | $GREP -v '.svn' \
         | while read DIR; do \
           CONTENT=\$(/bin/ls -d \$DIR/* \
                     | $GREP -v '.po$' \
                     | $GREP -v '.gmo$' \
                     | $GREP -v '.mo$' \
                     | $GREP -v '.h$' \
                     | sed -n '$p'); \
           [ -n "\$CONTENT" ] || continue; \
           echo \$DIR; \
	   done
         `

echo up to `echo $modules | wc -w | tr -d ' '` found

echo "Writing module linking rules"

echo -n [
for i in $modules; do echo -n ' '; done
echo -n -e ']\r['

for i in $modules; do
  echo -n '.'
  allobj="$allobj $i.o"
  deps=""
  for j in $i/*.c; do
    [ -f $j ] || continue
    newobj=`echo $j | sed -e 's@\.c$@.o@'`
    deps="$deps $newobj"
  done
  for j in $i/*; do
    [ -d "$j" ] || continue
    [ `basename $j` = "CVS" ] && continue
    [ `basename $j` = ".svn" ] && continue
    CONTENT=`/bin/ls -d $j/* \
             | $GREP -v '.po$' \
             | $GREP -v '.gmo$' \
             | $GREP -v '.mo$' \
             | $GREP -v '.h$' \
             | sed -n '$p'`
    [ -n "$CONTENT" ] || continue
    deps="$deps $j.o"
  done
  [ -n "$deps" ] || continue
  echo "$i.o: $deps" >> $outlink
  echo '	$(LD) $(LDFLAGS) -o $@' "$deps" >> $outlink
  echo >> $outlink
done

echo ']'

echo "Listing source, object and dependency files"

echo -n "allsrc = " >> $outlist
echo $allsrc | sed 's,src/nls/cat-id-tbl.c,,' | sed -e 's/ / \\!/g'\
| tr '!' '\n' >> $outlist
echo >> $outlist
echo -n "allobj = " >> $outlist
echo $allobj | sed -e 's/ / \\!/g' | tr '!' '\n' >> $outlist
echo >> $outlist
echo -n "alldep = " >> $outlist
echo $alldep | sed -e 's/ / \\!/g' | tr '!' '\n' >> $outlist

echo >> $outlist
echo >> $outlink

# EOF