News for hackers. Stuff that matters.
Re:A Tutorial on Portable Makefiles (2017) by matheusmoreira on Monday August 01, 2022 @06:57AM (#32304268)
Like many others, I too rediscovered the power of pure GNU Make years ago. Turns out it has some rather Lisp-like metaprogramming capabilities. It's extremely hard to do even basic processing but with enough effort some cool things can happen. I'm somewhat proud of my implementation of a simple version of the find utility as a pure GNU Make recursive function.

This rediscovery essentially derailed one of my side projects as I started writing a pure GNU Make build system and function library like this one:

https://gmsl.sourceforge.io/

https://www.cmcrossroads.com/article/gnu-make-standard-libra...

I even asked this author on Twitter and Stack Overflow about its implementation.

The end result was reinvention of code generation tools because that's what metaprogramming is. I didn't understand what autotools was doing before I tried doing it myself. My objective was to eliminate makefile regeneration whenever project structure changed, I ended up regenerating code 100% of the time and evaluating the resulting code inside the makefile itself. If we must metaprogram, it's better to do it in a proper programming language. At least it didn't have any dependencies other than GNU Make.

Re:A Tutorial on Portable Makefiles (2017) by jgrahamc on Monday August 01, 2022 @07:48AM (#32304666)
Hello! That’s me. Happy to answer further questions…
Re:A Tutorial on Portable Makefiles (2017) by matheusmoreira on Monday August 01, 2022 @10:15AM (#32306236)
Hello! Huge fan of your work and I've also read your book. Are you still developing GMSL? I wonder if you're open to contributions.

My find function has been the single most useful thing to come out of my side project. The first thing I do in my makefiles is get a list of all source files and it's always been annoying because I like organizing my project in trees which requires recursive file system walks. I managed to write a pure GNU Make function that simplifies that to:

  sources := $(call find,src,file?)
The find function recursively walks the src directory and returns a list of all paths satisfying the file? predicate function.

I think it would be a nice addition to GMSL. In my project, I doubt it will ever help anyone.

Re:A Tutorial on Portable Makefiles (2017) by jgrahamc on Wednesday August 03, 2022 @11:45AM (#32333288)
Yes, I still work on GMSL. It's pretty stable and I mostly just fix incompatibilities or bugs that people report. However, I'm happy to look at additions.

One of these days I'll get it off SourceForge...

Is your find function a bit like my rwildcard? https://news.ycombinator.com/item?id=23270235

Re:A Tutorial on Portable Makefiles (2017) by matheusmoreira on Saturday August 06, 2022 @12:06PM (#32369262)
That's awesome. I didn't know about rwildcard until now. Is it part of GMSL? I searched for rwildcard on gmsl.sourceforge.io but didn't find it.

I think my function is needlessly complicated compared to rwildcard. Here's my code:

https://github.com/matheusmoreira/liblinux/blob/modular-buil...

https://github.com/matheusmoreira/liblinux/blob/modular-buil...

The file? and directory? functions were inspired by GMSL. I think I learned how to check whether a path is a directory from one of your posts.

I wrote a general recursion function. It takes a function to apply to lists and a function to compute whether an element is a base case.

The recursive file system traversal function applies a directory globbing function to the list of paths and has file? as base case. It returns all files without filtering.

The find function recursively traverses the file system while filtering out all items not matching the given predicate function. It was my intention to provide predicates like c_file? and header_file? but I stopped developing that project before that happened. Users can easily write their own predicates too.

I think rwildcard is probably simpler and more efficient! If my code helps in any way though, feel free to use it.

Re:A Tutorial on Portable Makefiles (2017) by rasterdog on Thursday August 04, 2022 @03:02AM (#32340036)
"Like many others, I too rediscovered the power of pure GNU Make" ... wait a sec, GNU make is not "pure!" I like it but I recognize that it has features that a more portable make would not have.
Re:A Tutorial on Portable Makefiles (2017) by matheusmoreira on Saturday August 06, 2022 @01:09PM (#32369780)
Perhaps pure was not the right word. By pure GNU Make I meant writing makefiles myself without higher level makefile generation tools.