Move more build configuration to openssl.config

This patch makes openssl.config the only place where common
and architecture-specific sources and compiler flags are listed.

Its content is processed by import_openssl.sh to generate new
build config files (Crypto-config.mk, Ssl-config.mk, Apps-config.mk)
which are themselves included by simplified Crypto.mk, Ssl.mk, Apps.mk.

+ Add a new script (check-all-builds.sh) that can rebuild six
  different variants of openssl in one go. This is useful to quickly
  check that a change didn't break a specific build, e.g. when
  adding  new patch or upgrading the OpenSSL sources.

  See './check-all-builds.sh --help' for more info.

  Note: Clang-based builds are currently broken, so only GCC-based
        ones are activated at the moment.

Change-Id: If08c204e4dc9b081ce676bc7984d039670e115b0
diff --git a/Apps-config.mk b/Apps-config.mk
new file mode 100644
index 0000000..2ee8026
--- /dev/null
+++ b/Apps-config.mk
@@ -0,0 +1,133 @@
+# Auto-generated - DO NOT EDIT!
+# To regenerate, edit openssl.config, then run:
+#     ./import_openssl.sh import /path/to/openssl-1.0.1e.tar.gz
+#
+# 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
+#
+
+# Ensure these are empty.
+unknown_arch_c_flags :=
+unknown_arch_src_files :=
+unknown_arch_exclude_files :=
+
+
+common_c_flags := \
+  -DMONOLITH \
+
+common_src_files := \
+  apps/app_rand.c \
+  apps/apps.c \
+  apps/asn1pars.c \
+  apps/ca.c \
+  apps/ciphers.c \
+  apps/crl.c \
+  apps/crl2p7.c \
+  apps/dgst.c \
+  apps/dh.c \
+  apps/dhparam.c \
+  apps/dsa.c \
+  apps/dsaparam.c \
+  apps/ec.c \
+  apps/ecparam.c \
+  apps/enc.c \
+  apps/engine.c \
+  apps/errstr.c \
+  apps/gendh.c \
+  apps/gendsa.c \
+  apps/genpkey.c \
+  apps/genrsa.c \
+  apps/nseq.c \
+  apps/ocsp.c \
+  apps/openssl.c \
+  apps/passwd.c \
+  apps/pkcs12.c \
+  apps/pkcs7.c \
+  apps/pkcs8.c \
+  apps/pkey.c \
+  apps/pkeyparam.c \
+  apps/pkeyutl.c \
+  apps/prime.c \
+  apps/rand.c \
+  apps/req.c \
+  apps/rsa.c \
+  apps/rsautl.c \
+  apps/s_cb.c \
+  apps/s_client.c \
+  apps/s_server.c \
+  apps/s_socket.c \
+  apps/s_time.c \
+  apps/sess_id.c \
+  apps/smime.c \
+  apps/speed.c \
+  apps/spkac.c \
+  apps/srp.c \
+  apps/verify.c \
+  apps/version.c \
+  apps/x509.c \
+
+common_c_includes := \
+  . \
+  include \
+
+arm_c_flags :=
+
+arm_src_files :=
+
+arm_exclude_files :=
+
+x86_c_flags :=
+
+x86_src_files :=
+
+x86_exclude_files :=
+
+x86_64_c_flags :=
+
+x86_64_src_files :=
+
+x86_64_exclude_files :=
+
+mips_c_flags :=
+
+mips_src_files :=
+
+mips_exclude_files :=
+
+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/openssl/,$(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))
+
+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/openssl/,$(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)/Apps-config.mk
+
diff --git a/Apps.mk b/Apps.mk
index e6df452..57d43b9 100644
--- a/Apps.mk
+++ b/Apps.mk
@@ -2,76 +2,24 @@
 
 LOCAL_PATH:= $(call my-dir)
 
-local_src_files:= \
-	apps/app_rand.c \
-	apps/apps.c \
-	apps/asn1pars.c \
-	apps/ca.c \
-	apps/ciphers.c \
-	apps/crl.c \
-	apps/crl2p7.c \
-	apps/dgst.c \
-	apps/dh.c \
-	apps/dhparam.c \
-	apps/dsa.c \
-	apps/dsaparam.c \
-	apps/ecparam.c \
-	apps/ec.c \
-	apps/enc.c \
-	apps/engine.c \
-	apps/errstr.c \
-	apps/gendh.c \
-	apps/gendsa.c \
-	apps/genpkey.c \
-	apps/genrsa.c \
-	apps/nseq.c \
-	apps/ocsp.c \
-	apps/openssl.c \
-	apps/passwd.c \
-	apps/pkcs12.c \
-	apps/pkcs7.c \
-	apps/pkcs8.c \
-	apps/pkey.c \
-	apps/pkeyparam.c \
-	apps/pkeyutl.c \
-	apps/prime.c \
-	apps/rand.c \
-	apps/req.c \
-	apps/rsa.c \
-	apps/rsautl.c \
-	apps/s_cb.c \
-	apps/s_client.c \
-	apps/s_server.c \
-	apps/s_socket.c \
-	apps/s_time.c \
-	apps/sess_id.c \
-	apps/smime.c \
-	apps/speed.c \
-	apps/spkac.c \
-	apps/srp.c \
-	apps/verify.c \
-	apps/version.c \
-	apps/x509.c
-
 local_shared_libraries := \
 	libssl \
 	libcrypto
 
-local_c_includes := \
-	external/openssl \
-	external/openssl/include
-
-local_cflags := -DMONOLITH
+local_c_includes :=
+local_c_flags :=
 
 local_additional_dependencies := $(LOCAL_PATH)/android-config.mk $(LOCAL_PATH)/Apps.mk
 
+include $(LOCAL_PATH)/Apps-config.mk
+
 include $(CLEAR_VARS)
 LOCAL_MODULE:= openssl
 LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := $(local_src_files)
+LOCAL_SRC_FILES := $(target_src_files)
 LOCAL_SHARED_LIBRARIES := $(local_shared_libraries)
-LOCAL_C_INCLUDES := $(local_c_includes)
-LOCAL_CFLAGS := $(local_cflags)
+LOCAL_C_INCLUDES := $(target_c_includes)
+LOCAL_CFLAGS := $(target_c_flags)
 LOCAL_ADDITIONAL_DEPENDENCIES := $(local_additional_dependencies)
 include $(LOCAL_PATH)/android-config.mk
 include $(BUILD_EXECUTABLE)
@@ -79,10 +27,10 @@
 include $(CLEAR_VARS)
 LOCAL_MODULE:= openssl
 LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := $(local_src_files)
+LOCAL_SRC_FILES := $(host_src_files)
 LOCAL_SHARED_LIBRARIES := $(local_shared_libraries)
-LOCAL_C_INCLUDES := $(local_c_includes)
-LOCAL_CFLAGS := $(local_cflags)
+LOCAL_C_INCLUDES := $(host_c_includes)
+LOCAL_CFLAGS := $(host_c_flags)
 LOCAL_ADDITIONAL_DEPENDENCIES := $(local_additional_dependencies)
 include $(LOCAL_PATH)/android-config.mk
 include $(BUILD_HOST_EXECUTABLE)
diff --git a/Crypto-config.mk b/Crypto-config.mk
new file mode 100644
index 0000000..d74a791
--- /dev/null
+++ b/Crypto-config.mk
@@ -0,0 +1,686 @@
+# Auto-generated - DO NOT EDIT!
+# To regenerate, edit openssl.config, then run:
+#     ./import_openssl.sh import /path/to/openssl-1.0.1e.tar.gz
+#
+# 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
+#
+
+# Ensure these are empty.
+unknown_arch_c_flags :=
+unknown_arch_src_files :=
+unknown_arch_exclude_files :=
+
+
+common_c_flags := \
+  -DNO_WINDOWS_BRAINDEATH \
+
+common_src_files := \
+  crypto/aes/aes_cbc.c \
+  crypto/aes/aes_cfb.c \
+  crypto/aes/aes_core.c \
+  crypto/aes/aes_ctr.c \
+  crypto/aes/aes_ecb.c \
+  crypto/aes/aes_misc.c \
+  crypto/aes/aes_ofb.c \
+  crypto/aes/aes_wrap.c \
+  crypto/asn1/a_bitstr.c \
+  crypto/asn1/a_bool.c \
+  crypto/asn1/a_bytes.c \
+  crypto/asn1/a_d2i_fp.c \
+  crypto/asn1/a_digest.c \
+  crypto/asn1/a_dup.c \
+  crypto/asn1/a_enum.c \
+  crypto/asn1/a_gentm.c \
+  crypto/asn1/a_i2d_fp.c \
+  crypto/asn1/a_int.c \
+  crypto/asn1/a_mbstr.c \
+  crypto/asn1/a_object.c \
+  crypto/asn1/a_octet.c \
+  crypto/asn1/a_print.c \
+  crypto/asn1/a_set.c \
+  crypto/asn1/a_sign.c \
+  crypto/asn1/a_strex.c \
+  crypto/asn1/a_strnid.c \
+  crypto/asn1/a_time.c \
+  crypto/asn1/a_type.c \
+  crypto/asn1/a_utctm.c \
+  crypto/asn1/a_utf8.c \
+  crypto/asn1/a_verify.c \
+  crypto/asn1/ameth_lib.c \
+  crypto/asn1/asn1_err.c \
+  crypto/asn1/asn1_gen.c \
+  crypto/asn1/asn1_lib.c \
+  crypto/asn1/asn1_par.c \
+  crypto/asn1/asn_mime.c \
+  crypto/asn1/asn_moid.c \
+  crypto/asn1/asn_pack.c \
+  crypto/asn1/bio_asn1.c \
+  crypto/asn1/bio_ndef.c \
+  crypto/asn1/d2i_pr.c \
+  crypto/asn1/d2i_pu.c \
+  crypto/asn1/evp_asn1.c \
+  crypto/asn1/f_enum.c \
+  crypto/asn1/f_int.c \
+  crypto/asn1/f_string.c \
+  crypto/asn1/i2d_pr.c \
+  crypto/asn1/i2d_pu.c \
+  crypto/asn1/n_pkey.c \
+  crypto/asn1/nsseq.c \
+  crypto/asn1/p5_pbe.c \
+  crypto/asn1/p5_pbev2.c \
+  crypto/asn1/p8_pkey.c \
+  crypto/asn1/t_bitst.c \
+  crypto/asn1/t_crl.c \
+  crypto/asn1/t_pkey.c \
+  crypto/asn1/t_req.c \
+  crypto/asn1/t_spki.c \
+  crypto/asn1/t_x509.c \
+  crypto/asn1/t_x509a.c \
+  crypto/asn1/tasn_dec.c \
+  crypto/asn1/tasn_enc.c \
+  crypto/asn1/tasn_fre.c \
+  crypto/asn1/tasn_new.c \
+  crypto/asn1/tasn_prn.c \
+  crypto/asn1/tasn_typ.c \
+  crypto/asn1/tasn_utl.c \
+  crypto/asn1/x_algor.c \
+  crypto/asn1/x_attrib.c \
+  crypto/asn1/x_bignum.c \
+  crypto/asn1/x_crl.c \
+  crypto/asn1/x_exten.c \
+  crypto/asn1/x_info.c \
+  crypto/asn1/x_long.c \
+  crypto/asn1/x_name.c \
+  crypto/asn1/x_nx509.c \
+  crypto/asn1/x_pkey.c \
+  crypto/asn1/x_pubkey.c \
+  crypto/asn1/x_req.c \
+  crypto/asn1/x_sig.c \
+  crypto/asn1/x_spki.c \
+  crypto/asn1/x_val.c \
+  crypto/asn1/x_x509.c \
+  crypto/asn1/x_x509a.c \
+  crypto/bf/bf_cfb64.c \
+  crypto/bf/bf_ecb.c \
+  crypto/bf/bf_enc.c \
+  crypto/bf/bf_ofb64.c \
+  crypto/bf/bf_skey.c \
+  crypto/bio/b_dump.c \
+  crypto/bio/b_print.c \
+  crypto/bio/b_sock.c \
+  crypto/bio/bf_buff.c \
+  crypto/bio/bf_nbio.c \
+  crypto/bio/bf_null.c \
+  crypto/bio/bio_cb.c \
+  crypto/bio/bio_err.c \
+  crypto/bio/bio_lib.c \
+  crypto/bio/bss_acpt.c \
+  crypto/bio/bss_bio.c \
+  crypto/bio/bss_conn.c \
+  crypto/bio/bss_dgram.c \
+  crypto/bio/bss_fd.c \
+  crypto/bio/bss_file.c \
+  crypto/bio/bss_log.c \
+  crypto/bio/bss_mem.c \
+  crypto/bio/bss_null.c \
+  crypto/bio/bss_sock.c \
+  crypto/bn/bn_add.c \
+  crypto/bn/bn_asm.c \
+  crypto/bn/bn_blind.c \
+  crypto/bn/bn_const.c \
+  crypto/bn/bn_ctx.c \
+  crypto/bn/bn_div.c \
+  crypto/bn/bn_err.c \
+  crypto/bn/bn_exp.c \
+  crypto/bn/bn_exp2.c \
+  crypto/bn/bn_gcd.c \
+  crypto/bn/bn_gf2m.c \
+  crypto/bn/bn_kron.c \
+  crypto/bn/bn_lib.c \
+  crypto/bn/bn_mod.c \
+  crypto/bn/bn_mont.c \
+  crypto/bn/bn_mpi.c \
+  crypto/bn/bn_mul.c \
+  crypto/bn/bn_nist.c \
+  crypto/bn/bn_prime.c \
+  crypto/bn/bn_print.c \
+  crypto/bn/bn_rand.c \
+  crypto/bn/bn_recp.c \
+  crypto/bn/bn_shift.c \
+  crypto/bn/bn_sqr.c \
+  crypto/bn/bn_sqrt.c \
+  crypto/bn/bn_word.c \
+  crypto/buffer/buf_err.c \
+  crypto/buffer/buf_str.c \
+  crypto/buffer/buffer.c \
+  crypto/cmac/cm_ameth.c \
+  crypto/cmac/cm_pmeth.c \
+  crypto/cmac/cmac.c \
+  crypto/comp/c_rle.c \
+  crypto/comp/c_zlib.c \
+  crypto/comp/comp_err.c \
+  crypto/comp/comp_lib.c \
+  crypto/conf/conf_api.c \
+  crypto/conf/conf_def.c \
+  crypto/conf/conf_err.c \
+  crypto/conf/conf_lib.c \
+  crypto/conf/conf_mall.c \
+  crypto/conf/conf_mod.c \
+  crypto/conf/conf_sap.c \
+  crypto/cpt_err.c \
+  crypto/cryptlib.c \
+  crypto/cversion.c \
+  crypto/des/cbc_cksm.c \
+  crypto/des/cbc_enc.c \
+  crypto/des/cfb64ede.c \
+  crypto/des/cfb64enc.c \
+  crypto/des/cfb_enc.c \
+  crypto/des/des_enc.c \
+  crypto/des/des_old.c \
+  crypto/des/des_old2.c \
+  crypto/des/ecb3_enc.c \
+  crypto/des/ecb_enc.c \
+  crypto/des/ede_cbcm_enc.c \
+  crypto/des/enc_read.c \
+  crypto/des/enc_writ.c \
+  crypto/des/fcrypt.c \
+  crypto/des/fcrypt_b.c \
+  crypto/des/ofb64ede.c \
+  crypto/des/ofb64enc.c \
+  crypto/des/ofb_enc.c \
+  crypto/des/pcbc_enc.c \
+  crypto/des/qud_cksm.c \
+  crypto/des/rand_key.c \
+  crypto/des/read2pwd.c \
+  crypto/des/rpc_enc.c \
+  crypto/des/set_key.c \
+  crypto/des/str2key.c \
+  crypto/des/xcbc_enc.c \
+  crypto/dh/dh_ameth.c \
+  crypto/dh/dh_asn1.c \
+  crypto/dh/dh_check.c \
+  crypto/dh/dh_depr.c \
+  crypto/dh/dh_err.c \
+  crypto/dh/dh_gen.c \
+  crypto/dh/dh_key.c \
+  crypto/dh/dh_lib.c \
+  crypto/dh/dh_pmeth.c \
+  crypto/dsa/dsa_ameth.c \
+  crypto/dsa/dsa_asn1.c \
+  crypto/dsa/dsa_depr.c \
+  crypto/dsa/dsa_err.c \
+  crypto/dsa/dsa_gen.c \
+  crypto/dsa/dsa_key.c \
+  crypto/dsa/dsa_lib.c \
+  crypto/dsa/dsa_ossl.c \
+  crypto/dsa/dsa_pmeth.c \
+  crypto/dsa/dsa_prn.c \
+  crypto/dsa/dsa_sign.c \
+  crypto/dsa/dsa_vrf.c \
+  crypto/dso/dso_dl.c \
+  crypto/dso/dso_dlfcn.c \
+  crypto/dso/dso_err.c \
+  crypto/dso/dso_lib.c \
+  crypto/dso/dso_null.c \
+  crypto/dso/dso_openssl.c \
+  crypto/ebcdic.c \
+  crypto/ec/ec2_mult.c \
+  crypto/ec/ec2_oct.c \
+  crypto/ec/ec2_smpl.c \
+  crypto/ec/ec_ameth.c \
+  crypto/ec/ec_asn1.c \
+  crypto/ec/ec_check.c \
+  crypto/ec/ec_curve.c \
+  crypto/ec/ec_cvt.c \
+  crypto/ec/ec_err.c \
+  crypto/ec/ec_key.c \
+  crypto/ec/ec_lib.c \
+  crypto/ec/ec_mult.c \
+  crypto/ec/ec_oct.c \
+  crypto/ec/ec_pmeth.c \
+  crypto/ec/ec_print.c \
+  crypto/ec/eck_prn.c \
+  crypto/ec/ecp_mont.c \
+  crypto/ec/ecp_nist.c \
+  crypto/ec/ecp_oct.c \
+  crypto/ec/ecp_smpl.c \
+  crypto/ecdh/ech_err.c \
+  crypto/ecdh/ech_key.c \
+  crypto/ecdh/ech_lib.c \
+  crypto/ecdh/ech_ossl.c \
+  crypto/ecdsa/ecs_asn1.c \
+  crypto/ecdsa/ecs_err.c \
+  crypto/ecdsa/ecs_lib.c \
+  crypto/ecdsa/ecs_ossl.c \
+  crypto/ecdsa/ecs_sign.c \
+  crypto/ecdsa/ecs_vrf.c \
+  crypto/engine/eng_all.c \
+  crypto/engine/eng_cnf.c \
+  crypto/engine/eng_ctrl.c \
+  crypto/engine/eng_dyn.c \
+  crypto/engine/eng_err.c \
+  crypto/engine/eng_fat.c \
+  crypto/engine/eng_init.c \
+  crypto/engine/eng_lib.c \
+  crypto/engine/eng_list.c \
+  crypto/engine/eng_pkey.c \
+  crypto/engine/eng_table.c \
+  crypto/engine/tb_asnmth.c \
+  crypto/engine/tb_cipher.c \
+  crypto/engine/tb_dh.c \
+  crypto/engine/tb_digest.c \
+  crypto/engine/tb_dsa.c \
+  crypto/engine/tb_ecdh.c \
+  crypto/engine/tb_ecdsa.c \
+  crypto/engine/tb_pkmeth.c \
+  crypto/engine/tb_rand.c \
+  crypto/engine/tb_rsa.c \
+  crypto/engine/tb_store.c \
+  crypto/err/err.c \
+  crypto/err/err_all.c \
+  crypto/err/err_prn.c \
+  crypto/evp/bio_b64.c \
+  crypto/evp/bio_enc.c \
+  crypto/evp/bio_md.c \
+  crypto/evp/bio_ok.c \
+  crypto/evp/c_all.c \
+  crypto/evp/c_allc.c \
+  crypto/evp/c_alld.c \
+  crypto/evp/digest.c \
+  crypto/evp/e_aes.c \
+  crypto/evp/e_aes_cbc_hmac_sha1.c \
+  crypto/evp/e_bf.c \
+  crypto/evp/e_des.c \
+  crypto/evp/e_des3.c \
+  crypto/evp/e_null.c \
+  crypto/evp/e_old.c \
+  crypto/evp/e_rc2.c \
+  crypto/evp/e_rc4.c \
+  crypto/evp/e_rc4_hmac_md5.c \
+  crypto/evp/e_rc5.c \
+  crypto/evp/e_xcbc_d.c \
+  crypto/evp/encode.c \
+  crypto/evp/evp_acnf.c \
+  crypto/evp/evp_cnf.c \
+  crypto/evp/evp_enc.c \
+  crypto/evp/evp_err.c \
+  crypto/evp/evp_key.c \
+  crypto/evp/evp_lib.c \
+  crypto/evp/evp_pbe.c \
+  crypto/evp/evp_pkey.c \
+  crypto/evp/m_dss.c \
+  crypto/evp/m_dss1.c \
+  crypto/evp/m_ecdsa.c \
+  crypto/evp/m_md4.c \
+  crypto/evp/m_md5.c \
+  crypto/evp/m_mdc2.c \
+  crypto/evp/m_null.c \
+  crypto/evp/m_ripemd.c \
+  crypto/evp/m_sha1.c \
+  crypto/evp/m_sigver.c \
+  crypto/evp/m_wp.c \
+  crypto/evp/names.c \
+  crypto/evp/p5_crpt.c \
+  crypto/evp/p5_crpt2.c \
+  crypto/evp/p_dec.c \
+  crypto/evp/p_enc.c \
+  crypto/evp/p_lib.c \
+  crypto/evp/p_open.c \
+  crypto/evp/p_seal.c \
+  crypto/evp/p_sign.c \
+  crypto/evp/p_verify.c \
+  crypto/evp/pmeth_fn.c \
+  crypto/evp/pmeth_gn.c \
+  crypto/evp/pmeth_lib.c \
+  crypto/ex_data.c \
+  crypto/hmac/hm_ameth.c \
+  crypto/hmac/hm_pmeth.c \
+  crypto/hmac/hmac.c \
+  crypto/krb5/krb5_asn.c \
+  crypto/lhash/lh_stats.c \
+  crypto/lhash/lhash.c \
+  crypto/md4/md4_dgst.c \
+  crypto/md4/md4_one.c \
+  crypto/md5/md5_dgst.c \
+  crypto/md5/md5_one.c \
+  crypto/mem.c \
+  crypto/mem_clr.c \
+  crypto/mem_dbg.c \
+  crypto/modes/cbc128.c \
+  crypto/modes/ccm128.c \
+  crypto/modes/cfb128.c \
+  crypto/modes/ctr128.c \
+  crypto/modes/gcm128.c \
+  crypto/modes/ofb128.c \
+  crypto/modes/xts128.c \
+  crypto/o_dir.c \
+  crypto/o_init.c \
+  crypto/o_str.c \
+  crypto/o_time.c \
+  crypto/objects/o_names.c \
+  crypto/objects/obj_dat.c \
+  crypto/objects/obj_err.c \
+  crypto/objects/obj_lib.c \
+  crypto/objects/obj_xref.c \
+  crypto/ocsp/ocsp_asn.c \
+  crypto/ocsp/ocsp_cl.c \
+  crypto/ocsp/ocsp_err.c \
+  crypto/ocsp/ocsp_ext.c \
+  crypto/ocsp/ocsp_ht.c \
+  crypto/ocsp/ocsp_lib.c \
+  crypto/ocsp/ocsp_prn.c \
+  crypto/ocsp/ocsp_srv.c \
+  crypto/ocsp/ocsp_vfy.c \
+  crypto/pem/pem_all.c \
+  crypto/pem/pem_err.c \
+  crypto/pem/pem_info.c \
+  crypto/pem/pem_lib.c \
+  crypto/pem/pem_oth.c \
+  crypto/pem/pem_pk8.c \
+  crypto/pem/pem_pkey.c \
+  crypto/pem/pem_seal.c \
+  crypto/pem/pem_sign.c \
+  crypto/pem/pem_x509.c \
+  crypto/pem/pem_xaux.c \
+  crypto/pem/pvkfmt.c \
+  crypto/pkcs12/p12_add.c \
+  crypto/pkcs12/p12_asn.c \
+  crypto/pkcs12/p12_attr.c \
+  crypto/pkcs12/p12_crpt.c \
+  crypto/pkcs12/p12_crt.c \
+  crypto/pkcs12/p12_decr.c \
+  crypto/pkcs12/p12_init.c \
+  crypto/pkcs12/p12_key.c \
+  crypto/pkcs12/p12_kiss.c \
+  crypto/pkcs12/p12_mutl.c \
+  crypto/pkcs12/p12_npas.c \
+  crypto/pkcs12/p12_p8d.c \
+  crypto/pkcs12/p12_p8e.c \
+  crypto/pkcs12/p12_utl.c \
+  crypto/pkcs12/pk12err.c \
+  crypto/pkcs7/pk7_asn1.c \
+  crypto/pkcs7/pk7_attr.c \
+  crypto/pkcs7/pk7_doit.c \
+  crypto/pkcs7/pk7_lib.c \
+  crypto/pkcs7/pk7_mime.c \
+  crypto/pkcs7/pk7_smime.c \
+  crypto/pkcs7/pkcs7err.c \
+  crypto/pqueue/pqueue.c \
+  crypto/rand/md_rand.c \
+  crypto/rand/rand_egd.c \
+  crypto/rand/rand_err.c \
+  crypto/rand/rand_lib.c \
+  crypto/rand/rand_unix.c \
+  crypto/rand/rand_win.c \
+  crypto/rand/randfile.c \
+  crypto/rc2/rc2_cbc.c \
+  crypto/rc2/rc2_ecb.c \
+  crypto/rc2/rc2_skey.c \
+  crypto/rc2/rc2cfb64.c \
+  crypto/rc2/rc2ofb64.c \
+  crypto/rc4/rc4_enc.c \
+  crypto/rc4/rc4_skey.c \
+  crypto/rc4/rc4_utl.c \
+  crypto/ripemd/rmd_dgst.c \
+  crypto/ripemd/rmd_one.c \
+  crypto/rsa/rsa_ameth.c \
+  crypto/rsa/rsa_asn1.c \
+  crypto/rsa/rsa_chk.c \
+  crypto/rsa/rsa_crpt.c \
+  crypto/rsa/rsa_eay.c \
+  crypto/rsa/rsa_err.c \
+  crypto/rsa/rsa_gen.c \
+  crypto/rsa/rsa_lib.c \
+  crypto/rsa/rsa_none.c \
+  crypto/rsa/rsa_null.c \
+  crypto/rsa/rsa_oaep.c \
+  crypto/rsa/rsa_pk1.c \
+  crypto/rsa/rsa_pmeth.c \
+  crypto/rsa/rsa_prn.c \
+  crypto/rsa/rsa_pss.c \
+  crypto/rsa/rsa_saos.c \
+  crypto/rsa/rsa_sign.c \
+  crypto/rsa/rsa_ssl.c \
+  crypto/rsa/rsa_x931.c \
+  crypto/sha/sha1_one.c \
+  crypto/sha/sha1dgst.c \
+  crypto/sha/sha256.c \
+  crypto/sha/sha512.c \
+  crypto/sha/sha_dgst.c \
+  crypto/srp/srp_lib.c \
+  crypto/srp/srp_vfy.c \
+  crypto/stack/stack.c \
+  crypto/ts/ts_err.c \
+  crypto/txt_db/txt_db.c \
+  crypto/ui/ui_compat.c \
+  crypto/ui/ui_err.c \
+  crypto/ui/ui_lib.c \
+  crypto/ui/ui_openssl.c \
+  crypto/ui/ui_util.c \
+  crypto/uid.c \
+  crypto/x509/by_dir.c \
+  crypto/x509/by_file.c \
+  crypto/x509/x509_att.c \
+  crypto/x509/x509_cmp.c \
+  crypto/x509/x509_d2.c \
+  crypto/x509/x509_def.c \
+  crypto/x509/x509_err.c \
+  crypto/x509/x509_ext.c \
+  crypto/x509/x509_lu.c \
+  crypto/x509/x509_obj.c \
+  crypto/x509/x509_r2x.c \
+  crypto/x509/x509_req.c \
+  crypto/x509/x509_set.c \
+  crypto/x509/x509_trs.c \
+  crypto/x509/x509_txt.c \
+  crypto/x509/x509_v3.c \
+  crypto/x509/x509_vfy.c \
+  crypto/x509/x509_vpm.c \
+  crypto/x509/x509cset.c \
+  crypto/x509/x509name.c \
+  crypto/x509/x509rset.c \
+  crypto/x509/x509spki.c \
+  crypto/x509/x509type.c \
+  crypto/x509/x_all.c \
+  crypto/x509v3/pcy_cache.c \
+  crypto/x509v3/pcy_data.c \
+  crypto/x509v3/pcy_lib.c \
+  crypto/x509v3/pcy_map.c \
+  crypto/x509v3/pcy_node.c \
+  crypto/x509v3/pcy_tree.c \
+  crypto/x509v3/v3_akey.c \
+  crypto/x509v3/v3_akeya.c \
+  crypto/x509v3/v3_alt.c \
+  crypto/x509v3/v3_bcons.c \
+  crypto/x509v3/v3_bitst.c \
+  crypto/x509v3/v3_conf.c \
+  crypto/x509v3/v3_cpols.c \
+  crypto/x509v3/v3_crld.c \
+  crypto/x509v3/v3_enum.c \
+  crypto/x509v3/v3_extku.c \
+  crypto/x509v3/v3_genn.c \
+  crypto/x509v3/v3_ia5.c \
+  crypto/x509v3/v3_info.c \
+  crypto/x509v3/v3_int.c \
+  crypto/x509v3/v3_lib.c \
+  crypto/x509v3/v3_ncons.c \
+  crypto/x509v3/v3_ocsp.c \
+  crypto/x509v3/v3_pci.c \
+  crypto/x509v3/v3_pcia.c \
+  crypto/x509v3/v3_pcons.c \
+  crypto/x509v3/v3_pku.c \
+  crypto/x509v3/v3_pmaps.c \
+  crypto/x509v3/v3_prn.c \
+  crypto/x509v3/v3_purp.c \
+  crypto/x509v3/v3_skey.c \
+  crypto/x509v3/v3_sxnet.c \
+  crypto/x509v3/v3_utl.c \
+  crypto/x509v3/v3err.c \
+
+common_c_includes := \
+  . \
+  crypto \
+  crypto/asn1 \
+  crypto/evp \
+  crypto/modes \
+  include \
+  include/openssl \
+
+arm_c_flags := \
+  -DAES_ASM \
+  -DGHASH_ASM \
+  -DOPENSSL_BN_ASM_GF2m \
+  -DOPENSSL_BN_ASM_MONT \
+  -DSHA1_ASM \
+  -DSHA256_ASM \
+  -DSHA512_ASM \
+
+arm_src_files := \
+  crypto/aes/asm/aes-armv4.S \
+  crypto/bn/asm/armv4-gf2m.S \
+  crypto/bn/asm/armv4-mont.S \
+  crypto/modes/asm/ghash-armv4.S \
+  crypto/sha/asm/sha1-armv4-large.S \
+  crypto/sha/asm/sha256-armv4.S \
+  crypto/sha/asm/sha512-armv4.S \
+
+arm_exclude_files := \
+  crypto/aes/aes_core.c \
+
+x86_c_flags := \
+  -DAES_ASM \
+  -DDES_PTR \
+  -DDES_RISC1 \
+  -DDES_UNROLL \
+  -DGHASH_ASM \
+  -DMD5_ASM \
+  -DOPENSSL_BN_ASM_GF2m \
+  -DOPENSSL_BN_ASM_MONT \
+  -DOPENSSL_BN_ASM_PART_WORDS \
+  -DOPENSSL_CPUID_OBJ \
+  -DSHA1_ASM \
+  -DSHA256_ASM \
+  -DSHA512_ASM \
+
+x86_src_files := \
+  crypto/aes/asm/aes-586.S \
+  crypto/aes/asm/aesni-x86.S \
+  crypto/aes/asm/vpaes-x86.S \
+  crypto/bf/asm/bf-586.S \
+  crypto/bn/asm/bn-586.S \
+  crypto/bn/asm/co-586.S \
+  crypto/bn/asm/x86-gf2m.S \
+  crypto/bn/asm/x86-mont.S \
+  crypto/des/asm/crypt586.S \
+  crypto/des/asm/des-586.S \
+  crypto/md5/asm/md5-586.S \
+  crypto/modes/asm/ghash-x86.S \
+  crypto/sha/asm/sha1-586.S \
+  crypto/sha/asm/sha256-586.S \
+  crypto/sha/asm/sha512-586.S \
+  crypto/x86cpuid.S \
+
+x86_exclude_files := \
+  crypto/aes/aes_cbc.c \
+  crypto/aes/aes_core.c \
+  crypto/bf/bf_enc.c \
+  crypto/bn/bn_asm.c \
+  crypto/des/des_enc.c \
+  crypto/des/fcrypt_b.c \
+  crypto/mem_clr.c \
+
+x86_64_c_flags := \
+  -DAES_ASM \
+  -DDES_PTR \
+  -DDES_RISC1 \
+  -DDES_UNROLL \
+  -DGHASH_ASM \
+  -DMD5_ASM \
+  -DOPENSSL_BN_ASM_GF2m \
+  -DOPENSSL_BN_ASM_MONT \
+  -DOPENSSL_CPUID_OBJ \
+  -DSHA1_ASM \
+  -DSHA256_ASM \
+  -DSHA512_ASM \
+
+x86_64_src_files := \
+  crypto/aes/asm/aes-x86_64.S \
+  crypto/aes/asm/aesni-sha1-x86_64.S \
+  crypto/aes/asm/aesni-x86_64.S \
+  crypto/aes/asm/bsaes-x86_64.S \
+  crypto/aes/asm/vpaes-x86_64.S \
+  crypto/bn/asm/modexp512-x86_64.S \
+  crypto/bn/asm/x86_64-gcc.c \
+  crypto/bn/asm/x86_64-gf2m.S \
+  crypto/bn/asm/x86_64-mont.S \
+  crypto/bn/asm/x86_64-mont5.S \
+  crypto/md5/asm/md5-x86_64.S \
+  crypto/modes/asm/ghash-x86_64.S \
+  crypto/rc4/asm/rc4-md5-x86_64.S \
+  crypto/rc4/asm/rc4-x86_64.S \
+  crypto/sha/asm/sha1-x86_64.S \
+  crypto/sha/asm/sha256-x86_64.S \
+  crypto/sha/asm/sha512-x86_64.S \
+  crypto/x86_64cpuid.S \
+
+x86_64_exclude_files := \
+  crypto/aes/aes_cbc.c \
+  crypto/aes/aes_core.c \
+  crypto/mem_clr.c \
+  crypto/rc4/rc4_enc.c \
+
+mips_c_flags := \
+  -DAES_ASM \
+  -DOPENSSL_BN_ASM_MONT \
+  -DSHA1_ASM \
+  -DSHA256_ASM \
+
+mips_src_files := \
+  crypto/aes/asm/aes-mips.S \
+  crypto/bn/asm/bn-mips.S \
+  crypto/bn/asm/mips-mont.S \
+  crypto/sha/asm/sha1-mips.S \
+  crypto/sha/asm/sha256-mips.S \
+
+mips_exclude_files := \
+  crypto/aes/aes_core.c \
+  crypto/bn/bn_asm.c \
+
+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/openssl/,$(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))
+
+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/openssl/,$(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)/Crypto-config.mk
+
diff --git a/Crypto.mk b/Crypto.mk
index 1ea3939..8827383 100644
--- a/Crypto.mk
+++ b/Crypto.mk
@@ -1,570 +1,11 @@
-arm_cflags := -DOPENSSL_BN_ASM_GF2m -DOPENSSL_BN_ASM_MONT -DGHASH_ASM -DAES_ASM -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM
-mips_cflags := -DOPENSSL_BN_ASM_MONT -DAES_ASM -DSHA1_ASM -DSHA256_ASM
-x86_cflags := -DOPENSSL_BN_ASM_GF2m -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_PART_WORDS -DAES_ASM -DGHASH_ASM -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DDES_PTR -DDES_RISC1 -DDES_UNROLL -DOPENSSL_CPUID_OBJ
+local_c_flags :=
 
