部分重用makefile的模式

huangapple go评论91阅读模式
英文:

Patterns of partially reused makefiles

问题

我目前正在使用golang创建越来越多的小型项目,但我发现许多makefile任务都是从其他项目中直接复制粘贴的。例如,在每个项目中,我都有以下内容:

${APP_NAME}: $(SOURCES)
	go get ./...
	goimports -w $(SOURCES)
	go build -o ${APP_NAME}

我想知道是否有人有将片段提取到单独的项目并导入的经验。如果有的话,你是如何做到的?

  • 只需从raw.githubusercontent.com上使用curl获取文件吗?因为这似乎是我唯一找到的简单方法。

  • 我还考虑过使用git子模块,但对于只有几个文件来说,这似乎有点过头了。

英文:

I am at this time creating more and more of small one-off projects in golang but I see many makefile tasks are literally copy&paste from across projects. For example, in every project I have a:

${APP_NAME}: $(SOURCES)
	go get ./...
	goimports -w $(SOURCES)
	go build -o ${APP_NAME}

I would like to know if anyone has experience of fragment extraction into a separate project and importing it. If so, how do you do it?

  • Just curl a file from raw.githubusercontent.com? Because that's what I'm about to do since I don't see any other easy way.

  • I also thought about using git submodules but that seems also a bit over the top for a couple of files.

答案1

得分: 0

我找到了一个简单的解决方法:我使用从起始的单体Makefile创建的Makefile进行include

我将分割的Makefile放在一个单独的git项目中,该项目只包含它们。

我从根项目中引用这些Makefile,并通过git子模块在本地拥有它们。这需要一些额外的工作,但它允许我在根目录下拥有简单的Makefile,并将所有复杂(经常重复)的逻辑放在单独的项目中。

以下是我如何使其工作的示例:

  • 分割的Makefile项目:https://github.com/milanaleksic/gomakefiles
  • 通过子模块利用上述项目的根Makefile:https://github.com/milanaleksic/jenkins_ping
英文:

I have found a simple workaround: I include Makefiles which I made from the starting monolithic Makefile.

I am putting split Makefiles in a separate git project, that contains only them.

I am referring to those Makefiles from root project and I have them locally via git submodule. A bit more work - yes, but it allows me to have trivial "root" Makefile and all hard (quite often - repeating) logic in the separate project.

Example of how I made this work:

huangapple
  • 本文由 发表于 2016年3月5日 14:51:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/35811095.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定