Reputation: 5524
So far, I have been compiling my c and c++ (and a little glsl) project with a shell script that recompiles the whole thing even when I wanted to make a small, simple change. It started taking almost 5 seconds. I couldn't stand for that, so I turned to Makefiles. I think my Makefile is good so far except for one problem: When I convert my CSOURCES
to COBJECTS
, I don't remove the directory that the source file is in, so I get these errors:
clang: error: no such file or directory: 'lib/key_store.o'
clang: error: no such file or directory: 'lib/logger.o'
clang: error: no such file or directory: 'lib/myglutils.o'
Here's the makefile:
CC=gcc
CPPC=g++
CCFLAGS=-std=c11 -Wall -pedantic
CPPFLAGS=-std=c++11 -Wall -pedantic
INC=-Iinclude/
LDFLAGS=lib/libGLEW.a lib/libglfw3.a -framework OpenGL -framework CoreVideo -framework Cocoa -framework IOKit
CSOURCES=$(wildcard lib/*.c)
COBJECTS=$(CSOURCES:.c=.o)
CPPSOURCES=$(wildcard *.cpp)
CPPOBJECTS=$(CPPSOURCES:.cpp=.o)
TARGET=Ultra-Fighters
all: $(TARGET)
$(TARGET): $(COBJECTS) $(CPPOBJECTS)
$(CPPC) -o $@ $^ $(LDFLAGS)
%.o: %.cpp %.hpp
$(CPPC) $(CPPFLAGS) $(INC) -c $<
%.o: %.cpp
$(CPPC) $(CPPFLAGS) $(INC) -c $<
%.o: %.c %.h
$(CC) $(CFLAGS) $(INC) -c $<
%.o: %.c
$(CC) $(CCFLAGS) $(INC) -c $<
clean:
rm -f *.o
My question is: How do I remove the directory part of the path from CSOURCES
when I assign to COBJECTS
?
Upvotes: 1
Views: 4711