diff options
author | Ben Laurie <ben@links.org> | 2013-03-23 19:05:19 +0000 |
---|---|---|
committer | Ben Laurie <ben@links.org> | 2013-04-06 15:11:11 +0100 |
commit | 3b4d86bff5a8911a061a8a6e5ec1d21b1f651c18 (patch) | |
tree | 7e32c770cbc99e393c8f7be586be18bd22dfa421 /util | |
parent | 282a480a352e2aac4fad6e75932d951659bff62d (diff) |
Get closer to a working single Makefile with test support.
Diffstat (limited to 'util')
-rwxr-xr-x | util/mk1mf.pl | 40 | ||||
-rw-r--r-- | util/pl/unix.pl | 154 |
2 files changed, 181 insertions, 13 deletions
diff --git a/util/mk1mf.pl b/util/mk1mf.pl index 087671b6c3..7860375c56 100755 --- a/util/mk1mf.pl +++ b/util/mk1mf.pl @@ -2,8 +2,12 @@ # A bit of an evil hack but it post processes the file ../MINFO which # is generated by `make files` in the top directory. # This script outputs one mega makefile that has no shell stuff or any -# funny stuff -# +# funny stuff (if the target is not "copy"). +# If the target is "copy", then it tries to create a makefile that can be +# safely used with the -j flag and that is compatible with the top-level +# Makefile, in the sense that it uses the same options and assembler files etc. + +use Cwd; $INSTALLTOP="/usr/local/ssl"; $OPENSSLDIR="/usr/local/ssl"; @@ -188,7 +192,7 @@ $mkdir="-mkdir" unless defined $mkdir; $ranlib="echo ranlib"; $cc=(defined($VARS{'CC'}))?$VARS{'CC'}:'cc'; -$src_dir=(defined($VARS{'SRC'}))?$VARS{'SRC'}:'.'; +$src_dir=(defined($VARS{'SRC'}))?$VARS{'SRC'}:getcwd(); $bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:''; # $bin_dir.=$o causes a core dump on my sparc :-( @@ -748,6 +752,10 @@ $banner \$(INC_D): \$(MKDIR) \"\$(INC_D)\" +# This needs to be invoked once, when the makefile is first constructed, or +# after cleaning. +init: \$(TMP_D) \$(LIB_D) headers + headers: \$(HEADER) \$(EXHEADER) lib: \$(LIBS_DEP) \$(E_SHLIB) @@ -762,11 +770,6 @@ install: all \$(MKDIR) \"\$(INSTALLTOP)${o}lib\" $extra_install - -test: \$(T_EXE) - cd \$(BIN_D) - ..${o}ms${o}test - clean: \$(RM) \$(TMP_D)$o*.* @@ -782,7 +785,17 @@ reallyclean: \$(RM) -rf \$(INC_D) EOF - + +if ($orig_platform ne 'copy') + { + $rules .= <<"EOF"; +test: \$(T_EXE) + cd \$(BIN_D) + ..${o}ms${o}test + +EOF + } + my $platform_cpp_symbol = "MK1MF_PLATFORM_$platform"; $platform_cpp_symbol =~ s/-/_/g; if (open(IN,"crypto/buildinf.h")) @@ -1014,6 +1027,8 @@ if ($fips) $rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)", ($fips && !$shlib) ? 2 : 0); +$rules .= get_tests('test/Makefile') if $orig_platform eq 'copy'; + print $defs; if ($platform eq "linux-elf") { @@ -1288,9 +1303,10 @@ sub cc_compile_target $ex_flags.=" -DMK1MF_BUILD -D$platform_cpp_symbol" if ($source =~ /cversion/); $target =~ s/\//$o/g if $o ne "/"; $source =~ s/\//$o/g if $o ne "/"; -# FIXME: do dependencies instead of all headers. - $ret ="$target: \$(SRC_D)$o$source \$(HEADER) \$(EXHEADER)\n\t"; - $ret.="\$(CC) ${ofile}$target $ex_flags -c \$(SRC_D)$o$source\n\n"; + $ret ="$target: \$(SRC_D)$o$source\n\t"; + $ret.="\$(CC) -MMD ${ofile}$target $ex_flags -c \$(SRC_D)$o$source\n\n"; + $target =~ s/\.o$/.d/; + $ret.=".sinclude \"$target\"\n\n"; return($ret); } diff --git a/util/pl/unix.pl b/util/pl/unix.pl index b8e1ff7d9e..7d901f0f14 100644 --- a/util/pl/unix.pl +++ b/util/pl/unix.pl @@ -152,7 +152,7 @@ sub do_link_rule { local($target,$files,$dep_libs,$libs)=@_; local($ret,$_); - + $file =~ s/\//$o/g if $o ne '/'; $n=&bname($target); $ret.="$target: $files $dep_libs\n"; @@ -173,4 +173,156 @@ sub which } } +sub fixtests + { + my ($str, $tests) = @_; + + foreach my $t (keys %$tests) + { + $str =~ s/(\.\/)?\$\($t\)/\$(TEST_D)\/$tests->{$t}/g; + } + + return $str; + } + +sub fixdeps + { + my ($str) = @_; + + my @t = split(/\s+/, $str); + $str = ''; + foreach my $t (@t) + { + $str .= ' ' if $str ne ''; + if ($t =~ /^[^\/]+$/) + { + $str .= '$(TEST_D)/' . $t; + } + else + { + $str .= $t; + } + } + + return $str; + } + +sub fixrules + { + my ($str) = @_; + + return $str; + + my @t = split("\n", $str); + $str = ''; + foreach my $t (@t) + { + $t =~ s/^\s+//; + if ($t =~ /^@/) + { + $t =~ s/^@/\@cd \$(TEST_D) && /; + } + else + { + $t = 'cd $(TEST_D) && ' . $t; + } + $str .= "\t$t\n"; + } + return $str; +} + +sub get_tests + { + my ($makefile) = @_; + + open(M, $makefile) || die "Can't open $makefile: $!"; + my %targets; + my %deps; + my %tests; + while (my $line = <M>) + { + chomp $line; + while ($line =~ /^(.*)\\$/) + { + $line = $1 . <M>; + } + + if ($line =~ /^alltests:(.*)$/) + { + my @t = split(/\s+/, $1); + foreach my $t (@t) + { + $targets{$t} = ''; + } + } + + if (($line =~ /^(\S+):(.*)$/ && exists $targets{$1}) + || $line =~ /^(test_ss .*):(.*)/) + { + my $t = $1; + $deps{$t} = $2; + $deps{$t} =~ s/#.*$//; + for (;;) + { + $line = <M>; + chomp $line; + last if $line eq ''; + $targets{$t} .= "$line\n"; + } + next; + } + + if ($line =~ /^(\S+TEST)=\s*(\S+)$/) + { + $tests{$1} = $2; + next; + } + } + + delete $targets{test_jpake} if $no_jpake; + delete $targets{test_ige} if $no_ige; + delete $targets{test_md2} if $no_md2; + delete $targets{test_rc5} if $no_rc5; + + my $tests; + foreach my $t (keys %tests) + { + $tests .= "$t = $tests{$t}\n"; + } + + my $all = 'test:'; + my $each; + foreach my $t (keys %targets) + { + next if $t eq ''; + + if ($t =~ /^test_ss/) + { + $t =~ s/\s+/ \$(TEST_D)\//g; + $all .= ' test_ss'; + } + else + { + $all .= " $t"; + } + + my $d = $deps{$t}; + $d =~ s/\.\.\/apps/\$(BIN_D)/g; + $d = fixtests($d, \%tests); + $d = fixdeps($d); + + my $r = $targets{$t}; + $r =~ s/\.\.\/apps/\$(BIN_D)/g; + $r =~ s/\.\.\/(\S+)/\$(SRC_D)\/$1/g; + $r = fixrules($r); + + $each .= "$t: \$(TEST_D) $d\n\tcd \$(TEST_D)\n$r\n"; + } + + # FIXME: Might be a clever way to figure out what needs copying + my $copies = do_copy_rule('$(TEST_D)', 'test/bctest test/evptests.txt test/testgen test/cms-test.pl', ''); + + return "$copies\n$tests\n$all\n\n$each"; + } + 1; |