-arm_src_files := \
- crypto/aes/asm/aes-armv4.S \
- crypto/bn/asm/armv4-gf2m.S \
- crypto/bn/asm/armv4-mont.S \
- crypto/bn/bn_asm.c \
- crypto/modes/asm/ghash-armv4.S \
- crypto/sha/asm/sha1-armv4-large.S \
- crypto/sha/asm/sha256-armv4.S \
- crypto/sha/asm/sha512-armv4.S
-
-mips_src_files := \
- crypto/aes/asm/aes-mips.S \
- crypto/bn/asm/bn-mips.S \
- crypto/bn/asm/mips-mont.S \
- crypto/sha/asm/sha1-mips.S \
- crypto/sha/asm/sha256-mips.S
-
-x86_src_files := \
- crypto/aes/asm/aes-586.S \
- crypto/aes/asm/vpaes-x86.S \
- crypto/aes/asm/aesni-x86.S \
- crypto/bn/asm/bn-586.S \
- crypto/bn/asm/co-586.S \
- crypto/bn/asm/x86-mont.S \
- crypto/bn/asm/x86-gf2m.S \
- crypto/modes/asm/ghash-x86.S \
- crypto/sha/asm/sha1-586.S \
- crypto/sha/asm/sha256-586.S \
- crypto/sha/asm/sha512-586.S \
- crypto/md5/asm/md5-586.S \
- crypto/des/asm/des-586.S \
- crypto/des/asm/crypt586.S \
- crypto/bf/asm/bf-586.S \
- crypto/x86cpuid.S
-
-x86_exclude_files := \
- crypto/aes/aes_cbc.c \
- crypto/des/des_enc.c \
- crypto/des/fcrypt_b.c \
- crypto/bf/bf_enc.c \
- crypto/mem_clr.c
-
-other_arch_src_files := \
- crypto/aes/aes_core.c \
- crypto/bn/bn_asm.c
-
-local_src_files := \
- crypto/cryptlib.c \
- crypto/mem.c \
- crypto/mem_clr.c \
- crypto/mem_dbg.c \
- crypto/cversion.c \
- crypto/ex_data.c \
- crypto/cpt_err.c \
- crypto/ebcdic.c \
- crypto/uid.c \
- crypto/o_time.c \
- crypto/o_str.c \
- crypto/o_dir.c \
- crypto/aes/aes_cbc.c \
- crypto/aes/aes_cfb.c \
- crypto/aes/aes_ctr.c \
- crypto/aes/aes_ecb.c \
- crypto/aes/aes_misc.c \
- crypto/aes/aes_ofb.c \
- crypto/aes/aes_wrap.c \
- crypto/asn1/a_bitstr.c \
- crypto/asn1/a_bool.c \
- crypto/asn1/a_bytes.c \
- crypto/asn1/a_d2i_fp.c \
- crypto/asn1/a_digest.c \
- crypto/asn1/a_dup.c \
- crypto/asn1/a_enum.c \
- crypto/asn1/a_gentm.c \
- crypto/asn1/a_i2d_fp.c \
- crypto/asn1/a_int.c \
- crypto/asn1/a_mbstr.c \
- crypto/asn1/a_object.c \
- crypto/asn1/a_octet.c \
- crypto/asn1/a_print.c \
- crypto/asn1/a_set.c \
- crypto/asn1/a_sign.c \
- crypto/asn1/a_strex.c \
- crypto/asn1/a_strnid.c \
- crypto/asn1/a_time.c \
- crypto/asn1/a_type.c \
- crypto/asn1/a_utctm.c \
- crypto/asn1/a_utf8.c \
- crypto/asn1/a_verify.c \
- crypto/asn1/ameth_lib.c \
- crypto/asn1/asn1_err.c \
- crypto/asn1/asn1_gen.c \
- crypto/asn1/asn1_lib.c \
- crypto/asn1/asn1_par.c \
- crypto/asn1/asn_mime.c \
- crypto/asn1/asn_moid.c \
- crypto/asn1/asn_pack.c \
- crypto/asn1/bio_asn1.c \
- crypto/asn1/bio_ndef.c \
- crypto/asn1/d2i_pr.c \
- crypto/asn1/d2i_pu.c \
- crypto/asn1/evp_asn1.c \
- crypto/asn1/f_enum.c \
- crypto/asn1/f_int.c \
- crypto/asn1/f_string.c \
- crypto/asn1/i2d_pr.c \
- crypto/asn1/i2d_pu.c \
- crypto/asn1/n_pkey.c \
- crypto/asn1/nsseq.c \
- crypto/asn1/p5_pbe.c \
- crypto/asn1/p5_pbev2.c \
- crypto/asn1/p8_pkey.c \
- crypto/asn1/t_bitst.c \
- crypto/asn1/t_crl.c \
- crypto/asn1/t_pkey.c \
- crypto/asn1/t_req.c \
- crypto/asn1/t_spki.c \
- crypto/asn1/t_x509.c \
- crypto/asn1/t_x509a.c \
- crypto/asn1/tasn_dec.c \
- crypto/asn1/tasn_enc.c \
- crypto/asn1/tasn_fre.c \
- crypto/asn1/tasn_new.c \
- crypto/asn1/tasn_prn.c \
- crypto/asn1/tasn_typ.c \
- crypto/asn1/tasn_utl.c \
- crypto/asn1/x_algor.c \
- crypto/asn1/x_attrib.c \
- crypto/asn1/x_bignum.c \
- crypto/asn1/x_crl.c \
- crypto/asn1/x_exten.c \
- crypto/asn1/x_info.c \
- crypto/asn1/x_long.c \
- crypto/asn1/x_name.c \
- crypto/asn1/x_nx509.c \
- crypto/asn1/x_pkey.c \
- crypto/asn1/x_pubkey.c \
- crypto/asn1/x_req.c \
- crypto/asn1/x_sig.c \
- crypto/asn1/x_spki.c \
- crypto/asn1/x_val.c \
- crypto/asn1/x_x509.c \
- crypto/asn1/x_x509a.c \
- crypto/bf/bf_cfb64.c \
- crypto/bf/bf_ecb.c \
- crypto/bf/bf_enc.c \
- crypto/bf/bf_ofb64.c \
- crypto/bf/bf_skey.c \
- crypto/bio/b_dump.c \
- crypto/bio/b_print.c \
- crypto/bio/b_sock.c \
- crypto/bio/bf_buff.c \
- crypto/bio/bf_nbio.c \
- crypto/bio/bf_null.c \
- crypto/bio/bio_cb.c \
- crypto/bio/bio_err.c \
- crypto/bio/bio_lib.c \
- crypto/bio/bss_acpt.c \
- crypto/bio/bss_bio.c \
- crypto/bio/bss_conn.c \
- crypto/bio/bss_dgram.c \
- crypto/bio/bss_fd.c \
- crypto/bio/bss_file.c \
- crypto/bio/bss_log.c \
- crypto/bio/bss_mem.c \
- crypto/bio/bss_null.c \
- crypto/bio/bss_sock.c \
- crypto/bn/bn_add.c \
- crypto/bn/bn_blind.c \
- crypto/bn/bn_const.c \
- crypto/bn/bn_ctx.c \
- crypto/bn/bn_div.c \
- crypto/bn/bn_err.c \
- crypto/bn/bn_exp.c \
- crypto/bn/bn_exp2.c \
- crypto/bn/bn_gcd.c \
- crypto/bn/bn_gf2m.c \
- crypto/bn/bn_kron.c \
- crypto/bn/bn_lib.c \
- crypto/bn/bn_mod.c \
- crypto/bn/bn_mont.c \
- crypto/bn/bn_mpi.c \
- crypto/bn/bn_mul.c \
- crypto/bn/bn_nist.c \
- crypto/bn/bn_prime.c \
- crypto/bn/bn_print.c \
- crypto/bn/bn_rand.c \
- crypto/bn/bn_recp.c \
- crypto/bn/bn_shift.c \
- crypto/bn/bn_sqr.c \
- crypto/bn/bn_sqrt.c \
- crypto/bn/bn_word.c \
- crypto/buffer/buf_err.c \
- crypto/buffer/buf_str.c \
- crypto/buffer/buffer.c \
- crypto/cmac/cm_ameth.c \
- crypto/cmac/cm_pmeth.c \
- crypto/cmac/cmac.c \
- crypto/comp/c_rle.c \
- crypto/comp/c_zlib.c \
- crypto/comp/comp_err.c \
- crypto/comp/comp_lib.c \
- crypto/conf/conf_api.c \
- crypto/conf/conf_def.c \
- crypto/conf/conf_err.c \
- crypto/conf/conf_lib.c \
- crypto/conf/conf_mall.c \
- crypto/conf/conf_mod.c \
- crypto/conf/conf_sap.c \
- crypto/des/cbc_cksm.c \
- crypto/des/cbc_enc.c \
- crypto/des/cfb64ede.c \
- crypto/des/cfb64enc.c \
- crypto/des/cfb_enc.c \
- crypto/des/des_enc.c \
- crypto/des/des_old.c \
- crypto/des/des_old2.c \
- crypto/des/ecb3_enc.c \
- crypto/des/ecb_enc.c \
- crypto/des/ede_cbcm_enc.c \
- crypto/des/enc_read.c \
- crypto/des/enc_writ.c \
- crypto/des/fcrypt.c \
- crypto/des/fcrypt_b.c \
- crypto/des/ofb64ede.c \
- crypto/des/ofb64enc.c \
- crypto/des/ofb_enc.c \
- crypto/des/pcbc_enc.c \
- crypto/des/qud_cksm.c \
- crypto/des/rand_key.c \
- crypto/des/read2pwd.c \
- crypto/des/rpc_enc.c \
- crypto/des/set_key.c \
- crypto/des/str2key.c \
- crypto/des/xcbc_enc.c \
- crypto/dh/dh_ameth.c \
- crypto/dh/dh_asn1.c \
- crypto/dh/dh_check.c \
- crypto/dh/dh_depr.c \
- crypto/dh/dh_err.c \
- crypto/dh/dh_gen.c \
- crypto/dh/dh_key.c \
- crypto/dh/dh_lib.c \
- crypto/dh/dh_pmeth.c \
- crypto/dsa/dsa_ameth.c \
- crypto/dsa/dsa_asn1.c \
- crypto/dsa/dsa_depr.c \
- crypto/dsa/dsa_err.c \
- crypto/dsa/dsa_gen.c \
- crypto/dsa/dsa_key.c \
- crypto/dsa/dsa_lib.c \
- crypto/dsa/dsa_ossl.c \
- crypto/dsa/dsa_pmeth.c \
- crypto/dsa/dsa_prn.c \
- crypto/dsa/dsa_sign.c \
- crypto/dsa/dsa_vrf.c \
- crypto/dso/dso_dl.c \
- crypto/dso/dso_dlfcn.c \
- crypto/dso/dso_err.c \
- crypto/dso/dso_lib.c \
- crypto/dso/dso_null.c \
- crypto/dso/dso_openssl.c \
- crypto/ec/ec2_mult.c \
- crypto/ec/ec2_oct.c \
- crypto/ec/ec2_smpl.c \
- crypto/ec/ec_ameth.c \
- crypto/ec/ec_asn1.c \
- crypto/ec/ec_check.c \
- crypto/ec/ec_curve.c \
- crypto/ec/ec_cvt.c \
- crypto/ec/ec_err.c \
- crypto/ec/ec_key.c \
- crypto/ec/ec_lib.c \
- crypto/ec/ec_mult.c \
- crypto/ec/ec_oct.c \
- crypto/ec/ec_pmeth.c \
- crypto/ec/ec_print.c \
- crypto/ec/eck_prn.c \
- crypto/ec/ecp_mont.c \
- crypto/ec/ecp_nist.c \
- crypto/ec/ecp_oct.c \
- crypto/ec/ecp_smpl.c \
- crypto/ecdh/ech_err.c \
- crypto/ecdh/ech_key.c \
- crypto/ecdh/ech_lib.c \
- crypto/ecdh/ech_ossl.c \
- crypto/ecdsa/ecs_asn1.c \
- crypto/ecdsa/ecs_err.c \
- crypto/ecdsa/ecs_lib.c \
- crypto/ecdsa/ecs_ossl.c \
- crypto/ecdsa/ecs_sign.c \
- crypto/ecdsa/ecs_vrf.c \
- crypto/engine/eng_all.c \
- crypto/engine/eng_cnf.c \
- crypto/engine/eng_ctrl.c \
- crypto/engine/eng_dyn.c \
- crypto/engine/eng_err.c \
- crypto/engine/eng_fat.c \
- crypto/engine/eng_init.c \
- crypto/engine/eng_lib.c \
- crypto/engine/eng_list.c \
- crypto/engine/eng_pkey.c \
- crypto/engine/eng_table.c \
- crypto/engine/tb_asnmth.c \
- crypto/engine/tb_cipher.c \
- crypto/engine/tb_dh.c \
- crypto/engine/tb_digest.c \
- crypto/engine/tb_dsa.c \
- crypto/engine/tb_ecdh.c \
- crypto/engine/tb_ecdsa.c \
- crypto/engine/tb_pkmeth.c \
- crypto/engine/tb_rand.c \
- crypto/engine/tb_rsa.c \
- crypto/engine/tb_store.c \
- crypto/err/err.c \
- crypto/err/err_all.c \
- crypto/err/err_prn.c \
- crypto/evp/bio_b64.c \
- crypto/evp/bio_enc.c \
- crypto/evp/bio_md.c \
- crypto/evp/bio_ok.c \
- crypto/evp/c_all.c \
- crypto/evp/c_allc.c \
- crypto/evp/c_alld.c \
- crypto/evp/digest.c \
- crypto/evp/e_aes.c \
- crypto/evp/e_aes_cbc_hmac_sha1.c \
- crypto/evp/e_bf.c \
- crypto/evp/e_des.c \
- crypto/evp/e_des3.c \
- crypto/evp/e_null.c \
- crypto/evp/e_old.c \
- crypto/evp/e_rc2.c \
- crypto/evp/e_rc4.c \
- crypto/evp/e_rc4_hmac_md5.c \
- crypto/evp/e_rc5.c \
- crypto/evp/e_xcbc_d.c \
- crypto/evp/encode.c \
- crypto/evp/evp_acnf.c \
- crypto/evp/evp_cnf.c \
- crypto/evp/evp_enc.c \
- crypto/evp/evp_err.c \
- crypto/evp/evp_key.c \
- crypto/evp/evp_lib.c \
- crypto/evp/evp_pbe.c \
- crypto/evp/evp_pkey.c \
- crypto/evp/m_dss.c \
- crypto/evp/m_dss1.c \
- crypto/evp/m_ecdsa.c \
- crypto/evp/m_md4.c \
- crypto/evp/m_md5.c \
- crypto/evp/m_mdc2.c \
- crypto/evp/m_null.c \
- crypto/evp/m_ripemd.c \
- crypto/evp/m_sha1.c \
- crypto/evp/m_sigver.c \
- crypto/evp/m_wp.c \
- crypto/evp/names.c \
- crypto/evp/p5_crpt.c \
- crypto/evp/p5_crpt2.c \
- crypto/evp/p_dec.c \
- crypto/evp/p_enc.c \
- crypto/evp/p_lib.c \
- crypto/evp/p_open.c \
- crypto/evp/p_seal.c \
- crypto/evp/p_sign.c \
- crypto/evp/p_verify.c \
- crypto/evp/pmeth_fn.c \
- crypto/evp/pmeth_gn.c \
- crypto/evp/pmeth_lib.c \
- crypto/hmac/hm_ameth.c \
- crypto/hmac/hm_pmeth.c \
- crypto/hmac/hmac.c \
- crypto/krb5/krb5_asn.c \
- crypto/lhash/lh_stats.c \
- crypto/lhash/lhash.c \
- crypto/md4/md4_dgst.c \
- crypto/md4/md4_one.c \
- crypto/md5/md5_dgst.c \
- crypto/md5/md5_one.c \
- crypto/modes/cbc128.c \
- crypto/modes/ccm128.c \
- crypto/modes/cfb128.c \
- crypto/modes/ctr128.c \
- crypto/modes/gcm128.c \
- crypto/modes/ofb128.c \
- crypto/modes/xts128.c \
- crypto/o_init.c \
- crypto/objects/o_names.c \
- crypto/objects/obj_dat.c \
- crypto/objects/obj_err.c \
- crypto/objects/obj_lib.c \
- crypto/objects/obj_xref.c \
- crypto/ocsp/ocsp_asn.c \
- crypto/ocsp/ocsp_cl.c \
- crypto/ocsp/ocsp_err.c \
- crypto/ocsp/ocsp_ext.c \
- crypto/ocsp/ocsp_ht.c \
- crypto/ocsp/ocsp_lib.c \
- crypto/ocsp/ocsp_prn.c \
- crypto/ocsp/ocsp_srv.c \
- crypto/ocsp/ocsp_vfy.c \
- crypto/pem/pem_all.c \
- crypto/pem/pem_err.c \
- crypto/pem/pem_info.c \
- crypto/pem/pem_lib.c \
- crypto/pem/pem_oth.c \
- crypto/pem/pem_pk8.c \
- crypto/pem/pem_pkey.c \
- crypto/pem/pem_seal.c \
- crypto/pem/pem_sign.c \
- crypto/pem/pem_x509.c \
- crypto/pem/pem_xaux.c \
- crypto/pem/pvkfmt.c \
- crypto/pkcs12/p12_add.c \
- crypto/pkcs12/p12_asn.c \
- crypto/pkcs12/p12_attr.c \
- crypto/pkcs12/p12_crpt.c \
- crypto/pkcs12/p12_crt.c \
- crypto/pkcs12/p12_decr.c \
- crypto/pkcs12/p12_init.c \
- crypto/pkcs12/p12_key.c \
- crypto/pkcs12/p12_kiss.c \
- crypto/pkcs12/p12_mutl.c \
- crypto/pkcs12/p12_npas.c \
- crypto/pkcs12/p12_p8d.c \
- crypto/pkcs12/p12_p8e.c \
- crypto/pkcs12/p12_utl.c \
- crypto/pkcs12/pk12err.c \
- crypto/pkcs7/pk7_asn1.c \
- crypto/pkcs7/pk7_attr.c \
- crypto/pkcs7/pk7_doit.c \
- crypto/pkcs7/pk7_lib.c crypto/\
- crypto/pkcs7/pk7_mime.c \
- crypto/pkcs7/pk7_smime.c \
- crypto/pkcs7/pkcs7err.c \
- crypto/pqueue/pqueue.c \
- crypto/rand/md_rand.c \
- crypto/rand/rand_egd.c \
- crypto/rand/rand_err.c \
- crypto/rand/rand_lib.c \
- crypto/rand/rand_unix.c \
- crypto/rand/rand_win.c \
- crypto/rand/randfile.c \
- crypto/rc2/rc2_cbc.c \
- crypto/rc2/rc2_ecb.c \
- crypto/rc2/rc2_skey.c \
- crypto/rc2/rc2cfb64.c \
- crypto/rc2/rc2ofb64.c \
- crypto/rc4/rc4_enc.c \
- crypto/rc4/rc4_skey.c \
- crypto/rc4/rc4_utl.c \
- crypto/ripemd/rmd_dgst.c \
- crypto/ripemd/rmd_one.c \
- crypto/rsa/rsa_ameth.c \
- crypto/rsa/rsa_asn1.c \
- crypto/rsa/rsa_chk.c \
- crypto/rsa/rsa_crpt.c \
- crypto/rsa/rsa_eay.c \
- crypto/rsa/rsa_err.c \
- crypto/rsa/rsa_gen.c \
- crypto/rsa/rsa_lib.c \
- crypto/rsa/rsa_none.c \
- crypto/rsa/rsa_null.c \
- crypto/rsa/rsa_oaep.c \
- crypto/rsa/rsa_pk1.c \
- crypto/rsa/rsa_pmeth.c \
- crypto/rsa/rsa_prn.c \
- crypto/rsa/rsa_pss.c \
- crypto/rsa/rsa_saos.c \
- crypto/rsa/rsa_sign.c \
- crypto/rsa/rsa_ssl.c \
- crypto/rsa/rsa_x931.c \
- crypto/sha/sha1_one.c \
- crypto/sha/sha1dgst.c \
- crypto/sha/sha256.c \
- crypto/sha/sha512.c \
- crypto/sha/sha_dgst.c \
- crypto/srp/srp_lib.c \
- crypto/srp/srp_vfy.c \
- crypto/stack/stack.c \
- crypto/ts/ts_err.c \
- crypto/txt_db/txt_db.c \
- crypto/ui/ui_compat.c \
- crypto/ui/ui_err.c \
- crypto/ui/ui_lib.c \
- crypto/ui/ui_openssl.c \
- crypto/ui/ui_util.c \
- crypto/x509/by_dir.c \
- crypto/x509/by_file.c \
- crypto/x509/x509_att.c \
- crypto/x509/x509_cmp.c \
- crypto/x509/x509_d2.c \
- crypto/x509/x509_def.c \
- crypto/x509/x509_err.c \
- crypto/x509/x509_ext.c \
- crypto/x509/x509_lu.c \
- crypto/x509/x509_obj.c \
- crypto/x509/x509_r2x.c \
- crypto/x509/x509_req.c \
- crypto/x509/x509_set.c \
- crypto/x509/x509_trs.c \
- crypto/x509/x509_txt.c \
- crypto/x509/x509_v3.c \
- crypto/x509/x509_vfy.c \
- crypto/x509/x509_vpm.c \
- crypto/x509/x509cset.c \
- crypto/x509/x509name.c \
- crypto/x509/x509rset.c \
- crypto/x509/x509spki.c \
- crypto/x509/x509type.c \
- crypto/x509/x_all.c \
- crypto/x509v3/pcy_cache.c \
- crypto/x509v3/pcy_data.c \
- crypto/x509v3/pcy_lib.c \
- crypto/x509v3/pcy_map.c \
- crypto/x509v3/pcy_node.c \
- crypto/x509v3/pcy_tree.c \
- crypto/x509v3/v3_akey.c \
- crypto/x509v3/v3_akeya.c \
- crypto/x509v3/v3_alt.c \
- crypto/x509v3/v3_bcons.c \
- crypto/x509v3/v3_bitst.c \
- crypto/x509v3/v3_conf.c \
- crypto/x509v3/v3_cpols.c \
- crypto/x509v3/v3_crld.c \
- crypto/x509v3/v3_enum.c \
- crypto/x509v3/v3_extku.c \
- crypto/x509v3/v3_genn.c \
- crypto/x509v3/v3_ia5.c \
- crypto/x509v3/v3_info.c \
- crypto/x509v3/v3_int.c \
- crypto/x509v3/v3_lib.c \
- crypto/x509v3/v3_ncons.c \
- crypto/x509v3/v3_ocsp.c \
- crypto/x509v3/v3_pci.c \
- crypto/x509v3/v3_pcia.c \
- crypto/x509v3/v3_pcons.c \
- crypto/x509v3/v3_pku.c \
- crypto/x509v3/v3_pmaps.c \
- crypto/x509v3/v3_prn.c \
- crypto/x509v3/v3_purp.c \
- crypto/x509v3/v3_skey.c \
- crypto/x509v3/v3_sxnet.c \
- crypto/x509v3/v3_utl.c \
- crypto/x509v3/v3err.c
-
-local_c_includes := \
- external/openssl \
- external/openssl/crypto \
- external/openssl/crypto/asn1 \
- external/openssl/crypto/evp \
- external/openssl/crypto/modes \
- external/openssl/include \
- external/openssl/include/openssl \
- external/zlib
-
-local_c_flags := -DNO_WINDOWS_BRAINDEATH
-
-local_c_includes += $(log_c_includes)
+local_c_includes := $(log_c_includes)
 
 local_additional_dependencies := $(LOCAL_PATH)/android-config.mk $(LOCAL_PATH)/Crypto.mk
 
