Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The simplest option to do what you want is probably to just use a shell escape and call <code>find</code>:</p> <pre><code>SOURCES := $(shell find $(SOURCEDIR) -name '*.c') </code></pre> <p>This gets you a list of source files with paths. Note that the use of immediate assignment <code>:=</code> rather than recursive assignment <code>=</code> is important here: you do <strong>not</strong> want to be running the shell escape every time <code>SOURCES</code> is inspected by make (which happens a lot more than you'd think in Makefiles). A general rule I find helpful is to <em>always</em> use immediate assignment unless I actually need recursive expansion (which is rare; it looks like all of your assignments in this example could be immediate). This then means use of recursive assignment is also a helpful signal that the variable needs to be used carefully.</p> <p>Back to your problem. What you do next depends on whether you want a mirror of your source tree in your build tree, or whether the build dir is just supposed to contain a flat list of object files for all your source files, or whether you want a separate build dir under every source dir in the tree.</p> <p>Assuming you want the mirrored build tree, you could do something like the following:</p> <pre><code># Get list of object files, with paths OBJECTS := $(addprefix $(BUILDDIR)/,$(SOURCES:%.c=%.o)) $(BINARY): $(OBJECTS) $(CC) $(CFLAGS) $(LDFLAGS) $(OBJECTS) -o $(BINARY) $(BUILDDIR)/%.o: %.c $(CC) $(CFLAGS) $(LDFLAGS) -I$(HEADERDIR) -I$(dir $&lt;) -c $&lt; -o $@ </code></pre> <p>This doesn't quite take into account the full complexity of the job, as it doesn't ensure the directories in the build tree actually exist (which would be moderately painful to do in Makefile syntax).</p> <p>I removed the -I directives from your $(BINARY) build rule; do you really need them when linking objects? The reason I didn't leave them is that you don't have just one source dir anymore, and it's non-trivial to get the list of source dirs from the list of objects (like so much in Makefile syntax it would be doable but really annoying).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload