Closed drskoolie closed 1 month ago
For the patsubst, does this do what you're looking for? -
# Define source directory
SRC_DIR := 'src'
# Define object directory
OBJ_DIR := 'obj'
# Define source files using wildcard
SRC_FILES := `echo src/*.c`
# Define object files
OBJ_FILES := replace_regex(SRC_FILES, SRC_DIR / '([^/]+)\.c(\s|$)', OBJ_DIR / '${1}.o$2')
Yes, that's what I was looking for! Thanks. How do I know where the replace_regex function is in the docs @laniakea64?
How do I know where the replace_regex function is in the docs
It's on the same page as other just
functions are documented: https://just.systems/man/en/chapter_31.html#string-manipulation
When compiling C code, you need to convert every .c to a .o. Unfortunately, gcc isn't smart enough to do that by itself. So you need to employ a make file that does it.
The code below is a simple example of using Makefile's wildcard and patsubst functions to do it.
The wildcard is easy, it's just globbing (
src/*.c
). The patsubst is the harder part for me. It replaces every string that it got from the wildcard to look like this ('obj/*.o').After that, it runs gcc per each individual string that it got out. I've been looking through the docs of
just
, but I couldn't get it working.