Revision 8d3bc517

b/Makefile
173 173
test-qmp-input-visitor.o test-qmp-output-visitor.o test-qmp-commands.o qemu-ga$(EXESUF): QEMU_CFLAGS += -I $(qapi-dir)
174 174
qemu-ga$(EXESUF): LIBS = $(LIBS_QGA)
175 175

  
176
gen-out-type = $(subst .,-,$@)
177

  
176 178
$(qapi-dir)/test-qapi-types.c $(qapi-dir)/test-qapi-types.h :\
177 179
$(SRC_PATH)/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-types.py
178
	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py -o "$(qapi-dir)" -p "test-" < $<, "  GEN   $@")
180
	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py $(gen-out-type) -o "$(qapi-dir)" -p "test-" < $<, "  GEN   $@")
179 181
$(qapi-dir)/test-qapi-visit.c $(qapi-dir)/test-qapi-visit.h :\
180 182
$(SRC_PATH)/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-visit.py
181
	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py -o "$(qapi-dir)" -p "test-" < $<, "  GEN   $@")
183
	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py $(gen-out-type) -o "$(qapi-dir)" -p "test-" < $<, "  GEN   $@")
182 184
$(qapi-dir)/test-qmp-commands.h $(qapi-dir)/test-qmp-marshal.c :\
183 185
$(SRC_PATH)/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-commands.py
184
	    $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py -o "$(qapi-dir)" -p "test-" < $<, "  GEN   $@")
186
	    $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py $(gen-out-type) -o "$(qapi-dir)" -p "test-" < $<, "  GEN   $@")
185 187

  
186 188
$(qapi-dir)/qga-qapi-types.c $(qapi-dir)/qga-qapi-types.h :\
187 189
$(SRC_PATH)/qapi-schema-guest.json $(SRC_PATH)/scripts/qapi-types.py
188
	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py -o "$(qapi-dir)" -p "qga-" < $<, "  GEN   $@")
190
	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py $(gen-out-type) -o "$(qapi-dir)" -p "qga-" < $<, "  GEN   $@")
189 191
$(qapi-dir)/qga-qapi-visit.c $(qapi-dir)/qga-qapi-visit.h :\
190 192
$(SRC_PATH)/qapi-schema-guest.json $(SRC_PATH)/scripts/qapi-visit.py
191
	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py -o "$(qapi-dir)" -p "qga-" < $<, "  GEN   $@")
193
	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py $(gen-out-type) -o "$(qapi-dir)" -p "qga-" < $<, "  GEN   $@")
192 194
$(qapi-dir)/qga-qmp-commands.h $(qapi-dir)/qga-qmp-marshal.c :\
193 195
$(SRC_PATH)/qapi-schema-guest.json $(SRC_PATH)/scripts/qapi-commands.py
194
	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py -o "$(qapi-dir)" -p "qga-" < $<, "  GEN   $@")
196
	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py $(gen-out-type) -o "$(qapi-dir)" -p "qga-" < $<, "  GEN   $@")
195 197

  
196 198
qapi-types.c qapi-types.h :\
197 199
$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-types.py
198
	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py -o "." < $<, "  GEN   $@")
200
	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py $(gen-out-type) -o "." < $<, "  GEN   $@")
199 201
qapi-visit.c qapi-visit.h :\
200 202
$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-visit.py
201
	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py -o "."  < $<, "  GEN   $@")
203
	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py $(gen-out-type) -o "."  < $<, "  GEN   $@")
202 204
qmp-commands.h qmp-marshal.c :\
203 205
$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py
204
	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py -m -o "." < $<, "  GEN   $@")
206
	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py $(gen-out-type) -m -o "." < $<, "  GEN   $@")
205 207

  
206 208
test-qmp-output-visitor.o: $(addprefix $(qapi-dir)/, test-qapi-types.c test-qapi-types.h test-qapi-visit.c test-qapi-visit.h) $(qapi-obj-y)
207 209
test-qmp-output-visitor: test-qmp-output-visitor.o $(qobject-obj-y) $(qapi-obj-y) $(tools-obj-y) $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.o
b/scripts/qapi-commands.py
372 372

  
373 373

  
374 374
try:
375
    opts, args = getopt.gnu_getopt(sys.argv[1:], "p:o:m", ["prefix=", "output-dir=", "type=", "middle"])
375
    opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:o:m",
376
                                   ["source", "header", "prefix=",
377
                                    "output-dir=", "type=", "middle"])
376 378
except getopt.GetoptError, err:
377 379
    print str(err)
378 380
    sys.exit(1)
......
384 386
h_file = 'qmp-commands.h'
385 387
middle_mode = False
386 388

  
389
do_c = False
390
do_h = False
391

  
387 392
for o, a in opts:
388 393
    if o in ("-p", "--prefix"):
389 394
        prefix = a
......
393 398
        dispatch_type = a
