Makefile Pattern Rules & Dependency Generation/Update archive with newer objects

Use `$?` to add only changed prerequisites.

Section: Archives and libraries

Update archive with newer objects

makefile
makefile
libfoo.a: $(OBJ)
	ar rcs $@ $?
Explanation

Efficient for large archives.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Archives and libraries
Build static library
Create an archive from object files.
OpenIn sheetmakefilesame section
$@ target name
Expand to the current target file.
OpenIn sheetmakefile1 tag match
$< first prerequisite
Expand to the first prerequisite.
OpenIn sheetmakefile1 tag match
$^ all prerequisites
Expand to all prerequisites without duplicates.
OpenIn sheetmakefile1 tag match
$? newer prerequisites
Expand to prerequisites newer than the target.
OpenIn sheetmakefile1 tag match
$* stem in pattern rules
Use the matched stem from the target pattern.
OpenIn sheetmakefile1 tag match