private void generateStructBinding(
      Element element, Struct struct, String root, String pakage, File header) throws IOException {

    String declaredType = element.asType().toString();
    String structName = struct.name().equals(DEFAULT) ? declaredType : struct.name();

    if (generatedStructs.contains(structName)) {
      messager.printMessage(
          Kind.WARNING, "struct " + structName + " already defined elsewhere.", element);
      return;
    }

    System.out.println("generating struct accessor for struct: " + structName);

    generatedStructs.add(structName);

    String output = root + separator + outputDir;
    String config = output + separator + header.getName() + ".cfg";

    File configFile = new File(config);

    FileWriter writer = null;
    try {
      writer = new FileWriter(configFile);
      writer.write("Package " + pakage + "\n");
      writer.write("EmitStruct " + structName + "\n");
      if (!struct.name().equals(DEFAULT)) {
        writer.write("RenameJavaType " + struct.name() + " " + declaredType + "\n");
      }
    } finally {
      if (writer != null) {
        writer.close();
      }
    }

    // TODO this isn't very clean since we won't get any exceptions this way
    GlueGen.main(
        //                "-I"+path+"/build/",
        "-O" + output,
        "-E" + AnnotationProcessorJavaStructEmitter.class.getName(),
        "-C" + config,
        header.getPath());

    configFile.delete();
  }
  @Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment env) {

    Set<? extends Element> elements = env.getElementsAnnotatedWith(Struct.class);

    for (Element element : elements) {

      String pakage = eltUtils.getPackageOf(element).toString();

      try {
        Struct struct = element.getAnnotation(Struct.class);
        String headerRelPath = struct.header();
        // yes, this is a hack but there are simple to many bugs in this api.
        // e.g.: 6647998
        FileObject header = filer.getResource(StandardLocation.SOURCE_PATH, pakage, headerRelPath);

        String root = basedir;
        File headerFile = null;
        if (header.toUri().isAbsolute()) {
          headerFile = new File(header.toUri());

          root = headerFile.getAbsolutePath();
          root = root.substring(0, root.length() - headerFile.getName().length() - 1);
          root = root.substring(0, root.length() - pakage.length()) + "../";
        } else {
          root = System.getProperty("user.dir");
          headerFile = new File(root + separator + header.toUri());
        }

        System.out.println("processing header: " + header.toUri());

        generateStructBinding(element, struct, root, pakage, headerFile);
      } catch (IOException ex) {
        throw new RuntimeException("IOException encountered, run if you can!", ex);
      }
    }
    return true;
  }