Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP to export Makefiles that replace include with file content #39

Closed
wants to merge 4 commits into from

Conversation

zph
Copy link
Collaborator

@zph zph commented Sep 24, 2019

This spike is to transpile makefiles to replace include statements with
their file contents.

This will solve 2 issues:

I spiked it out in ruby for easy of scripting: https://gist.github.com/zph/8b3f6afd7a56613a80ef09319c20c7be

mmake export will read the Makefile, then parse it line by line for include statements, then each include will be recursively filled in with the file content of the include Makefile, which will be recursively parsed for include statements...

So running mmake export on the Makefile at root of this project would yield a portable Makefile like:

#- start=include github.com/tj/make/golang
#- start=include github.com/tj/make/cloc
# Output source statistics.
cloc:
        @cloc --exclude-dir=client,vendor .
.PHONY: cloc
#- end=include github.com/tj/make/cloc

#- start=include github.com/tj/make/todo
# Output to-do items per file.
todo:
        @grep \
                --exclude-dir=./vendor \
                --exclude-dir=./client/node_modules \
                --text \
                --color \
                -nRo ' TODO:.*' .
.PHONY: todo
#- end=include github.com/tj/make/todo

# Run all tests.
test:
        @go test -cover ./...
.PHONY: test

# Install the commands.
install:
        @go install ./cmd/...
.PHONY: install

# Release binaries to GitHub.
release:
        @goreleaser --rm-dist --config .goreleaser.yml
.PHONY: release

# Show size of imports.
size:
        @curl -sL https://gist.githubusercontent.com/tj/04e0965e23da00ca33f101e5b2ed4ed4/raw/9aa16698b2bc606cf911219ea540972edef05c4b/gistfile1.txt | bash
.PHONY: size
#- end=include github.com/tj/make/golang

That full Makefile output can then be used for mmake help to correctly report all targets :D.

Anyway, it looked fun and caught my attention. Now I need to do the actual work of transcribing and re-implementing.

This spike is to transpile makefiles to replace include statements with
their file contents.
@zph zph added the Priority: Low Low priority issue label Sep 24, 2019
"github.com/tj/mmake/help"
"github.com/tj/mmake/installer"
"github.com/tj/mmake/resolver"
)

var makefileVariants = [3]string{"GNUmakefile", "makefile", "Makefile"}
var makefileVariants = [3]string{"GNUmakefile", "Makefile", "makefile"}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching this order due to case-insensitive file systems (OSX :-/) finding the less common naming of file first.

}

func IncludedMakefilePaths(path string) []string {
stubMakefile := fmt.Sprintf(`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trick to get full paths of all included files.

@zph
Copy link
Collaborator Author

zph commented Sep 28, 2019

So the current mmake export output for Makefile from room of this project is:

#- start=include github.com/tj/make/golang
#- start=include github.com/tj/make/cloc

# Output source statistics.
cloc:
	@cloc --exclude-dir=client,vendor .
.PHONY: cloc
#- end=include github.com/tj/make/cloc
#- start=include github.com/tj/make/todo

# Output to-do items per file.
todo:
	@grep \
		--exclude-dir=./vendor \
		--exclude-dir=./client/node_modules \
		--text \
		--color \
		-nRo ' TODO:.*' .
.PHONY: todo
#- end=include github.com/tj/make/todo

# Run all tests.
test:
	@go test -cover ./...
.PHONY: test

# Install the commands.
install:
	@go install ./cmd/...
.PHONY: install

# Release binaries to GitHub.
release:
	@goreleaser --rm-dist --config .goreleaser.yml
.PHONY: release

# Show size of imports.
size:
	@curl -sL https://gist.githubusercontent.com/tj/04e0965e23da00ca33f101e5b2ed4ed4/raw/9aa16698b2bc606cf911219ea540972edef05c4b/gistfile1.txt | bash
.PHONY: size
#- end=include github.com/tj/make/golang

@zph zph closed this Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: Low Low priority issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant