Help with makefile using subdir for object files

I'm trying to rewrite some Makefiles to allow for intermediate files to be stored in an object subdirectory (./obj) and final executables to be stored in ./bin. However, make doesn't seem to like what I've done. Any ideas on how I could fix this?

Here is one of the simpler Makefiles after I've made modifications:

CC = gcc
CFLAGS = -Wall -s -O2

OBJDIR = obj
BINDIR = bin
kpengine = $(BINDIR)/kpengine
mkdircmd = mkdir -p

kpadsources = $(shell ls -t kanjipad/*.c) # Compile most recently edicted files first.
kpadobjects = $(sources:%.c=$(OBJDIR)/%.o)

$(kpengine) : $(kpadobjects)
    $(mkdircmd) $(BINDIR)/kanjipad
    $(CC) $(CFLAGS) -o $(kpengine) $(OBJDIR)/kanjipad/kpengine.o $(OBJDIR)/kanjipad/scoring.o $(OBJDIR)/kanjipad/util.o

$(OBJDIR)/kanjipad/%.o: kanjipad/%.c
    $(mkdircmd) $(OBJDIR)/kanjipad
    $(CC) $(CFLAGS) -c -o $@ -DFOR_PILOT_COMPAT -Ikanjipad $<

And here's the output:

mkdir -p bin/kanjipad
gcc -Wall -s -O2 -o bin/kpengine obj/kanjipad/kpengine.o obj/kanjipad/scoring.o obj/kanjipad/util.o
gcc: obj/kanjipad/kpengine.o: No such file or directory
gcc: obj/kanjipad/scoring.o: No such file or directory
gcc: obj/kanjipad/util.o: No such file or directory
gcc: no input files
make: *** [bin/kpengine] Error 1

0

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Help with makefile using

I think it might be a simple fix:

kpadobjects = $(sources:%.c=$(OBJDIR)/%.o)

should read

kpadobjects = $(kpadsources:%.c=$(OBJDIR)/%.o)

Help with makefile using

Yeah, that was wrong... there was a number of other things too; I rearranged my subdirs a bit and missed some of the old references. Fixed those, and it works now. Thanks for pointing out my PEBKAC there. :P

Syndicate content