Home > Mobile >  How does install in the Makefile keep the directory structure unchanged?
How does install in the Makefile keep the directory structure unchanged?

Time:11-13

I wrote some functions in a directory, and I want to generate static libraries and move the header files to a dedicated folder.

THIS_DIR  := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
all: install_header
HEADERS =  \
    ps_evset.h \
    list/list_utils.h \
    list/list_traverse.h \
    list/list_struct.h 

install_header: ${HEADERS}
    install -d ${THIS_DIR}/../build/include/evsets
    install ${HEADERS} ${THIS_DIR}/../build/include/evsets

But when I got to that directory, I found that the list directory was not created.

├── list_struct.h
├── list_traverse.h
├── list_utils.h
└── ps_evset.h

the directory structure is completely unchanged and moved? If changed, files that use #include "list/list_traverse.h" will have file not found errors.

CodePudding user response:

This doesn't have anything to do with C or with Makefiles. You are using the install utility to copy the files, and that's how the install utility works: it takes the files on the command line and copies them to the directory you specified. It doesn't recreate the directory structure.

If you want to preserve the directory structure then your install_header recipe will need to be modified to do that, perhaps by writing multiple install commands with different directories or by invoking cp directly.

  • Related