<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Makefile sucht sich sourcen zusammen. $&lt; leer]]></title><description><![CDATA[<p>Hallo ihrs,</p>
<p>Disclaimer: Makefiles habe ich das letzte Mal vor 137 Jahren gemacht..</p>
<p>Ich bastle mir gerade an einem Projekttemplate für mittelkomplexe C-Projekte herum und habe mir was zusammen gestrickt das sich seine Sourcen selbst zusammen sucht. Wahrscheinlich funktioniert das nicht in allen Fällen super aber es ist ein Anfang..</p>
<p>Grundsätzlich funktioniert das jetzt auch aber eine Kleinigkeit verstehe ich nicht. Daher hier erst mal der Source:</p>
<pre><code class="language-plain">PROG = projectname
SRCDIR = src 
BINDIR = build

CC = /usr/bin/gcc
CFLAGS = -g -Wall
LDFLAGS =

# these targets are not incremental
.PHONY: clean program

# this only gets the source directory structure
STRUCTURE = $(shell find $(SRCDIR) -type d)
# this lists the files inside the directory structure
FILES = $(wildcard $(STRUCTURE)/*)

# filter the source files
SOURCES = $(filter %.c, $(FILES))
OBJECTS = $(subst $(SRCDIR),$(BINDIR),$(SOURCES:%.c=%.o))

# how to create an object file
$(BINDIR)/%.o: $(subst $(BINDIR),$(SRCDIR),$(@:.o=.c))
    <a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/9067">@echo</a> &quot;Compiling object $@&quot;
    $(CC) -c $(subst $(BINDIR),$(SRCDIR),$(@:.o=.c)) -o $@ $(CFLAGS)

# compile means, that all objects have to exist
compile: $(OBJECTS)

program: compile
    $(CC) $(CFLAGS) $(LDFLAGS) -o $(BINDIR)/$(PROG) $(OBJECTS)

clean:
    -rm -r $(BINDIR)/*

all: clean compile program
</code></pre>
<p>Im Block 21-24 erzeuge ich ein object file im bin directory aus dem C-File. Theoretisch sollte ja hier der Aufruf</p>
<pre><code class="language-plain">$(BINDIR)/%.o: $(subst $(BINDIR),$(SRCDIR),$(@:.o=.c))
    $(CC) -c$&lt; -o $@ $(CFLAGS)
</code></pre>
<p>reichen, tuts aber nicht. $&lt; ist leer. Kann mir wer sagen warum?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/353989/makefile-sucht-sich-sourcen-zusammen-leer</link><generator>RSS for Node</generator><lastBuildDate>Sat, 10 Oct 2026 17:18:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/353989.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 25 Mar 2023 09:18:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Makefile sucht sich sourcen zusammen. $&lt; leer on Sat, 25 Mar 2023 09:18:43 GMT]]></title><description><![CDATA[<p>Hallo ihrs,</p>
<p>Disclaimer: Makefiles habe ich das letzte Mal vor 137 Jahren gemacht..</p>
<p>Ich bastle mir gerade an einem Projekttemplate für mittelkomplexe C-Projekte herum und habe mir was zusammen gestrickt das sich seine Sourcen selbst zusammen sucht. Wahrscheinlich funktioniert das nicht in allen Fällen super aber es ist ein Anfang..</p>
<p>Grundsätzlich funktioniert das jetzt auch aber eine Kleinigkeit verstehe ich nicht. Daher hier erst mal der Source:</p>
<pre><code class="language-plain">PROG = projectname
SRCDIR = src 
BINDIR = build

CC = /usr/bin/gcc
CFLAGS = -g -Wall
LDFLAGS =

# these targets are not incremental
.PHONY: clean program

# this only gets the source directory structure
STRUCTURE = $(shell find $(SRCDIR) -type d)
# this lists the files inside the directory structure
FILES = $(wildcard $(STRUCTURE)/*)

# filter the source files
SOURCES = $(filter %.c, $(FILES))
OBJECTS = $(subst $(SRCDIR),$(BINDIR),$(SOURCES:%.c=%.o))

# how to create an object file
$(BINDIR)/%.o: $(subst $(BINDIR),$(SRCDIR),$(@:.o=.c))
    <a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/9067">@echo</a> &quot;Compiling object $@&quot;
    $(CC) -c $(subst $(BINDIR),$(SRCDIR),$(@:.o=.c)) -o $@ $(CFLAGS)

# compile means, that all objects have to exist
compile: $(OBJECTS)

program: compile
    $(CC) $(CFLAGS) $(LDFLAGS) -o $(BINDIR)/$(PROG) $(OBJECTS)

clean:
    -rm -r $(BINDIR)/*

all: clean compile program
</code></pre>
<p>Im Block 21-24 erzeuge ich ein object file im bin directory aus dem C-File. Theoretisch sollte ja hier der Aufruf</p>
<pre><code class="language-plain">$(BINDIR)/%.o: $(subst $(BINDIR),$(SRCDIR),$(@:.o=.c))
    $(CC) -c$&lt; -o $@ $(CFLAGS)
</code></pre>
<p>reichen, tuts aber nicht. $&lt; ist leer. Kann mir wer sagen warum?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2615128</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2615128</guid><dc:creator><![CDATA[DocJunioR]]></dc:creator><pubDate>Sat, 25 Mar 2023 09:18:43 GMT</pubDate></item><item><title><![CDATA[Reply to Makefile sucht sich sourcen zusammen. $&lt; leer on Sat, 25 Mar 2023 11:00:46 GMT]]></title><description><![CDATA[<p>Ich würde bei so etwas erst einmal <code>make -d</code> versuchen, ob man sich daran erschließen kann, was da falsch läuft. Oder ist das schon, was du gemacht hast, um zu deiner Diagnose zu kommen?</p>
<p>Dass da kein Leerzeichen zwischen <code>-c</code> und <code>$&lt;</code> ist, ist das bei dir wirklich so oder nur ein Tippfehler in der Frage hier?</p>
<p><code>compile</code>  und <code>all</code> sollten Phony-Targets sein, oder? Da könnte es eventuell Probleme geben, wenn irgendwelche Sourcen verwandte Namen haben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2615130</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2615130</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sat, 25 Mar 2023 11:00:46 GMT</pubDate></item><item><title><![CDATA[Reply to Makefile sucht sich sourcen zusammen. $&lt; leer on Sat, 25 Mar 2023 17:24:22 GMT]]></title><description><![CDATA[<p>Ich habe das makefile etwas umgeschrieben, und es macht nun das was Du wohl erreichen willst. Wenn man automatisch Listen von Objekten generieren will, kommt man um die höheren Funktionen von make nicht herum. Ich hoffe es ist halbwegs nachvollziehbar.</p>
<pre><code class="language-plain">PROG=projectname
SRCDIR=src
BINDIR=objs
C_SRC_SUFFIX=.c
C_OBJ_SUFFIX=.o

CC=gcc
CFLAGS= -g -Wall -Wextra -std=c11 -Wpedantic
LDFLAGS=

# these targets are not incremental
.PHONY: clean program directories

# this only gets the source directory structure
STRUCTURE = $(shell find $(SRCDIR) -type d)
# this lists the files inside the directory structure
FILES = $(wildcard $(STRUCTURE)/*)

#$(info $(FILES))

# filter the source files
SOURCES = $(filter %.c, $(FILES))
BASEFILE=$(basename $(notdir $(SOURCES)))
OBJECTS=$(addprefix  $(BINDIR)/, $(addsuffix .o, $(BASEFILE)))

define GENERATE_OBJECT_RULES
$(BINDIR)/$O$(C_OBJ_SUFFIX): $(SRCDIR)/$O$(C_SRC_SUFFIX)
	$(CC) $(CFLAGS) -c $$&lt; -o $$@
endef

all: program

$(foreach O, $(BASEFILE), $(eval $(GENERATE_OBJECT_RULES)))
#$(foreach O, $(BASEFILE), $(info $(GENERATE_OBJECT_RULES)))

#$(info $(OBJECTS))

directories:
	@mkdir -p $(BINDIR)

program: directories $(OBJECTS) 
	$(CC) $(CFLAGS) -o $(BINDIR)/$(PROG) $(LDFLAGS) $(OBJECTS)

clean:
	@rm -rf $(BINDIR)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2615131</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2615131</guid><dc:creator><![CDATA[*john 0]]></dc:creator><pubDate>Sat, 25 Mar 2023 17:24:22 GMT</pubDate></item><item><title><![CDATA[Reply to Makefile sucht sich sourcen zusammen. $&lt; leer on Sat, 25 Mar 2023 19:20:30 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/16792">@john-0</a> So im Groben versteh ich das Ganze glaub ich. Habe bisher define nie genutzt aber hat wohl Sinn.. danke dir!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2615135</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2615135</guid><dc:creator><![CDATA[DocJunioR]]></dc:creator><pubDate>Sat, 25 Mar 2023 19:20:30 GMT</pubDate></item></channel></rss>