linuxlizard / pymake

Parse GNU Makefiles with Python. Work in progress!
GNU General Public License v2.0
31 stars 9 forks source link

Something simple on usage #1

Closed dafvid closed 1 year ago

dafvid commented 2 years ago

Hi I'd really like to use this but it's pretty hard to know where to start. Could you add something short on usage in the Readme perhaps?

linuxlizard commented 2 years ago

Wow. I had no idea anyone even noticed this project yet. I'll add a readme. What kind of use were you thinking of?

The project is very early on. I can parse almost all of fully formed makefiles. I can output S-expressions, regenerate the makefile.

dafvid commented 2 years ago

Heh, 8 years in the making though. First hit on Google for python parse make files. My usage is I wanna follow changes in default versions in the FreeBSD ports tree and they are defined in a make file. So I thought there must a package for it and there was!

dafvid commented 2 years ago

So this is the file I want to parse https://raw.githubusercontent.com/freebsd/freebsd-ports/main/Mk/bsd.default-versions.mk

linuxlizard commented 2 years ago

I was bored at a previous job so started working on pymake in my spare time to give my brain something to chew on. Then I started a new job and got distracted for 6 years. :-D I keep needing to debug vendor makefiles so dragged myself back to this project. Taking a look at that bsd makefile...

linuxlizard commented 2 years ago

I don't think my little project can help you. https://man.openbsd.org/make.1 Unfortunately, BSD make is quite a different dialect than GNU make. Looks like BSD make uses a ".name" structure which is very different than the $() style GNU make uses. (That's so weird. BSD probably preceded GNU so why did GNU use such a different syntax?)

dafvid commented 2 years ago

Aw that's too bad. I'll have to keep looking or maybe try and parse just this one file.

linuxlizard commented 2 years ago

Take a look at pyparsing. Really powerful, easy to use python parser generator. I started with it but turns out GNU make has very particular uses of whitespace the pyparsing couldn't handle.

benji-york commented 2 years ago

Aw that's too bad. I'll have to keep looking or maybe try and parse just this one file.

I've been playing with using a tree-sitter based Makefile parser and have been relatively happy with the results. The one I'm using is at https://github.com/alemuller/tree-sitter-make.

linuxlizard commented 1 year ago

I finally added a usage()