- Motivation
- organization of modules
- cut problem and abstraction
- information hiding
- software module re-use
- programming team logistics
- multiple developers
- distinct locations
- organization of modules
- Typical case
- each module in separate source file
- include head file for a function in other source file
- Steps in software build
- Linker
- merges together independently-complied object code modules
- resolve external reference among modules
- typically loading
- output
- executable file
- dynamically loading libraries
- other


- Linker
- Makefiles
- make command control file defaults to makefile
- target
- objects(files) that must be brought up-to-date
- dependency
- list of target influence the main target
- action
- command that are executed if any of the dependency objects has a time-stamp more recent than the target
- rule
- specification of target, dependency and action.
- makefile format

- make [-f makfile] [option] [target0…..](use makefile in make command)
- all target and makefile must located in current working directory
- Phony rules
- .PHONY tell make that the rule doesn`t generate a file with the target name
- Macros
- observation: compiler opitions keep having to be repeated all over the place
- tedious
- error-prone
- difficult to maintain
- use Macros
- variableName = text
- use $variableName in makefile
- pre-defined Marcos
- CC
- C compiler to use
- CXX
- C++ compiler to use
- CFLAGS
- Flags to C compiler
- CXXFLAGS
- Flags to C++ compiler
- LDFLAGS
- Flag to Linker (ld)
- …
- CC
- can used in avoid retyping filename in makefile
- observation: compiler opitions keep having to be repeated all over the place
- Implicit rules
- make have predefined rules for “standard dependency” for generate .o file from .cc and .c file
- use suffixes(后缀) of file to infer what command to perform
- use of pre-defined Macros
- Features
- automatic generate dependency
- conditionals(if / else between file)
- all environment variable available with same name
- automatic generate makefile
- cmake
- automake
- Options
- -n: Don’t actually run any recipe; just print them.
- -W file: pretend target file is just modified
- -trace: Print tracing information.