想知道这个 makefile 是什么意思

时间:2021-06-07 22:01:46

标签: python makefile

所以我在浏览 repl.it 时看到有人让在 repl 窗口中运行 firefox 成为可能。有一个名为 Makefile 的文件,其中包含此代码。我想知道这意味着什么以及他们从哪里获得 Firefox。


.PHONY: run

run:
    install-pkg python firefox
    python3 launch.py 

然后有一个名为launch.py​​的python文件

def delete():
  time.sleep(10)
  os.remove("nohup.out")
  print ("Deleted nohup.out.")
thread = threading.Thread(target=delete)
thread.start()
os.system("firefox")

我真的很好奇 Firefox 来自哪里,以及我是否可以替代其他应用程序,例如 discord。 以及什么是makefile 这是repl的链接,您可以在其中查看代码。 https://replit.com/@Jackerin0/Firefox-fixed-originally-made-by-polygott?v=1

1 个答案:

答案 0 :(得分:0)

Makefile 是一个实用程序,用于编写和执行一系列命令行指令,用于编译代码、测试代码、格式化代码、运行代码、下载/上传数据、清理目录等......基本上,它有助于将您的开发工作流程自动化为简单的命令(make runmake testmake clean)。

这是它在这种情况下的作用:

.PHONY: run # explicitly declare the a routine "run" exists, which can be called with `make run`

run: # run routine
    install-pkg python firefox # first, install python and firefox. This will make both firefox and python available as executable binaries that can be launched from the command line
    python3 launch.py # this runs the python script

因此,当您在终端中键入 make run 时,它将运行 install-pkgpython3 命令。

然后在python文件中:

def delete():
  time.sleep(10) # sleep for 10 seconds
  os.remove("nohup.out") # remove the file named nohup.out
  print ("Deleted nohup.out.")
thread = threading.Thread(target=delete) # create a thread to run the delete function
thread.start() # start the thread
os.system("firefox") # run the executable for firefox (you can replace this with any command from the command line)

nohup 文件是在运行后台任务时创建的。不确定为什么在这种情况下创建它(可能是因为特定于 firefoxrepl),或者为什么需要删除它。