PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Rekursives Makefile



Mat
07-12-2009, 18:47
Hallo,

ich habe folgendes Makefile welches mir in meinem aktuellen ordner alle *.cpp dateigen kompiliert.


TARGET := out
CXXFLAGS := -O3 -Wall
CXX := g++
LIBS :=
EXT := cpp
SOURCES := $(wildcard *.$(EXT))
OBJECTS := $(patsubst %.$(EXT), %.o, $(SOURCES))

.PHONY: all
all: $(TARGET)

$(TARGET): $(OBJECTS)
$(CXX) $(CXXFLAGS) -o $(TARGET) $(OBJECTS) $(LIBS)

$(OBJECTS): %.o: %.$(EXT)
$(CXX) $(CXXFLAGS) -c $< -o $@

.PHONY: clean
clean:
rm -rf *.o

Nun habe 2 unterordner erstellt subdir1 und subdir2 indem files liegen. Ich schaffe es allerdings nicht dass make meine files dort drin erknent. Mir ist klar dass jeder unterordner ein eigenes makefile braucht doch:

1) soll dieses makefile dort genauso aussehen wie das obige ?
2) und wie erkennt jetzt das root-makefile welche abhängigkeiten entstehen?

Kann mir jemand helfen und das obige makefile ergänzen?

Danke

undefined
16-12-2009, 11:18
Also bei größeren Projekten sollte man immer Automake verwenden ;)


SUBDIRS = subdir1

## .....

# This directory's subdirectories are mostly independent; you can cd
# into them and run `make' without going through this Makefile.
# To change the values of `make' variables: instead of editing Makefiles,
# (1) if the variable is set in `config.status', edit `config.status'
# (which will cause the Makefiles to be regenerated when you run `make');
# (2) otherwise, pass the desired values on the `make' command line.
$(RECURSIVE_TARGETS):
@fail= failcom='exit 1'; \
for f in x $$MAKEFLAGS; do \
case $$f in \
*=* | --[!k]*);; \
*k*) failcom='fail=yes';; \
esac; \
done; \
dot_seen=no; \
target=`echo $@ | sed s/-recursive//`; \
list='$(SUBDIRS)'; for subdir in $$list; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
dot_seen=yes; \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| eval $$failcom; \
done; \
if test "$$dot_seen" = "no"; then \
$(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
fi; test -z "$$fail"

.PHONY: $(TARGET) $(RECURSIVE_TARGETS)