Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: third_party/libvpx/generate_gni.sh

Issue 2318053003: Remove gyp support from libvpx (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libvpx/ads2gas.gypi ('k') | third_party/libvpx/generate_gypi.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/bash -e 1 #!/bin/bash -e
2 # 2 #
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 # This script is used to generate .gypi, .gni files and files in the 7 # This script is used to generate .gni files and files in the
8 # config/platform directories needed to build libvpx. 8 # config/platform directories needed to build libvpx.
9 # Every time libvpx source code is updated just run this script. 9 # Every time libvpx source code is updated just run this script.
10 # 10 #
11 # Usage: 11 # Usage:
12 # $ ./generate_gypi.sh [--disable-avx] [--only-configs] 12 # $ ./generate_gni.sh [--disable-avx] [--only-configs]
13 # 13 #
14 # The following optional flags are supported: 14 # The following optional flags are supported:
15 # --disable-avx : AVX+AVX2 support is disabled. 15 # --disable-avx : AVX+AVX2 support is disabled.
16 # --only-configs: Excludes generation of GN and GYP files (i.e. only 16 # --only-configs: Excludes generation of GN and GYP files (i.e. only
17 # configuration headers are generated). 17 # configuration headers are generated).
18 18
19 export LC_ALL=C 19 export LC_ALL=C
20 BASE_DIR=$(pwd) 20 BASE_DIR=$(pwd)
21 LIBVPX_SRC_DIR="source/libvpx" 21 LIBVPX_SRC_DIR="source/libvpx"
22 LIBVPX_CONFIG_DIR="source/config" 22 LIBVPX_CONFIG_DIR="source/config"
(...skipping 23 matching lines...) Expand all
46 echo "# This file is generated. Do not edit." >> $1 46 echo "# This file is generated. Do not edit." >> $1
47 echo "# Copyright (c) 2014 The Chromium Authors. All rights reserved." >> $1 47 echo "# Copyright (c) 2014 The Chromium Authors. All rights reserved." >> $1
48 echo "# Use of this source code is governed by a BSD-style license that can be " >> $1 48 echo "# Use of this source code is governed by a BSD-style license that can be " >> $1
49 echo "# found in the LICENSE file." >> $1 49 echo "# found in the LICENSE file." >> $1
50 echo "" >> $1 50 echo "" >> $1
51 } 51 }
52 52
53 # Search for source files with the same basename in vp8, vp9, and vpx_dsp. The 53 # Search for source files with the same basename in vp8, vp9, and vpx_dsp. The
54 # build can support such files but only when they are built into disparate 54 # build can support such files but only when they are built into disparate
55 # modules. Configuring such modules for both gyp and gn are tricky so avoid the 55 # modules. Configuring such modules for both gyp and gn are tricky so avoid the
56 # issue at least until vp10 is added. 56 # issue at least until gyp is removed.
57 function find_duplicates { 57 function find_duplicates {
58 local readonly duplicate_file_names=$(find \ 58 local readonly duplicate_file_names=$(find \
59 $BASE_DIR/$LIBVPX_SRC_DIR/vp8 \ 59 $BASE_DIR/$LIBVPX_SRC_DIR/vp8 \
60 $BASE_DIR/$LIBVPX_SRC_DIR/vp9 \ 60 $BASE_DIR/$LIBVPX_SRC_DIR/vp9 \
61 $BASE_DIR/$LIBVPX_SRC_DIR/vpx_dsp \ 61 $BASE_DIR/$LIBVPX_SRC_DIR/vpx_dsp \
62 -type f -name \*.c | xargs -I {} basename {} | sort | uniq -d \ 62 -type f -name \*.c | xargs -I {} basename {} | sort | uniq -d \
63 ) 63 )
64 64
65 if [ -n "${duplicate_file_names}" ]; then 65 if [ -n "${duplicate_file_names}" ]; then
66 echo "WARNING: DUPLICATE FILES FOUND" 66 echo "WARNING: DUPLICATE FILES FOUND"
67 for file in ${duplicate_file_names}; do 67 for file in ${duplicate_file_names}; do
68 find \ 68 find \
69 $BASE_DIR/$LIBVPX_SRC_DIR/vp8 \ 69 $BASE_DIR/$LIBVPX_SRC_DIR/vp8 \
70 $BASE_DIR/$LIBVPX_SRC_DIR/vp9 \ 70 $BASE_DIR/$LIBVPX_SRC_DIR/vp9 \
71 $BASE_DIR/$LIBVPX_SRC_DIR/vpx_dsp \ 71 $BASE_DIR/$LIBVPX_SRC_DIR/vpx_dsp \
72 -name $file 72 -name $file
73 done 73 done
74 exit 1 74 exit 1
75 fi 75 fi
76 } 76 }
77 77
78 # Print gypi boilerplate header.
79 # $1 - Output base name
80 function write_gypi_header {
81 echo "{" >> $1
82 }
83
84 # Print gypi boilerplate footer.
85 # $1 - Output base name
86 function write_gypi_footer {
87 echo "}" >> $1
88 }
89
90 # Generate a gypi with a list of source files.
91 # $1 - Array name for file list. This is processed with 'declare' below to
92 # regenerate the array locally.
93 # $2 - Output file
94 function write_gypi {
95 # Convert the first argument back in to an array.
96 local readonly file_list=(${!1})
97
98 rm -rf "$2"
99 write_license "$2"
100 write_gypi_header "$2"
101
102 echo " 'sources': [" >> "$2"
103 for f in ${file_list[@]}
104 do
105 echo " '<(libvpx_source)/$f'," >> "$2"
106 done
107 echo " ]," >> "$2"
108
109 write_gypi_footer "$2"
110 }
111
112 # Generate a gni with a list of source files. 78 # Generate a gni with a list of source files.
113 # $1 - Array name for file list. This is processed with 'declare' below to 79 # $1 - Array name for file list. This is processed with 'declare' below to
114 # regenerate the array locally. 80 # regenerate the array locally.
115 # $2 - GN variable name. 81 # $2 - GN variable name.
116 # $3 - Output file. 82 # $3 - Output file.
117 function write_gni { 83 function write_gni {
118 # Convert the first argument back in to an array. 84 # Convert the first argument back in to an array.
119 declare -a file_list=("${!1}") 85 declare -a file_list=("${!1}")
120 86
121 echo "$2 = [" >> "$3" 87 echo "$2 = [" >> "$3"
122 for f in $file_list 88 for f in $file_list
123 do 89 do
124 echo " \"//third_party/libvpx/source/libvpx/$f\"," >> "$3" 90 echo " \"//third_party/libvpx/source/libvpx/$f\"," >> "$3"
125 done 91 done
126 echo "]" >> "$3" 92 echo "]" >> "$3"
127 } 93 }
128 94
129 # Target template function 95 # Convert a list of source files into gni files.
130 # $1 - Array name for file list.
131 # $2 - Output file
132 # $3 - Target name
133 # $4 - Compiler flag
134 function write_target_definition {
135 declare -a sources_list=("${!1}")
136
137 echo " {" >> "$2"
138 echo " 'target_name': '$3'," >> "$2"
139 echo " 'type': 'static_library'," >> "$2"
140 echo " 'include_dirs': [" >> "$2"
141 echo " 'source/config/<(OS_CATEGORY)/<(target_arch_full)'," >> "$2"
142 echo " '<(libvpx_source)'," >> "$2"
143 echo " ]," >> "$2"
144 echo " 'sources': [" >> "$2"
145 for f in $sources_list
146 do
147 echo " '<(libvpx_source)/$f'," >> $2
148 done
149 echo " ]," >> "$2"
150 if [[ $4 == fpu=neon ]]; then
151 echo " 'includes': [ 'ads2gas.gypi' ]," >> "$2"
152 echo " 'cflags!': [ '-mfpu=vfpv3-d16' ]," >> "$2"
153 echo " 'conditions': [" >> $2
154 echo " # Disable GCC LTO in neon targets due to compiler bug" >> "$2"
155 echo " # crbug.com/408997" >> "$2"
156 echo " ['clang==0 and use_lto==1', {" >> "$2"
157 echo " 'cflags!': [" >> "$2"
158 echo " '-flto'," >> "$2"
159 echo " '-ffat-lto-objects'," >> "$2"
160 echo " ]," >> "$2"
161 echo " }]," >> "$2"
162 echo " ]," >> "$2"
163 echo " 'cflags': [ '-m$4', ]," >> "$2"
164 echo " 'asmflags': [ '-m$4', ]," >> "$2"
165 else
166 echo " 'cflags': [ '-m$4', ]," >> "$2"
167 echo " 'xcode_settings': { 'OTHER_CFLAGS': [ '-m$4' ] }," >> "$2"
168 fi
169 if [[ -z $DISABLE_AVX && $4 == avx ]]; then
170 echo " 'msvs_settings': {" >> "$2"
171 echo " 'VCCLCompilerTool': {" >> "$2"
172 echo " 'EnableEnhancedInstructionSet': '3', # /arch:AVX" >> "$2"
173 echo " }," >> "$2"
174 echo " }," >> "$2"
175 fi
176 if [[ -z $DISABLE_AVX && $4 == avx2 ]]; then
177 echo " 'msvs_settings': {" >> "$2"
178 echo " 'VCCLCompilerTool': {" >> "$2"
179 echo " 'EnableEnhancedInstructionSet': '5', # /arch:AVX2" >> "$2"
180 echo " }," >> "$2"
181 echo " }," >> "$2"
182 fi
183 if [[ $4 == ssse3 || $4 == sse4.1 ]]; then
184 echo " 'conditions': [" >> "$2"
185 echo " ['OS==\"win\" and clang==1', {" >> "$2"
186 echo " # cl.exe's /arch flag doesn't have a setting for SSSE3/4, and cl.exe" >> "$2"
187 echo " # doesn't need it for intrinsics. clang-cl does need it, thoug h." >> "$2"
188 echo " 'msvs_settings': {" >> "$2"
189 echo " 'VCCLCompilerTool': { 'AdditionalOptions': [ '-m$4' ] }," >> "$2"
190 echo " }," >> "$2"
191 echo " }]," >> "$2"
192 echo " ]," >> "$2"
193 fi
194 echo " }," >> "$2"
195 }
196
197
198 # Generate a gypi which applies additional compiler flags based on the file
199 # name.
200 # $1 - Array name for file list.
201 # $2 - Output file
202 function write_intrinsics_gypi {
203 declare -a file_list=("${!1}")
204
205 local mmx_sources=$(echo "$file_list" | grep '_mmx\.c$')
206 local sse2_sources=$(echo "$file_list" | grep '_sse2\.c$')
207 local sse3_sources=$(echo "$file_list" | grep '_sse3\.c$')
208 local ssse3_sources=$(echo "$file_list" | grep '_ssse3\.c$')
209 local sse4_1_sources=$(echo "$file_list" | grep '_sse4\.c$')
210 local avx_sources=$(echo "$file_list" | grep '_avx\.c$')
211 local avx2_sources=$(echo "$file_list" | grep '_avx2\.c$')
212 local neon_sources=$(echo "$file_list" | grep '_neon\.c$\|\.asm$')
213
214 # Intrinsic functions and files are in flux. We can selectively generate them
215 # but we can not selectively include them in libvpx.gyp. Throw some errors
216 # when new targets are needed.
217
218 rm -rf "$2"
219 write_license "$2"
220 write_gypi_header "$2"
221
222 echo " 'targets': [" >> "$2"
223
224 # x86[_64]
225 if [ 0 -ne ${#mmx_sources} ]; then
226 write_target_definition mmx_sources[@] "$2" libvpx_intrinsics_mmx mmx
227 fi
228 if [ 0 -ne ${#sse2_sources} ]; then
229 write_target_definition sse2_sources[@] "$2" libvpx_intrinsics_sse2 sse2
230 fi
231 if [ 0 -ne ${#sse3_sources} ]; then
232 #write_target_definition sse3_sources[@] "$2" libvpx_intrinsics_sse3 sse3
233 echo "ERROR: Uncomment sse3 sections in libvpx.gyp"
234 exit 1
235 fi
236 if [ 0 -ne ${#ssse3_sources} ]; then
237 write_target_definition ssse3_sources[@] "$2" libvpx_intrinsics_ssse3 ssse3
238 fi
239 if [ 0 -ne ${#sse4_1_sources} ]; then
240 write_target_definition sse4_1_sources[@] "$2" libvpx_intrinsics_sse4_1 sse4 .1
241 fi
242 if [[ -z $DISABLE_AVX && 0 -ne ${#avx_sources} ]]; then
243 write_target_definition avx_sources[@] "$2" libvpx_intrinsics_avx avx
244 fi
245 if [[ -z $DISABLE_AVX && 0 -ne ${#avx2_sources} ]]; then
246 write_target_definition avx2_sources[@] "$2" libvpx_intrinsics_avx2 avx2
247 fi
248
249 # arm neon
250 if [ 0 -ne ${#neon_sources} ]; then
251 write_target_definition neon_sources[@] "$2" libvpx_intrinsics_neon fpu=neon
252 fi
253
254 echo " ]," >> "$2"
255
256 write_gypi_footer "$2"
257 }
258
259 # Convert a list of source files into gypi and gni files.
260 # $1 - Input file. 96 # $1 - Input file.
261 # $2 - Output gypi file base. Will generate additional .gypi files when
262 # different compilation flags are required.
263 function convert_srcs_to_project_files { 97 function convert_srcs_to_project_files {
264 # Do the following here: 98 # Do the following here:
265 # 1. Filter .c, .h, .s, .S and .asm files. 99 # 1. Filter .c, .h, .s, .S and .asm files.
266 # 2. Move certain files to a separate include to allow applying different 100 # 2. Move certain files to a separate lists to allow applying different
267 # compiler options. 101 # compiler options.
268 # 3. Replace .asm.s to .asm because gyp will do the conversion. 102 # 3. Replace .asm.s to .asm because gn will do the conversion.
269 103
270 local source_list=$(grep -E '(\.c|\.h|\.S|\.s|\.asm)$' $1) 104 local source_list=$(grep -E '(\.c|\.h|\.S|\.s|\.asm)$' $1)
271 105
272 # Not sure why vpx_config is not included. 106 # Not sure why vpx_config.c is not included.
273 source_list=$(echo "$source_list" | grep -v 'vpx_config\.c') 107 source_list=$(echo "$source_list" | grep -v 'vpx_config\.c')
274 108
275 # The actual ARM files end in .asm. We have rules to translate them to .S 109 # The actual ARM files end in .asm. We have rules to translate them to .S
276 source_list=$(echo "$source_list" | sed s/\.asm\.s$/.asm/) 110 source_list=$(echo "$source_list" | sed s/\.asm\.s$/.asm/)
277 111
278 # Select all x86 files ending with .c 112 # Select all x86 files ending with .c
279 local intrinsic_list=$(echo "$source_list" | \ 113 local intrinsic_list=$(echo "$source_list" | \
280 egrep '(mmx|sse2|sse3|ssse3|sse4|avx|avx2).c$') 114 egrep '(mmx|sse2|sse3|ssse3|sse4|avx|avx2).c$')
281 115
282 # Select all neon files ending in C but only when building in RTCD mode 116 # Select all neon files ending in C but only when building in RTCD mode
283 if [ "libvpx_srcs_arm_neon_cpu_detect" == "$2" ]; then 117 if [ "libvpx_srcs_arm_neon_cpu_detect" == "$2" ]; then
284 # Select all arm neon files ending in _neon.c and all asm files. 118 # Select all arm neon files ending in _neon.c and all asm files.
285 # The asm files need to be included in the intrinsics target because 119 # The asm files need to be included in the intrinsics target because
286 # they need the -mfpu=neon flag. 120 # they need the -mfpu=neon flag.
287 # the pattern may need to be updated if vpx_scale gets intrinics 121 # the pattern may need to be updated if vpx_scale gets intrinics
288 local intrinsic_list=$(echo "$source_list" | \ 122 local intrinsic_list=$(echo "$source_list" | \
289 egrep 'neon.*(\.c|\.asm)$') 123 egrep 'neon.*(\.c|\.asm)$')
290 fi 124 fi
291 125
292 # Remove these files from the main list. 126 # Remove these files from the main list.
293 source_list=$(comm -23 <(echo "$source_list") <(echo "$intrinsic_list")) 127 source_list=$(comm -23 <(echo "$source_list") <(echo "$intrinsic_list"))
294 128
295 local x86_list=$(echo "$source_list" | egrep '/x86/') 129 local x86_list=$(echo "$source_list" | egrep '/x86/')
296 130
297 write_gypi source_list "$BASE_DIR/$2.gypi"
298
299 # All the files are in a single "element." Check if the first element has
300 # length 0.
301 if [ 0 -ne ${#intrinsic_list} ]; then
302 write_intrinsics_gypi intrinsic_list[@] "$BASE_DIR/$2_intrinsics.gypi"
303 fi
304
305 # Write a single .gni file that includes all source files for all archs. 131 # Write a single .gni file that includes all source files for all archs.
306 if [ 0 -ne ${#x86_list} ]; then 132 if [ 0 -ne ${#x86_list} ]; then
307 local c_sources=$(echo "$source_list" | egrep '.(c|h)$') 133 local c_sources=$(echo "$source_list" | egrep '.(c|h)$')
308 local assembly_sources=$(echo "$source_list" | egrep '.asm$') 134 local assembly_sources=$(echo "$source_list" | egrep '.asm$')
309 local mmx_sources=$(echo "$intrinsic_list" | grep '_mmx\.c$') 135 local mmx_sources=$(echo "$intrinsic_list" | grep '_mmx\.c$')
310 local sse2_sources=$(echo "$intrinsic_list" | grep '_sse2\.c$') 136 local sse2_sources=$(echo "$intrinsic_list" | grep '_sse2\.c$')
311 local sse3_sources=$(echo "$intrinsic_list" | grep '_sse3\.c$') 137 local sse3_sources=$(echo "$intrinsic_list" | grep '_sse3\.c$')
312 local ssse3_sources=$(echo "$intrinsic_list" | grep '_ssse3\.c$') 138 local ssse3_sources=$(echo "$intrinsic_list" | grep '_ssse3\.c$')
313 local sse4_1_sources=$(echo "$intrinsic_list" | grep '_sse4\.c$') 139 local sse4_1_sources=$(echo "$intrinsic_list" | grep '_sse4\.c$')
314 local avx_sources=$(echo "$intrinsic_list" | grep '_avx\.c$') 140 local avx_sources=$(echo "$intrinsic_list" | grep '_avx\.c$')
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 438
613 gn format --in-place $BASE_DIR/BUILD.gn 439 gn format --in-place $BASE_DIR/BUILD.gn
614 gn format --in-place $BASE_DIR/libvpx_srcs.gni 440 gn format --in-place $BASE_DIR/libvpx_srcs.gni
615 441
616 cd $BASE_DIR/$LIBVPX_SRC_DIR 442 cd $BASE_DIR/$LIBVPX_SRC_DIR
617 update_readme 443 update_readme
618 444
619 cd $BASE_DIR 445 cd $BASE_DIR
620 446
621 # TODO(fgalligan): Can we turn on "--enable-realtime-only" for mipsel? 447 # TODO(fgalligan): Can we turn on "--enable-realtime-only" for mipsel?
OLDNEW
« no previous file with comments | « third_party/libvpx/ads2gas.gypi ('k') | third_party/libvpx/generate_gypi.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698