Search code examples
makefiletarget

What does single OR character in Makefile


Short question. At my work I saw strange code in Makefile

$(DIR)/dir1 $(DIR)/dir2 $(DIR)/dir3: | $(DIR)
    mkdir -p $$(@)

What is the meaning of | character?


Solution

  • It separates normal prerequisite from order only prerequisites. Order only prerequisites must exist before the targets are made, but that's all. Targets are not remade if their timestamp is earlier than the one of order only prerequisites.

    Here if $(DIR) doesn't exist, it will be made before $(DIR)/dir1, $(DIR)/dir2 and $(DIR)/dir3 but if it exists and its timestamp is later than the one of the subdirs, the subdir won't be remade.