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 'aes-x86_64' => 'crypto/aes',
63 'vpaes-x86_64' => 'crypto/aes',
64 'bsaes-x86_64' => 'crypto/aes',
65 'aesni-x86_64' => 'crypto/aes',
66 'aesni-sha1-x86_64' => 'crypto/aes',
67 'sha1-x86_64' => 'crypto/sha',
68 'e_padlock-x86_64' => 'engines',
69 'rc4-x86_64' => 'crypto/rc4',
70 'rc4-md5-x86_64' => 'crypto/rc4',
71 'ghash-x86_64' => 'crypto/modes',
72 'aesni-gcm-x86_64' => 'crypto/modes',
73 'aesni-sha256-x86_64' => 'crypto/aes',
74 'rsaz-x86_64' => 'crypto/bn',
75 'rsaz-avx2' => 'crypto/bn',
76 'aesni-mb-x86_64' => 'crypto/aes',
77 'sha1-mb-x86_64' => 'crypto/sha',
78 'sha256-mb-x86_64' => 'crypto/sha',
79 'ecp_nistz256-x86_64' => 'crypto/ec',
80 'wp-x86_64' => 'crypto/whrlpool',
81 'cmll-x86_64' => 'crypto/camellia',
84 # If I were feeling more clever, these could probably be extracted
86 sub platform_perlasm_compile_target
88 local($target, $source, $bname) = @_;
92 # FIXME: export CC so rsaz-avx2 can test for it, since BSD make does
93 # not export variables, unlike GNU make. But this also requires fixing
94 # the .s.o rule to use CC!
95 if ($target eq "\$(OBJ_D)/$p.o")
98 \$(TMP_D)/$p.s: $perl1{$p}/asm/$p.pl
99 \$(PERL) $perl1{$p}/asm/$p.pl \$(PERLASM_SCHEME) > \$@
103 if ($target eq '$(OBJ_D)/x86_64cpuid.o')
106 $(TMP_D)/x86_64cpuid.s: crypto/x86_64cpuid.pl
107 $(PERL) crypto/x86_64cpuid.pl $(PERLASM_SCHEME) > $@
110 elsif ($target eq '$(OBJ_D)/sha256-x86_64.o')
113 $(TMP_D)/sha256-x86_64.s: crypto/sha/asm/sha512-x86_64.pl
114 $(PERL) crypto/sha/asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@
117 elsif ($target eq '$(OBJ_D)/sha512-x86_64.o')
120 $(TMP_D)/sha512-x86_64.s: crypto/sha/asm/sha512-x86_64.pl
121 $(PERL) crypto/sha/asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@
124 elsif ($target eq '$(OBJ_D)/sha512-x86_64.o')
127 $(TMP_D)/sha512-x86_64.s: crypto/sha/asm/sha512-x86_64.pl
128 $(PERL) crypto/sha/asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@
135 sub special_compile_target
139 if ($target eq 'crypto/bn/x86_64-gcc')
142 \$(TMP_D)/x86_64-gcc.o: crypto/bn/asm/x86_64-gcc.c
143 \$(CC) \$(LIB_CFLAGS) -c -o \$@ crypto/bn/asm/x86_64-gcc.c
151 local($obj,$target,$name,$shlib)=@_;
152 local($ret,$_,$Name);
154 $target =~ s/\//$o/g if $o ne '/';
156 ($Name=$name) =~ tr/a-z/A-Z/;
158 $ret.="$target: \$(${Name}OBJ)\n";
159 $ret.="\t\$(RM) $target\n";
160 $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
161 $ret.="\t\$(RANLIB) $target\n\n";
166 local($target,$files,$dep_libs,$libs)=@_;
169 $file =~ s/\//$o/g if $o ne '/';
171 $ret.="$target: $files $dep_libs\n";
172 $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
180 foreach $path (split /:/, $ENV{PATH})
182 if (-x "$path/$name")
184 return "$path/$name";
191 my ($str, $tests) = @_;
193 foreach my $t (keys %$tests)
195 $str =~ s/(\.\/)?\$\($t\)/\$(TEST_D)\/$tests->{$t}/g;
203 my ($str, $fakes) = @_;
205 my @t = split(/\s+/, $str);
209 $str .= ' ' if $str ne '';
210 if (exists($fakes->{$t}))
212 $str .= $fakes->{$t};
215 if ($t =~ /^[^\/]+$/)
217 $str .= '$(TEST_D)/' . $t;
232 # Compatible with -j...
233 $str =~ s/^(\s+@?)/$1cd \$(TEST_D) && /;
236 # Compatible with not -j.
237 my @t = split("\n", $str);
247 $t =~ s/^@/\@cd \$(TEST_D) && /;
249 elsif ($t !~ /^\s*#/)
251 $t = 'cd $(TEST_D) && ' . $t;
262 my ($sed, $src, @targets) = @_;
265 foreach my $t (@targets)
267 # Copy first so we get file modes...
268 $s .= "\$(TEST_D)/$t: \$(SRC_D)/$src/$t\n\tcp \$(SRC_D)/$src/$t \$(TEST_D)/$t\n";
269 $s .= "\tsed -e 's/\\.\\.\\/apps/..\\/\$(OUT_D)/' -e 's/\\.\\.\\/util/..\\/\$(TEST_D)/' < \$(SRC_D)/$src/$t > \$(TEST_D)/$t\n" if $sed;
279 open(M, $makefile) || die "Can't open $makefile: $!";
285 while (my $line = <M>)
288 while ($line =~ /^(.*)\\$/)
293 if ($line =~ /^alltests:(.*)$/)
295 my @t = split(/\s+/, $1);
299 $alltests{$t} = undef;
303 if (($line =~ /^(?<t>\S+):(?<d>.*)$/ && exists $targets{$1})
304 || $line =~ /^(?<t>test_(ss|gen) .*):(?<d>.*)/)
308 # If there are multiple targets stupid FreeBSD make runs the
309 # rules once for each dependency that matches one of the
310 # targets. Running the same rule twice concurrently causes
311 # breakage, so replace with a fake target.
315 my @targets = split /\s+/, $t;
317 foreach my $f (@targets)
323 $deps{$t} =~ s/#.*$//;
329 $targets{$t} .= "$line\n";
334 if ($line =~ /^(\S+TEST)=\s*(\S+)$/)
341 delete $alltests{test_jpake} if $no_jpake;
342 delete $targets{test_ige} if $no_ige;
343 delete $alltests{test_md2} if $no_md2;
344 delete $alltests{test_rc5} if $no_rc5;
347 foreach my $t (keys %tests)
349 $tests .= "$t = $tests{$t}\n";
353 foreach my $t (keys %targets)
358 $d =~ s/\.\.\/apps/\$(BIN_D)/g;
359 $d =~ s/\.\.\/util/\$(TEST_D)/g;
360 $d = fixtests($d, \%tests);
361 $d = fixdeps($d, \%fakes);
363 my $r = $targets{$t};
364 $r =~ s/\.\.\/apps/..\/\$(BIN_D)/g;
365 $r =~ s/\.\.\/util/..\/\$(TEST_D)/g;
366 $r =~ s/\.\.\/(\S+)/\$(SRC_D)\/$1/g;
371 $t =~ s/\s+/ \$(TEST_D)\//g;
373 $each .= "$t: test_scripts $d\n\t\@echo '$t test started'\n$r\t\@echo '$t test done'\n\n";
376 # FIXME: Might be a clever way to figure out what needs copying
377 my @copies = ( 'bctest',
411 my $copies = copy_scripts(1, 'test', @copies);
412 $copies .= copy_scripts(0, 'test', ('smcont.txt'));
414 my @utils = ( 'shlib_wrap.sh',
417 $copies .= copy_scripts(1, 'util', @utils);
419 my @apps = ( 'CA.sh',
423 $copies .= copy_scripts(1, 'apps', @apps);
425 $copies .= copy_scripts(1, 'crypto/evp', ('evptests.txt'));
427 $scripts = "test_scripts: \$(TEST_D)/CA.sh \$(TEST_D)/opensslwrap.sh \$(TEST_D)/openssl.cnf \$(TEST_D)/shlib_wrap.sh ocsp smime\n";
428 $scripts .= "\nocsp:\n\tcp -R test/ocsp-tests \$(TEST_D)\n";
429 $scripts .= "\smime:\n\tcp -R test/smime-certs \$(TEST_D)\n";
432 foreach my $t (keys %alltests)
434 if (exists($fakes{$t}))
436 $all .= " $fakes{$t}";
444 return "$scripts\n$copies\n$tests\n$all\n\n$each";