| 1 |
proc create_build_dir {Makefile} { |
| 2 |
global build_dir |
| 3 |
global srcdir subdir |
| 4 |
|
| 5 |
# If build_dir hasn't been set, create it. |
| 6 |
if {[string length $build_dir] == 0} { |
| 7 |
if {[catch {exec mktemp -d staptestXXXXXX} build_dir]} { |
| 8 |
verbose -log "Failed to create temporary directory: $build_dir" |
| 9 |
return 0 |
| 10 |
} |
| 11 |
foreach f [glob $srcdir/$subdir/*.c $srcdir/$subdir/*.d] { |
| 12 |
exec cp $f $build_dir/ |
| 13 |
} |
| 14 |
exec cp $srcdir/$subdir/$Makefile $build_dir/Makefile |
| 15 |
} else { |
| 16 |
# Otherwise, run "make clean" |
| 17 |
verbose -log "exec make -C $build_dir clean" |
| 18 |
set res [catch "exec make -C $build_dir clean" output] |
| 19 |
verbose -log "$output" |
| 20 |
} |
| 21 |
return 1 |
| 22 |
} |
| 23 |
|
| 24 |
proc build_test_progs {Makefile test_progs {CFLAGS ""}} { |
| 25 |
global build_dir |
| 26 |
global env |
| 27 |
|
| 28 |
# Create the build directory and populate it |
| 29 |
create_build_dir $Makefile |
| 30 |
|
| 31 |
# Run make. |
| 32 |
set includes "-isystem$env(SYSTEMTAP_INCLUDES)" |
| 33 |
if {$CFLAGS != ""} { |
| 34 |
set CFLAGS "$includes $CFLAGS" |
| 35 |
} else { |
| 36 |
set CFLAGS "$includes" |
| 37 |
} |
| 38 |
verbose -log "exec make -C $build_dir CFLAGS=\"$CFLAGS\"" |
| 39 |
set res [catch {eval { exec make -C $build_dir CFLAGS=$CFLAGS} } output] |
| 40 |
verbose -log "$output" |
| 41 |
|
| 42 |
# Check that the test progs were created |
| 43 |
foreach f $test_progs { |
| 44 |
if {![file exists $build_dir/$f]} { |
| 45 |
verbose -log "Test program $f doesn't exist!" |
| 46 |
return 0 |
| 47 |
} |
| 48 |
} |
| 49 |
return 1 |
| 50 |
} |
| 51 |
|
| 52 |
proc cleanup_test_progs {} { |
| 53 |
global build_dir |
| 54 |
if {$build_dir != ""} { |
| 55 |
catch { exec rm -rf $build_dir } |
| 56 |
} |
| 57 |
} |