c - Compile and link a source file containing object files to another data structure -
this current makefile:
cc=gcc include=./structures/ cflags=-wall -i$(include) objs=rlmain.o rlist.o queue.o .phony: clean all: rlmain queue.o: $(include)queue.c $(include)queue.h $(cc) $(cflags) -c $(include)queue.c -o queue.o rlist.o: $(include)rlist.c $(include)rlist.h $(cc) $(cflags) -c $(include)rlist.c -o rlist.o rlmain: main.c rlist.o queue.o $(cc) $(cflags) main.c rlist.o queue.o -o rlmain clean: rm -f *.o rlmain
makefile in top directory. in lower directory called "structures" collection of files data structures. data structures implement ready list - linked list of queues.
i managed queue.o working using '-c' cannot rlist.o make because rlist.c not contain main method, , must link queue.o functions. i'm using command make
everything else working except command. want write command tell compiler link queue.o functions rlist.c compilation not compile functions require main(). do in order make happen?
note: `<tab>` needs replaced tab character note: use `:=` when defining macros, evaluated once # select specific external executables run cc := /usr/bin/gcc rm := /usr/bin/rm include := ./structures/ cflags := -c -wall -wextra -pedantic -wconversion -std=gnu99 objs := main.o rlist.o queue.o .phony: clean all: rlmain queue.o: $(include)queue.c $(incs) <tab>$(cc) $(cflags) $< -o $@ -i$(include) rlist.o: $(include)rlist.c $(incs) <tab>$(cc) $(cflags) $< -o $@ -i$(include) main.o: $(include)main.c $(incs) <tab>$(cc) $(cflags) $< -o $@ -i$(include) rlmain: $(objs) <tab>$(cc) $(objs) $(lflags) clean: <tab>$(rm) -f *.o rlmain
--edit-- following added -- following of more common gnu make
utility macros
$@ <<-- name left of colon on `rule` file name of target. $% target member name, when target archive member. $< <<-- use reference first dependency on `rule` name of first prerequisite. $? <<-- more reliable method reference first dependency on `rule` names of prerequisites newer target, spaces between them. prerequisites archive members, named member used (see archives). $^ $+ names of prerequisites, spaces between them. prerequisites archive members, named member used (see archives). value of $^ omits duplicate prerequisites, while $+ retains them , preserves order. $* stem implicit rule matches (see how patterns match). $(@d) $(@f) directory part , file-within-directory part of $@. $(*d) $(*f) directory part , file-within-directory part of $*. $(%d) $(%f) directory part , file-within-directory part of $%. $(<d) $(<f) directory part , file-within-directory part of $<. $(^d) $(^f) directory part , file-within-directory part of $^. $(+d) $(+f) directory part , file-within-directory part of $+. $(?d) $(?f) directory part , file-within-directory part of $?.
Comments
Post a Comment