comparison scripts/mk-component.sh @ 13:f10cbd8a51c4

scripts: pruned import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Jul 2018 21:34:56 +0000
parents
children 294b440431fe
comparison
equal deleted inserted replaced
12:e825175be40d 13:f10cbd8a51c4
1 #!/bin/sh
2
3 if [ $# -lt 1 -o $# -gt 2 ]
4 then
5 echo "usage: $0 component-lib [flavor]" 1>&2
6 exit 1
7 fi
8
9 LIBNAME="$1"
10
11 if [ -n "$2" ]
12 then
13 recipe_file="components/$1-$2"
14 else
15 recipe_file="components/$1"
16 fi
17
18 if [ ! -f "$recipe_file" ]
19 then
20 echo "Error: $recipe_file not found" 1>&2
21 exit 1
22 fi
23
24 if [ -z "$BUILD_DIR" ]
25 then
26 echo "Error: BUILD_DIR= must be passed via environment" 1>&2
27 exit 1
28 fi
29
30 set -e
31
32 mkdir -p $BUILD_DIR/$LIBNAME
33
34 # beginning of the Makefile
35 echo "all: $LIBNAME.lib" > $BUILD_DIR/$LIBNAME/Makefile
36 echo >> $BUILD_DIR/$LIBNAME/Makefile
37
38 # shell functions to be used in the recipes
39
40 make_version() {
41 case $# in
42 1)
43 echo "$1_version.c:" >> $BUILD_DIR/$LIBNAME/Makefile
44 echo " ../../scripts/make-version.sh $1 > $1_version.c" \
45 >> $BUILD_DIR/$LIBNAME/Makefile
46 ;;
47 2)
48 echo "$2_version.c:" >> $BUILD_DIR/$LIBNAME/Makefile
49 echo " ../../scripts/make-version.sh $1 > $2_version.c" \
50 >> $BUILD_DIR/$LIBNAME/Makefile
51 ;;
52 *)
53 echo "Error: make_version takes 1 or 2 arguments" 1>&2
54 exit 1
55 ;;
56 esac
57 echo >> $BUILD_DIR/$LIBNAME/Makefile
58 }
59
60 asm_file() {
61 if [ $# != 1 ]
62 then
63 echo "Error: asm_file takes 1 argument" 1>&2
64 exit 1
65 fi
66 objname=`basename "$1" .s`.obj
67 helpers/makeline dep $objname "$1" >> $BUILD_DIR/$LIBNAME/Makefile
68 helpers/makeline cmd ../../toolwrap/asm470 ${ASMFLAGS} "$1" '$@' \
69 >> $BUILD_DIR/$LIBNAME/Makefile
70 echo >> $BUILD_DIR/$LIBNAME/Makefile
71 OBJS="$OBJS $objname"
72 }
73
74 cfile_plain() {
75 if [ $# != 1 ]
76 then
77 echo "Error: cfile_plain takes 1 argument" 1>&2
78 exit 1
79 fi
80 objname=`basename "$1" .c`.obj
81 helpers/makeline dep $objname "$1" >> $BUILD_DIR/$LIBNAME/Makefile
82 case "$objname" in
83 *[A-Z]*)
84 helpers/makeline cmd rm -f '$@' \
85 >> $BUILD_DIR/$LIBNAME/Makefile
86 ;;
87 esac
88 helpers/makeline cmd ../../toolwrap/cl470 -q -c ${CFLAGS} ${CPPFLAGS} \
89 "$1" >> $BUILD_DIR/$LIBNAME/Makefile
90 case "$objname" in
91 *[A-Z]*)
92 objname_lc=`echo $objname | tr A-Z a-z`
93 helpers/makeline cmd mv $objname_lc $objname \
94 >> $BUILD_DIR/$LIBNAME/Makefile
95 ;;
96 esac
97 echo >> $BUILD_DIR/$LIBNAME/Makefile
98 OBJS="$OBJS $objname"
99 }
100
101 cfile_str2ind() {
102 if [ $# != 1 ]
103 then
104 echo "Error: cfile_str2ind takes 1 argument" 1>&2
105 exit 1
106 fi
107 if [ "$USE_STR2IND" = 1 ]
108 then
109 objname=`basename "$1" .c`.obj
110 pp_name=`echo $1 | sed -e 's/\.c$/.pp/' | tr A-Z a-z`
111 pp__name=`echo $1 | sed -e 's/\.c$/.pp_/' | tr A-Z a-z`
112 helpers/makeline dep $objname "$1" \
113 >> $BUILD_DIR/$LIBNAME/Makefile
114 case "$objname" in
115 *[A-Z]*)
116 helpers/makeline cmd rm -f '$@' \
117 >> $BUILD_DIR/$LIBNAME/Makefile
118 ;;
119 esac
120 helpers/makeline cmd ../../toolwrap/cl470 -q -po -p? -x \
121 ${CPPFLAGS} "$1" >> $BUILD_DIR/$LIBNAME/Makefile
122 helpers/makeline cmd ../../toolwrap/str2ind -a \
123 -t ../str2ind.tab -l ../str2ind.log \
124 -f "$pp_name" >> $BUILD_DIR/$LIBNAME/Makefile
125 helpers/makeline cmd ../../toolwrap/cl470 -q -c ${CFLAGS} \
126 "$pp__name" >> $BUILD_DIR/$LIBNAME/Makefile
127 helpers/makeline cmd @rm -f "$pp_name" \
128 >> $BUILD_DIR/$LIBNAME/Makefile
129 helpers/makeline cmd @rm -f "$pp__name" \
130 >> $BUILD_DIR/$LIBNAME/Makefile
131 case "$objname" in
132 *[A-Z]*)
133 objname_lc=`echo $objname | tr A-Z a-z`
134 helpers/makeline cmd mv $objname_lc $objname \
135 >> $BUILD_DIR/$LIBNAME/Makefile
136 ;;
137 esac
138 echo >> $BUILD_DIR/$LIBNAME/Makefile
139 OBJS="$OBJS $objname"
140 else
141 cfile_plain "$1"
142 fi
143 }
144
145 # invoke the recipe
146
147 SRC=../../src
148 OBJS=
149 . "$recipe_file"
150
151 # finish the Makefile
152
153 helpers/makeline dep $LIBNAME.lib ${OBJS} >> $BUILD_DIR/$LIBNAME/Makefile
154 echo ' ../../toolwrap/ar470 r $@ $^' >> $BUILD_DIR/$LIBNAME/Makefile
155 echo >> $BUILD_DIR/$LIBNAME/Makefile
156 echo 'clean:' >> $BUILD_DIR/$LIBNAME/Makefile
157 echo ' rm -f *.obj *.lib *.c' >> $BUILD_DIR/$LIBNAME/Makefile