forked from Open-CAS/ocf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
100 lines (82 loc) · 2.4 KB
/
Makefile
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
#
# Copyright(c) 2012-2018 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
PWD:=$(shell pwd)
ifneq ($(strip $(O)),)
OUTDIR:=$(shell cd $(O) && pwd)
endif
validate:
ifeq ($(strip $(OUTDIR)),)
$(error No output specified for installing sources or headers)
endif
ifeq ($(strip $(CMD)),)
INSTALL=ln -s
else ifeq ($(strip $(CMD)),cp)
INSTALL=cp
else ifeq ($(strip $(CMD)),install)
INSTALL=install
else
$(error Not allowed program command)
endif
#
# Installing headers
#
INC_IN=$(shell find $(PWD)/inc -name '*.[h]' -type f)
INC_OUT=$(patsubst $(PWD)/inc/%,$(OUTDIR)/include/ocf/%,$(INC_IN))
INC_RM=$(shell find $(OUTDIR)/include/ocf -name '*.[h]' -xtype l 2>/dev/null)
inc: $(INC_OUT) $(INC_RM)
@$(MAKE) distcleandir
$(INC_OUT):
ifeq ($(strip $(OUTDIR)),)
$(error No output specified for installing headers)
endif
@echo " INSTALL $@"
@mkdir -p $(dir $@)
@$(INSTALL) $(subst $(OUTDIR)/include/ocf,$(PWD)/inc,$@) $@
$(INC_RM): validate
$(if $(shell readlink $@ | grep $(PWD)/inc), \
@echo " RM $@"; rm $@,)
#
# Installing sources
#
SRC_IN=$(shell find $(PWD)/src -name '*.[c|h]' -type f)
SRC_OUT=$(patsubst $(PWD)/src/%,$(OUTDIR)/src/ocf/%,$(SRC_IN))
SRC_RM=$(shell find $(OUTDIR)/src/ocf -name '*.[c|h]' -xtype l 2>/dev/null)
src: $(SRC_OUT) $(SRC_RM)
@$(MAKE) distcleandir
$(SRC_OUT):
ifeq ($(strip $(OUTDIR)),)
$(error No output specified for installing sources)
endif
@echo " INSTALL $@"
@mkdir -p $(dir $@)
@$(INSTALL) $(subst $(OUTDIR)/src/ocf,$(PWD)/src,$@) $@
$(SRC_RM): validate
$(if $(shell readlink $@ | grep $(PWD)/src), \
@echo " RM $@"; rm $@,)
#
# Distclean
#
dist_dir=$(foreach dir,$(shell find $(OUTDIR) -type d -empty), \
$(if $(wildcard $(subst $(OUTDIR)/src/ocf,$(PWD)/src,$(dir))),$(dir),))
distclean: validate
@rm -f $(SRC_OUT) $(INC_OUT)
@$(MAKE) distcleandir
distcleandir:
$(if $(strip $(dist_dir)), rm -r $(dist_dir),)
#
# Printing help
#
help:
$(info Available targets:)
$(info inc O=<OUTDIR> [CMD=cp|install] Install include files into specified directory)
$(info src O=<OUTDIR> [CMD=cp|install] Install source files into specified directory)
$(info distclean O=<OUTDIR> Uninstall source and headers from specified directory)
doc: validate
@cd doc && rm -rf html
@cd doc && doxygen doxygen.cfg
@mkdir -p $(OUTDIR)/doc
@cd doc && mv html $(OUTDIR)/doc/ocf
.PHONY: inc src validate help distclean distcleandir doc \
$(INC_RM) $(SRC_RM) $(DIST_DIR)