1# This Makefile is confirmed to be run only on Linux (CentOS and
2# Ubuntu). perl5 and gas(>=2.26) are needed.
3
4UNAME_S := $(shell uname -s)
5ifneq ($(UNAME_S),Linux)
6  $(error This can be run only on Linux)
7endif
8
9PERL    = perl
10
11# Supported architecture list
12ASM_ARCHS = aix64-gcc-as BSD-x86 BSD-x86_64 \
13darwin64-x86_64-cc darwin-i386-cc darwin64-arm64-cc linux-aarch64 \
14linux-armv4 linux-elf linux-x86_64 \
15linux-ppc64le linux32-s390x linux64-s390x linux64-mips64\
16solaris-x86-gcc solaris64-x86_64-gcc VC-WIN64A VC-WIN32
17
18NO_ASM_ARCHS = VC-WIN64-ARM linux64-riscv64 linux64-loongarch64
19
20CC = gcc
21FAKE_GCC = ../config/fake_gcc.pl
22
23CONFIGURE = ./Configure
24# no-comp: against CRIME attack
25# no-shared: openssl-cli needs static link
26# no-afalgeng: old Linux kernel < 4.0 does not support it
27# enable-ssl-trace: cause the optional SSL_trace API to be built
28COPTS =  no-comp no-shared no-afalgeng enable-ssl-trace enable-fips
29
30# disable platform check in Configure
31NO_WARN_ENV = CONFIGURE_CHECKER_WARN=1
32
33GENERATE = ./generate_gypi.pl
34
35OPSSL_SRC = ../openssl
36
37# Header files generated with Configure
38#INT_CFGS = bn_conf.h dso_conf.h
39INT_CFG_DIR = $(OPSSL_SRC)/include/crypto
40GEN_HEADERS = asn1 asn1t bio cmp cms configuration conf crmf crypto ct err    \
41              ess fipskey lhash ocsp opensslv pkcs12 pkcs7 safestack srp ssl  \
42	      ui x509 x509v3 x509_vfy conf
43
44CRYPTO_GEN_HEADERS = bn_conf dso_conf
45
46PHONY = all clean replace generate_headers
47.PHONY: $(PHONY)
48
49#all: $(ASM_ARCHS) $(NO_ASM_ARCHS) generate_headers replace
50all: $(ASM_ARCHS) $(NO_ASM_ARCHS) generate_headers
51
52# Configure and generate openssl asm files for each archs
53$(ASM_ARCHS):
54	cd $(OPSSL_SRC); $(NO_WARN_ENV) CC=$(CC) $(PERL) $(CONFIGURE) $(COPTS) $@;
55	$(PERL) -w -I$(OPSSL_SRC) $(GENERATE) asm $@ "${GEN_HEADERS}" "${CRYPTO_GEN_HEADERS}"
56# Confgure asm_avx2 and generate upto avx2 support
57	cd $(OPSSL_SRC); $(NO_WARN_ENV) CC=$(FAKE_GCC) $(PERL) $(CONFIGURE) \
58	$(COPTS) $@;
59	$(PERL) -w -I$(OPSSL_SRC) $(GENERATE) asm_avx2 $@ "${GEN_HEADERS}" "${CRYTO_GEN_HEADERS}"
60# Configure no-asm and generate no-asm sources
61	cd $(OPSSL_SRC); $(NO_WARN_ENV) $(PERL) $(CONFIGURE) $(COPTS) \
62	no-asm $@;
63	$(PERL) -w -I$(OPSSL_SRC) $(GENERATE) no-asm $@ "${GEN_HEADERS}" "${CRYPTO_GEN_HEADERS}"
64
65$(NO_ASM_ARCHS):
66# Configure no-asm and generate no-asm sources
67	cd $(OPSSL_SRC); $(NO_WARN_ENV) $(PERL) $(CONFIGURE) $(COPTS) \
68	no-asm $@;
69	$(PERL) -w -I$(OPSSL_SRC) $(GENERATE) no-asm $@ "${GEN_HEADERS}" "${CRYPTO_GEN_HEADERS}"
70
71generate_headers:
72	@$(PERL) -w -I$(OPSSL_SRC) ./generate_headers.pl "${GEN_HEADERS}" "${CRYPTO_GEN_HEADERS}"
73
74clean:
75	find archs \( -name \*.S -o -name \*.s -o -name \*.asm -o \
76	-name \*.gypi -o -name \*.h -o -name \*.pm -o -name \*.rc \) -exec rm "{}" \;
77