1# -*-makefile-*- 2# Instance/resource-set.make 3# 4# Instance makefile rules to install resource files 5# 6# Copyright (C) 2002 Free Software Foundation, Inc. 7# 8# Author: Nicola Pero <nicola@brainstorm.co.uk> 9# 10# This file is part of the GNUstep Makefile Package. 11# 12# This library is free software; you can redistribute it and/or 13# modify it under the terms of the GNU General Public License 14# as published by the Free Software Foundation; either version 3 15# of the License, or (at your option) any later version. 16# 17# You should have received a copy of the GNU General Public 18# License along with this library; see the file COPYING. 19# If not, write to the Free Software Foundation, 20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 22ifeq ($(RULES_MAKE_LOADED),) 23include $(GNUSTEP_MAKEFILES)/rules.make 24endif 25 26# 27# This is used to install a bunch of resource files somewhere. It is 28# different from a bundle without resources; in a bundle without 29# resources, we first create the bundle in the build directory, then 30# copy the build to the install dir, overwriting anything already 31# there. This instead will install the separate resource files 32# directly in the installation directory; it's more efficient as it 33# doesn't create a local bundle, and it doesn't overwrite an existing 34# bundle in the installation directory. 35# 36# 37# The name of the set of resources is in the RESOURCE_SET_NAME variable. 38# The list of resource files/dirs is in xxx_RESOURCE_FILES 39# The list of resource directories to create are in xxx_RESOURCE_DIRS 40# The directory in which to install the resources is in the 41# xxx_INSTALL_DIR 42# The directory in which the resources are found is 43# xxx_RESOURCE_FILES_DIR (defaults to ./ if omitted) 44# The list of LANGUAGES is in the xxx_LANGUAGES variable. 45# The list of localized files/dirs to be read 46# from $(xxx_RESOURCE_FILES_DIR)/yyy.lproj and copied 47# into $(RESOURCE_FILES_INSTALL_DIR)/yyy.lproj for each language yyy 48# is in the xxx_LOCALIZED_RESOURCE_FILES variable. 49# The list of localized dirs to be created empty inside each 50# $(RESOURCE_FILES_INSTALL_DIR)/yyy.lproj for each language yyy 51# is in the xxx_LOCALIZED_RESOURCE_DIRS variable. 52# 53# NB. Info-gnustep.plist and Info.plist are NOT considered resource files. 54# These files are generated automatically by certain projects, and if you 55# want to insert your own entries into Info0gnustep.plist or Info.plist 56# you should create a xxxInfo.plist file (where xxx is the application name) 57# in the same directory as your makefile, and gnustep-make will automatically 58# read it and merge it into the generated Info-gnustep.plist. 59# For more detail, see rules.make 60 61.PHONY: internal-resource_set-install_ \ 62 internal-resource_set-uninstall_ 63 64# 65# Determine where to install. 66# By default, install into GNUSTEP_RESOURCES/GNUSTEP_INSTANCE 67# 68ifneq ($($(GNUSTEP_INSTANCE)_INSTALL_DIR),) 69 RESOURCE_FILES_INSTALL_DIR = $($(GNUSTEP_INSTANCE)_INSTALL_DIR) 70endif 71 72ifeq ($(RESOURCE_FILES_INSTALL_DIR),) 73 RESOURCE_FILES_INSTALL_DIR = $(GNUSTEP_RESOURCES)/$(GNUSTEP_INSTANCE) 74endif 75 76# Determine the dir to take the resources from 77RESOURCE_FILES_DIR = $($(GNUSTEP_INSTANCE)_RESOURCE_FILES_DIR) 78ifeq ($(RESOURCE_FILES_DIR),) 79 RESOURCE_FILES_DIR = ./ 80endif 81 82 83# Determine the list of resource files 84RESOURCE_FILES = $($(GNUSTEP_INSTANCE)_RESOURCE_FILES) 85RESOURCE_DIRS = $($(GNUSTEP_INSTANCE)_RESOURCE_DIRS) 86 87ifneq ($(RESOURCE_DIRS),) 88# Rule to build the additional installation dirs 89$(addprefix $(RESOURCE_FILES_INSTALL_DIR)/,$(RESOURCE_DIRS)): 90 $(ECHO_CREATING)$(MKDIRS) $@$(END_ECHO) 91ifneq ($(CHOWN_TO),) 92 $(ECHO_CHOWNING)$(CHOWN) -R $(CHOWN_TO) $@$(END_ECHO) 93endif 94endif 95 96# Rule to build the installation dir 97$(RESOURCE_FILES_INSTALL_DIR): 98 $(ECHO_CREATING)$(MKDIRS) $@$(END_ECHO) 99ifneq ($(CHOWN_TO),) 100 $(ECHO_CHOWNING)$(CHOWN) -R $(CHOWN_TO) $@$(END_ECHO) 101endif 102 103# Determine the list of localized resource files 104LOCALIZED_RESOURCE_FILES = $($(GNUSTEP_INSTANCE)_LOCALIZED_RESOURCE_FILES) 105LOCALIZED_RESOURCE_DIRS = $($(GNUSTEP_INSTANCE)_LOCALIZED_RESOURCE_DIRS) 106 107ifneq ($(LOCALIZED_RESOURCE_DIRS),) 108# The following expression will create all the 109# RESOURCE_FILES_INSTALL_DIR/LANGUAGE/LOCALIZED_RESOURCE_DIR that we 110# need to build. 111$(foreach LANGUAGE,$(LANGUAGES),$(addprefix $(RESOURCE_FILES_INSTALL_DIR)/$(LANGUAGE), $(LOCALIZED_RESOURCE_DIRS))): 112 $(ECHO_CREATING)$(MKDIRS) $@$(END_ECHO) 113ifneq ($(CHOWN_TO),) 114 $(ECHO_CHOWNING)$(CHOWN) -R $(CHOWN_TO) $@$(END_ECHO) 115endif 116endif 117 118# 119# We provide two different algorithms of installing resource files. 120# 121 122ifeq ($(GNUSTEP_DEVELOPER),) 123 124# Standard one - just run a subshell and loop, and install everything. 125internal-resource_set-install_: \ 126 $(RESOURCE_FILES_INSTALL_DIR) \ 127 $(addprefix $(RESOURCE_FILES_INSTALL_DIR)/,$(RESOURCE_DIRS)) \ 128 $(foreach LANGUAGE,$(LANGUAGES),$(addprefix $(RESOURCE_FILES_INSTALL_DIR)/$(LANGUAGE), $(LOCALIZED_RESOURCE_DIRS))) 129ifneq ($(RESOURCE_FILES),) 130 $(ECHO_NOTHING)for f in $(RESOURCE_FILES); do \ 131 if [ -f $(RESOURCE_FILES_DIR)/$$f -o -d $(RESOURCE_FILES_DIR)/$$f ]; then \ 132 rm -rf $(RESOURCE_FILES_INSTALL_DIR)/$$f;\ 133 cp -fr $(RESOURCE_FILES_DIR)/$$f \ 134 $(RESOURCE_FILES_INSTALL_DIR)/$$f; \ 135 else \ 136 echo "Warning: $$f not found - ignoring"; \ 137 fi; \ 138 done$(END_ECHO) 139ifneq ($(CHOWN_TO),) 140 $(ECHO_CHOWNING)for f in $(RESOURCE_FILES); do \ 141 if [ -f $(RESOURCE_FILES_DIR)/$$f -o -d $(RESOURCE_FILES_DIR)/$$f ]; then \ 142 $(CHOWN) -R $(CHOWN_TO) $(RESOURCE_FILES_INSTALL_DIR)/$$f; \ 143 fi; \ 144 done$(END_ECHO) 145endif 146endif 147ifneq ($(LOCALIZED_RESOURCE_FILES),) 148 $(ECHO_NOTHING)for l in $(LANGUAGES); do \ 149 if [ -d $(RESOURCE_FILES_DIR)/$$l.lproj ]; then \ 150 $(MKINSTALLDIRS) $(RESOURCE_FILES_INSTALL_DIR)/$$l.lproj; \ 151 for f in $(LOCALIZED_RESOURCE_FILES); do \ 152 if [ -f $(RESOURCE_FILES_DIR)/$$l.lproj/$$f -o -d $(RESOURCE_FILES_DIR)$$l.lproj/$$f ]; then \ 153 cp -fr $(RESOURCE_FILES_DIR)/$$l.lproj/$$f \ 154 $(RESOURCE_FILES_INSTALL_DIR)/$$l.lproj; \ 155 else \ 156 echo "Warning: $(RESOURCE_FILES_DIR)/$$l.lproj/$$f not found - ignoring"; \ 157 fi; \ 158 done; \ 159 else \ 160 echo "Warning: $(RESOURCE_FILES_DIR)/$$l.lproj not found - ignoring"; \ 161 fi; \ 162 done$(END_ECHO) 163ifneq ($(CHOWN_TO),) 164 $(ECHO_CHOWNING)for l in $(LANGUAGES); do \ 165 if [ -d $(RESOURCE_FILES_DIR)/$$l.lproj ]; then \ 166 $(CHOWN) -R $(CHOWN_TO) $(RESOURCE_FILES_INSTALL_DIR)/$$l.lproj; \ 167 for f in $(LOCALIZED_RESOURCE_FILES); do \ 168 if [ -f $(RESOURCE_FILES_DIR)/$$l.lproj/$$f -o -d $(RESOURCE_FILES_DIR)/$$l.lproj/$$f ]; then \ 169 $(CHOWN) -R $(CHOWN_TO) $(RESOURCE_FILES_INSTALL_DIR)/$$l.lproj/$$f; \ 170 fi; \ 171 done; \ 172 fi; \ 173 done$(END_ECHO) 174endif 175endif 176 177else # Following code turned on by setting GNUSTEP_DEVELOPER=yes in the shell 178 179# TODO/FIXME: Update the code; implement proper 180# LOCALIZED_RESOURCE_FILES that also allows directories etc. 181 182.PHONY: internal-resource-set-install-languages 183 184# One optimized for recurrent installations during development - this 185# rule installs a single file only if strictly needed 186$(RESOURCE_FILES_INSTALL_DIR)/% : $(RESOURCE_FILES_DIR)/% 187 $(ECHO_NOTHING)cp -fr $< $(RESOURCE_FILES_DIR)$(END_ECHO) 188ifneq ($(CHOWN_TO),) 189 $(ECHO_CHOWNING)$(CHOWN) -R $(CHOWN_TO) $@$(END_ECHO) 190endif 191 192# This rule depends on having installed all files 193internal-resource_set-install_: \ 194 $(RESOURCE_FILES_INSTALL_DIR) \ 195 $(addprefix $(RESOURCE_FILES_INSTALL_DIR)/,$(RESOURCE_DIRS)) \ 196 $(addprefix $(RESOURCE_FILES_INSTALL_DIR)/,$(RESOURCE_FILES)) \ 197 internal-resource-set-install-languages 198 199ifeq ($(LOCALIZED_RESOURCE_FILES),) 200internal-resource-set-install-languages: 201 202else 203 204# Rule to build the language installation directories 205$(addsuffix .lproj,$(addprefix $(RESOURCE_FILES_INSTALL_DIR)/,$(LANGUAGES))): 206 $(ECHO_CREATING)$(MKDIRS) $@$(END_ECHO) 207 208# install the localized resources, checking the installation date by 209# using test -nt ... this doesn't seem to be easy to do using make 210# rules because we want to issue a warning if the directory/file can't 211# be found, rather than aborting with an error as make would do. 212internal-resource-set-install-languages: \ 213$(addsuffix .lproj,$(addprefix $(RESOURCE_FILES_INSTALL_DIR)/,$(LANGUAGES))) 214 $(ECHO_NOTHING)for l in $(LANGUAGES); do \ 215 if [ -d $(RESOURCE_FILES_DIR)/$$l.lproj ]; then \ 216 for f in $(LOCALIZED_RESOURCE_FILES); do \ 217 if [ -f $(RESOURCE_FILES_DIR)/$$l.lproj/$$f ]; then \ 218 if [ $(RESOURCE_FILES_DIR)/$$l.lproj -nt $(RESOURCE_FILES_INSTALL_DIR)/$$l.lproj/$$f ]; then \ 219 $(INSTALL_DATA) $(RESOURCE_FILES_DIR)/$$l.lproj/$$f \ 220 $(RESOURCE_FILES_INSTALL_DIR)/$$l.lproj; \ 221 fi; \ 222 else \ 223 echo "Warning: $(RESOURCE_FILES_DIR)/$$l.lproj/$$f not found - ignoring"; \ 224 fi; \ 225 done; \ 226 else \ 227 echo "Warning: $(RESOURCE_FILES_DIR)/$$l.lproj not found - ignoring"; \ 228 fi; \ 229 done$(END_ECHO) 230 231 232endif # LOCALIZED_RESOURCE_FILES 233 234endif 235 236# Here we try to remove the directories that we created on install. 237# We use a plain rmdir to remove them; if you're manually installing 238# any files in them (eg, in an 'after-install' custom rule), you need 239# to make sure you remove them (in an 'before-uninstall' custom rule) 240 241internal-resource_set-uninstall_: 242ifneq ($(LOCALIZED_RESOURCE_FILES),) 243 $(ECHO_NOTHING)for language in $(LANGUAGES); do \ 244 for file in $(LOCALIZED_RESOURCE_FILES); do \ 245 rm -rf $(RESOURCE_FILES_INSTALL_DIR)/$$language.lproj/$$file;\ 246 done; \ 247 done$(END_ECHO) 248endif 249ifneq ($(LOCALIZED_RESOURCE_DIRS),) 250 -$(ECHO_NOTHING)for language in $(LANGUAGES); do \ 251 for dir in $(LOCALIZED_RESOURCE_DIRS); do \ 252 rmdir $(RESOURCE_FILES_INSTALL_DIR)/$$language.lproj/$$dir;\ 253 done; \ 254 done$(END_ECHO) 255endif 256ifneq ($(LOCALIZED_RESOURCE_FILES)$(LOCALIZED_RESOURCE_DIRS),) 257 -$(ECHO_NOTHING)for language in $(LANGUAGES); do \ 258 rmdir $(RESOURCE_FILES_INSTALL_DIR)/$$language.lproj; \ 259 done$(END_ECHO) 260endif 261ifneq ($(RESOURCE_FILES),) 262 $(ECHO_NOTHING)for file in $(RESOURCE_FILES); do \ 263 rm -rf $(RESOURCE_FILES_INSTALL_DIR)/$$file ; \ 264 done$(END_ECHO) 265endif 266ifneq ($(RESOURCE_DIRS),) 267 -$(ECHO_NOTHING)for dir in $(RESOURCE_DIRS); do \ 268 rmdir $(RESOURCE_FILES_INSTALL_DIR)/$$dir ; \ 269 done$(END_ECHO) 270endif 271ifneq ($(RESOURCE_FILES)$(RESOURCE_DIRS),) 272 -$(ECHO_NOTHING)rmdir $(RESOURCE_FILES_INSTALL_DIR)$(END_ECHO) 273endif 274