1#   -*-makefile-*-
2#   Shared/headers.make
3#
4#   Makefile fragment with rules to install header files
5#
6#   Copyright (C) 2002, 2010 Free Software Foundation, Inc.
7#
8#   Author:  Nicola Pero <nicola.pero@meta-innovation.com>
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
22#
23# input variables:
24#
25#  $(GNUSTEP_INSTANCE)_HEADER_FILES : the list of .h files to install
26#
27#  $(GNUSTEP_INSTANCE)_HEADER_FILES_DIR : the dir in which the .h files are;
28#  defaults to `.' if no set.
29#
30#  $(GNUSTEP_INSTANCE)_HEADER_FILES_INSTALL_DIR : the dir in which to install
31#  the .h files; defaults to $(GNUSTEP_INSTANCE) if not set.  Please set it
32#  to `.' if you want it to be like empty.
33#
34
35#
36# public targets:
37#
38#  shared-instance-headers-install
39#  shared-instance-headers-uninstall
40#
41
42HEADER_FILES = $($(GNUSTEP_INSTANCE)_HEADER_FILES)
43
44.PHONY: \
45shared-instance-headers-install \
46shared-instance-headers-uninstall
47
48# We always compute HEADER_FILES_DIR and HEADER_FILES_INSTALL_DIR.
49# The reason is that frameworks might have headers in subprojects (and
50# not in the top framework makefile!).  Those headers are
51# automatically used and installed, but in the top-level makefile,
52# HEADER_FILES = '', still you might want to have a special
53# HEADER_FILES_DIR and HEADER_FILES_INSTALL_DIR even in this case.
54# NB: Header installation for frameworks is done by the framework
55# code.
56HEADER_FILES_DIR = $($(GNUSTEP_INSTANCE)_HEADER_FILES_DIR)
57
58ifeq ($(HEADER_FILES_DIR),)
59  HEADER_FILES_DIR = .
60endif
61
62HEADER_FILES_INSTALL_DIR = $($(GNUSTEP_INSTANCE)_HEADER_FILES_INSTALL_DIR)
63
64# Please use `.' to force it to stay empty
65ifeq ($(HEADER_FILES_INSTALL_DIR),)
66  HEADER_FILES_INSTALL_DIR = $(GNUSTEP_INSTANCE)
67endif
68
69ifeq ($(HEADER_FILES),)
70
71shared-instance-headers-install:
72
73shared-instance-headers-uninstall:
74
75else # we have some HEADER_FILES
76
77# First of all, we need to deal with a special complication, which is
78# if any HEADER_FILES include a subdirectory component (allowed since
79# gnustep-make 2.2.1).  Ie, something like
80#
81#  HEADER_FILES = Beauty/Pride.h
82#
83# This is a complication because to install such a file we first need
84# to create the directory to install it into.
85#
86# The following command determines the install (sub)directories that
87# we need to create.  'dir' extracts the directory from each file
88# ("./" will be returned if there is no such subdirectory); 'sort'
89# removes duplicates from the results, and makes sure that the
90# directories are in the order that they should be created in
91# ("Pride/" comes before "Pride/Beauty").  Finally, filter-out removes
92# ./ from the results as we create the root directory separately.
93HEADER_SUBDIRS = $(strip $(filter-out ./,$(sort $(dir $(HEADER_FILES)))))
94
95# The complete (full path) directories that we need to create when
96# installing.
97HEADER_INSTALL_DIRS_TO_CREATE = $(GNUSTEP_HEADERS)/$(HEADER_FILES_INSTALL_DIR) $(addprefix $(GNUSTEP_HEADERS)/$(HEADER_FILES_INSTALL_DIR)/,$(HEADER_SUBDIRS))
98
99#
100# We provide two different algorithms of installing headers.
101#
102
103ifeq ($(GNUSTEP_DEVELOPER),)
104
105#
106# The first one is the standard one.  We run a subshell, loop on all the
107# header files, and install all of them.  This is the default one.
108#
109
110shared-instance-headers-install: $(HEADER_INSTALL_DIRS_TO_CREATE)
111	$(ECHO_INSTALLING_HEADERS)for file in $(HEADER_FILES) __done; do \
112	  if [ $$file != __done ]; then \
113	    $(INSTALL_DATA) $(HEADER_FILES_DIR)/$$file \
114	          $(GNUSTEP_HEADERS)/$(HEADER_FILES_INSTALL_DIR)/$$file; \
115	  fi; \
116	done$(END_ECHO)
117
118else
119
120#
121# The second one (which you activate by setting GNUSTEP_DEVELOPER to
122# yes in your shell) is the one specifically optimized for faster
123# development.  We only install headers which are newer than the
124# installed version.  This is much faster if you are developing and
125# need to install headers often, and normally with just few changes.
126# It is slower the first time you install the headers, because we
127# install them using a lot of subshell processes (which is why it is not
128# the default - `users' install headers only once - the default
129# setup is for users).
130#
131
132shared-instance-headers-install: \
133  $(HEADER_INSTALL_DIRS_TO_CREATE) \
134  $(addprefix $(GNUSTEP_HEADERS)/$(HEADER_FILES_INSTALL_DIR)/,$(HEADER_FILES))
135
136$(GNUSTEP_HEADERS)/$(HEADER_FILES_INSTALL_DIR)/% : $(HEADER_FILES_DIR)/%
137	$(ECHO_NOTHING)$(INSTALL_DATA) $< $@$(END_ECHO)
138
139endif
140
141# Note that we create these directories, if not there yet.  In the
142# same way, upon uninstall, we delete the directories if they are
143# empty.
144$(HEADER_INSTALL_DIRS_TO_CREATE):
145	$(ECHO_CREATING)$(MKINSTALLDIRS) $@$(END_ECHO)
146
147
148# TODO/FIXME: the uninstall should delete directories in reverse
149# order, else it will not work when more than one are created.
150shared-instance-headers-uninstall:
151	$(ECHO_NOTHING)for file in $(HEADER_FILES) __done; do \
152	  if [ $$file != __done ]; then \
153	    rm -rf $(GNUSTEP_HEADERS)/$(HEADER_FILES_INSTALL_DIR)/$$file ; \
154	  fi; \
155	done$(END_ECHO)
156	-$(ECHO_NOTHING)rmdir $(HEADER_INSTALL_DIRS_TO_CREATE)$(END_ECHO)
157
158endif # HEADER_FILES = ''
159