394 399
    elif o in ("-m", "--middle"):
395 400
        middle_mode = True
401
    elif o in ("-c", "--source"):
402
        do_h = True
403
    elif o in ("-h", "--header"):
404
        do_c = True
405

  
406
if not do_c and not do_h:
407
    do_c = True
408
    do_h = True
396 409

  
397 410
c_file = output_dir + prefix + c_file
398 411
h_file = output_dir + prefix + h_file
399 412

  
413
def maybe_open(really, name, opt):
414
    class Null(object):
415
        def write(self, str):
416
            pass
417
        def read(self):
418
            return ''
419
    if really:
420
        return open(name, opt)
421
    else:
422
        return Null()
423

  
400 424
try:
401 425
    os.makedirs(output_dir)
402 426
except os.error, e:
......
408 432
commands = filter(lambda expr: not expr.has_key('gen'), commands)
409 433

  
410 434
if dispatch_type == "sync":
411
    fdecl = open(h_file, 'w')
412
    fdef = open(c_file, 'w')
435
    fdecl = maybe_open(do_h, h_file, 'w')
436
    fdef = maybe_open(do_c, c_file, 'w')
413 437
    ret = gen_command_decl_prologue(header=basename(h_file), guard=guardname(h_file), prefix=prefix)
414 438
    fdecl.write(ret)
415 439
    ret = gen_command_def_prologue(prefix=prefix)
b/scripts/qapi-types.py
163 163

  
164 164

  
165 165
try:
166
    opts, args = getopt.gnu_getopt(sys.argv[1:], "p:o:", ["prefix=", "output-dir="])
166
    opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:o:",
167
                                   ["source", "header", "prefix=", "output-dir="])
167 168
except getopt.GetoptError, err:
168 169
    print str(err)
169 170
    sys.exit(1)
......
173 174
c_file = 'qapi-types.c'
174 175
h_file = 'qapi-types.h'
175 176

  
177
do_c = False
178
do_h = False
179

  
176 180
for o, a in opts:
177 181
    if o in ("-p", "--prefix"):
178 182
        prefix = a
179 183
    elif o in ("-o", "--output-dir"):
180 184
        output_dir = a + "/"
185
    elif o in ("-c", "--source"):
186
        do_h = True
187
    elif o in ("-h", "--header"):
188
        do_c = True
189

  
190
if not do_c and not do_h:
191
    do_c = True
192
    do_h = True
181 193

  
182 194
c_file = output_dir + prefix + c_file
183 195
h_file = output_dir + prefix + h_file
......
188 200
    if e.errno != errno.EEXIST:
189 201
        raise
190 202

  
191
fdef = open(c_file, 'w')
192
fdecl = open(h_file, 'w')
203
def maybe_open(really, name, opt):
204
    class Null(object):
205
        def write(self, str):
206
            pass
207
        def read(self):
208
            return ''
209
    if really:
210
        return open(name, opt)
211

  
212
fdef = maybe_open(do_c, c_file, 'w')
213
fdecl = maybe_open(do_h, h_file, 'w')
193 214

  
194 215
fdef.write(mcgen('''
195 216
/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
b/scripts/qapi-visit.py
139 139
                name=name)
140 140

  
141 141
try:
142
    opts, args = getopt.gnu_getopt(sys.argv[1:], "p:o:", ["prefix=", "output-dir="])
142
    opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:o:",
143
                                   ["source", "header", "prefix=", "output-dir="])
143 144
except getopt.GetoptError, err:
144 145
    print str(err)
145 146
    sys.exit(1)
......
149 150
c_file = 'qapi-visit.c'
150 151
h_file = 'qapi-visit.h'
151 152

  
153
do_c = False
154
do_h = False
155

  
152 156
for o, a in opts:
153 157
    if o in ("-p", "--prefix"):
154 158
        prefix = a
155 159
    elif o in ("-o", "--output-dir"):
156 160
        output_dir = a + "/"
161
    elif o in ("-c", "--source"):
162
        do_h = True
163
    elif o in ("-h", "--header"):
164
        do_c = True
165

  
166
if not do_c and not do_h:
167
    do_c = True
168
    do_h = True
157 169

  
158 170
c_file = output_dir + prefix + c_file
159 171
h_file = output_dir + prefix + h_file
......
164 176
    if e.errno != errno.EEXIST:
165 177
        raise
166 178

  
167
fdef = open(c_file, 'w')
168
fdecl = open(h_file, 'w')
179
def maybe_open(really, name, opt):
180
    class Null(object):
181
        def write(self, str):
182
            pass
183
        def read(self):
184
            return ''
185
    if really:
186
        return open(name, opt)
187

  
188
fdef = maybe_open(do_c, c_file, 'w')
189
fdecl = maybe_open(do_h, h_file, 'w')
169 190

  
170 191
fdef.write(mcgen('''
171 192
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */

Also available in: Unified diff