target/linux: add preliminary 2.6.37 kernel support
[openwrt.git] / scripts / deptest.sh
1 #!/bin/bash
2 #
3 # Automated OpenWrt package dependency checker
4 #
5 # Copyright (C) 2009-2010 OpenWrt.org
6 #
7 # This is free software, licensed under the GNU General Public License v2.
8 # See /LICENSE for more information.
9 #
10
11 SCRIPTDIR="$(dirname "$0")"
12 [ "${SCRIPTDIR:0:1}" = "/" ] || SCRIPTDIR="$PWD/$SCRIPTDIR"
13 BASEDIR="$SCRIPTDIR/.."
14
15 DIR="$BASEDIR/tmp/deptest"
16 STAMP_DIR_SUCCESS="$DIR/stamp-success"
17 STAMP_DIR_FAILED="$DIR/stamp-failed"
18 STAMP_DIR_BLACKLIST="$DIR/stamp-blacklist"
19 BUILD_DIR="$DIR/build_dir/target"
20 BUILD_DIR_HOST="$DIR/build_dir/host"
21 STAGING_DIR="$DIR/staging_dir"
22 STAGING_DIR_HOST="$STAGING_DIR/host"
23 STAGING_DIR_HOST_TMPL="$DIR/staging_dir_host_tmpl"
24 LOG_DIR="$DIR/logs"
25
26 die()
27 {
28 echo "$@"
29 exit 1
30 }
31
32 usage()
33 {
34 echo "deptest.sh [OPTIONS] [PACKAGES]"
35 echo
36 echo "OPTIONS:"
37 echo " --lean Run a lean test. Do not clean the build directory for each"
38 echo " package test."
39 echo " --force Force a test, even if a success/blacklist stamp is available"
40 echo
41 echo "PACKAGES are packages to test. If not specified, all installed packages"
42 echo "will be tested."
43 }
44
45 test_package() # $1=pkgname
46 {
47 local pkg="$1"
48 [ -n "$pkg" -a -z "$(echo "$pkg" | grep -e '/')" -a "$pkg" != "." -a "$pkg" != ".." ] || \
49 die "Package name \"$pkg\" contains illegal characters"
50 local SELECTED=
51 for conf in `grep CONFIG_PACKAGE tmp/.packagedeps | grep -E "[ /]$pkg\$" | sed -e 's,package-$(\(CONFIG_PACKAGE_.*\)).*,\1,'`; do
52 grep "$conf=" .config > /dev/null && SELECTED=1 && break
53 done
54 local STAMP_SUCCESS="$STAMP_DIR_SUCCESS/$pkg"
55 local STAMP_FAILED="$STAMP_DIR_FAILED/$pkg"
56 local STAMP_BLACKLIST="$STAMP_DIR_BLACKLIST/$pkg"
57 rm -f "$STAMP_FAILED"
58 [ -f "$STAMP_SUCCESS" -a $force -eq 0 ] && return
59 rm -f "$STAMP_SUCCESS"
60 [ -n "$SELECTED" ] || {
61 echo "Package $pkg is not selected"
62 return
63 }
64 [ -f "$STAMP_BLACKLIST" -a $force -eq 0 ] && {
65 echo "Package $pkg is blacklisted"
66 return
67 }
68 echo "Testing package $pkg..."
69 rm -rf "$STAGING_DIR"
70 mkdir -p "$STAGING_DIR"
71 cp -al "$STAGING_DIR_HOST_TMPL" "$STAGING_DIR_HOST"
72 [ $lean_test -eq 0 ] && rm -rf "$BUILD_DIR" "$BUILD_DIR_HOST"
73 mkdir -p "$BUILD_DIR" "$BUILD_DIR_HOST"
74 make package/$pkg/compile \
75 BUILD_DIR="$BUILD_DIR" \
76 BUILD_DIR_HOST="$BUILD_DIR_HOST" \
77 STAGING_DIR="$STAGING_DIR" \
78 STAGING_DIR_HOST="$STAGING_DIR_HOST" \
79 FORCE_HOST_INSTALL=1 \
80 V=99 >"$LOG_DIR/$(basename $pkg).log" 2>&1
81 if [ $? -eq 0 ]; then
82 touch "$STAMP_SUCCESS"
83 else
84 touch "$STAMP_FAILED"
85 echo "Building package $pkg failed!"
86 fi
87 }
88
89 # parse commandline options
90 packages=
91 lean_test=0
92 force=0
93 while [ $# -ne 0 ]; do
94 case "$1" in
95 --help|-h)
96 usage
97 exit 0
98 ;;
99 --lean)
100 lean_test=1
101 ;;
102 --force)
103 force=1
104 ;;
105 *)
106 packages="$packages $1"
107 ;;
108 esac
109 shift
110 done
111
112 [ -f "$BASEDIR/include/toplevel.mk" ] || \
113 die "Error: Could not find buildsystem base directory"
114 [ -f "$BASEDIR/.config" ] || \
115 die "The buildsystem is not configured. Please run make menuconfig."
116 cd "$BASEDIR" || die "Failed to enter base directory"
117
118 mkdir -p "$STAMP_DIR_SUCCESS" "$STAMP_DIR_FAILED" "$STAMP_DIR_BLACKLIST" "$LOG_DIR"
119
120 [ -d "$STAGING_DIR_HOST_TMPL" ] || {
121 rm -rf staging_dir/host
122 make tools/install V=99 || die "make tools/install failed, please check"
123 cp -al staging_dir/host "$STAGING_DIR_HOST_TMPL"
124 make toolchain/install V=99 || die "make toolchain/install failed, please check"
125 make target/linux/install V=99 || die "make target/linux/install failed, please check"
126 }
127
128 if [ -z "$packages" ]; then
129 # iterate over all packages
130 for pkg in `cat tmp/.packagedeps | grep CONFIG_PACKAGE | grep -v curdir | sed -e 's,.*[/=]\s*,,' | sort -u`; do
131 test_package "$pkg"
132 done
133 else
134 # only check the specified packages
135 for pkg in $packages; do
136 test_package "$pkg"
137 done
138 fi
This page took 0.056743 seconds and 5 git commands to generate.