diff --git a/src/bin/pkg.rs b/src/bin/pkg.rs
index 8b0c397225057d48fef1c925b3e400ff0dcd14e4..65ea06ee391b38e89331e11d8620ddca00e8f8c7 100644
--- a/src/bin/pkg.rs
+++ b/src/bin/pkg.rs
@@ -87,10 +87,11 @@ fn upgrade(repo: Repo) -> io::Result<()> {
 }
 
 fn main() {
-    let repo = Repo::new(env!("TARGET"));
-
     let matches = App::new("pkg")
-        .subcommand(SubCommand::with_name("clean")
+        .arg(Arg::with_name("target")
+             .long("target")
+             .takes_value(true)
+        ).subcommand(SubCommand::with_name("clean")
             .arg(Arg::with_name("package")
                  .multiple(true)
                  .required(true)
@@ -128,6 +129,13 @@ fn main() {
         ).subcommand(SubCommand::with_name("upgrade")
         ).get_matches();
 
+    let target = matches.value_of("target")
+        .or(option_env!("TARGET"))
+        .expect(concat!("pkg was not compiled with a target, ",
+                        "and --target was not specified"));
+
+    let repo = Repo::new(target);
+
     match matches.subcommand() {
         ("clean", Some(m)) => {
             for package in m.values_of("package").unwrap() {