Score:0

how do I modify makefile which is already compiled?

cl flag

Let's say I have a makefile which looks like this:

all: a_functions.o b_functions.o c_functions.o d_functions.o main.o
     gcc -o all a_functions.o b_functions.o c_functions.o d_functions.o main.o
a_functions.o: a_functions.c
     gcc -c -o a_functions.o a_functions.c
b_functions.o: b_functions.c
     gcc -c -o b_functions.o b_functions.c
c_functions.o: c_functions.c
     gcc -c -o c_functions.o c_functions.c
main.o: main.c
     gcc -c -o main.o main.c

I could compile it using command

sudo make -f makefile

and program works nice if I run

./all

but how to do if I want to add for example a clean command in makefile? I added

clean:
     rm *.o all

at the end of the makefile but my terminal shows

-bash: ./clean: No such file or directory

when I do ./clean

Of course recompiling makefile doesn't work either. It shows

make: 'all' is up to date.

when I do sudo make -f makefile

I found here How to edit makefile? that you can use

$ CFLAGS="-std=c99" make

this command in terminal or I can add

CFLAGS=-std=c99

in my makefile but they still show

all is up to date

the image is just evidence that modifying did not work for me.

enter image description here

Score:4
hr flag

A makefile is never compiled - it's interpreted by the make command. When you run

make

or more explicitly

make -f makefile

then by default, make builds the first target in the makefile - in this case, that's the all target. To build a non-default target, you need to name it on the command line i.e.

make clean

or

make -f makefile clean

Note that the clean target does not actually build anything, so unlike ./all there is no program like ./clean to run afterwards. In fact, you might want to declare the clean target as a phony target.

game lover avatar
cl flag
thank you! your answer helped me a lot
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.