summaryrefslogtreecommitdiffstats
path: root/scripts/Kbuild.install
blob: df02159bf8be008e5dc759323decefd2d9887bc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#
# Install klibc
#
# File is logically seperated in two pieces.
# First piece is used when during a recursive descend of the klibc tree
# and second piece is used to do the final steps in the install
# If KLIBC_INSTALL is defined it tells us we are descending and we
# use first piece of the file.

# This indicates the location of the final version of the shared library.
# THIS MUST BE AN ABSOLUTE PATH WITH NO FINAL SLASH.
# Leave this empty to make it the root.
#
SHLIBDIR = /lib

# First rule
PHONY := __install install-rule
__install:

# Install commands
install-data := install -m 644
install-lib  := install -m 755
install-bin  := install -m 755

# Install command
quiet_cmd_install = INSTALL $(install-y)
      cmd_install = $(install-bin) $(install-y) \
                                   $(INSTALLROOT)$(INSTALLDIR)/$(KLIBCCROSS)bin

# Link install command
quiet_cmd_install_links = LN $(install-link-y)
      cmd_install_links = $(foreach l, $(install-link-y), ln -f $(INSTALLROOT)$(INSTALLDIR)/$(KLIBCCROSS)bin/$(word 2,$(subst =,$(space),$(l))) $(INSTALLROOT)$(INSTALLDIR)/$(KLIBCCROSS)bin/$(word 1,$(subst =,$(space),$(l))) &&) true

ifeq ($(KLIBC_INSTALL),1)
# First part - we are descending..

# Reset variables (to get right type of assingment)
subdir- :=

# Read .config if it exist, otherwise ignore
-include $(objtree)/.config

# Include Kbuild file
include $(srctree)/scripts/Kbuild.include

# Arch specific definitions for klibc
include $(srctree)/$(KLIBCSRC)/arch/$(KLIBCARCHDIR)/MCONFIG

include $(srctree)/$(obj)/Kbuild

# Directories to visit
# First find directories specified in lib-?, static-y and shared-y
find-dir = $(patsubst %/,%,$(filter %/, $(1)))

__subdir := $(call find-dir, $(lib-))
__subdir += $(call find-dir, $(lib-y))

__subdir += $(foreach e, $(static-y), $(call find-dir, $(e)))
__subdir += $(foreach e, $(shared-y), $(call find-dir, $(e)))

# Use subdir- in Kbuild file to tell kbuild to visit a specific dir
subdir-  += $(__subdir)

# Remove duplicates and add prefix
subdir- := $(addprefix $(obj)/,$(sort $(subdir-)))

# Files to install
install-y := $(strip $(addprefix $(obj)/, $(install-y)))

__install: $(subdir-) install-rule
ifneq ($(install-y),)
	$(call cmd,install)
else
	@:
endif
ifneq ($(install-link-y),)
	$(call cmd,install_links)
endif

# Descending
PHONY += $(subdir-)
$(subdir-):
	$(Q)$(MAKE) KLIBC_INSTALL=1 \
	            -f $(srctree)/scripts/Kbuild.install obj=$@

# If quiet is set, only print short version of command
cmd = @$(if $($(quiet)cmd_$(1)),echo '  $($(quiet)cmd_$(1))' &&) $(cmd_$(1))


else
##########################################################################
# This is the first time this file is invoked, so kick off the
# install process.
# First we descend all sub-directories to let them do their install.
# Second we do the final install steps.

# Do actual install as a three steps approach
# 1) Create directories, install headers and man pages
# 2) Tell that we now install binaries
# 3) Install binaries by descending
PHONY += header footer descend
header:
	$(Q)echo "  INSTALL headers + man pages to $(INSTALLROOT)$(INSTALLDIR)"
	$(Q)mkdir -p $(INSTALLROOT)$(bindir)
	$(Q)mkdir -p $(INSTALLROOT)$(mandir)/man1
	$(Q)mkdir -p $(INSTALLROOT)$(SHLIBDIR)
	$(Q)mkdir -p $(INSTALLROOT)$(INSTALLDIR)
	$(Q)-rm -rf $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include
	$(Q)mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include
	$(Q)mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)lib
	$(Q)mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)bin
	$(Q)cp -rfL $(KLIBCKERNELSRC)/include/. $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include/.
ifneq ($(srctree),$(objtree))
	$(Q)cp -rf $(srctree)/usr/include/. $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include/.
endif
	$(Q)cp -rf usr/include/. $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include/.
	$(Q)chmod -R a+rX,go-w $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include
	$(Q)$(install-data) $(srctree)/klcc/klcc.1 $(INSTALLROOT)$(mandir)/man1/$(KCROSS)klcc.1
	$(Q)$(install-bin) $(objtree)/klcc/$(KCROSS)klcc $(INSTALLROOT)$(bindir)

footer: header
	$(Q)echo "  INSTALL binaries to $(INSTALLROOT)$(INSTALLDIR)/$(KLIBCCROSS)bin"

descend: footer
	$(Q)$(MAKE) KLIBC_INSTALL=1 \
	            -f $(srctree)/scripts/Kbuild.install obj=$(obj)

__install: descend
	@:
endif

# Declare the contents of the PHONY variable as phony.  We keep the variable for
# if_changed.
.PHONY: $(PHONY)