1#
2# Copyright (C) 2010 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17define filter-ide-goals
18$(strip $(filter $(1)-%,$(MAKECMDGOALS)))
19endef
20
21define filter-ide-modules
22$(strip $(subst -,$(space),$(patsubst $(1)-%,%,$(2))))
23endef
24
25# eclipse
26eclipse_project_goals := $(call filter-ide-goals,ECLIPSE)
27ifdef eclipse_project_goals
28  ifneq ($(words $(eclipse_project_goals)),1)
29    $(error Only one ECLIPSE- goal may be specified: $(eclipse_project_goals))
30  endif
31  eclipse_project_modules := $(call filter-ide-modules,ECLIPSE,$(eclipse_project_goals))
32
33  ifneq ($(filter lunch,$(eclipse_project_modules)),)
34    eclipse_project_modules := $(filter-out lunch,$(eclipse_project_modules))
35    installed_modules := $(foreach m,$(ALL_DEFAULT_INSTALLED_MODULES),\
36        $(INSTALLABLE_FILES.$(m).MODULE))
37    java_modules := $(foreach m,$(installed_modules),\
38        $(if $(filter JAVA_LIBRARIES APPS,$(ALL_MODULES.$(m).CLASS)),$(m),))
39    eclipse_project_modules := $(sort $(eclipse_project_modules) $(java_modules))
40  endif
41
42  source_paths := $(foreach m,$(eclipse_project_modules),$(ALL_MODULES.$(m).PATH)) \
43              $(foreach m,$(eclipse_project_modules),$(ALL_MODULES.$(m).INTERMEDIATE_SOURCE_DIR))
44  source_paths := $(sort $(source_paths))
45
46.classpath: PRIVATE_MODULES := $(eclipse_project_modules)
47.classpath: PRIVATE_DIRS := $(source_paths)
48
49# the mess below with ./src tries to guess whether the src
50$(eclipse_project_goals): .classpath
51.classpath: FORCE
52	$(hide) echo Generating .classpath for eclipse
53	$(hide) echo '<classpath>' > $@
54	$(hide) for p in $(PRIVATE_DIRS) ; do \
55		echo -n '  <classpathentry kind="src" path="' >> $@ ; \
56		( if [ -d $$p/src ] ; then echo -n $$p/src ; else echo -n $$p ; fi ) >> $@ ; \
57		echo '"/>' >> $@ ; \
58	done
59	$(hide) echo '</classpath>' >> $@
60endif
61
62