Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何创建运行自定义生成事件的Makefile或.pro文件_Linux_Qt_Makefile - Fatal编程技术网

Linux 如何创建运行自定义生成事件的Makefile或.pro文件

Linux 如何创建运行自定义生成事件的Makefile或.pro文件,linux,qt,makefile,Linux,Qt,Makefile,我目前使用一个小程序来处理Qt表单(.ui)文件,并自动生成具有公共基类的类,并使用虚拟函数访问表单元素。 在windows上,我将此工具作为ui表单文件上的自定义构建步骤运行。该工具的唯一参数是输入文件名 为了澄清这一点,在Windows上,Qt在.ui文件上运行uic,创建一个ui_filename.h文件。我需要在那个文件上运行我的工具 在linux上如何/应该如何执行此操作?理想情况下,我会将其构建到.pro文件中,但我也很乐意编辑Makefile 我不擅长编写makefile,所以这可

我目前使用一个小程序来处理Qt表单(.ui)文件,并自动生成具有公共基类的类,并使用虚拟函数访问表单元素。 在windows上,我将此工具作为ui表单文件上的自定义构建步骤运行。该工具的唯一参数是输入文件名

为了澄清这一点,在Windows上,Qt在.ui文件上运行uic,创建一个ui_filename.h文件。我需要在那个文件上运行我的工具

在linux上如何/应该如何执行此操作?理想情况下,我会将其构建到.pro文件中,但我也很乐意编辑Makefile


我不擅长编写makefile,所以这可能非常简单。我很乐意为每个ui_u或*.ui文件手动编写命令,但理想情况下,它会自动为所有.ui文件编写

不需要手动写入makefile。调用自定义外部工具的makefile可以由项目文件
.pro
中的
qmake
生成

需要使用
QMAKE\u EXTRA\u TARGETS
创建自定义目标。然后,应将主目标设置为与该自定义目标相关(例如,应将自定义目标名称添加到
PRE_TARGETDEPS

该工具应在生成表单标题后运行,因此自定义目标应依赖于该文件
customtarget1.depends=ui\u mainwindow.h

customtarget1.target = form_scanner
customtarget1.commands = tool_win_bat_or_linux_shell.sh
customtarget1.depends = ui_mainwindow.h
QMAKE_EXTRA_TARGETS += customtarget1
PRE_TARGETDEPS += form_scanner
上述
qmake
命令创建以下
Makefile
规则:

# the form header depends on mainwindow.ui
ui_mainwindow.h: ..\test\mainwindow.ui
<tab>#build command...

# form scanner depends on ui_mainwindow.h
form_scanner: ui_mainwindow.h
<tab>tool_win_bat_or_linux_shell.sh

# the final target depends on form scanner
$(DESTDIR_TARGET): form_scanner ui_mainwindowm.h $(OBJECTS) 
因此,只有在生成所有表单头时才执行命令
tool\u win\u bat\u或\u linux\u shell.sh

还可以从项目目录
$$PWD
运行shell脚本,并将表单头文件名作为命令行参数传递:

customtarget1.commands = $$PWD/tool_win_bat_or_linux_shell.sh $$FORM_HEADERS
现在,shell脚本可以为每个表单头运行一些命令
工具\u win\u bat\u或\u linux\u shell.sh

# for each command line argument
for file in "$@"
do
    echo "$file"
    ls -l $file
done

谢谢-那看起来就像是一张票。我还没有检查它,但它肯定比手动编辑Makefile更有意义
# for each command line argument
for file in "$@"
do
    echo "$file"
    ls -l $file
done