e7180669 |
1 | #!/bin/bash |
2 | |
c4ba7a9a |
3 | if [ ! "$MAKE" ]; then |
4 | echo "Not run from within Makefile!" |
5 | exit 4 |
6 | fi |
e7180669 |
7 | |
e7180669 |
8 | |
e7180669 |
9 | # The suffix for library files (in and out) |
10 | LIB_SUFFIX=.lib |
11 | ####################################################################### |
c4ba7a9a |
12 | IFS=" |
13 | " |
e7180669 |
14 | |
15 | # Clean everything up |
16 | clean() { |
c4ba7a9a |
17 | rm -rf $LIB_DIR $ORG_OBJDIR |
e7180669 |
18 | } |
19 | |
20 | # Generate org directory containing the original library objects |
21 | make_org() { |
22 | if [ ! -d "$ORG_OBJDIR" ]; then |
fe67c7be |
23 | echo "Buildlib: Creating directory $ORG_OBJDIR." |
24 | mkdir $ORG_OBJDIR |
e7180669 |
25 | fi |
26 | tdir=$PWD |
27 | cd $ORG_OBJDIR |
fe67c7be |
28 | cat $tdir/$ORG_LIBDIR/*$LIB_SUFFIX | ldc -saq |
e7180669 |
29 | cd $tdir |
fe67c7be |
30 | touch $ORG_OBJDIR/lastrun |
e7180669 |
31 | } |
32 | |
33 | genlib(){ |
c4ba7a9a |
34 | if [ ! -d "$LIB_DIR" ]; then |
35 | echo -n "Creating $LIB_DIR:" |
36 | mkdir $LIB_DIR && echo "Ok." || echo "FAILED!" |
e7180669 |
37 | fi |
38 | |
c4ba7a9a |
39 | recipe=$1 |
40 | lib=$LIB_DIR/`basename $recipe $RECIPE_SUFFIX`$LIB_SUFFIX |
fe67c7be |
41 | echo -e "\nBuildlib: Building library \"$lib\" using recipe \"$1\":" |
e7180669 |
42 | rm -f $lib |
c4ba7a9a |
43 | for item in `cat $recipe| egrep -v '^[[:space:]]*(#.*)*$'`; do |
fe67c7be |
44 | iname=`echo $item | egrep -o '[^[:space:]].*[^[:space:]]' |sed 's/.obj$//g'` |
45 | echo "Buildlib: Appending \"$iname"\" |
46 | cat $iname >> $lib || (echo "Error! could not find:$item";exit 3) |
e7180669 |
47 | done |
48 | cat $ENDBLOCK >> $lib |
fe67c7be |
49 | echo "Buildlib: Done." |
e7180669 |
50 | } |
51 | |
e7180669 |
52 | case $1 in |
53 | clean) |
e7180669 |
54 | clean |
6f41bb44 |
55 | # echo "Buildlib: Cleaning up." |
e7180669 |
56 | ;; |
57 | makeorg) |
fe67c7be |
58 | echo "Buildlib: Splitting original libraries." |
e7180669 |
59 | make_org |
60 | ;; |
c4ba7a9a |
61 | genlib) |
c4ba7a9a |
62 | genlib $2 |
e7180669 |
63 | ;; |
64 | *) |
65 | clean |
66 | make_org |
67 | genlib |
68 | ;; |
69 | esac |
70 | |