246f1ed6ed6dc652fa05b16d5ff6aaaeeb7e36cf
[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 # $2 (opt): if set to "lib" the fPIC flag is added
17
18         # find makefile
19         if [ -f /usr/share/mbuild/cpp.make ]
20         then
21                 makefile=/usr/share/mbuild/cpp.make
22         elif [ -f $cwd/projects/tools/make/cpp.make ]
23         then
24                 makefile=$cwd/projects/tools/make/cpp.make
25         else
26                 echo "cannot find cpp makefile." >&2
27                 exit 1
28         fi
29         src=$(pwd);
30         pushd $1
31         if [ -f makefile ]; then rm makefile; fi
32         if [ -L makefile ]; then rm makefile; fi
33         if [ -f make.post ]; then rm make.post; fi
34         ln -s $makefile makefile
35         echo "SOURCE = \\" > make.pre
36         for file in $(ls *.cpp)
37         do
38                 echo "  $file \\" >> make.pre
39         done
40         echo >> make.pre
41         if [ "$ARCH" = "armel" ]
42         then
43                 echo "CXX = arm-linux-gnueabi-g++" >> make.pre
44                 echo "CC = arm-linux-gnueabi-g++" >> make.pre
45                 echo "CXXFLAGS += -D_ARMEL" >> make.pre
46                 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
47         else
48                 echo "CXXFLAGS += -std=c++0x" >> make.pre
49         fi
50         
51         # compilation of libraries need fPIC flag
52         if [ "$2" == "lib" ]
53         then
54                 echo "CXXFLAGS += -fPIC" >> make.pre
55         fi
56
57         popd
58 }
59
60 function append_dependency_common {
61 # common part of append_dependency and append_library
62 # parameter:
63 # $1: main directory
64 # $2: dependency directory
65 # $3: dependency artefact
66
67         src=$(pwd)
68         echo "DEPS += $3" >> $1/make.pre
69         echo "$3:" >> $1/make.post
70         echo "  cd $src/$2 && make TARGET=$3" >> $1/make.post
71 }
72
73 function append_dependency {
74 # adds another drectory, where a c++ compile is performed
75         append_dependency_common $*
76         echo "" >> $1/make.post
77 }
78
79 function add_include {
80 # adds a include directory
81 # parameter:
82 # $1: main directory
83 # $2: include dir
84
85         src=$(pwd)
86         echo "CXXFLAGS += -I$src/$2" >> $1/make.pre
87 }
88
89 function add_library {
90 # adds a extern library
91 # parameter:
92 # $1: main directory
93 # $2: library name (without l or lib )
94 # $3: library path (optional)
95
96         src=$(pwd)
97         echo "EXTLIB += -l$2" >> $1/make.pre
98         if [ -n "$3" ]
99         then
100                 lib_path=$3
101                 if [ ${lib_path:0:1} != "/" ]
102                 then
103                         lib_path="$src/$lib_path"
104                 fi
105                 echo "LDFLAGS += -L$lib_path" >> $1/make.pre
106         fi
107 }
108
109 function append_library {
110 # same as append_dependency. In addition a include statement + a link to the library is added to "main directory"
111 # parameter:
112 # $1: main directory
113 # $2: dependency directory
114 # $3: dependency artefact
115
116         append_dependency_common $*
117         echo "  ln -sf $src/$2/$3 ." >> $1/make.post
118         echo "" >> $1/make.post
119
120         echo "LDLIBS += $3" >> $1/make.pre
121         echo "CXXFLAGS += -I$src/$2" >> $1/make.pre
122
123 }
124