+include $(LOCAL_PATH)/Crypto-config.mk
+
 #######################################
 # target static library
 include $(CLEAR_VARS)
@@ -576,26 +17,9 @@
 LOCAL_SDK_VERSION := 9
 endif
 
-LOCAL_SRC_FILES += $(local_src_files)
-LOCAL_CFLAGS += $(local_c_flags)
-LOCAL_C_INCLUDES += $(local_c_includes)
-ifeq ($(TARGET_ARCH),arm)
- LOCAL_SRC_FILES += $(arm_src_files)
- LOCAL_CFLAGS += $(arm_cflags)
-endif
-ifeq ($(TARGET_ARCH),mips)
-  ifneq (($TARGET_HAS_BIGENDIAN),true)
-    LOCAL_SRC_FILES += $(mips_src_files)
-    LOCAL_CFLAGS += $(mips_cflags)
-  else
-    LOCAL_SRC_FILES += $(other_arch_src_files)
-  endif
-endif
-ifeq ($(TARGET_ARCH),x86)
-  LOCAL_SRC_FILES += $(x86_src_files)
-  LOCAL_SRC_FILES := $(filter-out $(x86_exclude_files),$(LOCAL_SRC_FILES))
-  LOCAL_CFLAGS += $(x86_cflags)
-endif
+LOCAL_SRC_FILES += $(target_src_files)
+LOCAL_CFLAGS += $(target_c_flags)
+LOCAL_C_INCLUDES += $(target_c_includes)
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE:= libcrypto_static
 LOCAL_ADDITIONAL_DEPENDENCIES := $(local_additional_dependencies)
@@ -613,26 +37,9 @@
 endif
 LOCAL_LDFLAGS += -ldl
 
-LOCAL_SRC_FILES += $(local_src_files)
-LOCAL_CFLAGS += $(local_c_flags)
-LOCAL_C_INCLUDES += $(local_c_includes)
-ifeq ($(TARGET_ARCH),arm)
-  LOCAL_SRC_FILES += $(arm_src_files)
-  LOCAL_CFLAGS += $(arm_cflags)
-endif
-ifeq ($(TARGET_ARCH),mips)
-  ifneq (($TARGET_HAS_BIGENDIAN),true)
-    LOCAL_SRC_FILES += $(mips_src_files)
-    LOCAL_CFLAGS += $(mips_cflags)
-  else
-    LOCAL_SRC_FILES += $(other_arch_src_files)
-  endif
-endif
-ifeq ($(TARGET_ARCH),x86)
-  LOCAL_SRC_FILES += $(x86_src_files)
-  LOCAL_SRC_FILES := $(filter-out $(x86_exclude_files),$(LOCAL_SRC_FILES))
-  LOCAL_CFLAGS += $(x86_cflags)
-endif
+LOCAL_SRC_FILES += $(target_src_files)
+LOCAL_CFLAGS += $(target_c_flags)
+LOCAL_C_INCLUDES += $(target_c_includes)
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE:= libcrypto
 LOCAL_ADDITIONAL_DEPENDENCIES := $(local_additional_dependencies)
@@ -643,16 +50,9 @@
 include $(CLEAR_VARS)
 include $(LOCAL_PATH)/android-config.mk
 LOCAL_SHARED_LIBRARIES := $(log_shared_libraries)
-LOCAL_SRC_FILES += $(local_src_files)
-ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
-  LOCAL_SRC_FILES += $(x86_src_files)
-  LOCAL_SRC_FILES := $(filter-out $(x86_exclude_files),$(LOCAL_SRC_FILES))
-  LOCAL_CFLAGS += $(x86_cflags)
-else
-  LOCAL_SRC_FILES += $(other_arch_src_files)
-endif
-LOCAL_CFLAGS += $(local_c_flags) -DPURIFY
-LOCAL_C_INCLUDES += $(local_c_includes)
+LOCAL_SRC_FILES += $(host_src_files)
+LOCAL_CFLAGS += $(host_c_flags) -DPURIFY
+LOCAL_C_INCLUDES += $(host_c_includes)
 LOCAL_LDLIBS += -ldl
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE:= libcrypto
@@ -665,16 +65,9 @@
 include $(CLEAR_VARS)
 include $(LOCAL_PATH)/android-config.mk
 LOCAL_SHARED_LIBRARIES := $(log_shared_libraries)
-LOCAL_SRC_FILES += $(local_src_files)
-ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
-  LOCAL_SRC_FILES += $(x86_src_files)
-  LOCAL_SRC_FILES := $(filter-out $(x86_exclude_files),$(LOCAL_SRC_FILES))
-  LOCAL_CFLAGS += $(x86_cflags)
-else
-  LOCAL_SRC_FILES += $(other_arch_src_files)
-endif
-LOCAL_CFLAGS += $(local_c_flags) -DPURIFY
-LOCAL_C_INCLUDES += $(local_c_includes)
+LOCAL_SRC_FILES += $(host_src_files)
+LOCAL_CFLAGS += $(host_c_flags) -DPURIFY
+LOCAL_C_INCLUDES += $(host_c_includes)
 LOCAL_LDLIBS += -ldl
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE:= libcrypto_static
diff --git a/README.android b/README.android
index 62456bf..a7c3cc1 100644
--- a/README.android
+++ b/README.android
@@ -53,17 +53,23 @@
      # Build and sync libcore tests
      (croot && cd libcore && mm -j16 snod && adb remount && adb sync)
      # Run tests from libcore
