ar71xx: improve the wndr3700 quirks - move most of the code out of ath9k and instead...
[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
40 echo "PACKAGES are packages to test. If not specified, all installed packages"
41 echo "will be tested."
42 }
43
44 test_package() # $1=pkgname
45 {
46 local pkg="$1"
47 [ -n "$pkg" -a -z "$(echo "$pkg" | grep -e '/')" -a "$pkg" != "." -a "$pkg" != ".." ] || \
48 die "Package name \"$pkg\" contains illegal characters"
49 local SELECTED=
50 for conf in `grep CONFIG_PACKAGE tmp/.packagedeps | grep -E "[ /]$pkg\$" | sed -e 's,package-$(\(CONFIG_PACKAGE_.*\)).*,\1,'`; do
51 grep "$conf=" .config > /dev/null && SELECTED=1 && break
52 done
53 local STAMP_SUCCESS="$STAMP_DIR_SUCCESS/$pkg"
54 local STAMP_FAILED="$STAMP_DIR_FAILED/$pkg"
55 local STAMP_BLACKLIST="$STAMP_DIR_BLACKLIST/$pkg"
56 rm -f "$STAMP_FAILED"
57 [ -f "$STAMP_SUCCESS" ] && return
58 [ -n "$SELECTED" ] || {
59 echo "Package $pkg is not selected"
60 return
61 }
62 [ -f "$STAMP_BLACKLIST" ] && {
63 echo "Package $pkg is blacklisted"
64 return
65 }
66 echo "Testing package $pkg..."
67 rm -rf "$STAGING_DIR"
68 mkdir -p "$STAGING_DIR"
69 cp -al "$STAGING_DIR_HOST_TMPL" "$STAGING_DIR_HOST"
70 [ $lean_test -eq 0 ] && rm -rf "$BUILD_DIR" "$BUILD_DIR_HOST"
71 mkdir -p "$BUILD_DIR" "$BUILD_DIR_HOST"
72 make package/$pkg/compile \
73 BUILD_DIR="$BUILD_DIR" \
74 BUILD_DIR_HOST="$BUILD_DIR_HOST" \
75 STAGING_DIR="$STAGING_DIR" \
76 STAGING_DIR_HOST="$STAGING_DIR_HOST" \
77 V=99 >"$LOG_DIR/$(basename $pkg).log" 2>&1
78 if [ $? -eq 0 ]; then
79 touch "$STAMP_SUCCESS"
80 else
81 touch "$STAMP_FAILED"
82 echo "Building package $pkg failed!"
83 fi
84 }
85
86 # parse commandline options
87 packages=
88 lean_test=0
89 while [ $# -ne 0 ]; do
90 case "$1" in
91 --help|-h)
92 usage
93 exit 0
94 ;;
95 --lean)
96 lean_test=1
97 ;;
98 *)
99 packages="$packages $1"
100 ;;
101 esac
102 shift
103 done
104
105 [ -f "$BASEDIR/include/toplevel.mk" ] || \
106 die "Error: Could not find buildsystem base directory"
107 [ -f "$BASEDIR/.config" ] || \
108 die "The buildsystem is not configured. Please run make menuconfig."
109 cd "$BASEDIR" || die "Failed to enter base directory"
110
111 mkdir -p "$STAMP_DIR_SUCCESS" "$STAMP_DIR_FAILED" "$STAMP_DIR_BLACKLIST" "$LOG_DIR"
112
113 [ -d "$STAGING_DIR_HOST_TMPL" ] || {
114 rm -rf staging_dir/host
115 make tools/install V=99 || die "make tools/install failed, please check"
116 cp -al staging_dir/host "$STAGING_DIR_HOST_TMPL"
117 make toolchain/install V=99 || die "make toolchain/install failed, please check"
118 make target/linux/install V=99 || die "make target/linux/install failed, please check"
119 }
120
121 if [ -z "$packages" ]; then
122 # iterate over all packages
123 for pkg in `cat tmp/.packagedeps | grep CONFIG_PACKAGE | grep -v curdir | sed -e 's,.*[/=]\s*,,' | sort -u`; do
124 test_package "$pkg"
125 done
126 else
127 # only check the specified packages
128 for pkg in $packages; do
129 test_package "$pkg"
130 done
131 fi
This page took 0.047463 seconds and 5 git commands to generate.