Zed_Blade
Zed_Blade

Reputation: 1081

Makefile .o file rule issue

I'm trying to make a simple makefile to compile a sample app that I'm developing in linux (just to learn a few things) but I'm running into a strange issue, that I don't see why it's happening..

I have this makefile:

# Easily adaptable makefile for Advanced Programming

# Compiler flags
CFLAGS=-Wall -W -g -Wmissing-prototypes

# Indentation flags
IFLAGS=-br -brs -npsl -ce -cli4

# Name of the executable
PROGRAM=ex2
# Prefix for the gengetopt file (if gengetopt is used)
PROGRAM_OPT=config
# Object files required to build the executable
PROGRAM_OBJS=debug.o ${PROGRAM_OPT}.o

# Clean and all are not files
.PHONY: clean all docs indent

all: ${PROGRAM} 

# compile with debug
debugon: CFLAGS += -D SHOW_DEBUG -g
debugon: ${PROGRAM}

${PROGRAM}: ${PROGRAM_OBJS}
    ${CC} -o $@ ${PROGRAM_OBJS}

# Generates command line arguments code from gengetopt configuration file
${PROGRAM_OPT}.h: ${PROGRAM_OPT}.ggo
    gengetopt < ${PROGRAM_OPT}.ggo --file-name=${PROGRAM_OPT}

# Dependencies
${PROGRAM_OPT}.o: ${PROGRAM_OPT}.c ${PROGRAM_OPT}.h
debug.o: debug.c debug.h
main.o: debug.h ${PROGRAM_OPT}.h

#how to create an object file (.o) from C file (.c)
.c.o:
    ${CC} ${CFLAGS} -c $<

clean:
    rm -f *.o core.* *~ ${PROGRAM} *.bak ${PROGRAM_OPT}.h ${PROGRAM_OPT}.c

indent:
    indent ${IFLAGS} *.c *.h

Once I type make, I get an error telling me that:

make: *** No rule to make target `config.c', needed by `config.o'.  Stop.

I might be missing something, but if I'm not mistaken, the line is explicitly there under PROGRAM_OPT

Here's the file list in the directory:

Upvotes: 0

Views: 589

Answers (2)

Joshua
Joshua

Reputation: 43278

I'm pretty sure ${PROGRAM_OPT}.c should not be referenced.

Upvotes: 0

Sergey L.
Sergey L.

Reputation: 22542

This says that make can't find your source file config.c. You have a rule to make config.h, but I don't see one to make config.c.

Upvotes: 1

Related Questions