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',
79 # If I were feeling more clever, these could probably be extracted
81 sub platform_perlasm_compile_target
83 local($target, $source, $bname) = @_;
87 if ($target eq "\$(OBJ_D)/$p.o")
90 \$(TMP_D)/$p.s: $perl1{$p}/asm/$p.pl
91 \$(PERL) $perl1{$p}/asm/$p.pl \$(PERLASM_SCHEME) > \$@
95 if ($target eq '$(OBJ_D)/x86_64cpuid.o')
98 $(TMP_D)/x86_64cpuid.s: crypto/x86_64cpuid.pl
99 $(PERL) crypto/x86_64cpuid.pl $(PERLASM_SCHEME) > $@
102 elsif ($target eq '$(OBJ_D)/sha256-x86_64.o')
105 $(TMP_D)/sha256-x86_64.s: crypto/sha/asm/sha512-x86_64.pl
106 $(PERL) crypto/sha/asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@
109 elsif ($target eq '$(OBJ_D)/sha512-x86_64.o')
112 $(TMP_D)/sha512-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) $@
127 sub special_compile_target
131 if ($target eq 'crypto/bn/x86_64-gcc')
134 \$(TMP_D)/x86_64-gcc.o: crypto/bn/asm/x86_64-gcc.c
135 \$(CC) \$(CFLAGS) -c -o \$@ crypto/bn/asm/x86_64-gcc.c
143 local($obj,$target,$name,$shlib)=@_;
144 local($ret,$_,$Name);
146 $target =~ s/\//$o/g if $o ne '/';
148 ($Name=$name) =~ tr/a-z/A-Z/;
150 $ret.="$target: \$(${Name}OBJ)\n";
151 $ret.="\t\$(RM) $target\n";
152 $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
153 $ret.="\t\$(RANLIB) $target\n\n";
158 local($target,$files,$dep_libs,$libs)=@_;
161 $file =~ s/\//$o/g if $o ne '/';
163 $ret.="$target: $files $dep_libs\n";
164 $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
172 foreach $path (split /:/, $ENV{PATH})
174 if (-x "$path/$name")
176 return "$path/$name";
183 my ($str, $tests) = @_;
185 foreach my $t (keys %$tests)
187 $str =~ s/(\.\/)?\$\($t\)/\$(TEST_D)\/$tests->{$t}/g;
195 my ($str, $fakes) = @_;
197 my @t = split(/\s+/, $str);
201 $str .= ' ' if $str ne '';
202 if (exists($fakes->{$t}))
204 $str .= $fakes->{$t};
207 if ($t =~ /^[^\/]+$/)
209 $str .= '$(TEST_D)/' . $t;
224 # Compatible with -j...
225 $str =~ s/^(\s+@?)/$1cd \$(TEST_D) && /;
228 # Compatible with not -j.
229 my @t = split("\n", $str);
239 $t =~ s/^@/\@cd \$(TEST_D) && /;
241 elsif ($t !~ /^\s*#/)
243 $t = 'cd $(TEST_D) && ' . $t;
254 my ($sed, $src, @targets) = @_;
257 foreach my $t (@targets)
259 # Copy first so we get file modes...
260 $s .= "\$(TEST_D)/$t: \$(SRC_D)/$src/$t\n\tcp \$(SRC_D)/$src/$t \$(TEST_D)/$t\n";
261 $s .= "\tsed -e 's/\\.\\.\\/apps/..\\/\$(OUT_D)/' -e 's/\\.\\.\\/util/..\\/\$(TEST_D)/' < \$(SRC_D)/$src/$t > \$(TEST_D)/$t\n" if $sed;
271 open(M, $makefile) || die "Can't open $makefile: $!";
277 while (my $line = <M>)
280 while ($line =~ /^(.*)\\$/)
285 if ($line =~ /^alltests:(.*)$/)
287 my @t = split(/\s+/, $1);
291 $alltests{$t} = undef;
295 if (($line =~ /^(?<t>\S+):(?<d>.*)$/ && exists $targets{$1})
296 || $line =~ /^(?<t>test_(ss|gen) .*):(?<d>.*)/)
300 # If there are multiple targets stupid FreeBSD make runs the
301 # rules once for each dependency that matches one of the
302 # targets. Running the same rule twice concurrently causes
303 # breakage, so replace with a fake target.
307 my @targets = split /\s+/, $t;
309 foreach my $f (@targets)
315 $deps{$t} =~ s/#.*$//;
321 $targets{$t} .= "$line\n";
326 if ($line =~ /^(\S+TEST)=\s*(\S+)$/)
333 delete $alltests{test_jpake} if $no_jpake;
334 delete $targets{test_ige} if $no_ige;
335 delete $alltests{test_md2} if $no_md2;
336 delete $alltests{test_rc5} if $no_rc5;
339 foreach my $t (keys %tests)
341 $tests .= "$t = $tests{$t}\n";
345 foreach my $t (keys %targets)
350 $d =~ s/\.\.\/apps/\$(BIN_D)/g;
351 $d =~ s/\.\.\/util/\$(TEST_D)/g;
352 $d = fixtests($d, \%tests);
353 $d = fixdeps($d, \%fakes);
355 my $r = $targets{$t};
356 $r =~ s/\.\.\/apps/..\/\$(BIN_D)/g;
357 $r =~ s/\.\.\/util/..\/\$(TEST_D)/g;
358 $r =~ s/\.\.\/(\S+)/\$(SRC_D)\/$1/g;
363 $t =~ s/\s+/ \$(TEST_D)\//g;
365 $each .= "$t: test_scripts $d\n\t\@echo '$t test started'\n$r\t\@echo '$t test done'\n\n";
368 # FIXME: Might be a clever way to figure out what needs copying
369 my @copies = ( 'bctest',
403 my $copies = copy_scripts(1, 'test', @copies);
404 $copies .= copy_scripts(0, 'test', ('smcont.txt'));
406 my @utils = ( 'shlib_wrap.sh',
409 $copies .= copy_scripts(1, 'util', @utils);
411 my @apps = ( 'CA.sh',
415 $copies .= copy_scripts(1, 'apps', @apps);
417 $copies .= copy_scripts(1, 'crypto/evp', ('evptests.txt'));
419 $scripts = "test_scripts: \$(TEST_D)/CA.sh \$(TEST_D)/opensslwrap.sh \$(TEST_D)/openssl.cnf \$(TEST_D)/shlib_wrap.sh ocsp smime\n";
420 $scripts .= "\nocsp:\n\tcp -R test/ocsp-tests \$(TEST_D)\n";
421 $scripts .= "\smime:\n\tcp -R test/smime-certs \$(TEST_D)\n";
424 foreach my $t (keys %alltests)
426 if (exists($fakes{$t}))
428 $all .= " $fakes{$t}";
436 return "$scripts\n$copies\n$tests\n$all\n\n$each";