summaryrefslogtreecommitdiff
path: root/import_scrypt.sh
diff options
context:
space:
mode:
Diffstat (limited to 'import_scrypt.sh')
-rwxr-xr-ximport_scrypt.sh268
1 files changed, 119 insertions, 149 deletions
diff --git a/import_scrypt.sh b/import_scrypt.sh
index 324eae6..0aa5168 100755
--- a/import_scrypt.sh
+++ b/import_scrypt.sh
@@ -90,7 +90,7 @@ function main() {
declare -r patch=$1
shift || usage "No patch file specified."
[ -d $SCRYPT_DIR ] || usage "$SCRYPT_DIR not found, did you mean to use generate?"
- [ -d $SCRYPT_DIR_ORIG_ORIG ] || usage "$SCRYPT_DIR_ORIG not found, did you mean to use generate?"
+ [ -d $SCRYPT_DIR_ORIG ] || usage "$SCRYPT_DIR_ORIG not found, did you mean to use generate?"
regenerate $patch
elif [ "$command" = "generate" ]; then
declare -r patch=$1
@@ -166,37 +166,15 @@ function filter_by_egrep() {
# $1: space-separated list
# Out: new space-separated list
function uniq_sort () {
- echo "$@" | tr ' ' '\n' | sort -u | tr '\n' ' '
+ echo "$@" | tr ' ' '\n' | sort -u | tr '\n' ' ' | \
+ sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'
}
function print_autogenerated_header() {
- echo "# Auto-generated - DO NOT EDIT!"
- echo "# To regenerate, edit scrypt.config, then run:"
- echo "# ./import_scrypt.sh import /path/to/scrypt-$SCRYPT_VERSION.tar.gz"
- echo "#"
-}
-
-function generate_build_config_mk() {
- ./configure $CONFIGURE_ARGS
- #rm -f apps/CA.pl.bak crypto/scryptconf.h.bak
-
- declare -r tmpfile=$(mktemp)
- (grep -e -D Makefile | grep -v CONFIGURE_ARGS= | grep -v OPTIONS=) > $tmpfile
-
- declare -r cflags=$(filter_by_egrep "^-D" $(grep -e "^CFLAG=" $tmpfile))
- declare -r depflags=$(filter_by_egrep "^-D" $(grep -e "^DEPFLAG=" $tmpfile))
- rm -f $tmpfile
-
- echo "Generating $(basename $1)"
- (
- print_autogenerated_header
-
- echo "scrypt_cflags := \\"
- for cflag in $cflags $depflags; do
- echo " $cflag \\"
- done
- echo ""
- ) > $1
+ echo "// Auto-generated - DO NOT EDIT!"
+ echo "// To regenerate, edit scrypt.config, then run:"
+ echo "// ./import_scrypt.sh import /path/to/scrypt-$SCRYPT_VERSION.tar.gz"
+ echo "//"
}
# Return the value of a computed variable name.
@@ -219,134 +197,130 @@ var_sorted_value() {
uniq_sort $(var_value $1)
}
-# Print the definition of a given variable in a GNU Make build file.
-# $1: Variable name (e.g. common_src_files)
-# $2+: Variable value (e.g. list of sources)
-print_vardef_in_mk() {
- declare -r varname=$1
+# $1: Property name
+# $2: Indent
+# $3: Values
+print_list_in_bp() {
+ declare -r indent="$1"
shift
- if [ -z "$1" ]; then
- echo "$varname :="
- else
- echo "$varname := \\"
- for src; do
- echo " $src \\"
- done
- fi
- echo ""
-}
-
-# Same as print_vardef_in_mk, but print a CFLAGS definition from
-# a list of compiler defines.
-# $1: Variable name (e.g. common_c_flags)
-# $2: List of defines (e.g. SCRYPT_NO_DONKEYS ...)
-print_defines_in_mk() {
- declare -r varname=$1
+ declare -r name="$1"
shift
- if [ -z "$1" ]; then
- echo "$varname :="
- else
- echo "$varname := \\"
- for def; do
- echo " -D$def \\"
+
+ if [ -n "$*" ]; then
+ echo "${indent}${name}: ["
+ for value in "$@"; do
+ echo "${indent} \"${value}\","
done
+ echo "${indent}],"
fi
- echo ""
}
-# Generate a configuration file like Scrypt-config.mk
-# This uses variable definitions from scrypt.config to build a config
-# file that can compute the list of target- and host-specific sources /
-# compiler flags for a given component.
-#
-# $1: Target file name. (e.g. Scrypt-config.mk)
-function generate_config_mk() {
- declare -r output="$1"
- declare -r all_archs="arm arm_neon x86 x86_64 mips"
+# Print an architecture-specific section
+# $1: Arch
+# $2: Arch variant
+print_arch_section_in_bp() {
+ declare -r arch="$1"
+ declare -r variant="$2"
- echo "Generating $(basename $output)"
- (
- print_autogenerated_header
- echo \
-"# Before including this file, the local Android.mk must define the following
-# variables:
-#
-# local_c_flags
-# local_c_includes
-# local_additional_dependencies
-#
-# This script will define the following variables:
-#
-# target_c_flags
-# target_c_includes
-# target_src_files
-#
-# host_c_flags
-# host_c_includes
-# host_src_files
-#
+ declare -r srcs="$(var_sorted_value SCRYPT_SOURCES_${arch})"
+ declare -r exclude_srcs="$(var_sorted_value SCRYPT_SOURCES_EXCLUDES_${arch})"
-# Ensure these are empty.
-unknown_arch_c_flags :=
-unknown_arch_src_files :=
-unknown_arch_exclude_files :=
+ declare -r srcs_variant="$(var_sorted_value SCRYPT_SOURCES_${arch}_${variant})"
+ declare -r exclude_srcs_variant="$(var_sorted_value SCRYPT_SOURCES_EXCLUDES_${arch}_${variant})"
-"
- common_defines=$(var_sorted_value SCRYPT_DEFINES)
- print_defines_in_mk common_c_flags $common_defines
+ if [ -n "${srcs}${exclude_srcs}${srcs_variant}${exclude_srcs_variant}" ]; then
+ echo " ${arch}: {"
- common_sources=$(var_sorted_value SCRYPT_SOURCES)
- print_vardef_in_mk common_src_files $common_sources
+ print_list_in_bp " " "srcs" ${srcs}
+ print_list_in_bp " " "exclude_srcs" ${exclude_srcs}
- common_includes=$(var_sorted_value SCRYPT_INCLUDES)
- print_vardef_in_mk common_c_includes $common_includes
+ if [ -n "${src_variant}${exclude_srcs_variant}" ]; then
+ echo " ${variant}: {"
+ print_list_in_bp " " "srcs" ${srcs_variant}
+ print_list_in_bp " " "exclude_srcs" ${exclude_srcs_variant}
+ echo " },"
+ fi
- for arch in $all_archs; do
- arch_defines=$(var_sorted_value SCRYPT_DEFINES_${arch})
- print_defines_in_mk ${arch}_c_flags $arch_defines
+ echo " },"
+ fi
+}
- arch_sources=$(var_sorted_value SCRYPT_SOURCES_${arch})
- print_vardef_in_mk ${arch}_src_files $arch_sources
+# Generate sources.bp from scrypt.config
+#
+# $1: Target file name. (e.g. sources.bp)
+function generate_android_bp() {
+ declare -r output="$1"
- arch_exclude_sources=$(var_sorted_value SCRYPT_SOURCES_EXCLUDES_${arch})
- print_vardef_in_mk ${arch}_exclude_files $arch_exclude_sources
+ # Extract cflags from upstream `./configure` script
+ cd $SCRYPT_DIR
- done
+ ./configure $CONFIGURE_ARGS
+
+ declare -r tmpfile=$(mktemp)
+ (grep -e -D Makefile | grep -v CONFIGURE_ARGS= | grep -v OPTIONS=) > $tmpfile
+
+ declare -r ac_cflags=$(filter_by_egrep "^-D" $(grep -e "^CFLAG=" $tmpfile))
+ declare -r ac_depflags=$(filter_by_egrep "^-D" $(grep -e "^DEPFLAG=" $tmpfile))
+ rm -f $tmpfile
- echo "\
-target_arch := \$(TARGET_ARCH)
-ifeq (\$(target_arch)-\$(TARGET_HAS_BIGENDIAN),mips-true)
-target_arch := unknown_arch
-endif
-
-target_c_flags := \$(common_c_flags) \$(\$(target_arch)_c_flags) \$(local_c_flags)
-target_c_includes := \$(addprefix external/scrypt/,\$(common_c_includes)) \$(local_c_includes)
-target_src_files := \$(common_src_files) \$(\$(target_arch)_src_files)
-target_src_files := \$(filter-out \$(\$(target_arch)_exclude_files), \$(target_src_files))
-
-# Hacks for ARM NEON support
-ifeq (\$(target_arch),arm)
-ifeq (\$(ARCH_ARM_HAVE_NEON),true)
-target_c_flags += \$(arm_neon_c_flags)
-target_src_files += \$(arm_neon_src_files)
-target_src_files := \$(filter-out \$(arm_neon_exclude_files), \$(target_src_files))
-endif
-endif
-
-ifeq (\$(HOST_OS)-\$(HOST_ARCH),linux-x86)
-host_arch := x86
-else
-host_arch := unknown_arch
-endif
-
-host_c_flags := \$(common_c_flags) \$(\$(host_arch)_c_flags) \$(local_c_flags)
-host_c_includes := \$(addprefix external/scrypt/,\$(common_c_includes)) \$(local_c_includes)
-host_src_files := \$(common_src_files) \$(\$(host_arch)_src_files)
-host_src_files := \$(filter-out \$(\$(host_arch)_exclude_files), \$(host_src_files))
-
-local_additional_dependencies += \$(LOCAL_PATH)/$(basename $output)
-"
+ cd ..
+ # Generate sources.bp
+ echo "Generating $(basename $output)"
+ (
+ print_autogenerated_header
+
+ cat <<__EOF__
+
+//
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+cc_defaults {
+ name: "libscrypt_sources",
+
+__EOF__
+
+ print_list_in_bp " " "cflags" \
+ $(var_sorted_value SCRYPT_CFLAGS) ${ac_cflags} ${ac_depflags}
+ echo
+
+ print_list_in_bp " " "export_include_dirs" \
+ $(var_sorted_value SCRYPT_EXPORT_C_INCLUDE_DIRS)
+ echo
+
+ print_list_in_bp " " "local_include_dirs" \
+ $(var_sorted_value SCRYPT_INCLUDES)
+ echo
+
+ print_list_in_bp " " "srcs" $(var_sorted_value SCRYPT_SOURCES)
+ echo
+
+ echo " arch: {"
+
+ print_arch_section_in_bp "arm" "neon"
+ print_arch_section_in_bp "arm64"
+ print_arch_section_in_bp "x86"
+ print_arch_section_in_bp "x86_64"
+ print_arch_section_in_bp "mips"
+ print_arch_section_in_bp "mips64"
+
+ cat <<__EOF__
+ },
+}
+__EOF__
) > "$output"
}
@@ -356,15 +330,11 @@ function import() {
untar $SCRYPT_SOURCE readonly
applypatches $SCRYPT_DIR
- cd $SCRYPT_DIR
-
- generate_build_config_mk ../build-config.mk
-
- touch ../MODULE_LICENSE_BSD_LIKE
+ cd $SCRYPT_DIR/..
- cd ..
+ touch MODULE_LICENSE_BSD_LIKE
- generate_config_mk Scrypt-config.mk
+ generate_android_bp "sources.bp"
# Prune unnecessary sources
prune
@@ -395,7 +365,7 @@ function generate() {
for i in $NEEDED_SOURCES; do
echo "Restoring $i"
- rm -r $SCRYPT_DIR/$i
+ rm -rf $SCRYPT_DIR/$i
cp -rf $i $SCRYPT_DIR/$i
done
@@ -484,7 +454,7 @@ function generatepatch() {
rm -f $patch
touch $patch
for i in $sources; do
- LC_ALL=C TZ=UTC0 diff -aup $SCRYPT_DIR_ORIG/$i $SCRYPT_DIR/$i >> $patch && die "ERROR: No diff for patch $path in file $i"
+ LC_ALL=C TZ=UTC0 diff -aupN $SCRYPT_DIR_ORIG/$i $SCRYPT_DIR/$i >> $patch && die "ERROR: No diff for patch $path in file $i"
done
echo "Generated patch $patch"
echo "NOTE To make sure there are not unwanted changes from conflicting patches, be sure to review the generated patch."