Thank you for this article "resolved" Makefile:xxx:recipe for target XXX failed + "Incidentally understand" how to ignore the Makefile execution of some of the command errors and continue to run

Source: Internet
Author: User
Tags echo command

Reprinted from http://www.crifan.com/make_makefile_recipe_for_target_failed_omit_error_while_executing_makefile/




Problem

In Cygwin, execute makefile, which calls HHC to generate the CHM file from the hhp file.

The last step of the result is an error:

ADMINISTRATOR@K470/CYGDRIVE/E/DEV_ROOT/DOCBOOK/DEV/BOOKS/VBR/SRC
$ make chm ...
Created e:\Dev_Root\docbook\dev\books\VBR\output\htmlhelp\MPEG_VBR.chm, 181,978 bytes
Compression decreased File by 70,718 bytes.
Makefile:131:recipe for Target '. /output/htmlhelp/mpeg_vbr.chm ' failed make
: * * * [.. /output/htmlhelp/mpeg_vbr.chm] Error 1

However, it is strange that the corresponding required file Mpeg_vbr.chm, have been successfully generated, but there is still error.

The corresponding makefile source code is:

$ (Output_file_chm): $ (output_file_htmlhelp) $ (output_dir_chm)/htmlhelp.hhp $ (output_dir_chm)/TOC.HHC
	iconv-f UTF-8-T GB18030 < $ (output_dir_chm)/htmlhelp.hhp > $ (output_dir_chm)/HTMLHELP_GB18030.HHP
	MV $ (output_dir_ CHM)/htmlhelp_gb18030.hhp $ (output_dir_chm)/htmlhelp.hhp
	iconv-f UTF-8-T GB18030 < $ (output_dir_chm)/TOC.HHC > $ (output_dir_chm)/TOC_GB18030.HHC
	mv $ (output_dir_chm)/TOC_GB18030.HHC $ (output_dir_chm)/TOC.HHC
	echo "---before HHC"
	HHC $ (output_dir_chm)/htmlhelp.hhp
	echo "+++after HHC"

Chm:clean_chm $ (output_file_ CHM)

"Resolution Process"

1. Think it is the iconv in the above causes the error, the result is removed less than the number, or the same error.

2. Then add the above echo command, the result is HHC after that sentence: +++after HHC, is not shown, confirmed that the HHC command itself execution result is wrong, so HHC execution error, return to makefile, and then makefile reported above recipe For Target failed error.

3. It is strange, however, that the above-mentioned HHC command, which is executed separately from the Cygwin command, shows nothing wrong. It is estimated that the return value is incorrect and no one is capturing it, so you don't know the error.

4. Then I wanted to find a way to get the results from the last command line execution from makefile, but I couldn't get it because I couldn't execute the latter sentence of HHC.

5. Then think of itself HHC command although error, but the purpose has been achieved, has been able to generate the CHM normally, so, here to find ways to go in the makefile execution process, ignore this error can be.

Then we find a lot of information, such as here:

There is also a global way to add "-I" or "–ignore-errors" parameters to make, then all the commands in makefile will ignore the error. And if a rule is to ". IGNORE "as the target, then all commands in this rule will ignore the error. These are different levels of methods for preventing command errors, which you can set according to your preferences.

Another way to mention the make parameter is "-K" or "–keep-going", which means that if a command in a rule goes wrong, the rule is executed, but the other rules are executed.

The result is to say how to ignore the whole error, so it doesn't fit the requirements here.

Then finally found: Makefile's variables, which spoke of:

Two special characters in the makefile can be added before the command to execute: - : Make ignores the wrong command. If you want to produce a record, but want to ignore the bug, it may be because the recording already exists.

-mkdir/usr/local/repository



If you want to clear the target file, but want to ignore the bug, it may be because the file does not exist.

Clean:
   -rm main.o 2.o 3.o



@: Make does not display the command to execute on the standard output. The sentence break if starts with the symbol @, allowing make to stop printing the printed text when it performs the act.

Install:myapp
   @if [-D $ (instdir)]; \ then
    \
      ...; \
   fi

That is, the corresponding command preceded by a minus sign '-', you can ignore the error of the command, the subsequent command can continue to execute.

So, finally, using:

	-HHC $ (output_dir_chm)/htmlhelp.hhp

You can achieve the desired effect. In this way, the makefile execution process is not interrupted by the HHC error.

Although the problem is fixed here, but the root cause of the specific error is unclear, so try to figure out why it is wrong.

Then, about the return value of things, the last use:

	echo "---Before HHC" # Here's use
	'-' to ignore the HHC error
	-HHC $ (output_dir_chm)/htmlhelp.hhp
	echo $?
	echo "+++after HHC"

The result of the test is:

Makefile:131:recipe for Target '. /output/htmlhelp/mpeg_vbr.chm ' failed make
: [.. /output/htmlhelp/mpeg_vbr.chm] Error 1 (ignored)
Echo: /output/htmlhelp/mpeg_vbr.html. /OUTPUT/HTMLHELP/HTMLHELP.HHP. /OUTPUT/HTMLHELP/TOC.HHC.
/output/htmlhelp/mpeg_vbr.html. /OUTPUT/HTMLHELP/HTMLHELP.HHP. /OUTPUT/HTMLHELP/TOC.HHC
echo "+++after HHC"
+++after HHC

