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',
82 # If I were feeling more clever, these could probably be extracted
84 sub platform_perlasm_compile_target
86 local($target, $source, $bname) = @_;
90 if ($target eq "\$(OBJ_D)/$p.o")
93 \$(TMP_D)/$p.s: $perl1{$p}/asm/$p.pl
94 \$(PERL) $perl1{$p}/asm/$p.pl \$(PERLASM_SCHEME) > \$@
98 if ($target eq '$(OBJ_D)/x86_64cpuid.o')
101 $(TMP_D)/x86_64cpuid.s: crypto/x86_64cpuid.pl
102 $(PERL) crypto/x86_64cpuid.pl $(PERLASM_SCHEME) > $@
105 elsif ($target eq '$(OBJ_D)/sha256-x86_64.o')
108 $(TMP_D)/sha256-x86_64.s: crypto/sha/asm/sha512-x86_64.pl
109 $(PERL) crypto/sha/asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@
112 elsif ($target eq '$(OBJ_D)/sha512-x86_64.o')
115 $(TMP_D)/sha512-x86_64.s: crypto/sha/asm/sha512-x86_64.pl
116 $(PERL) crypto/sha/asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@
119 elsif ($target eq '$(OBJ_D)/sha512-x86_64.o')
122 $(TMP_D)/sha512-x86_64.s: crypto/sha/asm/sha512-x86_64.pl
123 $(PERL) crypto/sha/asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@
130 sub special_compile_target
134 if ($target eq 'crypto/bn/x86_64-gcc')
137 \$(TMP_D)/x86_64-gcc.o: crypto/bn/asm/x86_64-gcc.c
138 \$(CC) \$(CFLAGS) -c -o \$@ crypto/bn/asm/x86_64-gcc.c
146 local($obj,$target,$name,$shlib)=@_;
147 local($ret,$_,$Name);
149 $target =~ s/\//$o/g if $o ne '/';
151 ($Name=$name) =~ tr/a-z/A-Z/;
153 $ret.="$target: \$(${Name}OBJ)\n";
154 $ret.="\t\$(RM) $target\n";
155 $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
156 $ret.="\t\$(RANLIB) $target\n\n";
161 local($target,$files,$dep_libs,$libs)=@_;
164 $file =~ s/\//$o/g if $o ne '/';
166 $ret.="$target: $files $dep_libs\n";
167 $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
175 foreach $path (split /:/, $ENV{PATH})
177 if (-x "$path/$name")
179 return "$path/$name";
186 my ($str, $tests) = @_;
188 foreach my $t (keys %$tests)
190 $str =~ s/(\.\/)?\$\($t\)/\$(TEST_D)\/$tests->{$t}/g;
198 my ($str, $fakes) = @_;
200 my @t = split(/\s+/, $str);
204 $str .= ' ' if $str ne '';
205 if (exists($fakes->{$t}))
207 $str .= $fakes->{$t};
210 if ($t =~ /^[^\/]+$/)
212 $str .= '$(TEST_D)/' . $t;
227 # Compatible with -j...
228 $str =~ s/^(\s+@?)/$1cd \$(TEST_D) && /;
231 # Compatible with not -j.
232 my @t = split("\n", $str);
242 $t =~ s/^@/\@cd \$(TEST_D) && /;
244 elsif ($t !~ /^\s*#/)
246 $t = 'cd $(TEST_D) && ' . $t;
257 my ($sed, $src, @targets) = @_;
260 foreach my $t (@targets)
262 # Copy first so we get file modes...
263 $s .= "\$(TEST_D)/$t: \$(SRC_D)/$src/$t\n\tcp \$(SRC_D)/$src/$t \$(TEST_D)/$t\n";
264 $s .= "\tsed -e 's/\\.\\.\\/apps/..\\/\$(OUT_D)/' -e 's/\\.\\.\\/util/..\\/\$(TEST_D)/' < \$(SRC_D)/$src/$t > \$(TEST_D)/$t\n" if $sed;
274 open(M, $makefile) || die "Can't open $makefile: $!";
280 while (my $line = <M>)
283 while ($line =~ /^(.*)\\$/)
288 if ($line =~ /^alltests:(.*)$/)
290 my @t = split(/\s+/, $1);
294 $alltests{$t} = undef;
298 if (($line =~ /^(?<t>\S+):(?<d>.*)$/ && exists $targets{$1})
299 || $line =~ /^(?<t>test_(ss|gen) .*):(?<d>.*)/)
303 # If there are multiple targets stupid FreeBSD make runs the
304 # rules once for each dependency that matches one of the
305 # targets. Running the same rule twice concurrently causes
306 # breakage, so replace with a fake target.
310 my @targets = split /\s+/, $t;
312 foreach my $f (@targets)
318 $deps{$t} =~ s/#.*$//;
324 $targets{$t} .= "$line\n";
329 if ($line =~ /^(\S+TEST)=\s*(\S+)$/)
336 delete $alltests{test_jpake} if $no_jpake;
337 delete $targets{test_ige} if $no_ige;
338 delete $alltests{test_md2} if $no_md2;
339 delete $alltests{test_rc5} if $no_rc5;
342 foreach my $t (keys %tests)
344 $tests .= "$t = $tests{$t}\n";
348 foreach my $t (keys %targets)
353 $d =~ s/\.\.\/apps/\$(BIN_D)/g;
354 $d =~ s/\.\.\/util/\$(TEST_D)/g;
355 $d = fixtests($d, \%tests);
356 $d = fixdeps($d, \%fakes);
358 my $r = $targets{$t};
359 $r =~ s/\.\.\/apps/..\/\$(BIN_D)/g;
360 $r =~ s/\.\.\/util/..\/\$(TEST_D)/g;
361 $r =~ s/\.\.\/(\S+)/\$(SRC_D)\/$1/g;
366 $t =~ s/\s+/ \$(TEST_D)\//g;
368 $each .= "$t: test_scripts $d\n\t\@echo '$t test started'\n$r\t\@echo '$t test done'\n\n";
371 # FIXME: Might be a clever way to figure out what needs copying
372 my @copies = ( 'bctest',
406 my $copies = copy_scripts(1, 'test', @copies);
407 $copies .= copy_scripts(0, 'test', ('smcont.txt'));
409 my @utils = ( 'shlib_wrap.sh',
412 $copies .= copy_scripts(1, 'util', @utils);
414 my @apps = ( 'CA.sh',
418 $copies .= copy_scripts(1, 'apps', @apps);
420 $copies .= copy_scripts(1, 'crypto/evp', ('evptests.txt'));
422 $scripts = "test_scripts: \$(TEST_D)/CA.sh \$(TEST_D)/opensslwrap.sh \$(TEST_D)/openssl.cnf \$(TEST_D)/shlib_wrap.sh ocsp smime\n";
423 $scripts .= "\nocsp:\n\tcp -R test/ocsp-tests \$(TEST_D)\n";
424 $scripts .= "\smime:\n\tcp -R test/smime-certs \$(TEST_D)\n";
427 foreach my $t (keys %alltests)
429 if (exists($fakes{$t}))
431 $all .= " $fakes{$t}";
439 return "$scripts\n$copies\n$tests\n$all\n\n$each";