c - 在 make 文件中包含输入语句和条件
问题描述
我第一次尝试创建一个makefile。我浏览了一些教程并设法创建了一个,但我遇到了一些问题。以下是详细信息。
以下是按执行顺序排列的文件:
CSV_to_txt.c
- 不依赖任何其他文件。
我想CSV_files/Equilibrium_trajectories.csv
在 make 文件中包含我的输入。此外,我 tac Chemical_Equilibrium.txt
在终端中运行命令。我也可以将它包含在make文件中吗?
fluid_profile.c
- 取决于pdfutil.h
和beta_util.h
。
我在读取输入时遇到同样的问题,例如:
Enter the number of points
1000
--> 包含在 make 文件中。
此文件创建一个名为fluid_points.txt
. 我想在 makefile 中包含的是,如果该文件已经存在,请不要执行命令gcc fluid_points.c -o fluid_points.o -lm
。
make文件的结构:
all:
gcc CSV_to_txt.c -o CSV_to_txt.o -lm
./CSV_to_txt.o
#Include the file path and name when asked for it
#ubuntu terminal command --> tac filename.txt > filename_changed.txt
gcc fluid_profile.c -o fluid_profile.o -lm
./fluid_profile.o
#Enter the number of points when prompted to do so
#If fluid_points.txt file is already existing don't execute the above command, instead execute the below one
gcc blah.c -o blah.o -lm
./blah.o
clean:
$(RM) *.o *~
任何形式的帮助,甚至是教程的链接都会有所帮助。
解决方案
建议的makefile:
run:
.PHONY: run
CSV_to_txt: CSV_to_txt.c
gcc CSV_to_txt.c -o CSV_to_txt -lm
fluid_profile: fluid_profile.c
gcc fluid_profile.c -o fluid_profile -lm
blah: blah.c
gcc blah -o blah.c -lm
run: CSV_to_txt fluid_profile blah
echo "CSV_files/Equilibrium_trajectories.csv" | ./CSV_to_txt.o
tac Chemical_Equilibrium.txt
echo "1000" | ./fluid_profile.o
./blah.o
clean:
$(RM) *.o *~
所以,分解——第一行,预先声明目标run
,使其成为默认目标(如果你这样做make
,它将运行第一个目标)。将其声明为虚假目标(这意味着没有实际文件被称为run
正在生成。您可以查找.PHONY
更多详细信息)
然后创建一些规则来生成可执行文件。每个可执行文件都有自己的规则来生成它。通常你会为这些像和使用自动变量,但我现在想保持简单。$@
$<
然后规则为run
。这取决于可执行文件(因此可执行文件将在此规则运行之前完成构建)。
然后,要将文件名传递给可执行文件,您可以简单地echo
将文件名传递给可执行文件。
推荐阅读
- python - 更改 pyttsx3 语言
- android - 在android中进行BLE扫描后收到不正确的结果
- gatsby - 将 Tailwind 加载到 Gatsby 站点时延迟 300 毫秒
- python - 在 Python 3.8 中导入 tensorflow 时出错
- jmeter - 如何在 Azure-Event-Hub/(或任何 DB)中批量写入 JMeter 结果
- javascript - 从 Object 键调用方法
- c# - AutoMapper 版本 10 和 ASP.NET MVC
- r - 字符列拆分为 tibble 中的列表列
- php - Nginx 进程和 php-fpm 共享卷
- java - 窗格不适合窗口