-     (croot && vogar --classpath out/target/common/obj/JAVA_LIBRARIES/core-tests-support_intermediates/classes.jar --classpath out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/classes.jar javax.net.ssl tests.api.javax.net)
+     (croot && vogar --classpath out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/classes.jar javax.net.ssl tests.api.javax.net)
      # Run tests from Harmony
-     (croot && vogar --classpath harmony_tests.jar tests.api.java.math.BigIntegerTest org.apache.harmony.tests.java.math)
+     (croot && vogar --classpath out/target/common/obj/JAVA_LIBRARIES/apache-harmony-tests_intermediates/classes.jar tests.api.java.math.BigIntegerTest org.apache.harmony.tests.java.math)
      # try an https website
      adb shell am start https://online.citibank.com # confirm result in browser
 
      The vogar tool can be found externally at http://code.google.com/p/vogar/
-     Within Google it can be run with ~dalvik-prebuild/vogar/bin/vogar
 
-     harmony_tests.jar is built from Subversion http://harmony.apache.org/
-     Within Google it can be found at ~dalvik-prebuild/bin/harmony_tests.jar
+     Quick installation instructions (without rebuilding from source):
+        VOGAR=$HOME/vogar
+        svn co http://vogar.googlecode.com/svn/trunk/ $VOGAR
+        mkdir -p $VOGAR/build/
+        curl -o $VOGAR/build/vogar.jar https://vogar.googlecode.com/files/vogar.jar
+        PATH=$PATH:$VOGAR/bin
+
+     Within Google, you can find it under:
+       /home/dalvik-prebuild/vogar/bin/vogar
 
      # You can also run openssl s_server as a test server on the device:
      adb push ./android.testssl/CAss.cnf /sdcard/CAss.cnf
diff --git a/Ssl-config.mk b/Ssl-config.mk
new file mode 100644
index 0000000..e14e4bb
--- /dev/null
+++ b/Ssl-config.mk
@@ -0,0 +1,128 @@
+# Auto-generated - DO NOT EDIT!
+# To regenerate, edit openssl.config, then run:
+#     ./import_openssl.sh import /path/to/openssl-1.0.1e.tar.gz
+#
+# 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
+#
+
+# Ensure these are empty.
+unknown_arch_c_flags :=
+unknown_arch_src_files :=
+unknown_arch_exclude_files :=
+
+
+common_c_flags :=
+
+common_src_files := \
+  ssl/bio_ssl.c \
+  ssl/d1_both.c \
+  ssl/d1_enc.c \
+  ssl/d1_lib.c \
+  ssl/d1_pkt.c \
+  ssl/d1_srtp.c \
+  ssl/kssl.c \
+  ssl/s23_clnt.c \
+  ssl/s23_lib.c \
+  ssl/s23_meth.c \
+  ssl/s23_pkt.c \
+  ssl/s23_srvr.c \
+  ssl/s2_clnt.c \
+  ssl/s2_enc.c \
+  ssl/s2_lib.c \
+  ssl/s2_meth.c \
+  ssl/s2_pkt.c \
+  ssl/s2_srvr.c \
+  ssl/s3_both.c \
+  ssl/s3_cbc.c \
+  ssl/s3_clnt.c \
+  ssl/s3_enc.c \
+  ssl/s3_lib.c \
+  ssl/s3_meth.c \
+  ssl/s3_pkt.c \
+  ssl/s3_srvr.c \
+  ssl/ssl_algs.c \
+  ssl/ssl_asn1.c \
+  ssl/ssl_cert.c \
+  ssl/ssl_ciph.c \
+  ssl/ssl_err.c \
+  ssl/ssl_err2.c \
+  ssl/ssl_lib.c \
+  ssl/ssl_rsa.c \
+  ssl/ssl_sess.c \
+  ssl/ssl_stat.c \
+  ssl/ssl_txt.c \
+  ssl/t1_clnt.c \
+  ssl/t1_enc.c \
+  ssl/t1_lib.c \
+  ssl/t1_meth.c \
+  ssl/t1_reneg.c \
+  ssl/t1_srvr.c \
+  ssl/tls_srp.c \
+
+common_c_includes := \
+  . \
+  crypto \
+  include \
+
+arm_c_flags :=
+
+arm_src_files :=
+
+arm_exclude_files :=
+
+x86_c_flags :=
+
+x86_src_files :=
+
+x86_exclude_files :=
+
+x86_64_c_flags :=
+
+x86_64_src_files :=
+
+x86_64_exclude_files :=
+
+mips_c_flags :=
+
+mips_src_files :=
+
+mips_exclude_files :=
+
+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/openssl/,$(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))
+
+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/openssl/,$(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)/Ssl-config.mk
+
diff --git a/Ssl.mk b/Ssl.mk
index d4a7e95..ca1290a 100644
--- a/Ssl.mk
+++ b/Ssl.mk
@@ -1,58 +1,11 @@
-local_c_includes := \
-	external/openssl \
-	external/openssl/include \
-	external/openssl/crypto
+local_c_flags :=
 
-local_src_files:= \
-	ssl/bio_ssl.c \
-	ssl/d1_both.c \
-	ssl/d1_enc.c \
-	ssl/d1_lib.c \
-	ssl/d1_pkt.c \
-	ssl/d1_srtp.c \
-	ssl/kssl.c \
-	ssl/s23_clnt.c \
-	ssl/s23_lib.c \
-	ssl/s23_meth.c \
-	ssl/s23_pkt.c \
-	ssl/s23_srvr.c \
-	ssl/s2_clnt.c \
-	ssl/s2_enc.c \
-	ssl/s2_lib.c \
-	ssl/s2_meth.c \
-	ssl/s2_pkt.c \
-	ssl/s2_srvr.c \
-	ssl/s3_both.c \
-	ssl/s3_cbc.c \
-	ssl/s3_clnt.c \
-	ssl/s3_enc.c \
-	ssl/s3_lib.c \
-	ssl/s3_meth.c \
-	ssl/s3_pkt.c \
-	ssl/s3_srvr.c \
-	ssl/ssl_algs.c \
-	ssl/ssl_asn1.c \
-	ssl/ssl_cert.c \
-	ssl/ssl_ciph.c \
-	ssl/ssl_err.c \
-	ssl/ssl_err2.c \
-	ssl/ssl_lib.c \
-	ssl/ssl_rsa.c \
-	ssl/ssl_sess.c \
-	ssl/ssl_stat.c \
-	ssl/ssl_txt.c \
-	ssl/t1_clnt.c \
-	ssl/t1_enc.c \
-	ssl/t1_lib.c \
-	ssl/t1_meth.c \
-	ssl/t1_reneg.c \
-	ssl/t1_srvr.c \
-	ssl/tls_srp.c
-
-local_c_includes += $(log_c_includes)
+local_c_includes := $(log_c_includes)
 
 local_additional_dependencies := $(LOCAL_PATH)/android-config.mk $(LOCAL_PATH)/Ssl.mk
 
+include $(LOCAL_PATH)/Ssl-config.mk
+
 #######################################
 # target static library
 include $(CLEAR_VARS)
@@ -62,8 +15,9 @@
 LOCAL_SDK_VERSION := 9
 endif
 
-LOCAL_SRC_FILES += $(local_src_files)
-LOCAL_C_INCLUDES += $(local_c_includes)
+LOCAL_SRC_FILES += $(target_src_files)
+LOCAL_CFLAGS += $(target_c_flags)
+LOCAL_C_INCLUDES += $(target_c_includes)
 LOCAL_SHARED_LIBRARIES = $(log_shared_libraries)
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE:= libssl_static
@@ -79,8 +33,9 @@
 LOCAL_SDK_VERSION := 9
 endif
 
-LOCAL_SRC_FILES += $(local_src_files)
-LOCAL_C_INCLUDES += $(local_c_includes)
+LOCAL_SRC_FILES += $(target_src_files)
+LOCAL_CFLAGS += $(target_c_flags)
+LOCAL_C_INCLUDES += $(target_c_includes)
 LOCAL_SHARED_LIBRARIES += libcrypto $(log_shared_libraries)
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE:= libssl
@@ -91,8 +46,9 @@
 # host shared library
 include $(CLEAR_VARS)
 include $(LOCAL_PATH)/android-config.mk
-LOCAL_SRC_FILES += $(local_src_files)
-LOCAL_C_INCLUDES += $(local_c_includes)
+LOCAL_SRC_FILES += $(host_src_files)
+LOCAL_CFLAGS += $(host_c_flags)
+LOCAL_C_INCLUDES += $(host_c_includes)
 LOCAL_SHARED_LIBRARIES += libcrypto $(log_shared_libraries)
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE:= libssl
@@ -104,7 +60,7 @@
 include $(CLEAR_VARS)
 include $(LOCAL_PATH)/android-config.mk
 LOCAL_SRC_FILES:= ssl/ssltest.c
-LOCAL_C_INCLUDES += $(local_c_includes)
+LOCAL_C_INCLUDES += $(host_c_includes)
 LOCAL_SHARED_LIBRARIES := libssl libcrypto $(log_shared_libraries)
 LOCAL_MODULE:= ssltest
 LOCAL_MODULE_TAGS := optional
