obj-m := lgecrypto_module.o

ifeq ($(ARCH),arm64)
    BLOB_DIR := blob_64bits
	ARMDIR := arm64
else
    BLOB_DIR := blob_32bits
	ARMDIR := arm
endif

CONFIG_LGCRYPTO_FIPS_RECOMPILE := y

ifeq ($(CONFIG_LGCRYPTO_FIPS_ENABLE),y)
ifeq ($(CONFIG_LGCRYPTO_FIPS_RECOMPILE),y)
ifeq ($(ARMDIR),arm64)
lgecrypto_module-objs := lgecrypto_wrapper.o \
                         src/lgecrypto.o \
                         src/ecb.o \
                         src/cbc.o \
                         src/ctr.o \
                         src/xts.o \
                         src/des_generic.o \
                         src/aes_generic.o \
                         src/sha1_generic.o \
                         src/sha256_generic.o \
                         src/sha512_generic.o \
                         src/hmac.o \
                         src/drbg.o \
                         src/chainiv.o \
                         src/eseqiv.o \
                         src/seqiv.o \
                         src/lgecrypto_fips.o \
                         src/lgecrypto_selftest.o \
                         src/lgecrypto_integrity.o \
                         src/$(ARMDIR)/sha1-ce-glue.o \
                         src/$(ARMDIR)/sha1-ce-core.o \
                         src/$(ARMDIR)/sha2-ce-glue.o \
                         src/$(ARMDIR)/sha2-ce-core.o \
                         src/$(ARMDIR)/aes-ce-cipher.o \
                         src/$(ARMDIR)/aes-glue-ce.o \
                         src/$(ARMDIR)/aes-ce.o 

CFLAGS_aes-ce-cipher.o += -march=armv8-a+crypto
AFLAGS_aes-ce.o     := -DINTERLEAVE=2 -DINTERLEAVE_INLINE
CFLAGS_aes-glue-ce.o    := -DUSE_V8_CRYPTO_EXTENSIONS
CFLAGS_lgecrypto_wrapper.o := -DARM64_PLATFORM
CFLAGS_lgecrypto.o := -DARM64_PLATFORM
CFLAGS_lgecrypto_selftest.o := -DARM64_PLATFORM

else

lgecrypto_module-objs := lgecrypto_wrapper.o \
                         src/lgecrypto.o \
                         src/ecb.o \
                         src/cbc.o \
                         src/ctr.o \
                         src/xts.o \
                         src/des_generic.o \
                         src/aes_generic.o \
                         src/sha1_generic.o \
                         src/sha256_generic.o \
                         src/sha512_generic.o \
                         src/hmac.o \
                         src/drbg.o \
                         src/chainiv.o \
                         src/eseqiv.o \
                         src/seqiv.o \
                         src/lgecrypto_fips.o \
                         src/lgecrypto_selftest.o \
                         src/lgecrypto_integrity.o \
                         src/$(ARMDIR)/aes-armv4.o \
                         src/$(ARMDIR)/aesbs-core.o \
                         src/$(ARMDIR)/aesbs-glue.o \
                         src/$(ARMDIR)/aes-ce-core.o \
                         src/$(ARMDIR)/aes-ce-glue.o \
                         src/$(ARMDIR)/sha1-armv4-large.o \
                         src/$(ARMDIR)/sha1-armv7-neon.o \
                         src/$(ARMDIR)/sha1_neon_glue.o \
                         src/$(ARMDIR)/sha256-core.o \
                         src/$(ARMDIR)/sha256_glue.o \
                         src/$(ARMDIR)/sha256_neon_glue.o \
                         src/$(ARMDIR)/sha512-armv7-neon.o \
                         src/$(ARMDIR)/sha512_neon_glue.o \
                         src/$(ARMDIR)/sha2-ce-core.o \
                         src/$(ARMDIR)/sha2-ce-glue.o

quiet_cmd_perl = PERL    $@
      cmd_perl = $(PERL) $(<) > $(@)

$(src)/aesbs-core.S_shipped: $(src)/bsaes-armv7.pl
	$(call cmd,perl)

$(src)/sha256-core.S_shipped: $(src)/sha256-armv4.pl
	$(call cmd,perl)

.PRECIOUS: $(obj)/aesbs-core.S $(obj)/sha256-core.S
endif

else

