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',
83 # If I were feeling more clever, these could probably be extracted
85 sub platform_perlasm_compile_target
87 local($target, $source, $bname) = @_;
91 # FIXME: export CC so rsaz-avx2 can test for it, since BSD make does
92 # not export variables, unlike GNU make. But this also requires fixing
93 # the .s.o rule to use CC!
94 if ($target eq "\$(OBJ_D)/$p.o")
97 \$(TMP_D)/$p.s: $perl1{$p}/asm/$p.pl
98 \$(PERL) $perl1{$p}/asm/$p.pl \$(PERLASM_SCHEME) > \$@
102 if ($target eq '$(OBJ_D)/x86_64cpuid.o')
105 $(TMP_D)/x86_64cpuid.s: crypto/x86_64cpuid.pl
106 $(PERL) crypto/x86_64cpuid.pl $(PERLASM_SCHEME) > $@
109 elsif ($target eq '$(OBJ_D)/sha256-x86_64.o')
112 $(TMP_D)/sha256-x86_64.s: crypto/sha/asm/sha512-x86_64.pl
113 $(PERL) crypto/sha/asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@
116 elsif ($target eq '$(OBJ_D)/sha512-x86_64.o')
119 $(TMP_D)/sha512-x86_64.s: crypto/sha/asm/sha512-x86_64.pl
120 $(PERL) crypto/sha/asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@
123 elsif ($target eq '$(OBJ_D)/sha512-x86_64.o')
126 $(TMP_D)/sha512-x86_64.s: crypto/sha/asm/sha512-x86_64.pl
127 $(PERL) crypto/sha/asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@
134 sub special_compile_target
138 if ($target eq 'crypto/bn/x86_64-gcc')
141 \$(TMP_D)/x86_64-gcc.o: crypto/bn/asm/x86_64-gcc.c
142 \$(CC) \$(LIB_CFLAGS) -c -o \$@ crypto/bn/asm/x86_64-gcc.c
150 local($obj,$target,$name,$shlib)=@_;
151 local($ret,$_,$Name);
153 $target =~ s/\//$o/g if $o ne '/';
155 ($Name=$name) =~ tr/a-z/A-Z/;
157 $ret.="$target: \$(${Name}OBJ)\n";
158 $ret.="\t\$(RM) $target\n";
159 $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
160 $ret.="\t\$(RANLIB) $target\n\n";
165 local($target,$files,$dep_libs,$libs)=@_;
168 $file =~ s/\//$o/g if $o ne '/';
170 $ret.="$target: $files $dep_libs\n";
171 $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
179 foreach $path (split /:/, $ENV{PATH})
181 if (-x "$path/$name")
183 return "$path/$name";
190 my ($str, $tests) = @_;
192 foreach my $t (keys %$tests)
194 $str =~ s/(\.\/)?\$\($t\)/\$(TEST_D)\/$tests->{$t}/g;
202 my ($str, $fakes) = @_;
204 my @t = split(/\s+/, $str);
208 $str .= ' ' if $str ne '';
209 if (exists($fakes->{$t}))
211 $str .= $fakes->{$t};
214 if ($t =~ /^[^\/]+$/)
216 $str .= '$(TEST_D)/' . $t;
231 # Compatible with -j...
232 $str =~ s/^(\s+@?)/$1cd \$(TEST_D) && /;
235 # Compatible with not -j.
236 my @t = split("\n", $str);
246 $t =~ s/^@/\@cd \$(TEST_D) && /;
248 elsif ($t !~ /^\s*#/)
250 $t = 'cd $(TEST_D) && ' . $t;
261 my ($sed, $src, @targets) = @_;
264 foreach my $t (@targets)
266 # Copy first so we get file modes...
267 $s .= "\$(TEST_D)/$t: \$(SRC_D)/$src/$t\n\tcp \$(SRC_D)/$src/$t \$(TEST_D)/$t\n";
268 $s .= "\tsed -e 's/\\.\\.\\/apps/..\\/\$(OUT_D)/' -e 's/\\.\\.\\/util/..\\/\$(TEST_D)/' < \$(SRC_D)/$src/$t > \$(TEST_D)/$t\n" if $sed;
278 open(M, $makefile) || die "Can't open $makefile: $!";
284 while (my $line = <M>)
287 while ($line =~ /^(.*)\\$/)
292 if ($line =~ /^alltests:(.*)$/)
294 my @t = split(/\s+/, $1);
298 $alltests{$t} = undef;
302 if (($line =~ /^(?<t>\S+):(?<d>.*)$/ && exists $targets{$1})
303 || $line =~ /^(?<t>test_(ss|gen) .*):(?<d>.*)/)
307 # If there are multiple targets stupid FreeBSD make runs the
308 # rules once for each dependency that matches one of the
309 # targets. Running the same rule twice concurrently causes
310 # breakage, so replace with a fake target.
314 my @targets = split /\s+/, $t;
316 foreach my $f (@targets)
322 $deps{$t} =~ s/#.*$//;
328 $targets{$t} .= "$line\n";
333 if ($line =~ /^(\S+TEST)=\s*(\S+)$/)
340 delete $alltests{test_jpake} if $no_jpake;
341 delete $targets{test_ige} if $no_ige;
342 delete $alltests{test_md2} if $no_md2;
343 delete $alltests{test_rc5} if $no_rc5;
346 foreach my $t (keys %tests)
348 $tests .= "$t = $tests{$t}\n";
352 foreach my $t (keys %targets)
357 $d =~ s/\.\.\/apps/\$(BIN_D)/g;
358 $d =~ s/\.\.\/util/\$(TEST_D)/g;
359 $d = fixtests($d, \%tests);
360 $d = fixdeps($d, \%fakes);
362 my $r = $targets{$t};
363 $r =~ s/\.\.\/apps/..\/\$(BIN_D)/g;
364 $r =~ s/\.\.\/util/..\/\$(TEST_D)/g;
365 $r =~ s/\.\.\/(\S+)/\$(SRC_D)\/$1/g;
370 $t =~ s/\s+/ \$(TEST_D)\//g;
372 $each .= "$t: test_scripts $d\n\t\@echo '$t test started'\n$r\t\@echo '$t test done'\n\n";
375 # FIXME: Might be a clever way to figure out what needs copying
376 my @copies = ( 'bctest',
410 my $copies = copy_scripts(1, 'test', @copies);
411 $copies .= copy_scripts(0, 'test', ('smcont.txt'));
413 my @utils = ( 'shlib_wrap.sh',
416 $copies .= copy_scripts(1, 'util', @utils);
418 my @apps = ( 'CA.sh',
422 $copies .= copy_scripts(1, 'apps', @apps);
424 $copies .= copy_scripts(1, 'crypto/evp', ('evptests.txt'));
426 $scripts = "test_scripts: \$(TEST_D)/CA.sh \$(TEST_D)/opensslwrap.sh \$(TEST_D)/openssl.cnf \$(TEST_D)/shlib_wrap.sh ocsp smime\n";
427 $scripts .= "\nocsp:\n\tcp -R test/ocsp-tests \$(TEST_D)\n";
428 $scripts .= "\smime:\n\tcp -R test/smime-certs \$(TEST_D)\n";
431 foreach my $t (keys %alltests)
433 if (exists($fakes{$t}))
435 $all .= " $fakes{$t}";
443 return "$scripts\n$copies\n$tests\n$all\n\n$each";