Including another Makefile results in a failed build, why? -


problem

including external makefile makes stable build fail following error :

make: *** no rule make target 'build/main.o', needed 'all'. stop.

context

the context manage build of each of projects 1 makefile per project. since projects makefiles have lot of redundancy, want put common things in external makefile included in each project's makefile.

minimal example reproduce issue

in simple , minimalist example try build srcs/main.c build/main.o , try display inside variable foo in tools.mk :

folder structure :

|   makefile | +---build |       (main.o) +---mkf |       tools.mk | \---srcs         main.c 

content of makefile :

include ./mkf/tools.mk  mkfile_path :=$(realpath $(lastword $(makefile_list))) current_dir :=$(dir $(mkfile_path))  vpath = $(current_dir)/srcs ./build/%.o: %.c     @echo $< $@     gcc $< -o $@  all: ./build/main.o test     @echo done !   test:     @echo testing include : $(foo)    .phony: test 

content of tools.mk :

foo = 42 

content of main.c (basic hello world) :

# include <stdio.h> # include <stdlib.h>  int main(void) {        printf("hello, world!");     return exit_success; } /*main*/ 

now problem if place myself in root folder , type make all, build fail error mentioned above. if comment line include ./mkf/tools.mk build succeeds. guess fails because of include line, cannot figure out why.

can enlighten me on ?

the build performed gnu make 4.2 on windows 7 64-bits.

in

mkfile_path :=$(realpath $(lastword $(makefile_list))) 

that yields path of last included makefile, ./mkf/tools.mk. see other special variables details.

a fix:

mkfile_path :=$(realpath $(lastword $(makefile_list))) current_dir :=$(dir $(mkfile_path)) include ./mkf/tools.mk 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -