make/toolchain.sh

Wed, 14 Aug 2024 21:09:52 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 14 Aug 2024 21:09:52 +0200
changeset 71
baa73a0be3ce
parent 0
593b60458157
permissions
-rw-r--r--

centralize draw functions

0
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 #!/bin/sh
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 #
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 # toolchain detection
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 #
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 C_COMPILERS="gcc clang suncc cc"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 CPP_COMPILERS="g++ clang++ sunCC CC"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 unset TOOLCHAIN_NAME
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 unset TOOLCHAIN_CC
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 unset TOOLCHAIN_CXX
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 check_c_compiler()
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 {
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 cat > "$TEMP_DIR/test.c" << __EOF__
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 /* test file */
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 #include <stdio.h>
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 int main(int argc, char **argv) {
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 #if defined(__clang__)
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 printf("clang\n");
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 #elif defined(__GNUC__)
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 printf("gcc\n");
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 #elif defined(__sun)
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 printf("suncc\n");
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 #else
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 printf("unknown\n");
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 #endif
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 return 0;
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28 }
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 __EOF__
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 rm -f "$TEMP_DIR/checkcc"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 $1 -o "$TEMP_DIR/checkcc" $CFLAGS $LDFLAGS "$TEMP_DIR/test.c" 2> /dev/null
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32 }
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 check_cpp_compiler()
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 {
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 cat > "$TEMP_DIR/test.cpp" << __EOF__
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 /* test file */
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 #include <iostream>
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 int main(int argc, char **argv) {
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 #if defined(__clang__)
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 std::cout << "clang" << std::endl;
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 #elif defined(__GNUC__)
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43 std::cout << "gcc" << std::endl;
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 #elif defined(__sun)
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45 std::cout << "suncc" << std::endl;
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46 #else
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
47 std::cout << "cc" << std::endl;
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 #endif
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49 return 0;
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50 }
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51 __EOF__
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 rm -f "$TEMP_DIR/checkcc"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 $1 -o "$TEMP_DIR/checkcc" $CXXFLAGS $LDFLAGS "$TEMP_DIR/test.cpp" 2> /dev/null
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 }
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56 create_libtest_source()
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 {
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 # $1: filename
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 # $2: optional include
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 cat > "$TEMP_DIR/$1" << __EOF__
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61 /* libtest file */
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62 int main(int argc, char **argv) {
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 return 0;
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 }
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 __EOF__
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 if [ -n "$2" ]; then
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 echo "#include <$2>" >> "$TEMP_DIR/$1"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 fi
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69 }
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71 check_c_lib()
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72 {
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
73 # $1: libname
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
74 # $2: optional include
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75 if [ -z "$TOOLCHAIN_CC" ]; then
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
76 return 1
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
77 fi
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78 create_libtest_source "test.c" "$2"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 rm -f "$TEMP_DIR/checklib"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80 $TOOLCHAIN_CC -o "$TEMP_DIR/checklib" $CFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.c" 2> /dev/null
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81 }
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 check_cpp_lib()
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84 {
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85 # $1: libname
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 # $2: optional include
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 if [ -z "$TOOLCHAIN_CXX" ]; then
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 return 1
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 fi
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 create_libtest_source "test.cpp" "$2"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 rm -f "$TEMP_DIR/checklib"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92 $TOOLCHAIN_CXX -o "$TEMP_DIR/checklib" $CXXFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.cpp" 2> /dev/null
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93 }
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95 check_lib()
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 {
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 # $1: libname
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98 # $2: optional include
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 if [ -n "$TOOLCHAIN_CC" ]; then
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 check_c_lib "$1" "$2"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101 elif [ -n "$TOOLCHAIN_CXX" ]; then
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102 check_cpp_lib "$1" "$2"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 fi
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
104 }
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
105
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
106 detect_c_compiler()
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 {
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 if [ -n "$TOOLCHAIN_CC" ]; then
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 return 0
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110 fi
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
111 printf "detect C compiler... "
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112 if [ -n "$CC" ]; then
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113 if check_c_compiler "$CC"; then
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
114 TOOLCHAIN_CC=$CC
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115 TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"`
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 echo "$CC"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117 return 0
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118 else
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 echo "$CC is not a working C compiler"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120 return 1
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 fi
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122 else
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123 for COMP in $C_COMPILERS
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
124 do
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 if check_c_compiler "$COMP"; then
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
126 TOOLCHAIN_CC=$COMP
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
127 TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"`
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
128 echo "$COMP"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129 return 0
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130 fi
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131 done
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132 echo "not found"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
133 return 1
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 fi
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135 }
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137 detect_cpp_compiler()
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138 {
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 if [ -n "$TOOLCHAIN_CXX" ]; then
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140 return 0
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141 fi
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 printf "detect C++ compiler... "
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 if [ -n "$CXX" ]; then
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 if check_cpp_compiler "$CXX"; then
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 TOOLCHAIN_CXX=$CXX
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147 TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"`
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148 echo "$CXX"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 return 0
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 else
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151 echo "$CXX is not a working C++ compiler"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 return 1
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 fi
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 else
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155 for COMP in $CPP_COMPILERS
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156 do
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
157 if check_cpp_compiler "$COMP"; then
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
158 TOOLCHAIN_CXX=$COMP
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
159 TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"`
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160 echo "$COMP"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161 return 0
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 fi
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 done
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
164 echo "${TOOLCHAIN_CXX:-"not found"}"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165 return 1
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166 fi
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167 }
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
168
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
169 write_toolchain_defaults()
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
170 {
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
171 echo "# toolchain" >> "$1"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
172 if [ -n "$TOOLCHAIN_CC" ]; then
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
173 echo "CC = ${TOOLCHAIN_CC}" >> "$1"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
174 fi
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
175 if [ -n "$TOOLCHAIN_CXX" ]; then
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
176 echo "CXX = ${TOOLCHAIN_CXX}" >> "$1"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
177 fi
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
178 echo >> "$1"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
179 if [ -f "make/${TOOLCHAIN_NAME}.mk" ]; then
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
180 cat "make/${TOOLCHAIN_NAME}.mk" >> "$1"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
181 elif [ -f "make/cc.mk" ]; then
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
182 cat "make/cc.mk" >> "$1"
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
183 else
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
184 echo "!!! WARNING !!! Default toolchain flags not found. Configuration might be incomplete."
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
185 fi
593b60458157 initial commit
Mike Becker <universe@uap-core.de>
parents:
diff changeset
186 }

mercurial