Added script that updates list of source files for CMake build
[platform/core/uifw/dali-core.git] / build / tizen-cmake / update-file-lists.sh
1 #!/bin/bash
2
3 # check if there is 'realpath' tool installed
4 if [ "$(which realpath)" == "" ] ; then
5   echo "You need 'realpath' to run this script."
6   echo "to install: apt-get install realpath"
7   exit
8 fi
9
10 # test whether script is running in the right directory
11 if [[ $(realpath $(pwd)) != $(realpath $(dirname $0)) ]] ; then
12   echo "Error! You must launch this script from tizen-cmake directory!"
13   exit 0
14 fi
15
16 function find_file_lists_dirs()
17 {
18   for f in $(find ../../ -name 'file.list') ; do
19     dirname $(realpath $f);
20   done
21 }
22
23 # now prepare file-lists
24 # read line by line
25 # 1. line with '=' defines variable name
26 # 2. line with '#' defines comment
27 function write_cmake_file_lists()
28 {
29   doxy=
30
31   function update_list()
32   {
33     if [[ "$2" != "" ]] ; then
34       # update sources, headers, doxy
35       echo "  *** Updating $1 list..." >&2
36       echo ""
37       echo "SET( $1 \${$1}"
38       for var in $2 ; do
39         echo "  \${${var}}"
40       done
41       echo ")"
42     fi
43   }
44
45   for file_list_dir in ${file_cmake_lists} ; do
46     sources=
47     public_headers=
48     devel_headers=
49     integration_headers=
50     outfile=$file_list_dir/file-list.cmake
51     echo " * Writing $(realpath --relative-base=../../ $file_list_dir)/file-list.cmake..."
52     echo "# This file is auto-generated!" > $outfile
53     echo "#" >> $outfile
54
55     # look for *_src_dir variables ( should be just one ) and
56     # substitute it with current path
57     for dirpath in $(grep -oE '\(.*_src_dir\)' $file_list_dir/file.list | sort -u) ; do
58       src_dir=${dirpath:1:-1}
59       new_path=$(realpath --relative-base=../../ $file_list_dir)
60       echo -e "\n# Set the source directory\n" >> $outfile
61       echo "SET( $src_dir \${ROOT_SRC_DIR}/$new_path )" >> $outfile
62       echo "" >>$outfile
63     done
64     variable=
65     comment=
66     lines=$(cat $file_list_dir/file.list | sed -e 's/ /|/g;')
67     for l in $lines ; do
68       is_var=$(echo $l | grep '=')
69       is_comment=$(echo $l | grep '#')
70       if [ "$is_comment" ] ; then
71         comment="$(echo "$l" | sed -e 's/|/ /g;')"
72       elif [ "$is_var" ] ; then
73         if [ "$variable" ] ; then
74           echo ")"  >> $outfile
75           echo "" >> $outfile
76         fi
77         echo $comment >> $outfile
78         comment=
79         variable=$(echo $is_var | sed -e 's/|//g;' | awk -F '=' '{print $1}')
80         echo "SET( $variable " >> $outfile
81
82         # collect sources, headers and doxy to compile final
83         # set of vars to be included
84         if [[ ${variable:${#variable}-9:9} = src_files ]] ; then
85           sources="${sources} $variable"
86         elif [[ ${variable:${#variable}-12:12} = header_files ]] ; then
87           if [[ ${variable} = devel_api* ]] ; then
88             devel_headers="${devel_headers} $variable"
89           elif [[ ${variable} = public_api* ]] ; then
90             public_headers="${public_headers} $variable"
91           elif [[ ${variable} = platform_abstraction_* ]] ; then
92             integration_headers="${integration_headers} $variable"
93           else
94             echo "ERROR! Variable $variable in $file_list_dir unrecoginzed!"
95             exit 0
96           fi
97         elif [[ ${variable:${#variable}-10:10} = doxy_files ]] ; then
98           doxy="${doxy} $variable"
99         fi
100       else
101         echo "$(echo "$l" | sed -e 's/(/{/g;s/)/}/g;s/|/ /g;s/\\//g;')" >> $outfile
102       fi
103     done
104     if [ "$variable" ] ; then
105       echo ")" >> $outfile
106       echo "" >> $outfile
107     fi
108
109     update_list SOURCES "$sources" >> $outfile
110
111     update_list PUBLIC_API_HEADERS "$public_headers" >>$outfile
112
113     update_list DEVEL_API_HEADERS "$devel_headers" >>$outfile
114
115     update_list INTEGRATION_API_HEADERS "$integration_headers" >>$outfile
116
117     # Remove trailing whitespaces
118     cat $outfile | sed -e 's/[[:space:]]*$//' > /tmp/file-list.cmake
119     mv /tmp/file-list.cmake $outfile
120     echo "  * Done"
121   done
122
123 }
124
125 export file_cmake_lists=$(find_file_lists_dirs)
126
127 write_cmake_file_lists
128