diff --git a/check-all-builds.sh b/check-all-builds.sh
new file mode 100755
index 0000000..98dc391
--- /dev/null
+++ b/check-all-builds.sh
@@ -0,0 +1,628 @@
+#!/bin/sh
+#
+
+set -e
+export LANG=C
+export LC_ALL=C
+
+PROGDIR=$(dirname "$0")
+PROGNAME=$(basename "$0")
+
+panic () {
+  echo "ERROR: $@"
+  exit 1
+}
+
+VERBOSE=1
+
+# Dump message is $VERBOSE >= $1
+# $1+: message.
+dump_n () {
+  local LOG_LEVEL=$1
+  shift
+  if [ "$VERBOSE" -ge "$LOG_LEVEL" ]; then
+    printf "%s\n" "$@"
+  fi
+}
+
+# Dump a message unless --quiet is used.
+# $1+: message.
+dump () {
+  dump_n 1 "$@"
+}
+
+# Dump a message if --verbose is used only.
+# $1+: message.
+log () {
+  dump_n 2 "$@"
+}
+
+# Run a command silently, unless --verbose or '--verbose --verbose'
+# is used.
+# $1+: Command
+# Return: command status.
+run () {
+  log "COMMAND: $*"
+  case $VERBOSE in
+    0)
+      "$@" >/dev/null 2>&1 || return $?
+      ;;
+    1)
+      "$@" >/dev/null || return $?
+      ;;
+    *)
+      "$@" || return $?
+      ;;
+  esac
+}
+
+# $1: string
+# Out: input string, with capital letters replaced by small ones.
+tolower () {
+  echo "$1" | tr '[A-Z]' '[a-z]'
+}
+
+# Return value of a given variable.
+# $1: Variable name
+var_value () {
+  eval printf \"%s\" \"\$$1\"
+}
+
+# Remove some items from a list
+# $1: input space-separated list
+# $2: space-separated list of items to remove from 1
+# Out: items of $1 without items of $2
+filter_out () {
+  local TMP=$(mktemp)
+  local RESULT
+  printf "" > $TMP
+  echo "$2" | tr ' ' '\n' > $TMP
+  RESULT=$(echo "$1" | tr ' ' '\n' | fgrep -x -v -f $TMP | tr '\n' ' ')
+  rm -f $TMP
+  echo "$RESULT"
+}
+
+src_to_obj () {
+  case $1 in
+    *.c)
+      echo ${1%%.c}.o
+      ;;
+    *.S)
+      echo ${1%%.S}.o
+      ;;
+    *)
+      echo $1
+      ;;
+  esac
+}
+
+# Determine host operating system.
+HOST_OS=$(uname -s)
+case $HOST_OS in
+  Linux)
+    HOST_OS=linux
+    ;;
+  Darwin)
+    HOST_OS=darwin
+    ;;
+esac
+
+# Determine host architecture
+HOST_ARCH=$(uname -m)
+case $HOST_ARCH in
+  i?86)
+    HOST_ARCH=x86
+    ;;
+esac
+
+ANDROID_HOST_TAG=$HOST_OS-$HOST_ARCH
+
+case $ANDROID_HOST_TAG in
+  linux-x86_64|darwin-x86-64)
+    ANDROID_HOST_TAG=$HOST_OS-x86
+    ;;
+  *)
+    panic "Sorry, this script can only run on 64-bit Linux or Darwin"
+esac
+
+# Determine number of cores
+case $HOST_OS in
+  linux)
+    NUM_CORES=$(grep -c "processor" /proc/cpuinfo)
+    ;;
+  darwin)
+    NUM_CORES=$(sysctl -n hw.ncpu)
+    ;;
+  *)
+    NUM_CORES=1
+    ;;
+esac
+
+# The list of supported Android target architectures.
+ANDROID_ARCHS="arm x86 mips"
+
+BUILD_TYPES=
+for ARCH in $ANDROID_ARCHS; do
+  BUILD_TYPES="$BUILD_TYPES android-$ARCH"
+done
+ANDROID_BUILD_TYPES=$BUILD_TYPES
+
+# NOTE: The $HOST_OS-x86_64 is currently broken because the single
+#       <openssl/opensslconf.h> header is tailored for 32-bits.
+HOST_BUILD_TYPES="$HOST_OS-x86 $HOST_OS-generic32 $HOST_OS-generic64"
+
+BUILD_TYPES="$ANDROID_BUILD_TYPES $HOST_BUILD_TYPES"
+
+# Parse command-line
+DO_HELP=
+SRC_DIR=$(cd $PROGDIR && pwd)
+OUT_DIR=out
+BUILD_DIR=
+BUILD_TYPES=
+NUM_JOBS=$NUM_CORES
+ANDROID_BUILD_TOP=$(cd $PROGDIR/../.. && pwd)
+for OPT; do
+  case $OPT in
+    --help|-h|-?)
+      DO_HELP=true
+      ;;
+    --build-dir=*)
+      BUILD_DIR=${OPT##--build-dir=}
+      ;;
+    --verbose)
+      VERBOSE=$(( $VERBOSE + 1 ))
+      ;;
+    --jobs=*)
+      NUM_JOBS=${OPT##--jobs=}
+      ;;
+    --quiet)
+      VERBOSE=$(( $VERBOSE - 1 ))
+      ;;
+    -j*)
+      NUM_JOBS=${OPT##-j}
+      ;;
+    -*)
+      panic "Unknown option '$OPT', see --help for details."
+      ;;
+    *)
+      BUILD_TYPES="$BUILD_TYPES $OPT"
+      ;;
+  esac
+done
+
+# Print help when needed.
+if [ "$DO_HELP" ]; then
+  echo \
+"Usage: $PROGNAME [options] [<build-type> ...]
+
+This script is used to ensure that all OpenSSL build variants compile
+properly. It can be used after modifying external/openssl/openssl.config
+and re-running import_openssl.sh to check that any changes didn't break
+the build.
+
+A <build-type> is a description of a given build of the library and its
+program. Its format is:
+
+  <compiler>-<system>-<arch>
+
+Where: <compiler> is either 'gcc' or 'clang'.
+       <system>   is 'android', 'linux' or 'darwin'.
+       <arch>     is 'arm', 'x86'  or 'mips'.
+
+By default, it rebuilds the sources for the following build types:
+"
+  for BUILD_TYPE in $BUILD_TYPES; do
+    echo "  $BUILD_TYPE"
+  done
+
+  echo \
+"However, you can pass custom values on the command-line instead.
+
+This scripts generates a custom Makefile in a temporary directory, then
+launches 'make' in it to build all binaries in parallel. In case of
+problem, you can use the --build-dir=<path> option to specify a custom
+build-directory, which will _not_ be removed when the script exits.
+
+For example, to better see why a build fails:
+
+   ./$PROGNAME --build-dir=/tmp/mydir
+   make -C /tmp/mydir V=1
+
+Valid options:
+
+  --help|-h|-?        Print this message.
+  --build-dir=<path>  Specify build directory.
+  --jobs=<count>      Run <count> parallel build jobs [$NUM_JOBS].
+  -j<count>           Same as --jobs=<count>.
+  --verbose           Increase verbosity.
+  --quiet             Decrease verbosity.
+"
+  exit 0
+fi
+
+log "Host OS: $HOST_OS"
+log "Host arch: $HOST_ARCH"
+log "Host CPU count: $NUM_CORES"
+
+if [ -z "$BUILD_TYPES" ]; then
+  BUILD_TYPES="$ANDROID_BUILD_TYPES $HOST_BUILD_TYPES"
+fi
+log "Build types: $BUILD_TYPES"
+
+if [ -z "$BUILD_DIR" ]; then
+  # Create a temporary directory, ensure it gets destroyed properly
+  # when the script exits.
+  BUILD_DIR=$(mktemp -d)
+  clean_build_dir () {
+    log "Cleaning up temporary directory: $BUILD_DIR"
+    rm -rf "$BUILD_DIR"
+    exit $1
+  }
+  trap "clean_build_dir 0" EXIT
+  trap "clean_build_dir \$?" INT HUP QUIT TERM
+  log "Using temporary build directory: $BUILD_DIR"
+else
+  log "Using user build directory: $BUILD_DIR"
+fi
+
+mkdir -p "$BUILD_DIR" && rm -rf "$BUILD_DIR"/*
+
+MAKEFILE=$BUILD_DIR/GNUmakefile
+
+# Return source files for a given module and architecture.
+# $1: module prefix (e.g. CRYPTO)
+# $2: build arch.
+get_module_src_files_for_arch () {
+  local prefix=$1
+  local arch=$2
+  local src_files="$(var_value OPENSSL_${prefix}_SOURCES)"
+  src_files="$src_files $(var_value OPENSSL_${prefix}_SOURCES_${arch})"
+  local exclude_files="$(var_value OPENSSL_${prefix}_SOURCES_EXCLUDES_${arch})"
+  src_files=$(filter_out "$src_files" "$exclude_files")
+  echo "$src_files"
+}
+
+# Return the compiler defines for a given module and architecture
+# $1: module prefix (e.g. CRYPTO)
+# $2 build arch.
+get_module_defines_for_arch () {
+  local prefix=$1
+  local arch=$2
+  local defines="$(var_value OPENSSL_${prefix}_DEFINES)"
+  defines="$defines $(var_value OPENSSL_${prefix}_DEFINES_${arch})"
+  echo "$defines"
+}
+
+# $1: module prefix (e.g. CRYPTO)
+get_module_c_includes () {
+  var_value OPENSSL_$1_INCLUDES
+}
+
+# $1: build type (e.g. gcc-android-arm)
+# Out: build arch.
+get_build_arch () {
+  echo "$1" | cut -d- -f3
+}
+
+# $1: build arch
+# Out: GNU configuration target (e.g. arm-linux-androideabi)
+get_build_arch_target () {
+  case $1 in
+    arm)
+      echo "arm-linux-androideabi"
+      ;;
+    x86)
+      echo "i686-linux-android"
+      ;;
+    mips)
+      echo "mipsel-linux-android"
+      ;;
+    *)
+      echo "$1-linux-android"
+      ;;
+  esac
+}
+
+GCC_VERSION=4.7
+CLANG_VERSION=3.1
+
+get_prebuilt_gcc_dir_for_arch () {
+  local arch=$1
+  local target=$(get_build_arch_target $arch)
+  echo "$ANDROID_BUILD_TOP/prebuilts/gcc/$ANDROID_HOST_TAG/$arch/$target-$GCC_VERSION"
+}
+
+get_prebuilt_clang () {
+  echo "$ANDROID_BUILD_TOP/prebuilts/clang/$ANDROID_HOST_TAG/$CLANG_VERSION/clang"
+}
+
+get_prebuilt_ndk_sysroot_for_arch () {
+  echo "$ANDROID_BUILD_TOP/prebuilts/ndk/current/platforms/android-9/arch-$1"
+}
+
+get_c_runtime_file () {
+  local build_type=$1
+  local arch=$(get_build_arch $build_type)
+  local filename=$2
+  echo "$(get_prebuilt_ndk_sysroot_for_arch $arch)/usr/lib/$filename"
+}
+
+# $1: build type (e.g. gcc-android-arm)
+get_build_compiler () {
+  local arch=$(get_build_arch $1)
+  local target=$(get_build_arch_target $arch)
+  local gcc_dir=$(get_prebuilt_gcc_dir_for_arch $arch);
+  local result
+
+  # Get the toolchain binary.
+  case $1 in
+    gcc-android-*)
+      result="$gcc_dir/bin/$target-gcc"
+      ;;
+    clang-android-*)
+      result="$(get_prebuilt_clang) -target $target -B$gcc_dir/$target/bin -I$gcc_dir/lib/gcc/$target/$GCC_VERSION/include"
+      ;;
+    gcc-*)
+      result=gcc
+      ;;
+    clang-*) # Must have host clang compiler.
+      result=clang
+      ;;
+  esac
+
+  compiler_check=$(which $result 2>/dev/null || echo "")
+  if [ -z "$compiler_check" ]; then
+    panic "Could not find compiler: $result"
+  fi
+
+  # Get the Android sysroot if needed.
+  case $1 in
+    *-android-*)
+      result="$result --sysroot=$(get_prebuilt_ndk_sysroot_for_arch $arch)"
+      ;;
+  esac
+
+  # Force -m32 flag when needed for 32-bit builds.
+  case $1 in
+    *-linux-x86|*-darwin-x86|*-generic32)
+      result="$result -m32"
+      ;;
+  esac
+  echo "$result"
+}
+
+# $1: build type.
+# Out: common compiler flags for this build.
+get_build_c_flags () {
+  local result="-O2 -fPIC"
+  case $1 in
+    *-android-arm)
+      result="$result -march=armv7-a -mfpu=vfpv3-d16"
+      ;;
+  esac
+
+  case $1 in
+    *-generic32|*-generic64)
+      # Generic builds do not compile without this flag.
+      result="$result -DOPENSSL_NO_ASM"
+      ;;
+  esac
+  echo "$result"
+}
+
+# $1: build type.
+# Out: linker for this build.
+get_build_linker () {
+  get_build_compiler $1
+}
+
+clear_sources () {
+  g_all_objs=""
+}
+
+# Generate build instructions to compile source files.
+# Also update g_all_objs.
+# $1: module prefix (e.g. CRYPTO)
+# $2: build type
+build_sources () {
+  local prefix=$1
+  local build_type=$2
+  echo "## build_sources prefix='$prefix' build_type='$build_type'"
+  local arch=$(get_build_arch $build_type)
+  local src_files=$(get_module_src_files_for_arch $prefix $arch)
+  local c_defines=$(get_module_defines_for_arch $prefix $arch)
+  local c_includes=$(get_module_c_includes $prefix "$SRC_DIR")
+  local build_cc=$(get_build_compiler $build_type)
+  local build_cflags=$(get_build_c_flags $build_type)
+  local build_linker=$(get_build_linker $build_type)
+  local src obj def inc
+
+  printf "OUT_DIR := $OUT_DIR/$build_type\n\n"
+  printf "BUILD_CC := $build_cc\n\n"
+  printf "BUILD_LINKER := $build_linker\n\n"
+  printf "BUILD_CFLAGS := $build_cflags"
+  for inc in $c_includes; do
+    printf " -I\$(SRC_DIR)/$inc"
+  done
+  for def in $c_defines; do
+    printf " -D$def"
+  done
+  printf "\n\n"
+  printf "BUILD_OBJECTS :=\n\n"
+
+  case $build_type in
+    clang-android-*)
+      # The version of clang that comes with the platform build doesn't
+      # support simple linking of shared libraries and executables. One
+      # has to provide the C runtime files explicitely.
+      local crtbegin_so=$(get_c_runtime_file $build_type crtbegin_so.o)
+      local crtend_so=$(get_c_runtime_file $build_type crtend_so.o)
+      local crtbegin_exe=$(get_c_runtime_file $build_type crtbegin_dynamic.o)
+      local crtend_exe=$(get_c_runtime_file $build_type crtend_android.o)
+      printf "CRTBEGIN_SO := $crtbegin_so\n"
+      printf "CRTEND_SO := $crtend_so\n"
+      printf "CRTBEGIN_EXE := $crtbegin_exe\n"
+      printf "CRTEND_EXE := $crtend_exe\n"
+      printf "\n"
+      ;;
+  esac
+
+  for src in $src_files; do
+    obj=$(src_to_obj $src)
+    g_all_objs="$g_all_objs $obj"
+    printf "OBJ := \$(OUT_DIR)/$obj\n"
+    printf "BUILD_OBJECTS += \$(OBJ)\n"
+    printf "\$(OBJ): PRIVATE_CC := \$(BUILD_CC)\n"
+    printf "\$(OBJ): PRIVATE_CFLAGS := \$(BUILD_CFLAGS)\n"
+    printf "\$(OBJ): \$(SRC_DIR)/$src\n"
+    printf "\t@echo [$build_type] CC $src\n"
+    printf "\t@mkdir -p \$\$(dirname \$@)\n"
+    printf "\t\$(hide) \$(PRIVATE_CC) \$(PRIVATE_CFLAGS) -c -o \$@ \$<\n"
+    printf "\n"
+  done
+  printf "\n"
+}
+
+# $1: library name (e.g. crypto).
+# $2: module prefix (e.g. CRYPTO).
+# $3: build type.
+# $4: source directory.
+# $5: output directory.
+build_shared_library () {
+  local name=$1
+  local prefix=$2
+  local build_type=$3
+  local src_dir="$4"
+  local out_dir="$5"
+  local shlib="lib${name}.so"
+  local build_linker=$(get_build_linker $build_type)
+  clear_sources
+  build_sources $prefix $build_type
+
+  # TODO(digit): Make the clang build link properly.
+  printf "SHLIB=\$(OUT_DIR)/$shlib\n"
+  printf "\$(SHLIB): PRIVATE_LINKER := \$(BUILD_LINKER)\n"
+  case $build_type in
+    clang-android-*)
+      printf "\$(SHLIB): PRIVATE_CRTBEGIN := \$(CRTBEGIN_SO)\n"
+      printf "\$(SHLIB): PRIVATE_CRTEND := \$(CRTEND_SO)\n"
+      ;;
+  esac
+  printf "\$(SHLIB): \$(BUILD_OBJECTS)\n"
+  printf "\t@echo [$build_type] SHARED_LIBRARY $(basename $shlib)\n"
+  printf "\t@mkdir -p \$\$(dirname \$@)\n"
+  case $build_type in
+    clang-android-*)
+      printf "\t\$(hide) \$(PRIVATE_LINKER) -nostdlib -shared -o \$@ \$(PRIVATE_CRTBEGIN) \$^ \$(PRIVATE_CRTEND)\n"
+      ;;
+    *)
+      printf "\t\$(hide) \$(PRIVATE_LINKER) -shared -o \$@ \$^\n"
+      ;;
+  esac
+  printf "\n"
+}
+
+# $1: executable name.
+# $2: module prefix (e.g. APPS).
+# $3: build type.
+# $4: source directory.
+# $5: output directory.
+# $6: dependent shared libraries (e.g. 'crypto ssl')
+build_executable () {
+  local name=$1
+  local prefix=$2
+  local build_type=$3
+  local src_dir="$4"
+  local out_dir="$5"
+  local shlibs="$6"
+  local build_linker=$(get_build_linker $build_type)
+  clear_sources
+  build_sources $prefix $build_type
+
+  # TODO(digit): Make the clang build link properly.
+  exec=$name
+  all_shlibs=
+  printf "EXEC := \$(OUT_DIR)/$name\n"
+  printf "openssl_all: \$(EXEC)\n"
+  printf "\$(EXEC): PRIVATE_LINKER := \$(BUILD_LINKER)\n"
+  printf "\$(EXEC): \$(BUILD_OBJECTS)"
+  for lib in $shlibs; do
+    printf " \$(OUT_DIR)/lib${lib}.so"
+  done
+  printf "\n"
+  printf "\t@echo [$build_type] EXECUTABLE $name\n"
+  printf "\t@mkdir -p \$\$(dirname \$@)\n"
+  printf "\t\$(hide) \$(PRIVATE_LINKER) -o \$@ \$^\n"
+  printf "\n"
+}
+
+ALL_BUILDS=
+
+generate_openssl_build () {
+  local build_type=$1
+  local out="$OUT_DIR/$build_type"
+  ALL_BUILDS="$ALL_BUILDS $build_type"
+  echo "# Build type: $build_type"
+  build_shared_library crypto CRYPTO $build_type "$SRC_DIR" "$out"
+  build_shared_library ssl SSL $build_type "$SRC_DIR" "$out"
+  build_executable openssl APPS $build_type "$SRC_DIR" "$out" "crypto ssl"
+}
+
+generate_makefile () {
+  echo \
+"# Auto-generated by $PROGDIR - do not edit
+
+.PHONY: openssl_all
+
+all: openssl_all
+
+# Use 'make V=1' to print build commands.
+ifeq (1,\$(V))
+hide :=
+else
+hide := @
+endif
+
+SRC_DIR=$SRC_DIR
+OUT_DIR=$OUT_DIR
+"
+
+  for BUILD_TYPE in $BUILD_TYPES; do
+    generate_openssl_build gcc-$BUILD_TYPE
+  done
+
+# TODO(digit): Make the Clang build run.
+#   for BUILD_TYPE in $ANDROID_BUILD_TYPES; do
+#     generate_openssl_build clang-$BUILD_TYPE
+#   done
+}
+
+. $SRC_DIR/openssl.config
+
+
+
+dump "Generating Makefile"
+log "Makefile path: $MAKEFILE"
+generate_makefile > $MAKEFILE
+
+dump "Building libraries with $NUM_JOBS jobs"
+dump "For the following builds:"
+for BUILD in $ALL_BUILDS; do
+  dump "  $BUILD"
+done
+MAKE_FLAGS="-j$NUM_JOBS"
+if [ "$VERBOSE" -gt 2 ]; then
+  MAKE_FLAGS="$MAKE_FLAGS V=1"
+fi
+run make $MAKE_FLAGS -f "$MAKEFILE" -C "$BUILD_DIR"
+case $? in
+  0)
+    dump "All OK, congratulations!"
+    ;;
+  *)
+    dump "Error, try doing the following to inspect the issues:"
+    dump "   $PROGNAME --build-dir=/tmp/mybuild"
+    dump "   make -C /tmp/mybuild V=1"
+    dump ""
+    ;;
+esac
diff --git a/import_openssl.sh b/import_openssl.sh
index dd704d9..01bbc29 100755
--- a/import_openssl.sh
+++ b/import_openssl.sh
@@ -27,6 +27,10 @@
 set -e
 trap  "echo WARNING: Exiting on non-zero subprocess exit code" ERR;
 
+# Ensure consistent sorting order / tool output.
+export LANG=C
+export LC_ALL=C
+
 function die() {
   declare -r message=$1
 
@@ -155,6 +159,13 @@
   echo "$@" | tr ' ' '\n' | grep -e "$pattern" | tr '\n' ' '
 }
 
+# Sort and remove duplicates in a space-separated list
+# $1: space-separated list
+# Out: new space-separated list
+function uniq_sort () {
+  echo "$@" | tr ' ' '\n' | sort -u | tr '\n' ' '
+}
+
 function print_autogenerated_header() {
   echo "# Auto-generated - DO NOT EDIT!"
   echo "# To regenerate, edit openssl.config, then run:"
@@ -185,6 +196,150 @@
   ) > $1
 }
 
+# Return the value of a computed variable name.
+# E.g.:
+#   FOO=foo
+#   BAR=bar
+#   echo $(var_value FOO_$BAR)   -> prints the value of ${FOO_bar}
+# $1: Variable name
+# Out: variable value
+var_value() {
+  # Note: don't use 'echo' here, because it's sensitive to values
+  #       that begin with an underscore (e.g. "-n")
+  eval printf \"%s\\n\" \$$1
+}
+
+# Same as var_value, but returns sorted output without duplicates.
+# $1: Variable name
+# Out: variable value (if space-separated list, sorted with no duplicates)
+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
+  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. OPENSSL_NO_CAMELLIA ...)
+print_defines_in_mk() {
+  declare -r varname=$1
+  shift
+  if [ -z "$1" ]; then
+    echo "$varname :="
+  else
+    echo "$varname := \\"
+    for def; do
+    echo "  -D$def \\"
+    done
+  fi
+  echo ""
+}
+
+# Generate a configuration file like Crypto-config.mk
+# This uses variable definitions from openssl.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. Crypto-config.mk)
+# $2: Variable prefix.   (e.g. CRYPTO)
+function generate_config_mk() {
+  declare -r output="$1"
+  declare -r prefix="$2"
+  declare -r all_archs="arm x86 x86_64 mips"
+
+  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
+#
+
+# Ensure these are empty.
+unknown_arch_c_flags :=
+unknown_arch_src_files :=
+unknown_arch_exclude_files :=
+
+"
+    common_defines=$(var_sorted_value OPENSSL_${prefix}_DEFINES)
+    print_defines_in_mk common_c_flags $common_defines
+
+    common_sources=$(var_sorted_value OPENSSL_${prefix}_SOURCES)
+    print_vardef_in_mk common_src_files $common_sources
+
+    common_includes=$(var_sorted_value OPENSSL_${prefix}_INCLUDES)
+    print_vardef_in_mk common_c_includes $common_includes
+
+    for arch in $all_archs; do
+      arch_defines=$(var_sorted_value OPENSSL_${prefix}_DEFINES_${arch})
+      print_defines_in_mk ${arch}_c_flags $arch_defines
+
+      arch_sources=$(var_sorted_value OPENSSL_${prefix}_SOURCES_${arch})
+      print_vardef_in_mk ${arch}_src_files $arch_sources
+
+      arch_exclude_sources=$(var_sorted_value OPENSSL_${prefix}_SOURCES_EXCLUDES_${arch})
+      print_vardef_in_mk ${arch}_exclude_files $arch_exclude_sources
+
+    done
+
+    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/openssl/,\$(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))
+
+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/openssl/,\$(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)
+"
+
+  ) > "$output"
+}
+
 function import() {
   declare -r OPENSSL_SOURCE=$1
 
@@ -278,6 +433,10 @@
 
   cd ..
 
+  generate_config_mk Crypto-config.mk CRYPTO
+  generate_config_mk Ssl-config.mk SSL
+  generate_config_mk Apps-config.mk APPS
+
   # Prune unnecessary sources
   prune
 
diff --git a/openssl.config b/openssl.config
index ea54f2e..d5c0aa4 100644
--- a/openssl.config
+++ b/openssl.config
@@ -217,6 +217,773 @@
 include \
 "
 
+# Arch-specific compiler defines for crypto/ library.
+#
+OPENSSL_CRYPTO_DEFINES="\
+NO_WINDOWS_BRAINDEATH \
+"
+
+OPENSSL_CRYPTO_DEFINES_arm="\
+OPENSSL_BN_ASM_GF2m \
+OPENSSL_BN_ASM_MONT \
+GHASH_ASM \
+AES_ASM \
+SHA1_ASM \
+SHA256_ASM \
+SHA512_ASM \
+"
+
+OPENSSL_CRYPTO_DEFINES_mips="\
+OPENSSL_BN_ASM_MONT \
+AES_ASM \
+SHA1_ASM \
+SHA256_ASM \
+"
+
+OPENSSL_CRYPTO_DEFINES_x86="\
+OPENSSL_BN_ASM_GF2m \
+OPENSSL_BN_ASM_MONT \
+OPENSSL_BN_ASM_PART_WORDS \
+AES_ASM \
+GHASH_ASM \
+SHA1_ASM \
+SHA256_ASM \
+SHA512_ASM \
+MD5_ASM \
+DES_PTR \
+DES_RISC1 \
+DES_UNROLL \
+OPENSSL_CPUID_OBJ \
+"
+
+OPENSSL_CRYPTO_DEFINES_x86_64="\
+OPENSSL_BN_ASM_GF2m \
+OPENSSL_BN_ASM_MONT \
+AES_ASM \
+GHASH_ASM \
+SHA1_ASM \
+SHA256_ASM \
+SHA512_ASM \
+MD5_ASM \
+DES_PTR \
+DES_RISC1 \
+DES_UNROLL \
+OPENSSL_CPUID_OBJ \
+"
+
+OPENSSL_CRYPTO_INCLUDES="\
+. \
+include \
+crypto \
+crypto/asn1 \
+crypto/evp \
+crypto/modes \
+include \
+include/openssl \
+"
+
+OPENSSL_CRYPTO_SOURCES="\
+crypto/cryptlib.c \
+crypto/mem.c \
+crypto/mem_clr.c \
+crypto/mem_dbg.c \
+crypto/cversion.c \
+crypto/ex_data.c \
+crypto/cpt_err.c \
+crypto/ebcdic.c \
+crypto/uid.c \
+crypto/o_time.c \
+crypto/o_str.c \
+crypto/o_dir.c \
+crypto/aes/aes_cbc.c \
+crypto/aes/aes_cfb.c \
+crypto/aes/aes_core.c \
+crypto/aes/aes_ctr.c \
+crypto/aes/aes_ecb.c \
+crypto/aes/aes_misc.c \
+crypto/aes/aes_ofb.c \
+crypto/aes/aes_wrap.c \
+crypto/asn1/a_bitstr.c \
+crypto/asn1/a_bool.c \
+crypto/asn1/a_bytes.c \
+crypto/asn1/a_d2i_fp.c \
+crypto/asn1/a_digest.c \
+crypto/asn1/a_dup.c \
+crypto/asn1/a_enum.c \
+crypto/asn1/a_gentm.c \
+crypto/asn1/a_i2d_fp.c \
+crypto/asn1/a_int.c \
+crypto/asn1/a_mbstr.c \
+crypto/asn1/a_object.c \
+crypto/asn1/a_octet.c \
+crypto/asn1/a_print.c \
+crypto/asn1/a_set.c \
+crypto/asn1/a_sign.c \
+crypto/asn1/a_strex.c \
+crypto/asn1/a_strnid.c \
+crypto/asn1/a_time.c \
+crypto/asn1/a_type.c \
+crypto/asn1/a_utctm.c \
+crypto/asn1/a_utf8.c \
+crypto/asn1/a_verify.c \
+crypto/asn1/ameth_lib.c \
+crypto/asn1/asn1_err.c \
+crypto/asn1/asn1_gen.c \
+crypto/asn1/asn1_lib.c \
+crypto/asn1/asn1_par.c \
+crypto/asn1/asn_mime.c \
+crypto/asn1/asn_moid.c \
+crypto/asn1/asn_pack.c \
+crypto/asn1/bio_asn1.c \
+crypto/asn1/bio_ndef.c \
+crypto/asn1/d2i_pr.c \
+crypto/asn1/d2i_pu.c \
+crypto/asn1/evp_asn1.c \
+crypto/asn1/f_enum.c \
+crypto/asn1/f_int.c \
+crypto/asn1/f_string.c \
+crypto/asn1/i2d_pr.c \
+crypto/asn1/i2d_pu.c \
+crypto/asn1/n_pkey.c \
+crypto/asn1/nsseq.c \
+crypto/asn1/p5_pbe.c \
+crypto/asn1/p5_pbev2.c \
+crypto/asn1/p8_pkey.c \
+crypto/asn1/t_bitst.c \
+crypto/asn1/t_crl.c \
+crypto/asn1/t_pkey.c \
+crypto/asn1/t_req.c \
+crypto/asn1/t_spki.c \
+crypto/asn1/t_x509.c \
+crypto/asn1/t_x509a.c \
+crypto/asn1/tasn_dec.c \
+crypto/asn1/tasn_enc.c \
+crypto/asn1/tasn_fre.c \
+crypto/asn1/tasn_new.c \
+crypto/asn1/tasn_prn.c \
+crypto/asn1/tasn_typ.c \
+crypto/asn1/tasn_utl.c \
+crypto/asn1/x_algor.c \
+crypto/asn1/x_attrib.c \
+crypto/asn1/x_bignum.c \
+crypto/asn1/x_crl.c \
+crypto/asn1/x_exten.c \
+crypto/asn1/x_info.c \
+crypto/asn1/x_long.c \
+crypto/asn1/x_name.c \
+crypto/asn1/x_nx509.c \
+crypto/asn1/x_pkey.c \
+crypto/asn1/x_pubkey.c \
+crypto/asn1/x_req.c \
+crypto/asn1/x_sig.c \
+crypto/asn1/x_spki.c \
+crypto/asn1/x_val.c \
+crypto/asn1/x_x509.c \
+crypto/asn1/x_x509a.c \
+crypto/bf/bf_cfb64.c \
+crypto/bf/bf_ecb.c \
+crypto/bf/bf_enc.c \
+crypto/bf/bf_ofb64.c \
+crypto/bf/bf_skey.c \
+crypto/bio/b_dump.c \
+crypto/bio/b_print.c \
+crypto/bio/b_sock.c \
+crypto/bio/bf_buff.c \
+crypto/bio/bf_nbio.c \
+crypto/bio/bf_null.c \
+crypto/bio/bio_cb.c \
+crypto/bio/bio_err.c \
+crypto/bio/bio_lib.c \
+crypto/bio/bss_acpt.c \
+crypto/bio/bss_bio.c \
+crypto/bio/bss_conn.c \
+crypto/bio/bss_dgram.c \
+crypto/bio/bss_fd.c \
+crypto/bio/bss_file.c \
+crypto/bio/bss_log.c \
+crypto/bio/bss_mem.c \
+crypto/bio/bss_null.c \
+crypto/bio/bss_sock.c \
+crypto/bn/bn_add.c \
+crypto/bn/bn_asm.c \
+crypto/bn/bn_blind.c \
+crypto/bn/bn_const.c \
+crypto/bn/bn_ctx.c \
+crypto/bn/bn_div.c \
+crypto/bn/bn_err.c \
+crypto/bn/bn_exp.c \
+crypto/bn/bn_exp2.c \
+crypto/bn/bn_gcd.c \
+crypto/bn/bn_gf2m.c \
+crypto/bn/bn_kron.c \
+crypto/bn/bn_lib.c \
+crypto/bn/bn_mod.c \
+crypto/bn/bn_mont.c \
+crypto/bn/bn_mpi.c \
+crypto/bn/bn_mul.c \
+crypto/bn/bn_nist.c \
+crypto/bn/bn_prime.c \
+crypto/bn/bn_print.c \
+crypto/bn/bn_rand.c \
+crypto/bn/bn_recp.c \
+crypto/bn/bn_shift.c \
+crypto/bn/bn_sqr.c \
+crypto/bn/bn_sqrt.c \
+crypto/bn/bn_word.c \
+crypto/buffer/buf_err.c \
+crypto/buffer/buf_str.c \
+crypto/buffer/buffer.c \
+crypto/cmac/cm_ameth.c \
+crypto/cmac/cm_pmeth.c \
+crypto/cmac/cmac.c \
+crypto/comp/c_rle.c \
+crypto/comp/c_zlib.c \
+crypto/comp/comp_err.c \
+crypto/comp/comp_lib.c \
+crypto/conf/conf_api.c \
+crypto/conf/conf_def.c \
+crypto/conf/conf_err.c \
+crypto/conf/conf_lib.c \
+crypto/conf/conf_mall.c \
+crypto/conf/conf_mod.c \
+crypto/conf/conf_sap.c \
+crypto/des/cbc_cksm.c \
+crypto/des/cbc_enc.c \
+crypto/des/cfb64ede.c \
+crypto/des/cfb64enc.c \
+crypto/des/cfb_enc.c \
+crypto/des/des_enc.c \
+crypto/des/des_old.c \
+crypto/des/des_old2.c \
+crypto/des/ecb3_enc.c \
+crypto/des/ecb_enc.c \
+crypto/des/ede_cbcm_enc.c \
+crypto/des/enc_read.c \
+crypto/des/enc_writ.c \
+crypto/des/fcrypt.c \
+crypto/des/fcrypt_b.c \
+crypto/des/ofb64ede.c \
+crypto/des/ofb64enc.c \
+crypto/des/ofb_enc.c \
+crypto/des/pcbc_enc.c \
+crypto/des/qud_cksm.c \
+crypto/des/rand_key.c \
+crypto/des/read2pwd.c \
+crypto/des/rpc_enc.c \
+crypto/des/set_key.c \
+crypto/des/str2key.c \
+crypto/des/xcbc_enc.c \
+crypto/dh/dh_ameth.c \
+crypto/dh/dh_asn1.c \
+crypto/dh/dh_check.c \
+crypto/dh/dh_depr.c \
+crypto/dh/dh_err.c \
+crypto/dh/dh_gen.c \
+crypto/dh/dh_key.c \
+crypto/dh/dh_lib.c \
+crypto/dh/dh_pmeth.c \
+crypto/dsa/dsa_ameth.c \
+crypto/dsa/dsa_asn1.c \
+crypto/dsa/dsa_depr.c \
+crypto/dsa/dsa_err.c \
+crypto/dsa/dsa_gen.c \
+crypto/dsa/dsa_key.c \
+crypto/dsa/dsa_lib.c \
+crypto/dsa/dsa_ossl.c \
+crypto/dsa/dsa_pmeth.c \
+crypto/dsa/dsa_prn.c \
+crypto/dsa/dsa_sign.c \
+crypto/dsa/dsa_vrf.c \
+crypto/dso/dso_dl.c \
+crypto/dso/dso_dlfcn.c \
+crypto/dso/dso_err.c \
+crypto/dso/dso_lib.c \
+crypto/dso/dso_null.c \
+crypto/dso/dso_openssl.c \
+crypto/ec/ec2_mult.c \
+crypto/ec/ec2_oct.c \
+crypto/ec/ec2_smpl.c \
+crypto/ec/ec_ameth.c \
+crypto/ec/ec_asn1.c \
+crypto/ec/ec_check.c \
+crypto/ec/ec_curve.c \
+crypto/ec/ec_cvt.c \
+crypto/ec/ec_err.c \
+crypto/ec/ec_key.c \
+crypto/ec/ec_lib.c \
+crypto/ec/ec_mult.c \
+crypto/ec/ec_oct.c \
+crypto/ec/ec_pmeth.c \
+crypto/ec/ec_print.c \
+crypto/ec/eck_prn.c \
+crypto/ec/ecp_mont.c \
+crypto/ec/ecp_nist.c \
+crypto/ec/ecp_oct.c \
+crypto/ec/ecp_smpl.c \
+crypto/ecdh/ech_err.c \
+crypto/ecdh/ech_key.c \
+crypto/ecdh/ech_lib.c \
+crypto/ecdh/ech_ossl.c \
+crypto/ecdsa/ecs_asn1.c \
+crypto/ecdsa/ecs_err.c \
+crypto/ecdsa/ecs_lib.c \
+crypto/ecdsa/ecs_ossl.c \
+crypto/ecdsa/ecs_sign.c \
+crypto/ecdsa/ecs_vrf.c \
+crypto/engine/eng_all.c \
+crypto/engine/eng_cnf.c \
+crypto/engine/eng_ctrl.c \
+crypto/engine/eng_dyn.c \
+crypto/engine/eng_err.c \
+crypto/engine/eng_fat.c \
+crypto/engine/eng_init.c \
+crypto/engine/eng_lib.c \
+crypto/engine/eng_list.c \
+crypto/engine/eng_pkey.c \
+crypto/engine/eng_table.c \
+crypto/engine/tb_asnmth.c \
+crypto/engine/tb_cipher.c \
+crypto/engine/tb_dh.c \
+crypto/engine/tb_digest.c \
+crypto/engine/tb_dsa.c \
+crypto/engine/tb_ecdh.c \
+crypto/engine/tb_ecdsa.c \
+crypto/engine/tb_pkmeth.c \
+crypto/engine/tb_rand.c \
+crypto/engine/tb_rsa.c \
+crypto/engine/tb_store.c \
+crypto/err/err.c \
+crypto/err/err_all.c \
+crypto/err/err_prn.c \
+crypto/evp/bio_b64.c \
+crypto/evp/bio_enc.c \
+crypto/evp/bio_md.c \
+crypto/evp/bio_ok.c \
+crypto/evp/c_all.c \
+crypto/evp/c_allc.c \
+crypto/evp/c_alld.c \
+crypto/evp/digest.c \
+crypto/evp/e_aes.c \
+crypto/evp/e_aes_cbc_hmac_sha1.c \
+crypto/evp/e_bf.c \
+crypto/evp/e_des.c \
+crypto/evp/e_des3.c \
+crypto/evp/e_null.c \
+crypto/evp/e_old.c \
+crypto/evp/e_rc2.c \
+crypto/evp/e_rc4.c \
+crypto/evp/e_rc4_hmac_md5.c \
+crypto/evp/e_rc5.c \
+crypto/evp/e_xcbc_d.c \
+crypto/evp/encode.c \
+crypto/evp/evp_acnf.c \
+crypto/evp/evp_cnf.c \
+crypto/evp/evp_enc.c \
+crypto/evp/evp_err.c \
+crypto/evp/evp_key.c \
+crypto/evp/evp_lib.c \
+crypto/evp/evp_pbe.c \
+crypto/evp/evp_pkey.c \
+crypto/evp/m_dss.c \
+crypto/evp/m_dss1.c \
+crypto/evp/m_ecdsa.c \
+crypto/evp/m_md4.c \
+crypto/evp/m_md5.c \
+crypto/evp/m_mdc2.c \
+crypto/evp/m_null.c \
+crypto/evp/m_ripemd.c \
+crypto/evp/m_sha1.c \
+crypto/evp/m_sigver.c \
+crypto/evp/m_wp.c \
+crypto/evp/names.c \
+crypto/evp/p5_crpt.c \
+crypto/evp/p5_crpt2.c \
+crypto/evp/p_dec.c \
+crypto/evp/p_enc.c \
+crypto/evp/p_lib.c \
+crypto/evp/p_open.c \
+crypto/evp/p_seal.c \
+crypto/evp/p_sign.c \
+crypto/evp/p_verify.c \
+crypto/evp/pmeth_fn.c \
+crypto/evp/pmeth_gn.c \
+crypto/evp/pmeth_lib.c \
+crypto/hmac/hm_ameth.c \
+crypto/hmac/hm_pmeth.c \
+crypto/hmac/hmac.c \
+crypto/krb5/krb5_asn.c \
+crypto/lhash/lh_stats.c \
+crypto/lhash/lhash.c \
+crypto/md4/md4_dgst.c \
+crypto/md4/md4_one.c \
+crypto/md5/md5_dgst.c \
+crypto/md5/md5_one.c \
+crypto/modes/cbc128.c \
+crypto/modes/ccm128.c \
+crypto/modes/cfb128.c \
+crypto/modes/ctr128.c \
+crypto/modes/gcm128.c \
+crypto/modes/ofb128.c \
+crypto/modes/xts128.c \
+crypto/o_init.c \
+crypto/objects/o_names.c \
+crypto/objects/obj_dat.c \
+crypto/objects/obj_err.c \
+crypto/objects/obj_lib.c \
+crypto/objects/obj_xref.c \
+crypto/ocsp/ocsp_asn.c \
+crypto/ocsp/ocsp_cl.c \
+crypto/ocsp/ocsp_err.c \
+crypto/ocsp/ocsp_ext.c \
+crypto/ocsp/ocsp_ht.c \
+crypto/ocsp/ocsp_lib.c \
+crypto/ocsp/ocsp_prn.c \
+crypto/ocsp/ocsp_srv.c \
+crypto/ocsp/ocsp_vfy.c \
+crypto/pem/pem_all.c \
+crypto/pem/pem_err.c \
+crypto/pem/pem_info.c \
+crypto/pem/pem_lib.c \
+crypto/pem/pem_oth.c \
+crypto/pem/pem_pk8.c \
+crypto/pem/pem_pkey.c \
+crypto/pem/pem_seal.c \
+crypto/pem/pem_sign.c \
+crypto/pem/pem_x509.c \
+crypto/pem/pem_xaux.c \
+crypto/pem/pvkfmt.c \
+crypto/pkcs12/p12_add.c \
+crypto/pkcs12/p12_asn.c \
+crypto/pkcs12/p12_attr.c \
+crypto/pkcs12/p12_crpt.c \
+crypto/pkcs12/p12_crt.c \
+crypto/pkcs12/p12_decr.c \
+crypto/pkcs12/p12_init.c \
+crypto/pkcs12/p12_key.c \
+crypto/pkcs12/p12_kiss.c \
+crypto/pkcs12/p12_mutl.c \
+crypto/pkcs12/p12_npas.c \
+crypto/pkcs12/p12_p8d.c \
+crypto/pkcs12/p12_p8e.c \
+crypto/pkcs12/p12_utl.c \
+crypto/pkcs12/pk12err.c \
+crypto/pkcs7/pk7_asn1.c \
+crypto/pkcs7/pk7_attr.c \
+crypto/pkcs7/pk7_doit.c \
+crypto/pkcs7/pk7_lib.c \
+crypto/pkcs7/pk7_mime.c \
+crypto/pkcs7/pk7_smime.c \
+crypto/pkcs7/pkcs7err.c \
+crypto/pqueue/pqueue.c \
+crypto/rand/md_rand.c \
+crypto/rand/rand_egd.c \
+crypto/rand/rand_err.c \
+crypto/rand/rand_lib.c \
+crypto/rand/rand_unix.c \
+crypto/rand/rand_win.c \
+crypto/rand/randfile.c \
+crypto/rc2/rc2_cbc.c \
+crypto/rc2/rc2_ecb.c \
+crypto/rc2/rc2_skey.c \
+crypto/rc2/rc2cfb64.c \
+crypto/rc2/rc2ofb64.c \
+crypto/rc4/rc4_enc.c \
+crypto/rc4/rc4_skey.c \
+crypto/rc4/rc4_utl.c \
+crypto/ripemd/rmd_dgst.c \
+crypto/ripemd/rmd_one.c \
+crypto/rsa/rsa_ameth.c \
+crypto/rsa/rsa_asn1.c \
+crypto/rsa/rsa_chk.c \
+crypto/rsa/rsa_crpt.c \
+crypto/rsa/rsa_eay.c \
+crypto/rsa/rsa_err.c \
+crypto/rsa/rsa_gen.c \
+crypto/rsa/rsa_lib.c \
+crypto/rsa/rsa_none.c \
+crypto/rsa/rsa_null.c \
+crypto/rsa/rsa_oaep.c \
+crypto/rsa/rsa_pk1.c \
+crypto/rsa/rsa_pmeth.c \
+crypto/rsa/rsa_prn.c \
+crypto/rsa/rsa_pss.c \
+crypto/rsa/rsa_saos.c \
+crypto/rsa/rsa_sign.c \
+crypto/rsa/rsa_ssl.c \
+crypto/rsa/rsa_x931.c \
+crypto/sha/sha1_one.c \
+crypto/sha/sha1dgst.c \
+crypto/sha/sha256.c \
+crypto/sha/sha512.c \
+crypto/sha/sha_dgst.c \
+crypto/srp/srp_lib.c \
+crypto/srp/srp_vfy.c \
+crypto/stack/stack.c \
+crypto/ts/ts_err.c \
+crypto/txt_db/txt_db.c \
+crypto/ui/ui_compat.c \
+crypto/ui/ui_err.c \
+crypto/ui/ui_lib.c \
+crypto/ui/ui_openssl.c \
+crypto/ui/ui_util.c \
+crypto/x509/by_dir.c \
+crypto/x509/by_file.c \
+crypto/x509/x509_att.c \
+crypto/x509/x509_cmp.c \
+crypto/x509/x509_d2.c \
+crypto/x509/x509_def.c \
+crypto/x509/x509_err.c \
+crypto/x509/x509_ext.c \
+crypto/x509/x509_lu.c \
+crypto/x509/x509_obj.c \
+crypto/x509/x509_r2x.c \
+crypto/x509/x509_req.c \
+crypto/x509/x509_set.c \
+crypto/x509/x509_trs.c \
+crypto/x509/x509_txt.c \
+crypto/x509/x509_v3.c \
+crypto/x509/x509_vfy.c \
+crypto/x509/x509_vpm.c \
+crypto/x509/x509cset.c \
+crypto/x509/x509name.c \
+crypto/x509/x509rset.c \
+crypto/x509/x509spki.c \
+crypto/x509/x509type.c \
+crypto/x509/x_all.c \
+crypto/x509v3/pcy_cache.c \
+crypto/x509v3/pcy_data.c \
+crypto/x509v3/pcy_lib.c \
+crypto/x509v3/pcy_map.c \
+crypto/x509v3/pcy_node.c \
+crypto/x509v3/pcy_tree.c \
+crypto/x509v3/v3_akey.c \
+crypto/x509v3/v3_akeya.c \
+crypto/x509v3/v3_alt.c \
+crypto/x509v3/v3_bcons.c \
+crypto/x509v3/v3_bitst.c \
+crypto/x509v3/v3_conf.c \
+crypto/x509v3/v3_cpols.c \
+crypto/x509v3/v3_crld.c \
+crypto/x509v3/v3_enum.c \
+crypto/x509v3/v3_extku.c \
+crypto/x509v3/v3_genn.c \
+crypto/x509v3/v3_ia5.c \
+crypto/x509v3/v3_info.c \
+crypto/x509v3/v3_int.c \
+crypto/x509v3/v3_lib.c \
+crypto/x509v3/v3_ncons.c \
+crypto/x509v3/v3_ocsp.c \
+crypto/x509v3/v3_pci.c \
+crypto/x509v3/v3_pcia.c \
+crypto/x509v3/v3_pcons.c \
+crypto/x509v3/v3_pku.c \
+crypto/x509v3/v3_pmaps.c \
+crypto/x509v3/v3_prn.c \
+crypto/x509v3/v3_purp.c \
+crypto/x509v3/v3_skey.c \
+crypto/x509v3/v3_sxnet.c \
+crypto/x509v3/v3_utl.c \
+crypto/x509v3/v3err.c \
+"
+
+OPENSSL_CRYPTO_SOURCES_arm="\
+crypto/aes/asm/aes-armv4.S \
+crypto/bn/asm/armv4-gf2m.S \
+crypto/bn/asm/armv4-mont.S \
+crypto/modes/asm/ghash-armv4.S \
+crypto/sha/asm/sha1-armv4-large.S \
+crypto/sha/asm/sha256-armv4.S \
+crypto/sha/asm/sha512-armv4.S \
+"
+
+OPENSSL_CRYPTO_SOURCES_EXCLUDES_arm="\
+crypto/aes/aes_core.c \
+"
+
+OPENSSL_CRYPTO_SOURCES_mips="\
+crypto/aes/asm/aes-mips.S \
+crypto/bn/asm/bn-mips.S \
+crypto/bn/asm/mips-mont.S \
+crypto/sha/asm/sha1-mips.S \
+crypto/sha/asm/sha256-mips.S \
+"
+
+OPENSSL_CRYPTO_SOURCES_EXCLUDES_mips="\
+crypto/aes/aes_core.c \
+crypto/bn/bn_asm.c \
+"
+
+OPENSSL_CRYPTO_SOURCES_x86="\
+crypto/aes/asm/aes-586.S \
+crypto/aes/asm/aesni-x86.S \
+crypto/aes/asm/vpaes-x86.S \
+crypto/bf/asm/bf-586.S \
+crypto/bn/asm/bn-586.S \
+crypto/bn/asm/co-586.S \
+crypto/bn/asm/x86-gf2m.S \
+crypto/bn/asm/x86-mont.S \
+crypto/des/asm/crypt586.S \
+crypto/des/asm/des-586.S \
+crypto/md5/asm/md5-586.S \
+crypto/modes/asm/ghash-x86.S \
+crypto/sha/asm/sha1-586.S \
+crypto/sha/asm/sha256-586.S \
+crypto/sha/asm/sha512-586.S \
+crypto/x86cpuid.S \
+"
+
+OPENSSL_CRYPTO_SOURCES_EXCLUDES_x86="\
+crypto/aes/aes_core.c \
+crypto/aes/aes_cbc.c \
+crypto/bf/bf_enc.c \
+crypto/bn/bn_asm.c \
+crypto/des/des_enc.c \
+crypto/des/fcrypt_b.c \
+crypto/mem_clr.c \
+"
+
+OPENSSL_CRYPTO_SOURCES_x86_64="\
+crypto/aes/asm/aes-x86_64.S \
+crypto/aes/asm/aesni-x86_64.S \
+crypto/aes/asm/aesni-sha1-x86_64.S \
+crypto/aes/asm/bsaes-x86_64.S \
+crypto/aes/asm/vpaes-x86_64.S \
+crypto/bn/asm/modexp512-x86_64.S \
+crypto/bn/asm/x86_64-gcc.c \
+crypto/bn/asm/x86_64-gf2m.S \
+crypto/bn/asm/x86_64-mont.S \
+crypto/bn/asm/x86_64-mont5.S \
+crypto/md5/asm/md5-x86_64.S \
+crypto/modes/asm/ghash-x86_64.S \
+crypto/rc4/asm/rc4-md5-x86_64.S \
+crypto/rc4/asm/rc4-x86_64.S \
+crypto/sha/asm/sha1-x86_64.S \
+crypto/sha/asm/sha256-x86_64.S \
+crypto/sha/asm/sha512-x86_64.S \
+crypto/x86_64cpuid.S \
+"
+
+OPENSSL_CRYPTO_SOURCES_EXCLUDES_x86_64="\
+crypto/aes/aes_cbc.c \
+crypto/aes/aes_core.c \
+crypto/mem_clr.c \
+crypto/rc4/rc4_enc.c \
+"
+
+OPENSSL_SSL_INCLUDES="\
+. \
+include \
+crypto \
+"
+
+OPENSSL_SSL_SOURCES="\
+ssl/bio_ssl.c \
+ssl/d1_both.c \
+ssl/d1_enc.c \
+ssl/d1_lib.c \
+ssl/d1_pkt.c \
+ssl/d1_srtp.c \
+ssl/kssl.c \
+ssl/s23_clnt.c \
+ssl/s23_lib.c \
+ssl/s23_meth.c \
+ssl/s23_pkt.c \
+ssl/s23_srvr.c \
+ssl/s2_clnt.c \
+ssl/s2_enc.c \
+ssl/s2_lib.c \
+ssl/s2_meth.c \
+ssl/s2_pkt.c \
+ssl/s2_srvr.c \
+ssl/s3_both.c \
+ssl/s3_cbc.c \
+ssl/s3_clnt.c \
+ssl/s3_enc.c \
+ssl/s3_lib.c \
+ssl/s3_meth.c \
+ssl/s3_pkt.c \
+ssl/s3_srvr.c \
+ssl/ssl_algs.c \
+ssl/ssl_asn1.c \
+ssl/ssl_cert.c \
+ssl/ssl_ciph.c \
+ssl/ssl_err.c \
+ssl/ssl_err2.c \
+ssl/ssl_lib.c \
+ssl/ssl_rsa.c \
+ssl/ssl_sess.c \
+ssl/ssl_stat.c \
+ssl/ssl_txt.c \
+ssl/t1_clnt.c \
+ssl/t1_enc.c \
+ssl/t1_lib.c \
+ssl/t1_meth.c \
+ssl/t1_reneg.c \
+ssl/t1_srvr.c \
+ssl/tls_srp.c \
+"
+
+OPENSSL_APPS_DEFINES="\
+MONOLITH \
+"
+
+OPENSSL_APPS_INCLUDES="\
+. \
+include \
+"
+
+OPENSSL_APPS_SOURCES="\
+apps/app_rand.c \
+apps/apps.c \
+apps/asn1pars.c \
+apps/ca.c \
+apps/ciphers.c \
+apps/crl.c \
+apps/crl2p7.c \
+apps/dgst.c \
+apps/dh.c \
+apps/dhparam.c \
+apps/dsa.c \
+apps/dsaparam.c \
+apps/ecparam.c \
+apps/ec.c \
+apps/enc.c \
+apps/engine.c \
+apps/errstr.c \
+apps/gendh.c \
+apps/gendsa.c \
+apps/genpkey.c \
+apps/genrsa.c \
+apps/nseq.c \
+apps/ocsp.c \
+apps/openssl.c \
+apps/passwd.c \
+apps/pkcs12.c \
+apps/pkcs7.c \
+apps/pkcs8.c \
+apps/pkey.c \
+apps/pkeyparam.c \
+apps/pkeyutl.c \
+apps/prime.c \
+apps/rand.c \
+apps/req.c \
+apps/rsa.c \
+apps/rsautl.c \
+apps/s_cb.c \
+apps/s_client.c \
+apps/s_server.c \
+apps/s_socket.c \
+apps/s_time.c \
+apps/sess_id.c \
+apps/smime.c \
+apps/speed.c \
+apps/spkac.c \
+apps/srp.c \
+apps/verify.c \
+apps/version.c \
+apps/x509.c \
+"
+
 OPENSSL_PATCHES="\
 progs.patch \
 handshake_cutthrough.patch \