File: cmVTKGenerateJavaDependencies.c

package info (click to toggle)
vtk 5.0.4-1.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 51,084 kB
  • ctags: 70,426
  • sloc: cpp: 524,166; ansic: 220,276; tcl: 43,377; python: 14,037; perl: 3,102; java: 1,436; yacc: 1,033; sh: 339; lex: 248; makefile: 197; asm: 154
file content (195 lines) | stat: -rw-r--r-- 5,088 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/* this is a CMake loadable command to wrap vtk objects into Java */

#include "cmCPluginAPI.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

#define SINGLE_FILE_BUILD

/* do almost everything in the initial pass */
static int InitialPass(void *inf, void *mf, int argc, char *argv[])
{
  cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf;
  int i;
  int newArgc;
  int msize;
  int estimated;
  char **newArgv;
  int numClasses = 0;
  char **classes = 0;
  char **dependencies = 0;
  int numDep = 0;
  int numWrapped = 0;
  const char *cdir = info->CAPI->GetCurrentDirectory(mf);
  const char *def = 0;
  char *newName;
  char *target = 0;
  const char *javac = info->CAPI->GetDefinition(mf,"JAVA_COMPILE");
  const char *jar = info->CAPI->GetDefinition(mf,"JAVA_ARCHIVE");
  void *cfile = 0;
  char *args[5];
  char *jargs[5];
  int depends = 0;
  char **sargs = 0;
  int sargsCnt = 0;
  char **srcList = 0;
  int srcCnt = 0;
  char* javaPath = 0;
  const char *libpath = info->CAPI->GetDefinition(mf,"LIBRARY_OUTPUT_PATH");
  const char *vtkpath = info->CAPI->GetDefinition(mf,"VTK_BINARY_DIR");
  const char *userjavapath = info->CAPI->GetDefinition(mf,"USER_JAVA_CLASSPATH");
  const char *startTempFile;
  const char *endTempFile;

  FILE* outfile = 0;
  const char* filename = 0;

  if(argc < 2 )
    {
    info->CAPI->SetError(info, "called with incorrect number of arguments");
    return 0;
    }

  /* Now check and see if the value has been stored in the cache */
  /* already, if so use that value and don't look for the program */
  if(!info->CAPI->IsOn(mf,"VTK_WRAP_JAVA"))
    {
    info->CAPI->FreeArguments(newArgc, newArgv);
    return 1;
    }

  info->CAPI->ExpandSourceListArguments(mf, argc, (const char**)argv, 
                                        &newArgc, &newArgv, 2);
  
  /* keep the library name */
  target = strdup(newArgv[0]);

  if (userjavapath)
    {
    javaPath = (char *)malloc(strlen(vtkpath) + 20 + strlen(userjavapath));
    sprintf(javaPath, "%s;%s/java", userjavapath, vtkpath);
    }
  else
    {
    javaPath = (char *)malloc(strlen(vtkpath) + 20);
    sprintf(javaPath, "%s/java", vtkpath);
    }

  args[0] = strdup("-classpath");
  args[1] = strdup(javaPath);

  classes = (char**) malloc( newArgc * sizeof(char*));
  numClasses = 0;

  filename = (char*) malloc( strlen(vtkpath) + strlen("/java/vtk/") + strlen(target) + 100 );
  sprintf(filename, "%s/java/vtk/vtk%sDriver.java", vtkpath, target);
  outfile = fopen(filename, "w");
  if ( !outfile )
    {
    char buffer[1024];
    sprintf(buffer, "cannot generate output file: %s", filename);
    info->CAPI->SetError(info, buffer);
    return 0;
    }

  fprintf(outfile, 
    "// Do not edit\n"
    "// This file is generated by cmVTKGenerateJavaDependencies.c in VTK\n"
    "package vtk;\n"
    "import vtk.*;\n"
    "\n"
    "public class vtk%sDriver\n"
    "{\n"
    "  public static void Initialize(String[] args)\n"
    "    {\n"
    "    Object dummy;\n", target);
  
  /* get the classes for this lib */
  for(i = 1; i < newArgc; ++i)
    {   
    const char *srcName = newArgv[i];
    char *className = 0;
    char *srcNameWe;
    char *srcPath;

    srcNameWe = info->CAPI->GetFilenameWithoutExtension(srcName);
    srcPath   = info->CAPI->GetFilenamePath(srcName);
    
    className = (char *)malloc(strlen(srcPath) + strlen(srcNameWe) + 20);
    sprintf(className,"%s/%s.class",srcPath,srcNameWe);
    fprintf(outfile, 
      "    dummy = new %s();\n", srcNameWe);
    

    args[2] = (char*) malloc(strlen(srcName) + strlen(target) + 20);
    /* On Unix we can just call javac ... *.java */
    sprintf(args[2], "%s/vtk%sDriver.java", srcPath, target);
    info->CAPI->AddCustomCommand(mf, srcName, javac, 3, (const char**)args, 
                                 0, 0, 1, (const char**)&className, target);
    
    free(args[2]);
    info->CAPI->Free(srcNameWe);
    info->CAPI->Free(srcPath);
    classes[numClasses++] = strdup(className);
    free(className);
    }
  free(args[0]);
  free(args[1]);

  info->CAPI->AddCustomCommand(mf, target, "", 0, 0,
                               numClasses, (const char**)classes, 0, 0, target);
  
  for (i = 0; i < numClasses; i ++ )
    {
    free(classes[i]);
    }
  free(classes);

  free(javaPath);

  free(target);
  
  fprintf(outfile,
    "    }\n"
    "  }\n");
  fclose(outfile);

  info->CAPI->FreeArguments(newArgc, newArgv);
  return 1;
}
  
  
static void FinalPass(void *inf, void *mf) 
{
}

static void Destructor(void *inf) 
{
}

static const char* GetTerseDocumentation() 
{
  return "Create Java Archive.";
}

static const char* GetFullDocumentation()
{
  return
    "VTK_WRAP_JAVA(target SourceLists ...)";
}

void CM_PLUGIN_EXPORT VTK_GENERATE_JAVA_DEPENDENCIESInit(cmLoadedCommandInfo *info)
{
  info->InitialPass = InitialPass;
  info->FinalPass = FinalPass;
  info->Destructor = Destructor;
  info->GetTerseDocumentation = GetTerseDocumentation;
  info->GetFullDocumentation = GetFullDocumentation;  
  info->m_Inherited = 0;
  info->Name = "VTK_GENERATE_JAVA_DEPENDENCIES";
}