0
votes

I am trying to run my makefile using make run but its getting some errors : "No rule to make target 'put.h', needed by 'straps.o'. Stop". The error is about GCC can't find the headers file(put.h) when running makefile with the text below :

In kernel directory's Makefile

VPATH=../../include
all : straps.o entry.o head.o
straps.o : straps.c put.h
     $(GCC) -c straps.c $(CFLAG)
entry.o : entry.S 
     $(GCC) -c entry.S $(CFLAG) 
head.o : head.S 
     $(GCC) -c head.S $(CFLAG)

(straps.c include"put.h" so i need to include put.h) I am trying to include headers file in the gcc command line (by using $(GCC) -c straps.c $(CFLAG) -I../include) but still not working. Can anyone explain why I am getting this error and suggest a fix solution if possible. Thank you

My file list

Linux
├── arch
│   └── riscv
│       ├── kernel
│       │   ├── entry.S
│       │   ├── head.S
│       │   ├── Makefile
│       │   ├── straps.c
│       │   └── vmlinux.lds
│       └── Makefile
├── include
│   ├── put.h
│   └── test.h
├── init
│   ├── main.c
│   ├── Makefile
│   └── test.c
├── lib
│   ├── Makefile
│   └── put.c
└── Makefile

Main Makefile gives the variable as below :

export
CROSS_= riscv64-unknown-elf-
AR=${CROSS_}ar
GCC=${CROSS_}gcc
LD=${CROSS_}ld
OBJCOPY=${CROSS_}objcopy
ISA ?= rv64imafd
ABI ?= lp64
INCLUDE = -I ../include
CF = -g -O3 -march=$(ISA) -mabi=$(ABI) -mcmodel=medany -ffunction-sections -fdata-sections -nostartfiles -nostdlib -nostdinc -static -lgcc -Wl,--nmagic -Wl,--gc-sections
CFLAG = ${CF} ${INCLUDE}

***Solution : The kernel directory's Makefile Updated as below (refers to the answer given in the post below):

VPATH = ../../../include
CFLAG += -I../../../include
all : straps.o entry.o head.o
straps.o : straps.c put.h
        $(GCC) -c straps.c $(CFLAG)
entry.o : entry.S
        $(GCC) -c entry.S $(CFLAG)
head.o : head.S
        $(GCC) -c head.S $(CFLAG)
2
Based on your makefile it looks as if you run make from within the lab2/arch/riscv/kernel directory. If that's the case shouldn't you have VPATH=../../../include ? - G.M.

2 Answers

0
votes

I think that you're assuming that VPATH is somehow related to how the compiler locates header files. That is definitely not the case. VPATH is a make construct, and controls where make looks for prerequisites of targets appearing in the makefile.

It has absolutely nothing to do with where the compiler looks to find preprocessor include files. To control that you have to add -I options to the compile line.

So for example use:

VPATH = ../../../include
CFLAG += -I../../../include
0
votes

The dependency list following "straps.o:" must refer to objects you have rules to actualy make within the makefile. In that makefile you have rules to make straps.o, entry.o, and head.o, but not put.h. Or straps.c for that matter.