c++ - help with make file -


i have make file this....... of files in main directory , others in tests directory..

vpath = tests  objects = main.o script.o factory.o serve.o enter.o\            login.o notify.o check.o script : $(objects)     g++ $(objects) -lcurl -o script  main.o : script.h script.o : enter.h login.h factory.h factory.o : check.h notify.h serve.h check.o : serve.o : check.h notify.o : enter.o : check.h login.o : check.h  .phony : clean clean :     -rm *.o script 

i want make save object files directory cpp file comes from.. i.e. if script.cpp inside tests folder, want script.o tobe inside tests folder.. saves file inside main folder..

thanks in advance..

edit 1: need add files lateron tests folder.. there way make makefile recognise new files have been added , compile them also?

instead of hard-coding list of files build, can use wildcard find source files. can use substitution convert list of object files. provide generic rule building .c .o , should set.

files_to_build := $(wildcard *.c) $(wildcard tests\*.c) objects_files  := $(patsubst %.c,%.o,$(files_to_build))  %.o: %.c     $(cc) $(copts) $^ # or whatever compiler line  script: $(object_files)     g++ $^ -lcurl -o $@ 

i haven't tested makefile (it's off top of head) should give start with.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -