mk: split install rule
[dpdk.git] / mk / rte.sdkinstall.mk
1 #   BSD LICENSE
2 #
3 #   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
4 #   Copyright 2015 6WIND S.A.
5 #   All rights reserved.
6 #
7 #   Redistribution and use in source and binary forms, with or without
8 #   modification, are permitted provided that the following conditions
9 #   are met:
10 #
11 #     * Redistributions of source code must retain the above copyright
12 #       notice, this list of conditions and the following disclaimer.
13 #     * Redistributions in binary form must reproduce the above copyright
14 #       notice, this list of conditions and the following disclaimer in
15 #       the documentation and/or other materials provided with the
16 #       distribution.
17 #     * Neither the name of Intel Corporation nor the names of its
18 #       contributors may be used to endorse or promote products derived
19 #       from this software without specific prior written permission.
20 #
21 #   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 #   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 #   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 #   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 #   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 #   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 #   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 #   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 #   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 # Configuration, compilation and installation can be done at once
34 # with make install T=<config>
35
36 ifdef T # config, build and install combined
37 # The build directory is T and may be prepended with O
38 O ?= .
39 RTE_OUTPUT := $O/$T
40 else # standard install
41 # Build directory is given with O=
42 O ?= build
43 RTE_OUTPUT := $O
44 endif
45
46 ifdef T # defaults with T= will install an almost flat staging tree
47 export prefix ?=
48 else
49 prefix      ?=     /usr/local
50 endif
51 exec_prefix ?=      $(prefix)
52 bindir      ?= $(exec_prefix)/bin
53 libdir      ?= $(exec_prefix)/lib
54 includedir  ?=      $(prefix)/include/dpdk
55 datarootdir ?=      $(prefix)/share
56 datadir     ?=       $(datarootdir)/dpdk
57 sdkdir      ?=                $(datadir)
58 targetdir   ?=                $(datadir)/$(RTE_TARGET)
59
60 # The install directories may be staged in DESTDIR
61
62 # Create the directory $1 if not exists
63 rte_mkdir = test -d $1 || mkdir -p $1
64
65 # Create the relative symbolic link $2 -> $1
66 # May be replaced with --relative option of ln from coreutils-8.16
67 rte_symlink = ln -snf $$($(RTE_SDK)/scripts/relpath.sh $1 $(dir $2)) $2
68
69 .PHONY: pre_install
70 pre_install:
71 ifdef T
72         $(Q)if [ ! -f $(RTE_OUTPUT)/.config ]; then \
73                 $(MAKE) config O=$(RTE_OUTPUT); \
74         elif cmp -s $(RTE_OUTPUT)/.config.orig $(RTE_OUTPUT)/.config; then \
75                 $(MAKE) config O=$(RTE_OUTPUT); \
76         else \
77                 if [ -f $(RTE_OUTPUT)/.config.orig ] ; then \
78                         tmp_build=$(RTE_OUTPUT)/.config.tmp; \
79                         $(MAKE) config O=$$tmp_build; \
80                         if ! cmp -s $(RTE_OUTPUT)/.config.orig $$tmp_build/.config ; then \
81                                 echo "Conflict: local config and template config have both changed"; \
82                                 exit 1; \
83                         fi; \
84                 fi; \
85                 echo "Using local configuration"; \
86         fi
87         $(Q)$(MAKE) all O=$(RTE_OUTPUT)
88 endif
89
90 .PHONY: install
91 install:
92 ifeq ($(DESTDIR)$(if $T,,+),)
93         @echo Installation cannot run with T defined and DESTDIR undefined
94 else
95         @echo ================== Installing $(DESTDIR)$(prefix)/
96         $(Q)$(MAKE) O=$(RTE_OUTPUT) T= install-runtime
97         $(Q)$(MAKE) O=$(RTE_OUTPUT) T= install-sdk
98         @echo Installation in $(DESTDIR)$(prefix)/ complete
99 endif
100
101 install-runtime:
102         $(Q)$(call rte_mkdir, $(DESTDIR)$(libdir))
103         $(Q)cp -a    $O/lib/* $(DESTDIR)$(libdir)
104         $(Q)$(call rte_mkdir, $(DESTDIR)$(bindir))
105         $(Q)tar -cf -      -C $O app  --exclude 'app/*.map' \
106                 --exclude 'app/cmdline*' --exclude app/test \
107                 --exclude app/testacl --exclude app/testpipeline | \
108             tar -xf -      -C $(DESTDIR)$(bindir) --strip-components=1 \
109                 --keep-newer-files --warning=no-ignore-newer
110         $(Q)$(call rte_mkdir,      $(DESTDIR)$(datadir))
111         $(Q)cp -a $(RTE_SDK)/tools $(DESTDIR)$(datadir)
112
113 install-sdk:
114         $(Q)$(call rte_mkdir, $(DESTDIR)$(includedir))
115         $(Q)tar -chf -     -C $O include | \
116             tar -xf -      -C $(DESTDIR)$(includedir) --strip-components=1 \
117                 --keep-newer-files --warning=no-ignore-newer
118         $(Q)$(call rte_mkdir,                            $(DESTDIR)$(sdkdir))
119         $(Q)cp -a               $(RTE_SDK)/{mk,scripts}  $(DESTDIR)$(sdkdir)
120         $(Q)$(call rte_mkdir,                            $(DESTDIR)$(targetdir))
121         $(Q)cp -a               $O/.config               $(DESTDIR)$(targetdir)
122         $(Q)$(call rte_symlink, $(DESTDIR)$(includedir), $(DESTDIR)$(targetdir)/include)
123         $(Q)$(call rte_symlink, $(DESTDIR)$(libdir),     $(DESTDIR)$(targetdir)/lib)