9f21ef1729e55a1b7f2b692e0de0f7b6d24d3ba2
[projects.git] / tools / make / c_configure.sh
1 #!/bin/bash
2
3 # util routines for a C/C++ - build
4
5 function check_arch {
6         case $1 in
7         armel) ;;
8         i386) ;;
9         *)      echo "unknown architecture $1"
10                 exit 1
11         esac
12 }
13
14 function install_cpp_make {
15 # $1: dir to install
16         src=$(pwd);
17         pushd $1
18         if [ -f makefile ]; then rm makefile; fi
19         if [ -L makefile ]; then rm makefile; fi
20         if [ -f make.post ]; then rm make.post; fi
21         ln -s $cwd/projects/tools/make/cpp.make makefile
22         echo "SOURCE = \\" > make.pre
23         for file in $(ls *.cpp)
24         do
25                 echo "  $file \\" >> make.pre
26         done
27         echo >> make.pre
28         if [ "$ARCH" = "armel" ]
29         then
30                 echo "CXX = arm-linux-gnueabi-g++" >> make.pre
31                 echo "CC = arm-linux-gnueabi-g++" >> make.pre
32                 echo "CXXFLAGS += -D_ARMEL" >> make.pre
33                 echo 'export PATH := /opt/eldk-5.0/armv5te/sysroots/i686-oesdk-linux/usr/bin/armv5te-linux-gnueabi/:/opt/eldk-5.0/armv5te/sysroots/i686-oesdk-linux/bin/armv5te-linux-gnueabi/:$(PATH)' >> make.pre
34         else
35                 echo "CXXFLAGS += -std=c++0x" >> make.pre
36         fi
37         popd
38 }
39
40 function append_dependency {
41 # adds another drectory, where a c++ compile is performed
42 # parameter:
43 # $1: main directory
44 # $2: dependency directory
45 # $3: dependency artefact
46
47         src=$(pwd)
48         echo "DEPS += $3" >> $1/make.pre
49         echo "$3:" >> $1/make.post
50         echo "  cd $src/$2 && make TARGET=$3" >> $1/make.post
51         echo "" >> $1/make.post
52 }
53
54 function add_include {
55 # adds a include directory
56 # parameter:
57 # $1: main directory
58 # $2: include dir
59
60         src=$(pwd)
61         echo "CXXFLAGS += -I$src/$2" >> $1/make.pre
62 }
63
64 function add_library {
65 # adds a extern library
66 # parameter:
67 # $1: main directory
68 # $2: library name (without l or lib )
69 # $3: library path (optional)
70
71         src=$(pwd)
72         echo "EXTLIB += -l$2" >> $1/make.pre
73         if [ -n "$3" ]
74         then
75                 lib_path=$3
76                 if [ ${lib_path:0:1} != "/" ]
77                 then
78                         lib_path="$src/$lib_path"
79                 fi
80                 echo "LDFLAGS += -L$lib_path" >> $1/make.pre
81         fi
82 }
83
84 function append_library {
85 # same as append_dependency. In addition a include statement + a link to the library is added to "main directory"
86 # parameter:
87 # $1: main directory
88 # $2: dependency directory
89 # $3: dependency artefact
90
91         src=$(pwd)
92         echo "DEPS += $3" >> $1/make.pre
93         echo "LDLIBS += $3" >> $1/make.pre
94         echo "CXXFLAGS += -I$src/$2" >> $1/make.pre
95         echo "$3:" >> $1/make.post
96         echo "  cd $src/$2 && make TARGET=$3" >> $1/make.post
97         echo "  ln -sf $src/$2/$3 ." >> $1/make.post
98         echo "" >> $1/make.post
99 }
100