57b395e788b6bb6eb109fc0fbe3ef25aead86089
[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 [ "$DEB_HOST_ARCH" != "$DEB_BUILD_ARCH" ]
42         then
43                 #cross compiling
44                 echo "PREFIX = $DEB_HOST_GNU_TYPE-" >> make.pre
45                 echo "SYSROOT = --sysroot=$HOME/cross" >> make.pre
46         fi
47
48         if [ "$ARCH" = "armel" ]
49         then
50                 echo "CXX = arm-linux-gnueabi-g++" >> make.pre
51                 echo "CC = arm-linux-gnueabi-g++" >> make.pre
52                 echo "CXXFLAGS += -D_ARMEL" >> make.pre
53                 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
54         else
55                 echo "CXXFLAGS += -std=c++0x" >> make.pre
56         fi
57         
58         # compilation of libraries need fPIC flag
59         if [ "$2" == "lib" ]
60         then
61                 echo "CXXFLAGS += -fPIC" >> make.pre
62         fi
63
64         popd
65 }
66
67 function append_dependency_common {
68 # common part of append_dependency and append_library
69 # parameter:
70 # $1: main directory
71 # $2: dependency directory
72 # $3: dependency artefact
73
74         src=$(pwd)
75         echo "DEPS += $3" >> $1/make.pre
76         echo "$3:" >> $1/make.post
77         echo "  cd $src/$2 && make TARGET=$3" >> $1/make.post
78 }
79
80 function append_dependency {
81 # adds another drectory, where a c++ compile is performed
82         append_dependency_common $*
83         echo "" >> $1/make.post
84 }
85
86 function add_include {
87 # adds a include directory
88 # parameter:
89 # $1: main directory
90 # $2: include dir
91
92         src=$(pwd)
93         echo "CXXFLAGS += -I$src/$2" >> $1/make.pre
94 }
95
96 function add_library {
97 # adds a extern library
98 # parameter:
99 # $1: main directory
100 # $2: library name (without l or lib )
101 # $3: library path (optional)
102
103         src=$(pwd)
104         echo "EXTLIB += -l$2" >> $1/make.pre
105         if [ -n "$3" ]
106         then
107                 lib_path=$3
108                 if [ ${lib_path:0:1} != "/" ]
109                 then
110                         lib_path="$src/$lib_path"
111                 fi
112                 echo "LDFLAGS += -L$lib_path" >> $1/make.pre
113         fi
114 }
115
116 function append_library {
117 # same as append_dependency. In addition a include statement + a link to the library is added to "main directory"
118 # parameter:
119 # $1: main directory
120 # $2: dependency directory
121 # $3: dependency artefact
122
123         append_dependency_common $*
124         echo "  ln -sf $src/$2/$3 ." >> $1/make.post
125         echo "" >> $1/make.post
126
127         echo "LDLIBS += $3" >> $1/make.pre
128         echo "CXXFLAGS += -I$src/$2" >> $1/make.pre
129
130 }
131