If you want to use implicit rules to generate the goals you want, all you need to do is not write the rules for this goal. So, make will try to automatically derive the rules and commands that produce this goal, and if make can automatically deduce the rules and commands that generate the target, then this behavior is the automatic derivation of the implied rules. The implied rule is something that make a prior agreement.For example, we have the following one makefile:foo:foo.o bar.occ–o foo foo.o bar.o $ (CFLAGS) $ (ldflags) and there are no rules to write foo.o and BAR.O, and make will automatically introduce a lot of implied regulationsare defined by using the suffix rule, the default is to find the dependent file until you find The default list of suffixes is:. Out,. A,. LN,. O,. C,. CC,. C,. P,. F,. F,. R,. Y,. L,. S,. S,. MoD,. Sym,. def,. h,. info,. DVI,. Tex,. Texinfo,. Texi,. Txinfo,. W,. Ch. Web,. SH,. ELC,. El in the example above, make will find the "foo.o bar.o" dependent file "foo.c bar.c" if there is no "foo.cc bar.cc" ... Common implicit rules 1. Compile the implicit rules of C program. The target of ". O" is automatically deduced as ". C" and its generated command is"$ (CC) –c $ (cppflags) $ (CFLAGS)"2. Compile the implicit rules of C + + program. The target of ". O" is automatically deduced as ". CC" or ". C ", and its build command is"$ (CXX) –c $ (cppflags) $ (CFLAGS)"(". CC" is recommended as the suffix of the C + + source file instead of ". C ")3. Compile the implied rules of Pascal program. The target of ". O" is automatically deduced as ". P" and its generated command is"$ (PC) –c $ (pflags)"。4, compile the Fortran/ratfor program of the implicit rules. The target of ". O" is automatically deduced as ". R" or ". F "or". F ", and its generated commands are:". F" "$ (FC) –c $ (fflags)"". F "" $ (FC) –c $ (fflags) $ (cppflags) "". R" "$ (FC) –c $ (fflags) $ (rflags)"5, Pre-processing Fortran/ratfor program implicit rules. The target's dependent target for ". F" is automatically deduced as ". R" or ". F ". This rule simply converts ratfor or has a pre-processed FORTRAN program to a standard FORTRAN program. The commands it uses are:". F "" $ (FC) –F $ (cppflags) $ (fflags) "". R" "$ (FC) –F $ (fflags) $ (rflags)"6, compile the Modula-2 program of the implicit rules. The target dependent target for ". Sym" is automatically deduced as ". Def" and its build command is: "$ (M2C) $ (m2flags) $ (defflags)". The target of "" is automatically deduced as ". MoD" and its generated commands are:"$ (m2c) $ (m2flags) $ (modflags)"7, compilation and compilation of the implicit rules of preprocessing. The target's dependent target for ". O" is automatically deduced as ". S", which uses the compiled product "as" by default, and its generated command is: "$ (AS) $ (asflags)". The target of ". S" is automatically deduced as ". S ", the C pre-compiler" CPP "is used by default, and its generated commands are:"$ (AS) $ (asflags)"8. Link the implicit rules of the object file. The target relies on ". O" to run the linker generation (typically "LD") by running the C compiler, whose generated commands are:"$ (CC) $ (ldflags)." O $ (loadlibes) $ (ldlibs) "。 This rule is valid for projects with only one source file, and also for multiple object files (generated by different source files). For example, the following rule: x:y.o z.o and "x.c", "y.c", and "z.c" are present, the implied rule executes the following command: Cc-c x.c-o x.occ-c y.c-o y.occ-c z.c-o z.occ x.o y.o z.o-o XR M-f x.orm-f y.orm-f Z.O If you don't have a source file (like the one in the previous example) associated with your target name (as in the example above), then you'd better write your own build rule, otherwise the implied rule will report an error.9, YACC C program when the implied rules. The ". C" Dependent file is automatically deduced as "N.Y" (the YACC generated file), and its generated commands are:"$ (YACC) $ (YFALGS)"("Yacc" is a parser, for details please see the relevant information)10, Lex C program when the implied rules. The dependent file ". C" is automatically deduced as "N.L" (the lex-generated file), and its generated commands are:"$ (LEX) $ (LFALGS)"(For details on "Lex", please refer to the relevant information)11, Lex ratfor Program when the implicit rules. The dependent file for ". R" is automatically deduced as "N.L" (the lex-generated file), and its generated commands are:"$ (LEX) $ (LFALGS)" 12. Create an implicit rule for the lint library from a C program, a YACC file, or a lex file. The dependent file for ". Ln" (lint generated file) is automatically deduced as "N.C", and its generated commands are:"$ (LINT) $ (LINTFALGS) $ (cppflags)-I"(The same rules apply to ". Y" and ". L"). ) Here are the variables that are used in all implied rules: 1. Variables about the commandARfunction Library Packager. The default command is "AR". asAssembly language Compiler program. The default command is "as". CCC language Compiler program. The default command is "CC". CXXC + + language compiler program. The default command is "g++". The CO extends the file program from the RCS file. The default command is "CO".CPPC program's preprocessor (output is standard output device). The default command is "$ (CC) –E".FCFortran and Ratfor compilers and pre-processing programs. The default command is "F77".GETThe program that extends the file from the SCCs file. The default command is "get".LEXLex Method Parser Program (for C or ratfor). The default command is "Lex".PCPascal language Compiler program. The default command is "PC".YACCYACC Grammar Analyzer (for C programs). The default command is "YACC".YACCRYACC Grammar Analyzer (for ratfor programs). The default command is "Yacc–r".MakeinfoConvert texinfo source file (. texi) to info file program. The default command is "Makeinfo".TEXA program for creating Tex-DVI files from Tex source files. The default command is "Tex".Texi2dviCreate an Army Tex DVI file from the Texinfo source file program. The default command is "Texi2dvi".WEAVEConvert the Web to Tex program. The default command is "weave".CweaveConvert the C WEB to Tex program. The default command is "Cweave".TangleConvert the Web to Pascal language program. The default command is "Tangle".CtangleConvert c Web to C. The default command is "Ctangle".RMThe delete file command. The default command is "Rm–f".2. Variables for command parametersThe following variables are all parameters related to the command above. If the default value is not specified, the default value is null.ArflagsParameters of the Function Library Packager ar command. The default value is "rv".Asflagsassembly language compiler parameters. (when obviously called ". S" or ". S "file).CFLAGSC language Compiler parameters.CxxflagsC + + language compiler parameters.CoflagsRCS command parameters.CppflagsC Preprocessor parameters. (The C and Fortran compilers are also used).fflagsFortran language compiler parameters.GFLAGSSCCS "Get" program parameters.LdflagsLinker parameters. (eg: "LD")lflagsLex Grammar parser parameter.PflagsPascal language compiler parameter.RflagsThe Fortran compiler parameter for the RATFOR program. YflagsYACC Grammar Analyzer parameters.
Makefile implied rules and default variables used