ifeq ($(ARMDIR),arm64)
lgecrypto_module-objs := lgecrypto_wrapper.o \
                   $(BLOB_DIR)/lgecrypto_bin.o \
                   $(BLOB_DIR)/ecb_bin.o \
                   $(BLOB_DIR)/cbc_bin.o \
                   $(BLOB_DIR)/ctr_bin.o \
                   $(BLOB_DIR)/xts_bin.o \
                   $(BLOB_DIR)/des_generic_bin.o \
                   $(BLOB_DIR)/aes_generic_bin.o \
                   $(BLOB_DIR)/sha1_generic_bin.o \
                   $(BLOB_DIR)/sha256_generic_bin.o \
                   $(BLOB_DIR)/sha512_generic_bin.o \
                   $(BLOB_DIR)/hmac_bin.o \
                   $(BLOB_DIR)/drbg_bin.o \
                   $(BLOB_DIR)/chainiv_bin.o \
                   $(BLOB_DIR)/eseqiv_bin.o \
                   $(BLOB_DIR)/seqiv_bin.o \
                   $(BLOB_DIR)/lgecrypto_fips_bin.o \
                   $(BLOB_DIR)/lgecrypto_selftest_bin.o \
                   $(BLOB_DIR)/lgecrypto_integrity_bin.o \
                   $(BLOB_DIR)/arm64/sha1-ce-glue_bin.o \
                   $(BLOB_DIR)/arm64/sha1-ce-core_bin.o \
                   $(BLOB_DIR)/arm64/sha2-ce-glue_bin.o \
                   $(BLOB_DIR)/arm64/sha2-ce-core_bin.o \
                   $(BLOB_DIR)/arm64/aes-ce-cipher_bin.o \
                   $(BLOB_DIR)/arm64/aes-glue-ce_bin.o \
                   $(BLOB_DIR)/arm64/aes-ce_bin.o 
else
lgecrypto_module-objs := lgecrypto_wrapper.o \
                   $(BLOB_DIR)/lgecrypto_bin.o \
                   $(BLOB_DIR)/ecb_bin.o \
                   $(BLOB_DIR)/cbc_bin.o \
                   $(BLOB_DIR)/ctr_bin.o \
                   $(BLOB_DIR)/xts_bin.o \
                   $(BLOB_DIR)/des_generic_bin.o \
                   $(BLOB_DIR)/aes_generic_bin.o \
                   $(BLOB_DIR)/sha1_generic_bin.o \
                   $(BLOB_DIR)/sha256_generic_bin.o \
                   $(BLOB_DIR)/sha512_generic_bin.o \
                   $(BLOB_DIR)/hmac_bin.o \
                   $(BLOB_DIR)/drbg_bin.o \
                   $(BLOB_DIR)/chainiv_bin.o \
                   $(BLOB_DIR)/eseqiv_bin.o \
                   $(BLOB_DIR)/seqiv_bin.o \
                   $(BLOB_DIR)/lgecrypto_fips_bin.o \
                   $(BLOB_DIR)/lgecrypto_selftest_bin.o \
                   $(BLOB_DIR)/lgecrypto_integrity_bin.o \
                   $(BLOB_DIR)/arm/aes-armv4_bin.o \
                   $(BLOB_DIR)/arm/aesbs-core_bin.o \
                   $(BLOB_DIR)/arm/aesbs-glue_bin.o \
                   $(BLOB_DIR)/arm/aes-ce-core_bin.o \
                   $(BLOB_DIR)/arm/aes-ce-glue_bin.o \
                   $(BLOB_DIR)/arm/sha1-armv4-large_bin.o \
                   $(BLOB_DIR)/arm/sha1-armv7-neon_bin.o \
                   $(BLOB_DIR)/arm/sha1_neon_glue_bin.o \
                   $(BLOB_DIR)/arm/sha256-core_bin.o \
                   $(BLOB_DIR)/arm/sha256_glue_bin.o \
                   $(BLOB_DIR)/arm/sha256_neon_glue_bin.o \
                   $(BLOB_DIR)/arm/sha512-armv7-neon_bin.o \
                   $(BLOB_DIR)/arm/sha512_neon_glue_bin.o \
                   $(BLOB_DIR)/arm/sha2-ce-core_bin.o \
                   $(BLOB_DIR)/arm/sha2-ce-glue_bin.o 
endif
endif
endif
