- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编写一个可以在 Windows 和 Linux 上运行的 makefile。因此,只要有可能,我都会避免特定于操作系统的 shell 命令。
这是我的 makefile 中的一个片段,末尾带有 clean
函数:
# OS specific part
# -----------------
ifeq ($(OS),Windows_NT)
RM = del /F /Q
RMDIR = -RMDIR /S /Q
MKDIR = -mkdir
ERRIGNORE = 2>NUL || (exit 0)
SEP=\\
else
RM = rm -rf
RMDIR = rm -rf
MKDIR = mkdir -p
ERRIGNORE = 2>/dev/null
SEP=/
endif
PSEP = $(strip $(SEP))
# Definitions for nullstring and space
# -------------------------------------
nullstring :=
space := $(nullstring) #End
# Lists of all files and folders to keep or remove
# -------------------------------------------------
buildFiles_toKeep := ... # I wrote some scripts to
buildDirs_toKeep := ... # automatically generate
buildFiles_toRemove := ... # these lists. But that would lead
buildDirs_toRemove := ... # us too far here.
.PHONY: clean
clean:
@echo.
@echo ----------------------------------------------------------
@echo.$(space) __ ************** $(space)
@echo.$(space) __\ \___ * make clean * $(space)
@echo.$(space) \ _ _ _ \ ************** $(space)
@echo.$(space) \_`_`_`_\ $(space)
@echo.$(space) $(space)
@echo.$(space)Keep these files:
@echo.$(space) $(buildFiles_toKeep)
@echo.$(space)
@echo $(space)Keep these directories:
@echo.$(space) $(buildDirs_toKeep)
@echo.$(space)
@echo.$(space)Remove these files:
@echo.$(space) $(buildFiles_toRemove)
$(RM) $(buildFiles_toRemove)
@echo.
@echo.$(space)Remove these directories:
@echo.$(space) $(buildDirs_toRemove)
$(RMDIR) $(buildDirs_toRemove)
@echo.
@echo ----------------------------------------------------------
这个 makefile 效果很好。在 Windows 和 Linux 上,它都用正确的 shell 命令替换 $(RM)
和 $(RMDIR)
来删除文件和文件夹。但我想提示用户,让他/她可以按 Y 或 N。我不想删除他/她想要保留的文件。我尝试将一些批处理命令插入到提示用户输入的 clean
目标的配方中。但没有显示提示。也许是因为 GNU make 延迟了输入流。
我想知道是否可以使用“纯”make 语法(没有特定于操作系统的 shell 命令)生成 [Y/N] 提示符。我知道 make 语言有其局限性。也许一个聪明的解决方案可以在一个操作系统(例如 Linux)上运行,并以最小的开销移植到另一个操作系统(例如 Windows)上。
有人有想法吗?
<小时/>编辑:
我引用了此链接:How do I get `make` to prompt the user for a password and store it in a Makefile variable?
Gnu make 将通过提示用户创建变量 PASSWORD
:
$ cat Makefile
PASSWORD ?= $(shell bash -c 'read -s -p "Password: " pwd; echo $$pwd')
只要您希望在 解析 makefile 时出现提示,这种提示用户输入的方式就可以正常工作。但我的情况有所不同。我想在 makefile 已经运行时提示用户,换句话说,当 makefile 中的配方正在执行时。
<小时/>编辑:
运行 make multi-threaded 时无法提示用户。所以我完全可以单线程调用 clean
函数:
>> make clean -j1
毕竟,clean
函数不需要很长时间就能完成。我不打算在 build
函数中提示用户输入任何内容,以便可以多线程执行:-)
>> make all -j8 --output-sync=target
最佳答案
从概念上讲,make 是一个非常简单的应用程序,只有一个目的 - 构建一棵依赖关系树,并重新制作具有更新祖先的东西。交互不应该成为一个因素,因此 make 本身不会提供交互,理想情况下 make 应该已经拥有它所需的所有信息。如果您确实需要,可以使用 shell
、!=
解决此问题,甚至可以使用 guile 或 load
提供您自己的扩展。
但这并不真正适用于 clean
规则,因为 clean
不会首先重新制作任何内容,这只是一个快速技巧,让您能够使用 make 语法方便地表达非 make 操作。
就我个人而言,我不认为提示用户删除文件有什么值(value),除非您要删除不由您负责的内容,这本身就已经是一种反模式。
如果您绝对确定需要此功能,请将 clean
配方包装在脚本中,并为 bash 和 windows 提供两个版本。您也可以假设在 Windows 上运行 GNU make 的任何人都已经在使用 MSYS2、Cygwin 或 MS 批准的 bash for Windows 10 版本。 ,并完全放弃 cmd/powershell 脚本。
关于shell - 如何在我的 makefile 中提示用户输入 [y/n](使用纯 make 语法)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39272954/
我有一个 Makefile,它针对特定目标调用另一个 Makefile。假设主 Makefile 包含 some_dir/some_target: cd some_dir && make so
这两个文件大多出现在开源项目中。 它们的用途是什么?它们如何工作? 最佳答案 Makefile.am 是程序员定义的文件,由 automake 使用来生成 Makefile.in 文件( .am 代表
我的源代码位于一堆子目录中,例如: src/widgets/apple.cpp src/widgets/knob.cpp src/tests/blend.cpp src/ui/flash.cpp 在项
这就是我所拥有的: SUBDIRS = src/lib/ResourceManager all: $(SUBDIRS) $(SUBDIRS): make install -C $@ 我正在尝试
我想写一个 Makefile 来执行来自两个不同数组的两个输入的命令例如 a = A B C b = 1 2 3 ./run A 1 ./run B 2 ./run C 3 我不知道怎么写,因为在Ma
在 GNU make 手册的早期部分之一,Section 3.7 , 有一个 makefile 配方的大纲 immediate : immediate ; deferred defer
是否存在将 gmake 的 GNU Makefile 转换为可用于 make (FreeBSD-make) 的 Makefile 的实用程序? 最佳答案 该实用程序称为开发人员(程序员,制作大师,..
所以我前段时间了解了什么是 Makefile,创建了一个模板 Makefile,我所做的就是为我正在执行的每个程序复制和更改相同的文件。我改了几次,但它仍然是一个非常粗糙的Makefile。我应该如何
我正在做一些 Makefile 重构,并试图找出最简洁的方法来实现一个 Makefile,它执行以下操作: 有一个变量列出了所有源文件(可以是 C 和 C++ 文件) 所有目标文件都在 OBJ_DIR
我正在尝试创建一个 Makefile,它将通过 tic 编译位于目录中的 terminfo 文件。 tic 还将它自动创建的 termcap 文件复制到系统或用户特定的目标文件夹。对于普通用户,如果
我想要类似的东西 BROKEN_THINGS = \ thing1 \ # thing1 is completely broken thing2 \ # thing2 is broken to
如果我的程序必须为不同的结果(主要是错误)返回不同的值(例如 0、1、2、3 等),则调用该程序的 makefile 将不得不停止执行其余的 makefile 命令。即使该命令产生错误(返回非零值),
我正在学习使用漂亮的 Linux 工具:make。还有一点我想了解的: 让我们看一下这个简单的例子: JADE = $(shell find pages/*.jade) HTML = $(JADE:.
假设您有一个包含两个伪目标“all”和“debug”的 Makefile。 'debug' 目标旨在构建与 'all' 相同的项目,除了一些不同的编译开关(例如 -ggdb)。由于目标使用不同的编译开
我有一个调用多个其他生成文件的生成文件。 我想将 -j 参数传递给其他 makefile 调用。 类似(make -j8): all: make -f libpng_linux.mk -j
我处理过的 Makefile 大部分都很复杂,并且隐藏了很多关系。我自己从来没有写过一个,想知道是否有人有一些关于编写易于阅读和可重用的 Makefile 的提示? 最佳答案 我通常使用这样的东西,在
嘿,我有一个简单的“主” Makefile,它只是调用其他 makefile。我正在尝试执行以下操作,以便以正确的顺序构建组件: LIB_A = folder_a LIB_B = folder_b L
生成文件: #there is a whitespace after "/my/path/to" FOO = "/my/path/to" BAR = "dir" INCLUDE_DIRS = $(FO
我正在学习 makefile,我知道如何创建一个简单的 makefile。我正在继续使用嵌套的 makefile。这是我的目录结构 /src ...makefile ...main.cpp ...fo
什么TEMP0_FILES下面计算到? SOURCE_FILES可以等于多个源文件。请告诉我以下语法 :.cpp=.o 的用途 SOURCE_FILES = main.cpp TEMP0_FILES
我是一名优秀的程序员,十分优秀!