tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

generate_sources_mozbuild.sh (12437B)


      1 #!/bin/bash -e
      2 #
      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
      5 # found in the LICENSE file.
      6 
      7 # Modified from chromium/src/third_party/libvpx/generate_gni.sh
      8 
      9 # This script is used to generate sources.mozbuild and files in the
     10 # config/platform directories needed to build libvpx.
     11 # Every time libvpx source code is updated just run this script.
     12 #
     13 # Usage:
     14 # $ ./generate_sources_mozbuild.sh
     15 
     16 export LC_ALL=C
     17 BASE_DIR=$(pwd)
     18 LIBVPX_SRC_DIR="libvpx"
     19 LIBVPX_CONFIG_DIR="config"
     20 DISABLE_AVX="--disable-avx512"
     21 
     22 # Print license header.
     23 # $1 - Output base name
     24 function write_license {
     25  echo "# This file is generated. Do not edit." >> $1
     26  echo "" >> $1
     27 }
     28 
     29 # Search for source files with the same basename in vp8, vp9, and vpx_dsp. The
     30 # build does not support duplicate file names.
     31 function find_duplicates {
     32  local readonly duplicate_file_names=$(find \
     33    $BASE_DIR/$LIBVPX_SRC_DIR/vp8 \
     34    $BASE_DIR/$LIBVPX_SRC_DIR/vp9 \
     35    $BASE_DIR/$LIBVPX_SRC_DIR/vpx_dsp \
     36    -type f -name \*.c  | xargs -I {} basename {} | sort | uniq -d \
     37  )
     38 
     39  if [ -n "${duplicate_file_names}" ]; then
     40    echo "ERROR: DUPLICATE FILES FOUND"
     41    for file in  ${duplicate_file_names}; do
     42      find \
     43        $BASE_DIR/$LIBVPX_SRC_DIR/vp8 \
     44        $BASE_DIR/$LIBVPX_SRC_DIR/vp9 \
     45        $BASE_DIR/$LIBVPX_SRC_DIR/vpx_dsp \
     46        -name $file
     47    done
     48    exit 1
     49  fi
     50 }
     51 
     52 # Generate sources.mozbuild with a list of source files.
     53 # $1 - Array name for file list. This is processed with 'declare' below to
     54 #      regenerate the array locally.
     55 # $2 - Variable name.
     56 # $3 - Output file.
     57 function write_sources {
     58  # Convert the first argument back in to an array.
     59  declare -a file_list=("${!1}")
     60 
     61  echo "  '$2': [" >> "$3"
     62  for f in $file_list
     63  do
     64    echo "    'libvpx/$f'," >> "$3"
     65  done
     66  echo "]," >> "$3"
     67 }
     68 
     69 # Convert a list of source files into sources.mozbuild.
     70 # $1 - Input file.
     71 # $2 - Output prefix.
     72 # $3 - Path of vpx_config.c under $LIBVPX_CONFIG_DIR
     73 function convert_srcs_to_project_files {
     74  # Do the following here:
     75  # 1. Filter .c, .h, .s, .S and .asm files.
     76  # 3. Convert .asm.s to .asm because moz.build will do the conversion.
     77 
     78  local source_list=$(grep -E '(\.c|\.h|\.S|\.s|\.asm)$' $1)
     79 
     80  # Adjust the path for vpx_config.c while maintaining list order:
     81  # Since the config file resides in $BASE_DIR/$LIBVPX_CONFIG_DIR, while the
     82  # files in $source_list are placed under $BASE_DIR/libvpx (see write_sources),
     83  # the config file path requires adjustment. To ensure the list remains sorted,
     84  # we must first remove it and then insert it at the beginning of the list.
     85 
     86  # Remove vpx_config.c
     87  source_list=$(echo "$source_list" | grep -v 'vpx_config\.c')
     88  # Insert vpx_config.c at the beginning of the list.
     89  local config=$(echo "../$LIBVPX_CONFIG_DIR/$3/vpx_config.c")
     90  source_list=$(echo "$config" ; echo "$source_list")
     91 
     92  # Remove include-only asm files (no object code emitted)
     93  source_list=$(echo "$source_list" | grep -v 'x86_abi_support\.asm')
     94  source_list=$(echo "$source_list" | grep -v 'config\.asm')
     95 
     96  # The actual ARM files end in .asm. We have rules to translate them to .S
     97  source_list=$(echo "$source_list" | sed s/\.asm\.s$/.asm/)
     98 
     99  # Exports - everything in vpx, vpx_mem, vpx_ports, vpx_scale
    100  local exports_list=$(echo "$source_list" | \
    101    egrep '^(vpx|vpx_mem|vpx_ports|vpx_scale)/.*h$')
    102  # but not anything in one level down, like 'internal'
    103  exports_list=$(echo "$exports_list" | egrep -v '/(internal|src)/')
    104  # or any of the other internal-ish header files.
    105  exports_list=$(echo "$exports_list" | egrep -v '/(emmintrin_compat.h|mem_.*|msvc.h|vpx_once.h)$')
    106 
    107  # Remove these files from the main list.
    108  source_list=$(comm -23 <(echo "$source_list") <(echo "$exports_list"))
    109 
    110  # Write a single file that includes all source files for all archs.
    111  local c_sources=$(echo "$source_list" | egrep '.(asm|c)$')
    112  local exports_sources=$(echo "$exports_list" | egrep '.h$')
    113 
    114  write_sources exports_sources ${2}_EXPORTS "$BASE_DIR/sources.mozbuild"
    115  write_sources c_sources ${2}_SOURCES "$BASE_DIR/sources.mozbuild"
    116 }
    117 
    118 # Clean files from previous make.
    119 function make_clean {
    120  make clean > /dev/null
    121  rm -f libvpx_srcs.txt
    122 }
    123 
    124 # Print the configuration.
    125 # $1 - Header file directory.
    126 function print_config {
    127  $BASE_DIR/lint_config.sh -p \
    128    -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \
    129    -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm
    130 }
    131 
    132 # Generate *_rtcd.h files.
    133 # $1 - Header file directory.
    134 # $2 - Architecture.
    135 # $3 - Optional - any additional arguments to pass through.
    136 function gen_rtcd_header {
    137  echo "Generate $LIBVPX_CONFIG_DIR/$1/*_rtcd.h files."
    138 
    139  rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config
    140  $BASE_DIR/lint_config.sh -p \
    141    -h $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.h \
    142    -a $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_config.asm \
    143    -o $BASE_DIR/$TEMP_DIR/libvpx.config
    144 
    145  $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \
    146    --arch=$2 \
    147    --sym=vp8_rtcd $DISABLE_AVX $3 \
    148    --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
    149    $BASE_DIR/$LIBVPX_SRC_DIR/vp8/common/rtcd_defs.pl \
    150    > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp8_rtcd.h
    151 
    152  $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \
    153    --arch=$2 \
    154    --sym=vp9_rtcd $DISABLE_AVX $3 \
    155    --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
    156    $BASE_DIR/$LIBVPX_SRC_DIR/vp9/common/vp9_rtcd_defs.pl \
    157    > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp9_rtcd.h
    158 
    159  $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \
    160    --arch=$2 \
    161    --sym=vpx_scale_rtcd $DISABLE_AVX $3 \
    162    --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
    163    $BASE_DIR/$LIBVPX_SRC_DIR/vpx_scale/vpx_scale_rtcd.pl \
    164    > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_scale_rtcd.h
    165 
    166  $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \
    167    --arch=$2 \
    168    --sym=vpx_dsp_rtcd $DISABLE_AVX $3 \
    169    --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
    170    $BASE_DIR/$LIBVPX_SRC_DIR/vpx_dsp/vpx_dsp_rtcd_defs.pl \
    171    > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_dsp_rtcd.h
    172 
    173  rm -rf $BASE_DIR/$TEMP_DIR/libvpx.config
    174 }
    175 
    176 # Generate Config files. "--enable-external-build" must be set to skip
    177 # detection of capabilities on specific targets.
    178 # $1 - Header file directory.
    179 # $2 - Config command line.
    180 function gen_config_files {
    181  mkdir -p $BASE_DIR/$LIBVPX_CONFIG_DIR/$1
    182  ./configure $2 --log=$BASE_DIR/$LIBVPX_CONFIG_DIR/$1/config.log > /dev/null
    183  echo "Log file: $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/config.log"
    184 
    185  # Disable HAVE_UNISTD_H.
    186  ( echo '/HAVE_UNISTD_H'; echo 'd' ; echo 'w' ; echo 'q' ) | ed -s vpx_config.h
    187 
    188  local ASM_CONV=ads2gas.pl
    189 
    190  # Generate vpx_config.asm.
    191  if [[ "$1" == *x64* ]] || [[ "$1" == *ia32* ]]; then
    192    egrep "#define [A-Z0-9_]+ [01]" vpx_config.h | awk '{print "%define " $2 " " $3}' > vpx_config.asm
    193  else
    194    egrep "#define [A-Z0-9_]+ [01]" vpx_config.h | awk '{print $2 " EQU " $3}' | perl $BASE_DIR/$LIBVPX_SRC_DIR/build/make/$ASM_CONV > vpx_config.asm
    195  fi
    196 
    197  cp vpx_config.* $BASE_DIR/$LIBVPX_CONFIG_DIR/$1
    198  make_clean
    199  rm -rf vpx_config.*
    200 }
    201 
    202 find_duplicates
    203 
    204 echo "Create temporary directory."
    205 TEMP_DIR="$LIBVPX_SRC_DIR.temp"
    206 rm -rf $TEMP_DIR
    207 cp -R $LIBVPX_SRC_DIR $TEMP_DIR
    208 cd $TEMP_DIR
    209 
    210 echo "Generate config files."
    211 all_platforms="--enable-external-build --disable-examples --disable-install-docs --disable-unit-tests"
    212 all_platforms="${all_platforms} --enable-multi-res-encoding --size-limit=8192x4608 --enable-pic"
    213 all_platforms="${all_platforms} --disable-avx512"
    214 x86_platforms="--enable-postproc --enable-vp9-postproc --as=yasm"
    215 runtime_cpu_detect="--enable-runtime-cpu-detect"
    216 realtime_only="--enable-realtime-only"
    217 disable_sve="--disable-sve" # Bug 1885585, Bug 1889813
    218 
    219 gen_config_files linux/x64 "--target=x86_64-linux-gcc ${all_platforms} ${x86_platforms}"
    220 gen_config_files linux/ia32 "--target=x86-linux-gcc ${all_platforms} ${x86_platforms}"
    221 gen_config_files mac/x64 "--target=x86_64-darwin9-gcc ${all_platforms} ${x86_platforms}"
    222 gen_config_files mac/ia32 "--target=x86-darwin9-gcc ${all_platforms} ${x86_platforms}"
    223 gen_config_files win/x64 "--target=x86_64-win64-vs15 ${all_platforms} ${x86_platforms}"
    224 gen_config_files win/ia32 "--target=x86-win32-gcc ${all_platforms} ${x86_platforms}"
    225 
    226 gen_config_files linux/arm "--target=armv7-linux-gcc ${all_platforms} ${runtime_cpu_detect} ${realtime_only}"
    227 gen_config_files linux/arm64 "--target=arm64-linux-gcc ${all_platforms} ${realtime_only} ${disable_sve}" # Bug 1889813
    228 gen_config_files mac/arm64 "--target=arm64-darwin-gcc ${all_platforms}"
    229 gen_config_files win/aarch64 "--target=arm64-win64-vs15 ${all_platforms} ${realtime_only} ${disable_sve}" # Bug 1885585
    230 
    231 gen_config_files linux/loongarch64 "--target=loongarch64-linux-gcc ${all_platforms} ${runtime_cpu_detect} ${realtime_only}"
    232 
    233 gen_config_files generic "--target=generic-gnu ${all_platforms}"
    234 
    235 echo "Remove temporary directory."
    236 cd $BASE_DIR
    237 rm -rf $TEMP_DIR
    238 
    239 echo "Create temporary directory."
    240 TEMP_DIR="$LIBVPX_SRC_DIR.temp"
    241 rm -rf $TEMP_DIR
    242 cp -R $LIBVPX_SRC_DIR $TEMP_DIR
    243 cd $TEMP_DIR
    244 
    245 gen_rtcd_header linux/x64 x86_64
    246 gen_rtcd_header linux/ia32 x86
    247 gen_rtcd_header mac/x64 x86_64
    248 gen_rtcd_header mac/ia32 x86
    249 gen_rtcd_header win/x64 x86_64
    250 gen_rtcd_header win/ia32 x86
    251 
    252 gen_rtcd_header linux/arm armv7
    253 gen_rtcd_header linux/arm64 arm64 $disable_sve # Bug 1889813
    254 gen_rtcd_header mac/arm64 arm64
    255 gen_rtcd_header win/aarch64 arm64 $disable_sve # Bug 1885585
    256 
    257 gen_rtcd_header linux/loongarch64 loongarch64
    258 
    259 gen_rtcd_header generic generic
    260 
    261 echo "Prepare Makefile."
    262 ./configure --target=generic-gnu > /dev/null
    263 make_clean
    264 
    265 # Remove existing source files.
    266 rm -rf $BASE_DIR/sources.mozbuild
    267 write_license $BASE_DIR/sources.mozbuild
    268 echo "files = {" >> $BASE_DIR/sources.mozbuild
    269 
    270 echo "Generate X86_64 source list on Linux."
    271 config=$(print_config linux/x64)
    272 make_clean
    273 make libvpx_srcs.txt target=libs $config > /dev/null
    274 convert_srcs_to_project_files libvpx_srcs.txt LINUX_X64 linux/x64
    275 
    276 echo "Generate X86_64 source list on Mac."
    277 config=$(print_config mac/x64)
    278 make_clean
    279 make libvpx_srcs.txt target=libs $config > /dev/null
    280 convert_srcs_to_project_files libvpx_srcs.txt MAC_X64 mac/x64
    281 
    282 echo "Generate X86_64 source list on Windows."
    283 config=$(print_config win/x64)
    284 make_clean
    285 make libvpx_srcs.txt target=libs $config > /dev/null
    286 convert_srcs_to_project_files libvpx_srcs.txt WIN_X64 win/x64
    287 
    288 # Copy vpx_version.h once. The file is the same for all platforms.
    289 cp vpx_version.h $BASE_DIR/$LIBVPX_CONFIG_DIR
    290 
    291 echo "Generate IA32 source list on Linux."
    292 config=$(print_config linux/ia32)
    293 make_clean
    294 make libvpx_srcs.txt target=libs $config > /dev/null
    295 convert_srcs_to_project_files libvpx_srcs.txt LINUX_IA32 linux/ia32
    296 
    297 echo "Generate IA32 source list on Mac."
    298 config=$(print_config mac/ia32)
    299 make_clean
    300 make libvpx_srcs.txt target=libs $config > /dev/null
    301 convert_srcs_to_project_files libvpx_srcs.txt MAC_IA32 mac/ia32
    302 
    303 echo "Generate IA32 source list on Windows."
    304 config=$(print_config win/ia32)
    305 make_clean
    306 make libvpx_srcs.txt target=libs $config > /dev/null
    307 convert_srcs_to_project_files libvpx_srcs.txt WIN_IA32 win/ia32
    308 
    309 echo "Generate ARM source list on Linux."
    310 config=$(print_config linux/arm)
    311 make_clean
    312 make libvpx_srcs.txt target=libs $config > /dev/null
    313 convert_srcs_to_project_files libvpx_srcs.txt LINUX_ARM linux/arm
    314 
    315 echo "Generate ARM64 source list on Linux"
    316 config=$(print_config linux/arm64)
    317 make_clean
    318 make libvpx_srcs.txt target=libs $config > /dev/null
    319 convert_srcs_to_project_files libvpx_srcs.txt LINUX_ARM64 linux/arm64
    320 
    321 echo "Generate ARM64 source list on Mac"
    322 config=$(print_config mac/arm64)
    323 make_clean
    324 make libvpx_srcs.txt target=libs $config > /dev/null
    325 convert_srcs_to_project_files libvpx_srcs.txt MAC_ARM64 mac/arm64
    326 
    327 echo "Generate AARCH64 source list on Windows."
    328 config=$(print_config win/aarch64)
    329 make_clean
    330 make libvpx_srcs.txt target=libs $config > /dev/null
    331 convert_srcs_to_project_files libvpx_srcs.txt WIN_AARCH64 win/aarch64
    332 
    333 echo "Generate LoongArch64 source list on Linux"
    334 config=$(print_config linux/loongarch64)
    335 make_clean
    336 make libvpx_srcs.txt target=libs $config > /dev/null
    337 convert_srcs_to_project_files libvpx_srcs.txt LINUX_LOONGARCH64 linux/loongarch64
    338 
    339 echo "Generate generic source list."
    340 config=$(print_config generic)
    341 make_clean
    342 make libvpx_srcs.txt target=libs $config > /dev/null
    343 convert_srcs_to_project_files libvpx_srcs.txt GENERIC generic
    344 
    345 echo "}" >> $BASE_DIR/sources.mozbuild
    346 
    347 echo "Remove temporary directory."
    348 cd $BASE_DIR
    349 rm -rf $TEMP_DIR
    350 
    351 cd $BASE_DIR/$LIBVPX_SRC_DIR
    352 
    353 cd $BASE_DIR