Hi,
I'm trying to make recursive makefile work but it's giving me two problems. I have a top folder with the main Makefile and one Makefile for each sub folder 'one' and 'two'. Makefile in subfolder 'one' and 'two' are identical.
The top Makefile (still a bit messy) looking like this:
Code:
# Directories
CC = gcc
CFLAGS = -Wall -Wextra
TARGET_DIR = bin
MAIN_FILE = one.c
DIRS = one two
PATHS= $(PWD)/one:$(PWD)/two
OBJS = $(SOURCES:.c=.o)
.PHONY: all
all: $(DIRS) target
.PHONY: $(DIRS)
$(DIRS):
$(MAKE) $(CFLAGS) --directory=$@
target: $(OBJS)
# for d in $(DIRS); do (cd $$d; OBJS=$(wildcard *.o)); done#
# @echo $(OBJS)
# $(CC) $(CFLAGS) -o bin/oas -I .
clean:
@echo "Cleaning up..."
for d in $(DIRS); do (cd $$d; $(MAKE) clean); done
And makefile in each subfolder 'one' and 'two' looks like:
Code:
SRCS=$(wildcard *.c)
ifndef NDEBUG
BUILD_TYPE=debug
else
BUILD_TYPE=release
endif
#OBJS =$(addprefix $(OS_TARGET)/$(BUILD_TYPE)/, $(SRCS:.c=.o))
OBJS = $(SRCS:.c=.o)
.PHONY: all
all: os_target build place
os_target:
ifeq ($(OS_TARGET),)
@echo "No OS target supplied... aborting."
@exit 1
endif
mkdir -p $(OS_TARGET)/$(BUILD_TYPE)
build: $(OBJS)
@echo "*** Compiling $(CURDIR) for $(OS_TARGET) ***"
$(MAKE) $(OBJS) $(CFLAGS)
place:
mv -f *.o $(OS_TARGET)/$(BUILD_TYPE)
@echo "*** Compiling $(CURDIR) for $(OS_TARGET) COMPLETED ***"
clean:
ifeq ($(OS_TARGET),)
@echo "No OS target supplied... aborting."
@exit 1
endif
${RM} -frv $(PWD)/$(OS_TARGET)/$(BUILD_TYPE)/*.o
First problem is that if I only have variable 'DIRS = one' then I get the following output:
Code:
make -Wall -Wextra --directory=one
make[1]: Entering directory `/home/indy/development/tmp/top/one'
mkdir -p hasse/debug
cc -c -o one.o one.c
cc -c -o zero.o zero.c
*** Compiling /home/indy/development/tmp/top/one for hasse ***
make one.o zero.o
make[2]: Entering directory `/home/indy/development/tmp/top/one'
make[2]: `one.o' is up to date.
make[2]: `zero.o' is up to date.
make[2]: Leaving directory `/home/indy/development/tmp/top/one'
mv -f *.o hasse/debug
*** Compiling /home/indy/development/tmp/top/one for hasse COMPLETED ***
make[1]: Leaving directory `/home/indy/development/tmp/top/one'
It seems to try to compile twice. I don't understand why. If I change variable 'DIRS = one two'. The make goes one in infinite loop. I guess the problem is related to same error. Anyone can see why?
Thanks a million.
Indy