Makefile에서 notdir 동작

manpage의 이미지

Makefile에서 for 문 내에서는 notdir이 동작되지 않나요?

HDRS := include/a.h ./b.h ../lib/c.h
이 header file을 stage/include에 복사하고자 합니다.

install :
@for file in $(HDRS); do \
$(CP) $$file $(addprefix $(STAGE_DIR)/include/,$(notdir $$file)); \
done

이렇게 하면
$(STAGE_DIR)/include/ 뒤에 파일명만 추출되지 못하고 그대로 붙내요.

다른 좋은 방법이 없을까요?

ymir의 이미지

https://groups.google.com/g/comp.os.msdos.djgpp/c/GkBSzgOWsk8
https://stackoverflow.com/questions/40203608/why-basename-in-makefile-does-not-work-as-expected

addprefix 나 notdir 같은 Make 함수들은 쉘 변수와 같이 쓸 수 없다네요.

  $(CP) $$file $(STAGE_DIR)/include/`basename $$file`; \

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

manpage의 이미지

답변 감사합니다.
$(CP) $$file $(addprefix $(STAGE_DIR)/include/,`basename $$file`)
addprefix 기능은 동작되내요.

익명 사용자의 이미지

HDRS := include/a.h ./b.h ../lib/c.h
DEST := $(addprefix $(STAGE_DIR)/include/, $(notdir $(HDRS)))
 
install:
    $(info Copying header files...)
    @$(foreach hdr, $(HDRS), $(CP) $(hdr) $(STAGE_DIR)/include/$(notdir $(hdr));)
manpage의 이미지

foreach 쓸 생각을 못했내요!
이 방법으로 적용합니다 ^__^