File: winres.py

package info (click to toggle)
xiphos 4.1.0.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 18,572 kB
  • sloc: ansic: 25,543; cpp: 13,223; python: 12,684; xml: 2,951; sh: 144; makefile: 42
file content (52 lines) | stat: -rw-r--r-- 1,504 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env python
# encoding: utf-8
# Brant Young, 2007

"This hook is called when the class cpp/cc task generator encounters a '.rc' file: X{.rc -> [.res|.rc.o]}"

import os, sys, re
import TaskGen, Task
from Utils import quote_whitespace
from TaskGen import extension

EXT_WINRC = ['.rc']

winrc_str = '${WINRC} ${_CPPDEFFLAGS} ${_CCDEFFLAGS} ${WINRCFLAGS} ${_CPPINCFLAGS} ${_CCINCFLAGS} ${WINRC_TGT_F} ${TGT} ${WINRC_SRC_F} ${SRC}'

@extension(EXT_WINRC)
def rc_file(self, node):
	obj_ext = '.rc.o'
	if self.env['WINRC_TGT_F'] == '/fo': obj_ext = '.res'

	rctask = self.create_task('winrc')
	rctask.set_inputs(node)
	rctask.set_outputs(node.change_ext(obj_ext))

	# make linker can find compiled resource files
	self.compiled_tasks.append(rctask)

# create our action, for use with rc file
Task.simple_task_type('winrc', winrc_str, color='BLUE', before='cc cxx', shell=False)

def detect(conf):
	v = conf.env

	winrc = v['WINRC']
	v['WINRC_TGT_F'] = '-o'
	v['WINRC_SRC_F'] = '-i'
	# find rc.exe
	if not winrc:
		if v['CC_NAME'] in ['gcc', 'cc', 'g++', 'c++']:
			winrc = conf.find_program('windres', var='WINRC', path_list = v['PATH'])
			# cross-compilation
			if not winrc:
				winrc = conf.find_program('i686-mingw32-windres', var='WINRC', path_list = v['PATH'])
		elif v['CC_NAME'] == 'msvc':
			winrc = conf.find_program('RC', var='WINRC', path_list = v['PATH'])
			v['WINRC_TGT_F'] = '/fo'
			v['WINRC_SRC_F'] = ''
	if not winrc:
		conf.fatal('winrc was not found!')

	v['WINRCFLAGS'] = ''