It looks as if the value returned by HHC is:

.. /output/htmlhelp/mpeg_vbr.html. /OUTPUT/HTMLHELP/HTMLHELP.HHP. /OUTPUT/HTMLHELP/TOC.HHC. /output/htmlhelp/mpeg_vbr.html. /OUTPUT/HTMLHELP/HTMLHELP.HHP. /output/htmlhelp/toc.hhc

The results are then tossed:

ADMINISTRATOR@K470/CYGDRIVE/E/DEV_ROOT/DOCBOOK/DEV/BOOKS/VBR/SRC $ Iconv1retcode= ' iconv-f UTF-8-T GB18030 <. /OUTPUT/HTMLHELP/HTMLHELP.HHP >. /OUTPUT/HTMLHELP/HTMLHELP_GB18030.HHP ' ADMINISTRATOR@K470/CYGDRIVE/E/DEV_ROOT/DOCBOOK/DEV/BOOKS/VBR/SRC $ echo $ Iconv1retcode administrator@k470/cygdrive/e/dev_root/docbook/dev/books/vbr/src $ Mv1Retcode= ' mv. /OUTPUT/HTMLHELP/HTMLHELP_GB18030.HHP.


/OUTPUT/HTMLHELP/HTMLHELP.HHP ' Administrator@k470/cygdrive/e/dev_root/docbook/dev/books/vbr/src $ echo $mv 1Retcode
ADMINISTRATOR@K470/CYGDRIVE/E/DEV_ROOT/DOCBOOK/DEV/BOOKS/VBR/SRC $ echo $? 0 ADMINISTRATOR@K470/CYGDRIVE/E/DEV_ROOT/DOCBOOK/DEV/BOOKS/VBR/SRC $ iconv-f UTF-8-T GB18030 <. /OUTPUT/HTMLHELP/TOC.HHC >.
/OUTPUT/HTMLHELP/TOC_GB18030.HHC ADMINISTRATOR@K470/CYGDRIVE/E/DEV_ROOT/DOCBOOK/DEV/BOOKS/VBR/SRC $ echo $? 0 ADMINISTRATOR@K470/CYGDRIVE/E/DEV_ROOT/DOCBOOK/DEV/BOOKS/VBR/SRC $ mv. /OUTPUT/HTMLHELP/TOC_GB18030.HHC. /OUTPUT/HTMLHELP/TOC.HHC administrator@K470/CYGDRIVE/E/DEV_ROOT/DOCBOOK/DEV/BOOKS/VBR/SRC $ echo $? 0 ADMINISTRATOR@K470/CYGDRIVE/E/DEV_ROOT/DOCBOOK/DEV/BOOKS/VBR/SRC $ HHC. /OUTPUT/HTMLHELP/HTMLHELP.HHP Microsoft HTML help Compiler 4.74.8702 compiling e:\Dev_Root\docbook\dev\books\VBR\
Output\htmlhelp\mpeg_vbr.chm index.html ... Created e:\Dev_Root\docbook\dev\books\VBR\output\htmlhelp\MPEG_VBR.chm, 181,978 bytes Compression decreased file by

70,718 bytes.
ADMINISTRATOR@K470/CYGDRIVE/E/DEV_ROOT/DOCBOOK/DEV/BOOKS/VBR/SRC $ echo $? 1

Confirmed that the original Linux, such as the following commands, such as ICONV,MV, execution results, if there is no error, will return 0, indicating normal, and here HHC is a tool under Windows, its return 1 indicates that the execution result is normal, resulting in makefile received 1, Thought that the program was executed incorrectly, so the error:

Makefile:131:recipe for Target '. /output/htmlhelp/mpeg_vbr.chm ' failed

And that's error 1:

Make: [.. /output/htmlhelp/mpeg_vbr.chm] Error 1 (ignored)

Summary

The phenomenon here is the makefile execution process recipe for target XXX failed error, causing the execution process to break.

The direct reason is because the HHC command executes the wrong result.

And the reason is that the HHC command, which is a tool belonging to Microsoft (under Windows), is called by Cygwin, and then its return value is 1, (should be) indicates that the result is executed correctly, but the result is mistaken for the makefile under Linux.

Because the general program under Linux is a return value of 0 indicates that program execution is normal.

As a result, the tools used belong to different platforms and are not fully compatible.

The workaround here is to precede the corresponding HHC command with a minus sign, indicating that makefile executes the command, even if the command is wrong, you can ignore the command's error, and you can continue to execute the remaining other commands so that makefile can continue to execute normally.

So, if someone else encounters a similar problem:

One is to be careful, is not the use of different platform tools to cause the incompatibility problem

The second is that you can add a minus sign to a related command by makefile (intentionally) ignoring the (possible) errors of certain commands, which allows makefile to continue running even if there are (no serious) errors.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.