Skip to content

Commit 49e029a

Browse files
committed
stm8l buildlib
1 parent 67f91be commit 49e029a

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

  • sduino/hardware/sduino/stm8/system/STM8L_StdPeriph_Driver
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash
2+
3+
## parameter check
4+
5+
if [ $# -ne 1 ]; then
6+
cat << EOF
7+
split the library into individual source files for every single function,
8+
compile them seperately and pack them all together into one big library.
9+
10+
usage: $0 cputype
11+
12+
supported cpu types:
13+
STM8L15X_HD
14+
LSTM8L15X_MDP
15+
STM8L15X_MD
16+
STM8L15X_LD
17+
EOF
18+
exit 1
19+
fi
20+
21+
CPU=$1
22+
23+
24+
### main part starts here
25+
26+
27+
# define the compile parameter
28+
CC="sdcc"
29+
AR="sdar"
30+
CFLAGS="-mstm8 -D${CPU} -I ../inc -I ../src --opt-code-size -I."
31+
LDFLAGS="-rc"
32+
33+
BUILDDIR="build-${CPU}"
34+
35+
36+
37+
# name of the library: $CPU.lib in lower case
38+
LIBRARY=$(echo ${CPU}|tr '[:upper:]' '[:lower:]').lib
39+
40+
# check the dependencies, generate the list of needed c source files
41+
HFILES=$($CC -mstm8 -Iinc -Isrc -D$CPU "-Wp-MM" -E inc/stm8l15x.h|fmt -1|sed -n 's, *inc/stm8l15x_,stm8l15x_,p')
42+
CFILES=${HFILES//.h/.c}
43+
44+
# debug output
45+
echo "Needed source code modules for CPU $CPU:"
46+
echo $CFILES
47+
echo "Library name: $LIBRARY"
48+
echo "cflags: $CFLAGS"
49+
50+
51+
# the most important function: split on c source file in to a collection
52+
# of single-function source files.
53+
splitit() {
54+
awk "/\/\*\*\r/{n++; file=\"$1-\" n \".c\";print \"#include \\\"$1.h\\\"\">file}{print >file }" ../src/$1
55+
sed "1 d" $1-1.c > $1.h
56+
rm $1-1.c
57+
}
58+
59+
60+
# prepare a fresh build directory
61+
#BUILDDIR=$(mktemp -dp.)
62+
rm -rf $BUILDDIR
63+
mkdir $BUILDDIR
64+
cd $BUILDDIR
65+
echo "using $BUILDDIR"
66+
67+
# split all needed source files into single-function source files
68+
for i in $CFILES; do
69+
splitit $i;
70+
done
71+
72+
# compile all split files
73+
#cp ../compilelib.mk Makefile
74+
#make CPU=$CPU
75+
for i in stm8l15x_*.c; do
76+
echo "compiling $i"
77+
${CC} ${CFLAGS} -c $i || break
78+
done
79+
80+
# build the library
81+
${AR} ${LDFLAGS} ../lib/${LIBRARY} *.rel
82+
83+
# get the generated library
84+
#mv *.lib ..

0 commit comments

Comments
 (0)