1
votes

i'm new to Makefile. I've to write a Makefile to build a shared libary.

CC =g++
CFLAGS =-fPIC -Wall -Wextra -c
LDFLAGS =-shared
RM =rm -rf
TARGET_LIB =lib/Automat.so

SRC_DIR =src/
LIB_DIR =lib/
DEP_DIR =dep/

SRCS=IFSM.h IState.h ITransition.h FSM.h State.h Transition.h Wildcard.h PrimeTransition.h SingleTransition.h Exception.h Type.h Error.h
OBJS=$(SRCS:.h=.o)

.PHONY: all
all: $(TARGET_LIB)

$(TARGET_LIB): $(SRC_DIR)$(OBJS)
    $(CC) $(LDFLAGS) -o $@ $^

$(SRC_DIR)$(SRCS:.h=.d):%.d:$(SRC_DIR)%.h
    $(CC) $(CFLAGS) -MM $< > $(DEP_DIR)$@

include $(SRCS:.h=.d)

My problem is that i get the error

No rule to make target `IFSM.d'. Stop.

If i remove to file from SRCS the problem occurs with IState.d. All other .d files where builded correct (11 of 12).

All files exists and they are written correct (case-sensitiv).

I rly don't know where the error could be and i was searching for 2 hours now.

Any help would be great.

Best regards Alex

2

2 Answers

2
votes

You are including

$(SRCS:.h=.d)

that is, files called whatever.d in the local directory; but you have a rule to make

$(SRC_DIR)$(SRCS:.h=.d)

that is, files called src/whatever.d.

You need to decide where these files should live, and make both rules match.

0
votes

Make sure that you are using tabs for indentation. Such mysterious failures are usually caused by using spaces, which are not supported by make.