forked from danchang/sipxecs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.in
96 lines (75 loc) · 3.72 KB
/
Makefile.in
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
# Initial Version Copyright (C) 2010 eZuce, Inc., All Rights Reserved.
# Licensed to the User under the LGPL license.
#
BUILDDIR = $(abspath @builddir@)
SRC = $(abspath @srcdir@)
PACKAGE_VERSION = @PACKAGE_VERSION@
PACKAGE_REVISION = $(shell $(SRC)/config/revision-gen @PACKAGE_VERSION@)
help-var.DISTRO=To run a command for a different target distro. Default: $(DISTRO). Complete list of available values: @ALL_DISTROS@
DISTRO=@DISTRO@
DISTRO_OS = $(word 1,$(subst -, ,$(DISTRO)))
DISTRO_VER = $(word 2,$(subst -, ,$(DISTRO)))
DISTRO_ARCH = $(word 3,$(subst -, ,$(DISTRO)))
DISTRO_RESULTS_DIR = $(strip \
$(subst fedora,Fedora, \
$(subst centos,CentOS,$(DISTRO_OS)))_$(DISTRO_VER))
# utility
empty :=
space := $(empty) $(empty)
lowercase = $(shell echo $(1) | tr '[:upper:]' '[:lower:]')
# for each sipx-% target, define a variable for the corresponding project directory
PROJ = $(filter $(all),$(subst ., ,$@))
proj = $(call lowercase,$(PROJ))
PROJ_REVISION = $(shell cd $(SRC)/$(PROJ) && ./config/revision-gen @PACKAGE_VERSION@)
# find any matches of $(sipx) or $(lib) anywhere in a target string and expands it into multiple target that
# would follow the given target.
# example: foo.B.bar... becomes 'foo.B.bar foo.C.bar' when list is 'A B C'
after = $(shell echo $(space)$2$(space) | awk -F : '{if (match($$0,/ $1 /)) {print substr($$0,RSTART)}}')
..._sipx_list = $(call after,$(PROJ),$(sipx))
..._sipx_expanded = $(foreach T,$(..._sipx_list),$(subst $(PROJ),$(T),$*))
..._lib_list = $(call after,$(PROJ),$(lib))
..._lib_expanded = $(foreach T,$(..._lib_list),$(subst $(PROJ),$(T),$*))
..._app_list = $(call after,$(PROJ),$(app))
..._app_expanded = $(foreach T,$(..._app_list),$(subst $(PROJ),$(T),$*))
default-first-target : help;
sipx.% :
$(MAKE) $(foreach P,$(sipx),$(P).$*)
lib.% :
$(MAKE) $(foreach P,$(lib),$(P).$*)
app.% :
$(MAKE) $(foreach P,$(app),$(P).$*)
help.{sipx,lib}.list=list all sipx components
app.list lib.list sipx.list : %.list :
@echo $($*)
include $(sort $(wildcard mak/*.mk))
help.*{1|2}*... = Perform all targets would normally follow the given target in addition to the target itself.\
Very useful when you want to pick-up the build where it last stopped. For example 'make sipXthree...' would\
expand to 'make sipXthree sipXfour sipXfive' but it would not include 'make sipXone sipXtwo'. You can use\
the ... pattern anywhere you a specify a package name. Examples: 'make sipXconfig.rpm...',\
'make distro.centos-5-i386.OpenACD.rpm...'. See 'make sipx.list lib.list' for what the natural order of\
packages.
%... :
$(MAKE) $(..._sipx_expanded) $(..._lib_expanded) $(..._app_expanded)
help-values.{1} = Any sipXecs package. For all sipXecs packages use 'sipx'. Complete list of sipXecs packages : $(sipx)
help-values.{2} = Any dependency package. For all dependencies use 'lib'. Complete list of dependencies : $(lib)
help-values.{6} = Any sipXecs application. For all app use 'app'. Complete list of app : $(app)
.PHONY: help
help:
@echo -e "\nCOMMON TARGETS\n==================="
@$(MAKE) --no-print-directory -s help.print
@echo -e "\nALLOWED VALUES\n==================="
@$(MAKE) --no-print-directory -s help-values.print
@echo -e "\nSPECIAL VARIABLES\n==================="
@$(MAKE) --no-print-directory -s help-var.print
help-values.print help.print help-var.print: %.print :
@$(foreach H,$(filter $*.%,$(sort $(.VARIABLES))), \
echo "$$format_help" | Label="$(H:$*.%=%)" Text="$($(H))" bash;)
define format_help
MARGIN=18
WIDTH=`tput cols`
HELP_WIDTH=`echo $$[$${WIDTH} - $${MARGIN}]`
export TEXT=`echo "$${Text}" | fold -s -w $${HELP_WIDTH} | sed -e "2,10s|^| |g"`
export LABEL="$${Label}"
echo | awk '{printf("%-15s - %s\n", ENVIRON["LABEL"], ENVIRON["TEXT"]);}'
endef
export format_help