I am trying to learn make files.
My directory Structure is
$ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
.
|-bin
|---exe
|---obj
|-build
|-include
|-lib
|-make
|-source
What I am trying to do is place my include file conversion.h
in include
folder, all .c files
in source
, makefile
in make
, compiled all .o files
in bin/obj
and exe
in /bin/exe
I referred below posts:
makefile include *.h file in other directory
Using make to move .o files to a separate directory
my makefile is:
VPATH= ./../source
OBJDIR= ./../bin/obj
EXEDIR= ./../bin/exe
#vpath %.o $(OBJDIR)
CFLAGS= -Wall -c -I.
#INCLUDES= -I./../include
objects= binary.o hex.o octal.o
conversion: $(objects)
# gcc -Wall -o conversion $(objects) -I.
binary.o: binary.c conversion.h
gcc $(CFLAGS) $< -o $(OBJDIR)/$@
octal.o: octal.c conversion.h
gcc $(CFLAGS) $< -o $(OBJDIR)/$@
hex.o: hex.c conversion.h
gcc $(CFLAGS) $< -o $(OBJDIR)/$@
clean:
rm -rf $(OBJDIR)/*.o *.o *~ conversion
I am using cygwin. My questions are:
1) I am not able to include my conversion.h
from location ./../include
,-I.
works fine if I copy conversion.h
to make
folder
-but as soon as I replace with -I./../include
without any copy of conversion.h
in make
folder
I get below error
$ make
make: *** No rule to make target 'conversion.h', needed by 'binary.o'. Stop.
2) My makefile does place all .o
files to /bin/obj
but when I try to use vpath
as shown below (instead of using manual placement like --o $(OBJDIR)/$@
)
vpath %.o $(OBJDIR)
...
$(OBJDIR)/binary.o: binary.c conversion.h
gcc $(CFLAGS) $< -o $@
...
...
doing above replacement for all .o rules,does not place all .o files
to bin/obj
directory
Any help would be appreciated.
Thanks