]>
Commit | Line | Data |
---|---|---|
d02b48c6 RE |
1 | #!/usr/local/bin/perl |
2 | # | |
3 | # unix.pl - the standard unix makefile stuff. | |
4 | # | |
5 | ||
6 | $o='/'; | |
7 | $cp='/bin/cp'; | |
8 | $rm='/bin/rm -f'; | |
9 | ||
10 | # C compiler stuff | |
11 | ||
12 | if ($gcc) | |
13 | { | |
14 | $cc='gcc'; | |
15 | if ($debug) | |
16 | { $cflags="-g2 -ggdb"; } | |
17 | else | |
18 | { $cflags="-O3 -fomit-frame-pointer"; } | |
19 | } | |
20 | else | |
21 | { | |
22 | $cc='cc'; | |
23 | if ($debug) | |
24 | { $cflags="-g"; } | |
25 | else | |
26 | { $cflags="-O"; } | |
27 | } | |
28 | $obj='.o'; | |
045b2809 | 29 | $asm_suffix='.s'; |
d02b48c6 RE |
30 | $ofile='-o '; |
31 | ||
32 | # EXE linking stuff | |
33 | $link='${CC}'; | |
897dfd4e | 34 | $lflags='${CFLAG}'; |
d02b48c6 RE |
35 | $efile='-o '; |
36 | $exep=''; | |
37 | $ex_libs=""; | |
38 | ||
39 | # static library stuff | |
40 | $mklib='ar r'; | |
41 | $mlflags=''; | |
99aab161 | 42 | $ranlib=&which("ranlib") or $ranlib="true"; |
d02b48c6 RE |
43 | $plib='lib'; |
44 | $libp=".a"; | |
45 | $shlibp=".a"; | |
46 | $lfile=''; | |
47 | ||
48 | $asm='as'; | |
49 | $afile='-o '; | |
dfeab068 RE |
50 | $bn_asm_obj=""; |
51 | $bn_asm_src=""; | |
d02b48c6 RE |
52 | $des_enc_obj=""; |
53 | $des_enc_src=""; | |
54 | $bf_enc_obj=""; | |
55 | $bf_enc_src=""; | |
56 | ||
656829b7 BL |
57 | %perl1 = ( |
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', | |
6d84daa5 BL |
73 | 'aesni-gcm-x86_64' => 'crypto/modes', |
74 | 'aesni-sha256-x86_64' => 'crypto/aes', | |
82fe001b BL |
75 | 'rsaz-x86_64' => 'crypto/bn', |
76 | 'rsaz-avx2' => 'crypto/bn', | |
99fb2212 BL |
77 | 'aesni-mb-x86_64' => 'crypto/aes', |
78 | 'sha1-mb-x86_64' => 'crypto/sha', | |
79 | 'sha256-mb-x86_64' => 'crypto/sha', | |
656829b7 BL |
80 | ); |
81 | ||
82 | # If I were feeling more clever, these could probably be extracted | |
83 | # from makefiles. | |
84 | sub platform_perlasm_compile_target | |
85 | { | |
86 | local($target, $source, $bname) = @_; | |
87 | ||
88 | for $p (keys %perl1) | |
89 | { | |
c051cbc8 BL |
90 | # FIXME: export CC so rsaz-avx2 can test for it, since BSD make does |
91 | # not export variables, unlike GNU make. But this also requires fixing | |
92 | # the .s.o rule to use CC! | |
656829b7 BL |
93 | if ($target eq "\$(OBJ_D)/$p.o") |
94 | { | |
95 | return << "EOF"; | |
96 | \$(TMP_D)/$p.s: $perl1{$p}/asm/$p.pl | |
97 | \$(PERL) $perl1{$p}/asm/$p.pl \$(PERLASM_SCHEME) > \$@ | |
98 | EOF | |
99 | } | |
100 | } | |
101 | if ($target eq '$(OBJ_D)/x86_64cpuid.o') | |
102 | { | |
103 | return << 'EOF'; | |
104 | $(TMP_D)/x86_64cpuid.s: crypto/x86_64cpuid.pl | |
105 | $(PERL) crypto/x86_64cpuid.pl $(PERLASM_SCHEME) > $@ | |
106 | EOF | |
107 | } | |
108 | elsif ($target eq '$(OBJ_D)/sha256-x86_64.o') | |
109 | { | |
110 | return << 'EOF'; | |
111 | $(TMP_D)/sha256-x86_64.s: crypto/sha/asm/sha512-x86_64.pl | |
112 | $(PERL) crypto/sha/asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@ | |
113 | EOF | |
114 | } | |
115 | elsif ($target eq '$(OBJ_D)/sha512-x86_64.o') | |
116 | { | |
117 | return << 'EOF'; | |
118 | $(TMP_D)/sha512-x86_64.s: crypto/sha/asm/sha512-x86_64.pl | |
119 | $(PERL) crypto/sha/asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@ | |
120 | EOF | |
121 | } | |
122 | elsif ($target eq '$(OBJ_D)/sha512-x86_64.o') | |
123 | { | |
124 | return << 'EOF'; | |
125 | $(TMP_D)/sha512-x86_64.s: crypto/sha/asm/sha512-x86_64.pl | |
126 | $(PERL) crypto/sha/asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@ | |
127 | EOF | |
128 | } | |
129 | ||
130 | die $target; | |
131 | } | |
132 | ||
133 | sub special_compile_target | |
134 | { | |
135 | local($target) = @_; | |
136 | ||
137 | if ($target eq 'crypto/bn/x86_64-gcc') | |
138 | { | |
139 | return << "EOF"; | |
140 | \$(TMP_D)/x86_64-gcc.o: crypto/bn/asm/x86_64-gcc.c | |
141 | \$(CC) \$(CFLAGS) -c -o \$@ crypto/bn/asm/x86_64-gcc.c | |
142 | EOF | |
143 | } | |
144 | return undef; | |
145 | } | |
146 | ||
d02b48c6 RE |
147 | sub do_lib_rule |
148 | { | |
149 | local($obj,$target,$name,$shlib)=@_; | |
150 | local($ret,$_,$Name); | |
151 | ||
152 | $target =~ s/\//$o/g if $o ne '/'; | |
dfeab068 | 153 | $target="$target"; |
d02b48c6 RE |
154 | ($Name=$name) =~ tr/a-z/A-Z/; |
155 | ||
156 | $ret.="$target: \$(${Name}OBJ)\n"; | |
157 | $ret.="\t\$(RM) $target\n"; | |
158 | $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n"; | |
159 | $ret.="\t\$(RANLIB) $target\n\n"; | |
160 | } | |
161 | ||
162 | sub do_link_rule | |
163 | { | |
164 | local($target,$files,$dep_libs,$libs)=@_; | |
165 | local($ret,$_); | |
3b4d86bf | 166 | |
d02b48c6 RE |
167 | $file =~ s/\//$o/g if $o ne '/'; |
168 | $n=&bname($target); | |
169 | $ret.="$target: $files $dep_libs\n"; | |
170 | $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n"; | |
171 | return($ret); | |
172 | } | |
173 | ||
99aab161 UM |
174 | sub which |
175 | { | |
176 | my ($name)=@_; | |
177 | my $path; | |
178 | foreach $path (split /:/, $ENV{PATH}) | |
179 | { | |
180 | if (-x "$path/$name") | |
181 | { | |
182 | return "$path/$name"; | |
183 | } | |
184 | } | |
185 | } | |
186 | ||
3b4d86bf BL |
187 | sub fixtests |
188 | { | |
189 | my ($str, $tests) = @_; | |
190 | ||
191 | foreach my $t (keys %$tests) | |
192 | { | |
193 | $str =~ s/(\.\/)?\$\($t\)/\$(TEST_D)\/$tests->{$t}/g; | |
194 | } | |
195 | ||
196 | return $str; | |
197 | } | |
198 | ||
199 | sub fixdeps | |
200 | { | |
342ec250 | 201 | my ($str, $fakes) = @_; |
3b4d86bf BL |
202 | |
203 | my @t = split(/\s+/, $str); | |
204 | $str = ''; | |
205 | foreach my $t (@t) | |
206 | { | |
207 | $str .= ' ' if $str ne ''; | |
342ec250 BL |
208 | if (exists($fakes->{$t})) |
209 | { | |
210 | $str .= $fakes->{$t}; | |
211 | next; | |
212 | } | |
3b4d86bf BL |
213 | if ($t =~ /^[^\/]+$/) |
214 | { | |
215 | $str .= '$(TEST_D)/' . $t; | |
216 | } | |
217 | else | |
218 | { | |
219 | $str .= $t; | |
220 | } | |
221 | } | |
222 | ||
223 | return $str; | |
224 | } | |
225 | ||
226 | sub fixrules | |
227 | { | |
228 | my ($str) = @_; | |
229 | ||
3675fb88 BL |
230 | # Compatible with -j... |
231 | $str =~ s/^(\s+@?)/$1cd \$(TEST_D) && /; | |
3b4d86bf BL |
232 | return $str; |
233 | ||
3675fb88 | 234 | # Compatible with not -j. |
3b4d86bf BL |
235 | my @t = split("\n", $str); |
236 | $str = ''; | |
3675fb88 | 237 | my $prev; |
3b4d86bf BL |
238 | foreach my $t (@t) |
239 | { | |
240 | $t =~ s/^\s+//; | |
3675fb88 | 241 | if (!$prev) |
3b4d86bf | 242 | { |
3675fb88 BL |
243 | if ($t =~ /^@/) |
244 | { | |
245 | $t =~ s/^@/\@cd \$(TEST_D) && /; | |
246 | } | |
247 | elsif ($t !~ /^\s*#/) | |
248 | { | |
249 | $t = 'cd $(TEST_D) && ' . $t; | |
250 | } | |
3b4d86bf BL |
251 | } |
252 | $str .= "\t$t\n"; | |
3675fb88 | 253 | $prev = $t =~/\\$/; |
3b4d86bf BL |
254 | } |
255 | return $str; | |
256 | } | |
257 | ||
3675fb88 BL |
258 | sub copy_scripts |
259 | { | |
15e5f592 | 260 | my ($sed, $src, @targets) = @_; |
3675fb88 BL |
261 | |
262 | my $s = ''; | |
263 | foreach my $t (@targets) | |
264 | { | |
265 | # Copy first so we get file modes... | |
15e5f592 BL |
266 | $s .= "\$(TEST_D)/$t: \$(SRC_D)/$src/$t\n\tcp \$(SRC_D)/$src/$t \$(TEST_D)/$t\n"; |
267 | $s .= "\tsed -e 's/\\.\\.\\/apps/..\\/\$(OUT_D)/' -e 's/\\.\\.\\/util/..\\/\$(TEST_D)/' < \$(SRC_D)/$src/$t > \$(TEST_D)/$t\n" if $sed; | |
268 | $s .= "\n"; | |
3675fb88 BL |
269 | } |
270 | return $s; | |
271 | } | |
272 | ||
3b4d86bf BL |
273 | sub get_tests |
274 | { | |
275 | my ($makefile) = @_; | |
276 | ||
277 | open(M, $makefile) || die "Can't open $makefile: $!"; | |
278 | my %targets; | |
279 | my %deps; | |
280 | my %tests; | |
29d422e2 | 281 | my %alltests; |
342ec250 | 282 | my %fakes; |
3b4d86bf BL |
283 | while (my $line = <M>) |
284 | { | |
285 | chomp $line; | |
286 | while ($line =~ /^(.*)\\$/) | |
287 | { | |
288 | $line = $1 . <M>; | |
289 | } | |
290 | ||
291 | if ($line =~ /^alltests:(.*)$/) | |
292 | { | |
293 | my @t = split(/\s+/, $1); | |
294 | foreach my $t (@t) | |
295 | { | |
296 | $targets{$t} = ''; | |
29d422e2 | 297 | $alltests{$t} = undef; |
3b4d86bf BL |
298 | } |
299 | } | |
300 | ||
29d422e2 BL |
301 | if (($line =~ /^(?<t>\S+):(?<d>.*)$/ && exists $targets{$1}) |
302 | || $line =~ /^(?<t>test_(ss|gen) .*):(?<d>.*)/) | |
3b4d86bf | 303 | { |
29d422e2 | 304 | my $t = $+{t}; |
342ec250 BL |
305 | my $d = $+{d}; |
306 | # If there are multiple targets stupid FreeBSD make runs the | |
307 | # rules once for each dependency that matches one of the | |
308 | # targets. Running the same rule twice concurrently causes | |
309 | # breakage, so replace with a fake target. | |
310 | if ($t =~ /\s/) | |
311 | { | |
312 | ++$fake; | |
313 | my @targets = split /\s+/, $t; | |
314 | $t = "_fake$fake"; | |
315 | foreach my $f (@targets) | |
316 | { | |
317 | $fakes{$f} = $t; | |
318 | } | |
319 | } | |
320 | $deps{$t} = $d; | |
3b4d86bf BL |
321 | $deps{$t} =~ s/#.*$//; |
322 | for (;;) | |
323 | { | |
324 | $line = <M>; | |
325 | chomp $line; | |
326 | last if $line eq ''; | |
327 | $targets{$t} .= "$line\n"; | |
328 | } | |
329 | next; | |
330 | } | |
331 | ||
332 | if ($line =~ /^(\S+TEST)=\s*(\S+)$/) | |
333 | { | |
334 | $tests{$1} = $2; | |
335 | next; | |
336 | } | |
337 | } | |
338 | ||
29d422e2 | 339 | delete $alltests{test_jpake} if $no_jpake; |
3b4d86bf | 340 | delete $targets{test_ige} if $no_ige; |
29d422e2 BL |
341 | delete $alltests{test_md2} if $no_md2; |
342 | delete $alltests{test_rc5} if $no_rc5; | |
3b4d86bf BL |
343 | |
344 | my $tests; | |
345 | foreach my $t (keys %tests) | |
346 | { | |
347 | $tests .= "$t = $tests{$t}\n"; | |
348 | } | |
349 | ||
3b4d86bf BL |
350 | my $each; |
351 | foreach my $t (keys %targets) | |
352 | { | |
353 | next if $t eq ''; | |
354 | ||
3b4d86bf BL |
355 | my $d = $deps{$t}; |
356 | $d =~ s/\.\.\/apps/\$(BIN_D)/g; | |
3675fb88 | 357 | $d =~ s/\.\.\/util/\$(TEST_D)/g; |
3b4d86bf | 358 | $d = fixtests($d, \%tests); |
342ec250 | 359 | $d = fixdeps($d, \%fakes); |
3b4d86bf BL |
360 | |
361 | my $r = $targets{$t}; | |
3675fb88 BL |
362 | $r =~ s/\.\.\/apps/..\/\$(BIN_D)/g; |
363 | $r =~ s/\.\.\/util/..\/\$(TEST_D)/g; | |
3b4d86bf BL |
364 | $r =~ s/\.\.\/(\S+)/\$(SRC_D)\/$1/g; |
365 | $r = fixrules($r); | |
366 | ||
ea4507ee BL |
367 | next if $r eq ''; |
368 | ||
29d422e2 | 369 | $t =~ s/\s+/ \$(TEST_D)\//g; |
ea4507ee | 370 | |
e92ce4e3 | 371 | $each .= "$t: test_scripts $d\n\t\@echo '$t test started'\n$r\t\@echo '$t test done'\n\n"; |
3b4d86bf BL |
372 | } |
373 | ||
374 | # FIXME: Might be a clever way to figure out what needs copying | |
3675fb88 | 375 | my @copies = ( 'bctest', |
3675fb88 BL |
376 | 'testgen', |
377 | 'cms-test.pl', | |
378 | 'tx509', | |
379 | 'test.cnf', | |
380 | 'testenc', | |
381 | 'tocsp', | |
382 | 'testca', | |
383 | 'CAss.cnf', | |
384 | 'testtsa', | |
385 | 'CAtsa.cnf', | |
386 | 'Uss.cnf', | |
387 | 'P1ss.cnf', | |
388 | 'P2ss.cnf', | |
389 | 'tcrl', | |
390 | 'tsid', | |
391 | 'treq', | |
392 | 'tpkcs7', | |
393 | 'tpkcs7d', | |
394 | 'testcrl.pem', | |
395 | 'testx509.pem', | |
396 | 'v3-cert1.pem', | |
397 | 'v3-cert2.pem', | |
398 | 'testreq2.pem', | |
8c7f5f3b BL |
399 | 'testp7.pem', |
400 | 'pkcs7-1.pem', | |
509a83dd BL |
401 | 'trsa', |
402 | 'testrsa.pem', | |
f5cd3db5 | 403 | 'testsid.pem', |
ea4507ee | 404 | 'testss', |
92584bd3 BL |
405 | 'testssl', |
406 | 'testsslproxy', | |
a398f821 | 407 | 'serverinfo.pem', |
3675fb88 | 408 | ); |
15e5f592 BL |
409 | my $copies = copy_scripts(1, 'test', @copies); |
410 | $copies .= copy_scripts(0, 'test', ('smcont.txt')); | |
3675fb88 BL |
411 | |
412 | my @utils = ( 'shlib_wrap.sh', | |
413 | 'opensslwrap.sh', | |
414 | ); | |
15e5f592 | 415 | $copies .= copy_scripts(1, 'util', @utils); |
3675fb88 BL |
416 | |
417 | my @apps = ( 'CA.sh', | |
418 | 'openssl.cnf', | |
92584bd3 | 419 | 'server2.pem', |
3675fb88 | 420 | ); |
15e5f592 | 421 | $copies .= copy_scripts(1, 'apps', @apps); |
3675fb88 | 422 | |
29d422e2 BL |
423 | $copies .= copy_scripts(1, 'crypto/evp', ('evptests.txt')); |
424 | ||
425 | $scripts = "test_scripts: \$(TEST_D)/CA.sh \$(TEST_D)/opensslwrap.sh \$(TEST_D)/openssl.cnf \$(TEST_D)/shlib_wrap.sh ocsp smime\n"; | |
188f6443 | 426 | $scripts .= "\nocsp:\n\tcp -R test/ocsp-tests \$(TEST_D)\n"; |
15e5f592 | 427 | $scripts .= "\smime:\n\tcp -R test/smime-certs \$(TEST_D)\n"; |
3675fb88 | 428 | |
342ec250 BL |
429 | my $all = 'test:'; |
430 | foreach my $t (keys %alltests) | |
431 | { | |
432 | if (exists($fakes{$t})) | |
433 | { | |
434 | $all .= " $fakes{$t}"; | |
435 | } | |
436 | else | |
437 | { | |
438 | $all .= " $t"; | |
439 | } | |
440 | } | |
a7f5cd7f | 441 | |
3675fb88 | 442 | return "$scripts\n$copies\n$tests\n$all\n\n$each"; |
3b4d86bf BL |
443 | } |
444 | ||
d02b48c6 | 445 | 1; |