Bourne shell portability fix.
[oweals/openssl.git] / fips-1.0 / Makefile
1 #
2 # OpenSSL/crypto/Makefile
3 #
4
5 DIR=            fips-1.0
6 TOP=            ..
7 CC=             cc
8 INCLUDE=        -I. -I$(TOP) -I../include
9 # INCLUDES targets sudbirs!
10 INCLUDES=       -I.. -I../.. -I../../include
11 CFLAG=          -g
12 MAKEDEPPROG=    makedepend
13 MAKEDEPEND=     $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
14 MAKEFILE=       Makefile
15 RM=             rm -f
16 AR=             ar r
17 ARD=            ar d
18 TEST=           fips_test_suite.c
19 FIPS_TVDIR=     testvectors
20 FIPS_TVOK=      $$HOME/fips/tv.ok
21
22 FIPSCANLOC=     $(FIPSLIBDIR)fipscanister.o
23
24 RECURSIVE_MAKE= [ -n "$(FDIRS)" ] && for i in $(FDIRS) ; do \
25                     (cd $$i && echo "making $$target in $(DIR)/$$i..." && \
26                     $(MAKE) -e TOP=../.. DIR=$$i INCLUDES='${INCLUDES}' $$target ) || exit 1; \
27                 done;
28
29 PEX_LIBS=
30 EX_LIBS=
31  
32 CFLAGS= $(INCLUDE) $(CFLAG) -DHMAC_EXT=\"$${HMAC_EXT:-sha1}\"
33 ASFLAGS= $(INCLUDE) $(ASFLAG)
34 AFLAGS=$(ASFLAGS)
35
36 LIBS=
37
38 FDIRS=sha rand des aes dsa rsa dh hmac
39
40 GENERAL=Makefile README fips-lib.com install.com
41
42 LIB= $(TOP)/libcrypto.a
43 SHARED_LIB= $(FIPSCANLIB)$(SHLIB_EXT)
44 LIBSRC=fips.c 
45 LIBOBJ=fips.o
46
47 FIPS_OBJ_LISTS=sha/lib hmac/lib rand/lib des/lib aes/lib dsa/lib rsa/lib dh/lib
48
49 SRC= $(LIBSRC)
50
51 EXHEADER=fips.h
52 HEADER=$(EXHEADER) fips_utl.h
53 EXE=fipsld
54
55 ALL=    $(GENERAL) $(SRC) $(HEADER)
56
57 top:
58         @(cd ..; $(MAKE) DIRS=$(DIR) all)
59
60 testapps:
61         @if [ -z "$(THIS)" ]; then $(MAKE) -f $(TOP)/Makefile reflect THIS=$@; fi
62
63 all:
64         @if [ -n "$(FIPSCANLIB)" ]; then \
65                 $(MAKE) -e subdirs lib shared; \
66         fi
67
68 # Idea behind fipscanister.o is to "seize" the sequestered code between
69 # known symbols for fingerprinting purposes, which would be commonly
70 # done with ld -r start.o ... end.o. The latter however presents a minor
71 # challenge on multi-ABI platforms. As just implied, we'd rather use ld,
72 # but the trouble is that we don't generally know how ABI-selection
73 # compiler flag is translated to corresponding linker flag. All compiler
74 # drivers seem to recognize -r flag and pass it down to linker, but some
75 # of them, including gcc, erroneously add -lc, as well as run-time
76 # components, such as crt1.o and alike. Fortunately among those vendor
77 # compilers which were observed to misinterpret -r flag multi-ABI ones
78 # are equipped with smart linkers, which don't require any ABI-selection
79 # flag and simply assume that all objects are of the same type as first
80 # one in command line. So the idea is to identify gcc and deficient
81 # vendor compiler drivers...
82
83 fipscanister.o: fips_start.o $(LIBOBJ) $(FIPS_OBJ_LISTS) fips_end.o
84         FIPS_ASM=""; \
85         list="$(BN_ASM)"; for i in $$list; do FIPS_ASM="$$FIPS_ASM ../crypto/bn/$$i" ; done; \
86         list="$(AES_ASM_OBJ)"; for i in $$list; do FIPS_ASM="$$FIPS_ASM ../crypto/aes/$$i" ; done; \
87         list="$(DES_ENC)"; for i in $$list; do FIPS_ASM="$$FIPS_ASM ../crypto/des/$$i" ; done; \
88         list="$(SHA1_ASM_OBJ)"; for i in $$list; do FIPS_ASM="$$FIPS_ASM ../crypto/sha/$$i" ; done; \
89         if [ -n "$(CPUID_OBJ)" ]; then \
90                 CPUID=../crypto/$(CPUID_OBJ) ; \
91         else \
92                 CPUID="" ; \
93         fi ; \
94         objs="fips_start.o $(LIBOBJ) $(FIPS_EX_OBJ) $$CPUID $$FIPS_ASM"; \
95         for i in $(FIPS_OBJ_LISTS); do \
96                 dir=`dirname $$i`; script="s|^|$$dir/|;s| | $$dir/|g"; \
97                 objs="$$objs `sed "$$script" $$i`"; \
98         done; \
99         objs="$$objs fips_end.o" ; \
100         if [ -n "${FIPS_SITE_LD}" ]; then \
101                 set -x; ${FIPS_SITE_LD} -r -o $@ $$objs; \
102         elif $(CC) -dumpversion >/dev/null 2>&1; then \
103                 set -x; $(CC) $(CFLAGS) -r -nostdlib -o $@ $$objs ; \
104         else case "`(uname -s) 2>/dev/null`" in \
105                 HP-UX|OSF1|SunOS) set -x; /usr/ccs/bin/ld -r -o $@ $$objs ;; \
106                 AIX) set -x; $(CC) $(CFLAGS) -Wl,-bnoobjreorder -r -o $@ $$objs ;; \
107                 *) set -x; $(CC) $(CFLAGS) -r -o $@ $$objs ;; \
108         esac fi
109         sha/fips_standalone_sha1 fipscanister.o > fipscanister.o.sha1
110
111 # If another exception is immediately required, assign approprite
112 # site-specific ld command to FIPS_SITE_LD environment variable.
113
114 fips_start.o: fips_canister.c
115         $(CC) $(CFLAGS) -DFIPS_START -c -o $@ fips_canister.c
116 fips_end.o: fips_canister.c
117         $(CC) $(CFLAGS) -DFIPS_END -c -o $@ fips_canister.c
118 fips_premain_dso$(EXE_EXT): fips_premain.c
119         $(CC) $(CFLAGS) -DFINGERPRINT_PREMAIN_DSO_LOAD -o $@ fips_premain.c \
120                 ../libcrypto.a $(EX_LIBS)
121
122 subdirs:
123         @target=all; $(RECURSIVE_MAKE)
124
125 files:
126         $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
127         @target=files; $(RECURSIVE_MAKE)
128
129 links:
130         @$(PERL) $(TOP)/util/mklink.pl ../include/openssl $(EXHEADER)
131         @$(PERL) $(TOP)/util/mklink.pl ../test $(TEST)
132         @target=links; $(RECURSIVE_MAKE)
133
134 # lib: and $(LIB): are splitted to avoid end-less loop
135 lib:    $(FIPSCANLIB) $(FIPSCANLOC)
136         @touch lib
137
138 $(FIPSCANLIB):  $(FIPSCANLOC)
139         $(AR) ../$(FIPSCANLIB).a $(FIPSCANLOC)
140         if [ "$(FIPSCANLIB)" = "libfips" ]; then \
141                 $(AR) $(LIB) $(FIPSCANLOC) ; \
142                 $(RANLIB) $(LIB) || echo Never Mind. ; \
143         fi
144         $(RANLIB) ../$(FIPSCANLIB).a || echo Never mind.
145         @touch lib
146
147 shared: lib subdirs fips_premain_dso$(EXE_EXT)
148
149 libs:
150         @target=lib; $(RECURSIVE_MAKE)
151
152 fips_test: top
153         @target=fips_test; $(RECURSIVE_MAKE)
154
155 fips_test_diff:
156         @if diff -b -B -I '^\#' -cr -X fips-nodiff.txt $(FIPS_TVDIR) $(FIPS_TVOK) ; then \
157                 echo "FIPS diff OK" ; \
158         else \
159                 echo "***FIPS DIFF ERROR***" ; exit 1 ; \
160         fi
161
162
163 install:
164         @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
165         @headerlist="$(EXHEADER)"; for i in $$headerlist ;\
166         do \
167         (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
168         chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
169         done;
170         @target=install; $(RECURSIVE_MAKE)
171
172 lint:
173         @target=lint; $(RECURSIVE_MAKE)
174
175 depend:
176         @[ -z "$(THIS)" ] || $(MAKEDEPEND) -- $(CFLAG) $(INCLUDE) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
177         @[ -z "$(THIS)" ] || (set -e; target=depend; $(RECURSIVE_MAKE) )
178         @if [ -z "$(THIS)" ]; then $(MAKE) -f $(TOP)/Makefile reflect THIS=$@; fi
179
180 clean:
181         rm -f fipscanister.o.sha1 fips_premain_dso$(EXE_EXT) \
182                 *.s *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
183         @target=clean; $(RECURSIVE_MAKE)
184
185 dclean:
186         $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
187         mv -f Makefile.new $(MAKEFILE)
188         @target=dclean; $(RECURSIVE_MAKE)
189
190 # DO NOT DELETE THIS LINE -- make depend depends on it.
191
192 fips.o: ../include/openssl/asn1.h ../include/openssl/bio.h
193 fips.o: ../include/openssl/crypto.h ../include/openssl/des.h
194 fips.o: ../include/openssl/des_old.h ../include/openssl/e_os2.h
195 fips.o: ../include/openssl/err.h ../include/openssl/evp.h
196 fips.o: ../include/openssl/fips.h ../include/openssl/fips_rand.h
197 fips.o: ../include/openssl/hmac.h ../include/openssl/lhash.h
198 fips.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
199 fips.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
200 fips.o: ../include/openssl/ossl_typ.h ../include/openssl/rand.h
201 fips.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
202 fips.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
203 fips.o: ../include/openssl/ui.h ../include/openssl/ui_compat.h fips.c
204 fips.o: fips_locl.h