I have a directory structure with projects, and I need to make sure that when I copy new files, the directory structure has the correct permissions (basically, as if created with umask 022) and ownership:
root:users
755 for directories
644 for files
how can i automate this with a Makefile, so that when I run make
, the wrong permissions and ownership of files will be changed.
What target should i use inside my Makefile?
Or, will I need to change the permissions blindly on the whole directory structure, each time I run make? Can make have a target based on file ownership and permissions?
You're likely looking for something like this:
$(FILES_TO_COPY): $(DEST_DIR)/% : $(SRC_DIR)/%
dir=(notdir $@); [ -d $(dir) ] && mkdir -p $(dir) && chmod 755 $(dir)
cp $< $@ && chmod 644 $@
This is a static pattern rule to copy things from DEST_DIR
to SRC_DIR
. The first recipe line checks if the necessary directory under $(DEST_DIR)
exists and creates it, and sets its permissions if it does, and the next line copies the file, and sets its directories.
It's not clear from your question if this is what you were after though. You'll have to provide an example if this isn't it.