3 # unix.pl - the standard unix makefile stuff.
16 { $cflags="-g2 -ggdb"; }
18 { $cflags="-O3 -fomit-frame-pointer"; }
39 # static library stuff
42 $ranlib=&which("ranlib") or $ranlib="true";
58 'md5-x86_64' => 'crypto/md5',
59 'x86_64-mont' => 'crypto/bn',
60 'x86_64-mont5' => 'crypto/bn',
61 'x86_64-gf2m' => 'crypto/bn',
62 'modexp512-x86_64' => 'crypto/bn',
63 'aes-x86_64' => 'crypto/aes',
64 'vpaes-x86_64' => 'crypto/aes',
65 'bsaes-x86_64' => 'crypto/aes',
66 'aesni-x86_64' => 'crypto/aes',
67 'aesni-sha1-x86_64' => 'crypto/aes',
68 'sha1-x86_64' => 'crypto/sha',
69 'e_padlock-x86_64' => 'engines',
70 'rc4-x86_64' => 'crypto/rc4',
71 'rc4-md5-x86_64' => 'crypto/rc4',
72 'ghash-x86_64' => 'crypto/modes',
73 'aesni-gcm-x86_64' => 'crypto/modes',
74 'aesni-sha256-x86_64' => 'crypto/aes',
75 'rsaz-x86_64' => 'crypto/bn',
76 'rsaz-avx2' => 'crypto/bn',
77 'aesni-mb-x86_64' => 'crypto/aes',
78 'sha1-mb-x86_64' => 'crypto/sha',
79 'sha256-mb-x86_64' => 'crypto/sha',
80 'ecp_nistz256-x86_64' => 'crypto/ec',
81 'wp-x86_64' => 'crypto/whrlpool',
82 'cmll-x86_64' => 'crypto/camellia',
85 # If I were feeling more clever, these could probably be extracted
87 sub platform_perlasm_compile_target
89 local($target, $source, $bname) = @_;
93 # FIXME: export CC so rsaz-avx2 can test for it, since BSD make does
94 # not export variables, unlike GNU make. But this also requires fixing
95 # the .s.o rule to use CC!
96 if ($target eq "\$(OBJ_D)/$p.o")
99 \$(TMP_D)/$p.s: $perl1{$p}/asm/$p.pl
100 \$(PERL) $perl1{$p}/asm/$p.pl \$(PERLASM_SCHEME) > \$@
104 if ($target eq '$(OBJ_D)/x86_64cpuid.o')
107 $(TMP_D)/x86_64cpuid.s: crypto/x86_64cpuid.pl
108 $(PERL) crypto/x86_64cpuid.pl $(PERLASM_SCHEME) > $@
111 elsif ($target eq '$(OBJ_D)/sha256-x86_64.o')
114 $(TMP_D)/sha256-x86_64.s: crypto/sha/asm/sha512-x86_64.pl
115 $(PERL) crypto/sha/asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@
118 elsif ($target eq '$(OBJ_D)/sha512-x86_64.o')
121 $(TMP_D)/sha512-x86_64.s: crypto/sha/asm/sha512-x86_64.pl
122 $(PERL) crypto/sha/asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@
125 elsif ($target eq '$(OBJ_D)/sha512-x86_64.o')
128 $(TMP_D)/sha512-x86_64.s: crypto/sha/asm/sha512-x86_64.pl
129 $(PERL) crypto/sha/asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@
136 sub special_compile_target
140 if ($target eq 'crypto/bn/x86_64-gcc')
143 \$(TMP_D)/x86_64-gcc.o: crypto/bn/asm/x86_64-gcc.c
144 \$(CC) \$(LIB_CFLAGS) -c -o \$@ crypto/bn/asm/x86_64-gcc.c
152 local($obj,$target,$name,$shlib)=@_;
153 local($ret,$_,$Name);
155 $target =~ s/\//$o/g if $o ne '/';
157 ($Name=$name) =~ tr/a-z/A-Z/;
159 $ret.="$target: \$(${Name}OBJ)\n";
160 $ret.="\t\$(RM) $target\n";
161 $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
162 $ret.="\t\$(RANLIB) $target\n\n";
167 local($target,$files,$dep_libs,$libs)=@_;
170 $file =~ s/\//$o/g if $o ne '/';
172 $ret.="$target: $files $dep_libs\n";
173 $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
181 foreach $path (split /:/, $ENV{PATH})
183 if (-x "$path/$name")
185 return "$path/$name";
192 my ($str, $tests) = @_;
194 foreach my $t (keys %$tests)
196 $str =~ s/(\.\/)?\$\($t\)/\$(TEST_D)\/$tests->{$t}/g;
204 my ($str, $fakes) = @_;
206 my @t = split(/\s+/, $str);
210 $str .= ' ' if $str ne '';
211 if (exists($fakes->{$t}))
213 $str .= $fakes->{$t};
216 if ($t =~ /^[^\/]+$/)
218 $str .= '$(TEST_D)/' . $t;
233 # Compatible with -j...
234 $str =~ s/^(\s+@?)/$1cd \$(TEST_D) && /;
237 # Compatible with not -j.
238 my @t = split("\n", $str);
248 $t =~ s/^@/\@cd \$(TEST_D) && /;
250 elsif ($t !~ /^\s*#/)
252 $t = 'cd $(TEST_D) && ' . $t;
263 my ($sed, $src, @targets) = @_;
266 foreach my $t (@targets)
268 # Copy first so we get file modes...
269 $s .= "\$(TEST_D)/$t: \$(SRC_D)/$src/$t\n\tcp \$(SRC_D)/$src/$t \$(TEST_D)/$t\n";
270 $s .= "\tsed -e 's/\\.\\.\\/apps/..\\/\$(OUT_D)/' -e 's/\\.\\.\\/util/..\\/\$(TEST_D)/' < \$(SRC_D)/$src/$t > \$(TEST_D)/$t\n" if $sed;
280 open(M, $makefile) || die "Can't open $makefile: $!";
286 while (my $line = <M>)
289 while ($line =~ /^(.*)\\$/)
294 if ($line =~ /^alltests:(.*)$/)
296 my @t = split(/\s+/, $1);
300 $alltests{$t} = undef;
304 if (($line =~ /^(?<t>\S+):(?<d>.*)$/ && exists $targets{$1})
305 || $line =~ /^(?<t>test_(ss|gen) .*):(?<d>.*)/)
309 # If there are multiple targets stupid FreeBSD make runs the
310 # rules once for each dependency that matches one of the
311 # targets. Running the same rule twice concurrently causes
312 # breakage, so replace with a fake target.
316 my @targets = split /\s+/, $t;
318 foreach my $f (@targets)
324 $deps{$t} =~ s/#.*$//;
330 $targets{$t} .= "$line\n";
335 if ($line =~ /^(\S+TEST)=\s*(\S+)$/)
342 delete $alltests{test_jpake} if $no_jpake;
343 delete $targets{test_ige} if $no_ige;
344 delete $alltests{test_md2} if $no_md2;
345 delete $alltests{test_rc5} if $no_rc5;
348 foreach my $t (keys %tests)
350 $tests .= "$t = $tests{$t}\n";
354 foreach my $t (keys %targets)
359 $d =~ s/\.\.\/apps/\$(BIN_D)/g;
360 $d =~ s/\.\.\/util/\$(TEST_D)/g;
361 $d = fixtests($d, \%tests);
362 $d = fixdeps($d, \%fakes);
364 my $r = $targets{$t};
365 $r =~ s/\.\.\/apps/..\/\$(BIN_D)/g;
366 $r =~ s/\.\.\/util/..\/\$(TEST_D)/g;
367 $r =~ s/\.\.\/(\S+)/\$(SRC_D)\/$1/g;
372 $t =~ s/\s+/ \$(TEST_D)\//g;
374 $each .= "$t: test_scripts $d\n\t\@echo '$t test started'\n$r\t\@echo '$t test done'\n\n";
377 # FIXME: Might be a clever way to figure out what needs copying
378 my @copies = ( 'bctest',
412 my $copies = copy_scripts(1, 'test', @copies);
413 $copies .= copy_scripts(0, 'test', ('smcont.txt'));
415 my @utils = ( 'shlib_wrap.sh',
418 $copies .= copy_scripts(1, 'util', @utils);
420 my @apps = ( 'CA.sh',
424 $copies .= copy_scripts(1, 'apps', @apps);
426 $copies .= copy_scripts(1, 'crypto/evp', ('evptests.txt'));
428 $scripts = "test_scripts: \$(TEST_D)/CA.sh \$(TEST_D)/opensslwrap.sh \$(TEST_D)/openssl.cnf \$(TEST_D)/shlib_wrap.sh ocsp smime\n";
429 $scripts .= "\nocsp:\n\tcp -R test/ocsp-tests \$(TEST_D)\n";
430 $scripts .= "\smime:\n\tcp -R test/smime-certs \$(TEST_D)\n";
433 foreach my $t (keys %alltests)
435 if (exists($fakes{$t}))
437 $all .= " $fakes{$t}";
445 return "$scripts\n$copies\n$tests\n$all\n\n$each";