In a recent issue, I’ve found that DJGPP can only accept the DOS command line character limit. To work around this limitation, I’ve decided to try to write a makefile to allow me to pass longer strings. In the process of hacking together a makefile and testing it, I’ve come across a strange error. The makefile is as follows:
AS := nasm CC := gcc LD := ld TARGET := $(shell basename $(CURDIR)) BUILD := build SOURCES := source CFLAGS := -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions \ -nostdinc -fno-builtin -I./include ASFLAGS := -f aout export OUTPUT := $(CURDIR)/$(TARGET) CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) SOBJS := $(SFILES:.s=.o) COBJS := $(CFILES:.c=.o) OBJS := $(SOBJS) $(COBJS) build : $(TARGET).img $(TARGET).img : $(TARGET).bin concat.py $(TARGET).bin : $(OBJS) $(LD) -T link.ld -o $@ $^ $(SOBJS) : %.o : %.asm $(AS) $(ASFLAGS) $< -o $@ $(COBJS) : %.o : %.c $(CC) -c $< $(CFLAGS) -o $@
When attempting to run it, I receive this error:
make: *** No rule to make target `consoleio.c', needed by `consoleio.o'. Stop.
What I don’t understand is why it’s trying to find a rule for .c files. From what I understand, if the file is there, it should just use it. How do I make make not need a rule for .c files?
What you are trying to do will not work without VPATH, and since you are still learning makefiles, I would avoid using VPATH.
The rule is looking for ‘consoleio.c’, which if I understood your makefile correctly does not exist; what exists is ‘source/consoleio.c’. You probably should change it to something like ‘$(SOURCES)/%.c’ instead of ‘%c’.
I didn’t check your syntax for that rule, however. If it’s incorrect, the builtin ‘%.o: %.c’ rule will be used instead, which would have the same problem.
The way you are doing is not the usual way I’ve seen, however. The usual way is to: