Makefile: Remove single object file - makefile

I want to delete one single object file version.o from the directory myobj_x.
I used the following command:
(tab)-rm obj_kt_rfgw/version.o
But now i getting an error:
Makefile:8: *** commands commence before first target. Stop.

Related

Is there a way to get if a recipe for a target failed or succeded into a variable?

I wanted to get if a recipe for a target failed or succeded into a variable. Is there a way I can do it? My final purpose is to be able to print a modified(or aditional) message instead of the message error that is shown if the recipe fails :
path: reciped for target X failed
make: *** [path] Error 1
Not really.
GNU Make communicates with external environment only by files, so what you could do is write the message to file as part of the recipe.

Excecuting make is creating object file in wrong folder

I am new to ubuntu and hence to make file. I have successfully created make file with folder structure. However, if I add the similar structure, I get an error.
I successfully executed make command and ran application with one main cpp file and two files (list_menu.cpp and list_menu.h ) in sub folder cpp11_and_cpp14_menu
folder structure looks exactly like below where cpp11_and_cpp14.cpp has the main function.
../advancedcppproject/
cpp11_and_cpp14.cpp
Makefile
../advancedcppproject/cpp11_and_cpp14_menu
list_menu.cpp
list_menu.h
../advancedcppproject/multi_threading_example
multi_threading.cpp
multi_threading.h
Make file contents are
cpp11_and_cpp14 : cpp11_and_cpp14.o ./multi_threading_example/multi_threading.o ./cpp11_and_cpp14_menu/list_menu.o
g++ cpp11_and_cpp14.o ./multi_threading_example/multi_threading.o ./cpp11_and_cpp14_menu/list_menu.o -o cpp11_and_cpp14
cpp11_and_cpp14.o : cpp11_and_cpp14.cpp ./cpp11_and_cpp14_menu/list_menu.h ./multi_threading_example/multi_threading.h
g++ -c cpp11_and_cpp14.cpp
./cpp11_and_cpp14_menu/list_menu.0 : ./cpp11_and_cpp14_menu/list_menu.cpp ./cpp11_and_cpp14_menu/list_menu.h
g++ -c ./cpp11_and_cpp14_menu/list_menu.cpp
./multi_threading_example/multi_threading.o : ./multi_threading_example/multi_threading.cpp ./multi_threading_example/multi_threading.h
g++ -c ./multi_threading_example/multi_threading.cpp
After executing make command, it fails with an error message
g++ -c ./multi_threading_example/multi_threading.cpp
g++ cpp11_and_cpp14.o ./multi_threading_example/multi_threading.o ./cpp11_and_cpp14_menu/list_menu.o -o cpp11_and_cpp14
g++: error: ./multi_threading_example/multi_threading.o: No such file or directory
Makefile:6: recipe for target 'cpp11_and_cpp14' failed
make: *** [cpp11_and_cpp14] Error 1
I expect multi_threading.o to be created under folder ../advancedcppproject/multi_threading_example. However multi_threading.o is created under ../advancedcppproject.
Where as list_menu.o is correctly created under ../advancedcppproject/cpp11_and_cpp14_menu.
What is wrong?

Make threw out an error but no detailed error message

Here's the last few lines from the output of running "make install" at root level /home/gm/TEST/:
make[3]: Leaving directory `/home/gm/TEST/tppf/tm/ipmgt'
ld ipfac.o ipfacV.o ipfac_rset.o ipfac_args.o ipfac_d2a.o ipfac_a2d.o ipfac_modr.o ipfac_mod.o ipfac_read.o ipfac_add.o ipfac_del.o ipfac_list.o ipfac_unlk.o ipfac_lock.o ipfac_util.o ipfac_lkid.o -r -o /home/gm/TEST/tppf/lib/ipfac_tppf.o
make[3]: Leaving directory `/home/gm/TEST/tppf/tm/ipfac'
make[2]: Leaving directory `/home/gm/TEST/tppf/tm'
make[1]: *** [i_tm] Error 2
make[1]: Leaving directory `/home/gm/TEST/tppf'
make: *** [i_tppf] Error 2
And the Makefile under /home/gm/TEST/tppf/tm/ipfac contains this rule:
install: ipfac.h $(TPPLIB)/ipfac_tppf.o
$(TPPLIB)/ipfac_tppf.o: $(PROPOBJS)
ld $(PROPOBJS) -r -o $(TPPLIB)/ipfac_tppf.o
Is there something wrong with the linking process? Make should've told me what the error actually is, but it didn't.
BTW, I think /home/gm/TEST/tppf/lib/ipfac_tppf. O was linked and created successfully, or at least it was there in directory /home/gm/TEST/tppf/lib/ after make failed and exited.
That line is not the error line. You can tell that it succeeded because there was no error message there, for building the target /home/gm/TEST/tppf/lib/ipfac_tppf.o.
The error is here:
make[1]: *** [i_tm] Error 2
The [1] means that it was the first level of makefile (note the recipe you are quoting here was in the 3rd level of makefile) and the [i_tm] means that the build of the target i_tm failed. You need to look back up further in the output of make, earlier than what you've shown us, and find the *** error line for building the i_tm target and see what errors were generated there.

why is gcc gets executed in this make file?

I have the following makefile when type make i got the following output. why is gcc gets called in this case?
nasm -felf ./source/multiboot.s
gcc multiboot.o -o multiboot
gcc: error: multiboot.o: No such file or directory
gcc: fatal error: no input files
compilation terminated.
make: *** [multiboot] Error 4
makefile:
CC=gcc
ASM=nasm
ASMFLAG=-felf
SOURCE=./source/
all: multiboot
multiboot.o: $(SOURCE)multiboot.s
$(ASM) $(ASMFLAG) $(SOURCE)multiboot.s
The "all" command depends on "multiboot", but there is no explicit rule defining how to produce "multiboot". In this case, Make uses a predefined rule that understands that, if the "$target.o" target exists, then "$target" can be constructed from "$target.o" by running the linker (in this case, GCC).
It seems like the problem in this case is that your instructions for the "multiboot.o" command does not actually produce the file "multiboot.o" as output. Try simply doing:
multiboot.o: multiboot.s
(That is, without specifying the command to run). Simply declaring this dependency should, by a similar mechanism, result in an implicit rule/command to create the "multiboot.o" output from "multiboot.s".

Specifying different GNUmakefile for GNU make command

I have two GNUmakefiles in my directory as follows,
GNUmakefile &
GNUmakefile2
Could someone please let me know the command I have to use, if I have to let the "make" command to process "GNUmakefile2" instead of "GNUmakefile".
I used the below command,
make -f GNUmakefile2
but in that case, I am getting the following errors,
This is gnustep-make 2.6.1. Type 'make print-gnustep-make-help' for help.
make[1]: ** No rule to make target `internal-master-tool-all'. Stop.*
make: ** [internal-all] Error 2*
I think it is considering GNUmakefile as makefile (when I use make with -f command), so it is checking for rules in GNUmakefile.
At present what I am doing is I am renaming the required file (which I want, make command to execute) to "GNUmakefile". And I am not getting any errors while executing "make" command, but I don't think this is the correct solution.
Please let me know which command I need to use for this scenario. Thanks for your help.
After checking Beta's solution (i.e.,but that makefile is invoking Make a second time, and the second Make process is probably reading GNUmakefile) what I have done is I renamed existing "GNUmakefile" to "GNUmakefile3".
So at present in my directory the following makefiles are present:- "GNUmakefile2" & "GNUmakefile3".
And then I executed the following command:- $ make -f GNUmakefile2
I recieved the below errors,
This is gnustep-make 2.6.1. Type 'make print-gnustep-make-help' for help.
make[1]: GNUmakefile: No such file or directory
make[1]: * No rule to make target `GNUmakefile'. Stop.
make: * [internal-all] Error 2
Please let me know what is the problem here
Your makefile includes two huge makefiles from the FSF. The second, library.make, contains this rule:
ifeq ($(GNUSTEP_MAKE_PARALLEL_BUILDING), no)
# Standard building
...
else
# Parallel building. ...
internal-library-all_:: $(GNUSTEP_OBJ_INSTANCE_DIR) $(OBJ_DIRS_TO_CREATE)
$(ECHO_NOTHING_RECURSIVE_MAKE)$(MAKE) -f $(MAKEFILE_NAME) ...
endif
and the first, common.make contains this assignment:
# The default name of the makefile to be used in recursive invocations of make
ifeq ($(MAKEFILE_NAME),)
MAKEFILE_NAME = GNUmakefile
endif
So try either make -f GNUmakefile2 GNUSTEP_MAKE_PARALLEL_BUILDING=no or make -f GNUmakefile2 MAKEFILE_NAME=GNUmakefile2, and see if that solves the problem.

Resources