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