[Asterisk-code-review] build tools: Major changes to accomodate building from docker (repotools[master])

George Joseph asteriskteam at digium.com
Mon May 7 15:37:33 CDT 2018


George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/8937 )

Change subject: build_tools:  Major changes to accomodate building from docker
......................................................................

build_tools:  Major changes to accomodate building from docker

The original implementation wasn't very good at optimizing the
builds of product variants for architecure or libcp usage nor was
it good at reusing the subversion repositories.

Now, when making tarballs the architectures are grouped together so
asterisk will be reconifgured, and libcp built, as few times as
possible.

The staging and public subversion directories are also not cleaned out
after every build which saves significant time.

Change-Id: I6dd7cea2dc83c3d2e1c7ba4b64a38154598f719c
---
M build_tools/Makefile.dependencies
M build_tools/Makefile.product_rules
A build_tools/copy2svn
D build_tools/make_stage
M build_tools/make_tarball
5 files changed, 412 insertions(+), 243 deletions(-)

Approvals:
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/build_tools/Makefile.dependencies b/build_tools/Makefile.dependencies
index d979a7d..b336259 100644
--- a/build_tools/Makefile.dependencies
+++ b/build_tools/Makefile.dependencies
@@ -1,7 +1,7 @@
 # Extra compile-time flags to build dependencies. Recursively expanded.
 MAKE_DEPS=-MD -MT $@ -MF .$(subst /,_,$@).d -MP
 
-distclean::
+clean::
 	@rm -f .*.d
 
 ifneq ($(wildcard .*.d),)
diff --git a/build_tools/Makefile.product_rules b/build_tools/Makefile.product_rules
index eafeb8f..7d57617 100644
--- a/build_tools/Makefile.product_rules
+++ b/build_tools/Makefile.product_rules
@@ -1,18 +1,24 @@
 SHELL=/bin/bash
 
-MODULE_NAME?=$(notdir $(shell pwd))
+ifeq ($(wildcard /etc/os-release),)
+$(error Unable to identify disitrbution.  This product can be built only on CentOS 7+ or Fedora 26+.)
+endif
 
+_DISTRO_OK := $(shell grep -qE 'ID="(centos|fedora)"' /etc/os-release && echo yes)
+ifneq ($(_DISTRO_OK),yes)
+$(error This product can be built only on CentOS 7+ or Fedora 26+.)
+endif
+
+MODULE_NAME?=$(notdir $(shell pwd))
 export MODULE_NAME
 
 ifeq ($(NOISY_BUILD),)
     ECHO_PREFIX=@
     CMD_PREFIX=@
 else
-    ECHO_PREFIX=@\#
+    ECHO_PREFIX=@
     CMD_PREFIX=
 endif
-
-all:: $(MODULE_NAME).so $(MODULE_EXTRA_LIBRARIES)
 
 include repotools/build_tools/Makefile.version
 
@@ -25,18 +31,16 @@
 
 CFLAGS+=-D_REENTRANT -D_GNU_SOURCE -pipe
 
-ARCH?=$(subst i686,x86_32,$(shell uname -m))
-ARCH_BITS=$(subst x86_,,$(ARCH))
+DEFAULT_ARCHES=x86_32 x86_64
+ARCHES=$(DEFAULT_ARCHES)
+ARCH=$(subst i686,x86_32,$(shell uname -m))
 BUILD_ARCH=$(subst x86_32,i686,$(ARCH))
-FLAVOR_LDEMUL=$(if $(findstring x86_32,$(ARCH)),elf_i386,elf_x86_64)
 
-FLAVOR_MODE=$(if $(filter x86_32,$(ARCH)),-m32,-m64)
-FLAVOR_CFLAGS=$(FLAVOR_MODE) $(if $(findstring x86_64,$(ARCH)),-fPIC)
-FLAVOR_LIBDIR=$(if $(findstring x86_32,$(ARCH)),/usr/lib,$(if $(wildcard /usr/lib64),/usr/lib64,/usr/lib))
-FLAVOR_ASTLIBDIR=$(FLAVOR_LIBDIR)/asterisk
-DEBUG_OPT=$(if $(DEBUG:no=),-O0 -g3,-O3 -g0)
+CFLAGS+=$(if $(findstring x86_64,$(ARCH)),-m64 -fPIC,-m32)
+LIBDIR=$(if $(findstring x86_32,$(ARCH)),/usr/lib,$(if $(wildcard /usr/lib64),/usr/lib64,/usr/lib))
+ASTLIBDIR=$(LIBDIR)/asterisk
+DEBUG_CFLAGS=$(if $(DEBUG:no=),-O0 -g3,-O3 -g0)
 
-SOLINK=-shared -Wl,--version-script,$(subst .so,.exports,$@)
 STRIP:=strip
 INSTALL:=install
 ASTINCDIR:=./asterisk/include
@@ -44,42 +48,117 @@
 
 yesno=$(if $(findstring yes,$(1)),yes,no)
 yesonly=$(if $(findstring yes,$(1)),yes,)
+setflag=$(if $(findstring yes,$(1)),$(2))
+suffixnodot=$(subst .,,$(suffix $(1)))
 
-define libcp_build
-	echo "   [MAKE] libcp_build $(ARCH) ";\
-	$(MAKE) INDENT="+   " --quiet --no-print-directory -C libcp clean;\
-	$(MAKE) INDENT="+   " --quiet --no-print-directory -C libcp ARCH=$(ARCH) OPT="$(FLAVOR_CFLAGS)" DEBUG="$(DEBUG_OPT)" libcp.a;
+define help
+Choose a target variant to build.  You can choose one of the standard target
+variants like:
+base:  To build the standard target
+nocp:  To build the standard target without libcp copy protection.
+debug: To build the standard target with debug info.
+
+Each of these targets will, by default, build the module for the current
+architecture and create a tarball.  For this module and environment, they
+would be:
+$(MODULE_NAME)-$(PRODUCT_VERSION)-$(ARCH).tar.gz
+$(MODULE_NAME)-nocp-$(PRODUCT_VERSION)-$(ARCH).tar.gz
+$(MODULE_NAME)-debug-$(PRODUCT_VERSION)-$(ARCH).tar.gz
+
+You can build a target for a specific architecture by appending either
+".x86_32" or ".x86_64" to the target.
+For example: make base.x86_32
+Or you can build both architectures using "both".
+For example: make base.both
+
+By default, the version is constructed from current git information.
+If you want to override this and specify a specific version, set the
+PRODUCT_VERSION variable on the command line.
+For example: make base PRODUCT_VERSION='13.0_3.1.1'
+
+If you have module specific target variants defined in your Makefile, you can
+use those instead of the standard target variants.  Adding the architecture
+suffix works for them as well.
+
+You can build more than 1 variant by specifying them on the command line
+but if you're going to build more than a few, using the special target
+"tarballs" will be faster.  By default it will build tarballs for all
+variants and all architectures but you can limit what gets bult as follows:
+Build everything: make tarballs
+Build only 64 bit tarballs: make tarballs.x86_64
+Build only certain variants: make tarballs VARIANTS="base nocp"
+Of course, you can specify PRODUCT_VERSION as well.
+
+Using "tarballs" has the advantage of ordering the 32 and 64 bit builds to
+minimize the number of times asterisk has to be reconfigured or libraries
+built.
+
+Once tarballs are built you can copy them to the subversion repositories
+using the "web-staging" or "web-public" targets.  These targets DO NOT
+automatically build tarballs.  They only copy existing tarballs.
+BEFORE USING THESE TARGETS, MAKE SURE YOU"VE COMMITTED YOUR CHANGES AND
+CREATED AN ANNOTATED TAG FOR THIS RELEASE!!!
+For testing purposes, you can set the following variables on the command
+line:
+SKIP_CHECKS=yes : Skips the version tag checks.
+NO_COMMI=yes : Updates the local repo from the remote and copies in tarballs
+               but doesn't commit them.
+Like the tarballs target, you can copy a specific architecture or limit
+the variants to be copied
+Copy everything to the web-staging repo: make web-staging
+Copy only the 32 bit tarballs: make web-staging.x86_32
+Copy but don't commit: make web-staging NO_COMMIT=yes
+
 endef
 
-COPYPROTECT_BITS=$(shell ((objdump -f libcp/libcp.a 2>/dev/null) || echo "") | sed -n -r -e "s/^cp.o:.*elf(32|64)-.*/\1/p")
-COPYPROTECT_BUILD_NEEDED=$(if $(wildcard libcp),$(if $(findstring $(ARCH_BITS),$(COPYPROTECT_BITS)),,yes),)
-COPYPROTECT_BUILD=$(if $(filter-out FAKE no,$(COPYPROTECT)),$(if $(COPYPROTECT_BUILD_NEEDED),$(call libcp_build)))
-COPYPROTECT_CFLAGS=$(if $(wildcard libcp),$(if $(filter-out no,$(COPYPROTECT)),-DCOPYPROTECT $(if $(filter FAKE,$(COPYPROTECT)),-DFAKECOPYPROTECT) $(if $(MAXCALLS),-DMAXCALLS=$(MAXCALLS)) -Ilibcp))
-COPYPROTECT_LIBS=$(if $(wildcard libcp),$(if $(filter-out FAKE no,$(COPYPROTECT)),-Llibcp -lcp))
+ifeq ($(MAKECMDGOALS),)
+$(info $(help))
+endif
 
-define asterisk_configure
-	echo "   [MAKE] asterisk_configure $(ARCH) $(ASTERISK_CONFIGURE_FLAGS). This may take a minute or 2...";\
-	cd asterisk;\
-	$(MAKE) --quiet --no-print-directory distclean &>/dev/null;\
-	./configure $(ASTERISK_CONFIGURE_FLAGS) &>/dev/null || exit 1;\
-	$(MAKE) --quiet --no-print-directory include/asterisk/buildopts.h &>/dev/null;\
-	sed -i -e /GCC_ATOMICS/d include/asterisk/autoconfig.h;
-endef
+.PHONY: all
+all:
+	@echo
 
-ASTERISK_ARCH=$(shell sed -n -r -e "s/HOST_PLATFORM=([^-]+)-.+/\1/p" asterisk/makeopts 2>/dev/null || echo "unknown")
-ASTERISK_ARCH_MISMATCH=$(if $(findstring $(BUILD_ARCH),$(ASTERISK_ARCH)),,yes)
+.PHONY: libcp-build
+libcp-build:
+	$(CMD_PREFIX) [ "$(call yesno,$(COPYPROTECT))" != "yes" ] && exit 0 ;\
+	lastconfig=`cat last_$@~ 2>/dev/null || :`;\
+	currconfig="$(ARCH) $(CFLAGS) $(DEBUG_CFLAGS)";\
+	if [ "x$$lastconfig" != "x$$currconfig" ] ; then\
+		echo " [MAKE PREREQ] $@ $(ARCH) with $(DEBUG_CFLAGS)";\
+		$(MAKE) INDENT="+   " --quiet --no-print-directory -C libcp clean;\
+		$(MAKE) INDENT="+   " --quiet --no-print-directory -j -C libcp ARCH=$(ARCH) OPT="$(CFLAGS)" DEBUG="$(DEBUG_CFLAGS)" libcp.a && \
+		echo "$$currconfig" > last_libcp_build~;\
+	else \
+		echo " [MAKE PREREQ] $@ $(ARCH) with $(DEBUG_CFLAGS) not needed";\
+	fi;
+
+COPYPROTECT_CFLAGS=$(if $(call yesonly,$(COPYPROTECT)),-DCOPYPROTECT -Ilibcp) $(if $(MAXCALLS),-DMAXCALLS=$(MAXCALLS))
+COPYPROTECT_LIBS=$(if $(call yesonly,$(COPYPROTECT)),-Llibcp -lcp)
+
+.PHONY: asterisk-configure
+asterisk-configure:
+	@lastconfig=`cat last_$@~ 2>/dev/null || :`;\
+	currconfig="$(ARCH) $(ASTERISK_CONFIGURE_FLAGS)";\
+	if [ "x$$lastconfig" != "x$$currconfig" ] ; then \
+		cd asterisk;\
+		echo " [MAKE PREREQ] $@ $(ARCH) $(ASTERISK_CONFIGURE_FLAGS). This may take a minute or 2...";\
+		$(MAKE) --quiet --no-print-directory distclean &>/dev/null;\
+		./configure $(ASTERISK_CONFIGURE_FLAGS) &>/dev/null || exit 1;\
+		$(MAKE) --quiet --no-print-directory include/asterisk/buildopts.h &>/dev/null;\
+		sed -i -e /GCC_ATOMICS/d include/asterisk/autoconfig.h;\
+		cd ..;\
+		echo "$$currconfig" > last_asterisk_build~;\
+	else \
+		echo " [MAKE PREREQ] $@ $(ARCH) $(ASTERISK_CONFIGURE_FLAGS).  not needed";\
+	fi;
+
 
 PJPROJECT_BUNDLED_NEEDED=$(if $(PJPROJECT_BUNDLED),$(PJPROJECT_BUNDLED:no=),)
-ASTERISK_PJPROJECT_BUNDLED=$(shell sed -n -r -e "s/PJPROJECT_BUNDLED=(yes)/\1/p" asterisk/makeopts 2>/dev/null)
-ASTERISK_PJPROJECT_MISMATCH=$(if $(findstring $(call yesno,$(PJPROJECT_BUNDLED_NEEDED)),$(call yesno,$(ASTERISK_PJPROJECT_BUNDLED))),,yes)
-
-ASTERISK_CONFIGURE_NEEDED=$(if $(ASTERISK_ARCH_MISMATCH)$(ASTERISK_PJPROJECT_MISMATCH),yes,)
 ASTERISK_CONFIGURE_FLAGS=$(if $(PJPROJECT_BUNDLED_NEEDED),--with-pjproject-bundled) --host=$(BUILD_ARCH)-linux-gnu
-ASTERISK_CONFIGURE=$(if $(ASTERISK_CONFIGURE_NEEDED),$(asterisk_configure))
-
 PJPROJECT_INCLUDES=$(if $(PJPROJECT_BUNDLED_NEEDED),$(filter-out -O2,$(shell sed -n -r -e "s/PJPROJECT_INCLUDE=(.*)/\1/gp" asterisk/makeopts 2>/dev/null)))
 
-PRODUCT_DIR=$(MODULE_NAME)$(if $(VARIANT),-$(VARIANT))-$(PRODUCT_VERSION)-$(ARCH)
+PRECHECKS=asterisk-configure libcp-build
 
 optarch.h: FORCE
 	@echo "#define OPTARCH \" (optimized for $(BUILD_ARCH)\"" > $@.tmp
@@ -90,138 +169,197 @@
 
 CFLAGS+=$(MODULE_SDK_CFLAGS)
 MODULE_OBJS=$(MODULE_NAME).o $(MODULE_EXTRA_OBJS)
-
 $(MODULE_OBJS): CFLAGS+=-I$(ASTINCDIR) -I/usr/include -I -Iinclude -DAST_MODULE=\"$(MODULE_NAME)\" -DAST_MODULE_SELF_SYM=__internal_$(MODULE_NAME)_self
 
-.c.o::
+$(sort $(MODULE_OBJS) $(MODULE_EXTRA_LIBRARY_OBJS)): %.o : %.c optarch.h version.h
 	$(ECHO_PREFIX) echo "  [CC] $@"
-	$(CMD_PREFIX) $(CC) -c $< -o $@ $(PJPROJECT_INCLUDES) $(CFLAGS) $(FLAVOR_CFLAGS) $(DEBUG_OPT) $(WARN) $(MAKE_DEPS)
+	$(CMD_PREFIX) $(CC) -c $< -o $@ $(PJPROJECT_INCLUDES) $(CFLAGS) $(DEBUG_CFLAGS) $(WARN) $(MAKE_DEPS) $(COPYPROTECT_CFLAGS)
 
-$(sort $(MODULE_OBJS) $(MODULE_EXTRA_LIBRARY_OBJS)): %.o :%.c optarch.h version.h
-	$(ECHO_PREFIX) echo "  [CC] $@"
-	$(CMD_PREFIX) $(ASTERISK_CONFIGURE)
-	$(CMD_PREFIX) $(CC) -c $< -o $@ $(PJPROJECT_INCLUDES) $(CFLAGS) $(FLAVOR_CFLAGS) $(DEBUG_OPT) $(WARN) $(MAKE_DEPS) $(COPYPROTECT_CFLAGS)
 
-$(MODULE_NAME).so: $(MODULE_OBJS) $(MODULE_SDK_OBJS) $(MODULE_SDK_LIB)
-	$(ECHO_PREFIX) echo "  [LD] $@"
-	$(CMD_PREFIX) $(COPYPROTECT_BUILD)
-	$(CMD_PREFIX) $(CC) $(FLAVOR_CFLAGS) $(DEBUG_OPT) $(SOLINK) -o .$@ $^ $(LDFLAGS) $(LIBS) $(COPYPROTECT_LIBS)
-	$(CMD_PREFIX) echo "$(MODULE_NAME),$(VARIANT),$(PRODUCT_VERSION)" >.$@.ast_manifest
-	$(CMD_PREFIX) $(OBJCOPY) --add-section .ast_manifest=.$@.ast_manifest --set-section-flags .ast_manifest=noload,readonly .$@ $@
-	$(CMD_PREFIX) rm .$@ .$@.ast_manifest 2>/dev/null || :
-
+$(MODULE_EXTRA_LIBRARIES): LIBRARY_NAME=$(@)
+$(MODULE_EXTRA_LIBRARIES): SOLINK=-shared -Wl,--version-script,$(subst .so,.exports,$(LIBRARY_NAME))
 $(MODULE_EXTRA_LIBRARIES): $(MODULE_EXTRA_LIBRARY_OBJS) $(MODULE_SDK_OBJS) $(MODULE_SDK_LIB)
-	$(ECHO_PREFIX) echo "  [LD] $@"
-	$(CMD_PREFIX) $(COPYPROTECT_BUILD)
-	$(CMD_PREFIX) $(CC) $(FLAVOR_CFLAGS) $(DEBUG_OPT) $(SOLINK) -o .$@ $^ $(LDFLAGS) $(LIBS) $(COPYPROTECT_LIBS)
-	$(CMD_PREFIX) echo "$(MODULE_NAME),$(VARIANT),$(PRODUCT_VERSION)" >.$@.ast_manifest
-	$(CMD_PREFIX) $(OBJCOPY) --add-section .ast_manifest=.$@.ast_manifest --set-section-flags .ast_manifest=noload,readonly .$@ $@
-	$(CMD_PREFIX) rm .$@ .$@.ast_manifest 2>/dev/null || :
+	$(ECHO_PREFIX) echo "  [LD] $(LIBRARY_NAME) $(ARCH)"
+	$(CMD_PREFIX) $(CC) $(CFLAGS) $(DEBUG_CFLAGS) $(SOLINK) -o .$(LIBRARY_NAME) $^ $(LDFLAGS) $(LIBS) $(COPYPROTECT_LIBS)
+	$(CMD_PREFIX) echo "$(MODULE_NAME),$(VARIANT),$(PRODUCT_VERSION)" >.$(LIBRARY_NAME).ast_manifest
+	$(CMD_PREFIX) $(OBJCOPY) --add-section .ast_manifest=.$(LIBRARY_NAME).ast_manifest --set-section-flags .ast_manifest=noload,readonly .$(LIBRARY_NAME) $(LIBRARY_NAME)
+	$(CMD_PREFIX) rm .$(LIBRARY_NAME) .$(LIBRARY_NAME).ast_manifest *.o 2>/dev/null || :
 
+$(MODULE_NAME).so: LIBRARY_NAME=$(MODULE_NAME).so
+$(MODULE_NAME).so: SOLINK=-shared -Wl,--version-script,$(subst .so,.exports,$(LIBRARY_NAME))
+$(MODULE_NAME).so: $(MODULE_OBJS) $(MODULE_SDK_OBJS) $(MODULE_SDK_LIB)
+	$(ECHO_PREFIX) echo "  [LD] $(LIBRARY_NAME) $(ARCH)"
+	$(CMD_PREFIX) $(CC) $(CFLAGS) $(DEBUG_CFLAGS) $(SOLINK) -o .$(LIBRARY_NAME) $^ $(LDFLAGS) $(LIBS) $(COPYPROTECT_LIBS)
+	$(CMD_PREFIX) echo "$(LIBRARY_NAME),$(VARIANT),$(PRODUCT_VERSION)" >.$(LIBRARY_NAME).ast_manifest
+	$(CMD_PREFIX) $(OBJCOPY) --add-section .ast_manifest=.$(LIBRARY_NAME).ast_manifest --set-section-flags .ast_manifest=noload,readonly .$(LIBRARY_NAME) $(LIBRARY_NAME)
+	$(CMD_PREFIX) rm .$(LIBRARY_NAME) .$(LIBRARY_NAME).ast_manifest  *.o 2>/dev/null || :
+
+.PHONY: base nocp debug
+
+base: COPYPROTECT=yes
+base: MANIFEST_IN=manifest-base.xml.in
+
+nocp: export COPYPROTECT=
+nocp: export MANIFEST_IN=manifest-base.xml.in
+
+debug: export COPYPROTECT=yes
+debug: export DEBUG=yes
+debug: export NO_STRIP=yes
+debug: export MANIFEST_IN=manifest-base.xml.in
+
+#
+# Things get a little weird here.  Because the target variants all share
+# prerequiresites like clean, $(MODULE_NAME).so, etc, you can't just specify
+# multiple targets on the command line and expect them all to be built from
+# scratch.  make will think it's already build the module and won't bother
+# making it again with new options like COPYPROTECT or DEBUG.
+#
+# To get around this, we need to call submakes and test which level we're at.
+#
+
+.PHONY: $(VARIANTS)
+ifneq ($(findstring 2,$(MAKELEVEL))$(findstring 3,$(MAKELEVEL)),)
+
+# This is the actual build for a target variant for either architecture.
+    $(VARIANTS): V=$@
+# We strip out "base" if that's the variant because we don't want that as
+# part of the tarball name.
+    $(VARIANTS): TAR_VARIANT=$(if $(findstring base,$(V)),,$(V))
+    $(VARIANTS): PRODUCT_DIR=$(MODULE_NAME)$(if $(TAR_VARIANT),-$(TAR_VARIANT))-$(PRODUCT_VERSION)-$(ARCH)
+# We want the intro header printed before everything else.
+# Double colon "::" rules are executed independently of other "::" rules.
+    $(VARIANTS)::
+	    $(ECHO_PREFIX) echo "[BEGIN] $(PRODUCT_DIR) COPYPROTECT=$(COPYPROTECT) DEBUG=$(DEBUG) PJPROJECT_BUNDLED=$(PJPROJECT_BUNDLED)"
+# The clean and prechecks must be run before the regular prereqs are built and
+# we also don't want them in the $^ variable.  The "::" rules enforce both
+# conditions,
+    $(VARIANTS):: clean $(PRECHECKS)
+    $(VARIANTS):: $(MODULE_NAME).so $(MODULE_EXTRA_LIBRARIES)
+		$(ECHO_PREFIX) echo " [TAR] $(PRODUCT_DIR)"
+		$(CMD_PREFIX)repotools/build_tools/make_tarball $(call setflag,$(DEBUG),--no-strip) --version=$(PRODUCT_VERSION) \
+			--arch=$(ARCH) --package-name=$(MODULE_NAME) --variant=$(TAR_VARIANT) --manifest-in=$(MANIFEST_IN) --manifest-out=$(MANIFEST) $(PRODUCT_DIR).tar.gz $^
+		$(ECHO_PREFIX) echo "[COMPLETE] $(PRODUCT_DIR)  COPYPROTECT=$(COPYPROTECT) DEBUG=$(DEBUG) PJPROJECT_BUNDLED=$(PJPROJECT_BUNDLED)"
+		$(ECHO_PREFIX) echo
+
+else
+
+# These are the targets that will be called either directly from the command
+# line, or from the architecture specific targets.  We need submake for these.
+    $(VARIANTS):
+		@$(MAKE) --no-print-directory $@ ARCH=$(ARCH)
+endif
+
+# These are the architecture specific variant targets like base.x86_64.
+# They can get called from the command line or from the tarballs targets.
+
+_AV:=$(foreach da,$(DEFAULT_ARCHES),$(addsuffix .$(da),$(VARIANTS))) $(addsuffix .both,$(VARIANTS))
+.PHONY: $(_AV)
+$(_AV): ARCH=$(call suffixnodot,$@)
+$(_AV):
+	@if [ "$(ARCH)" != "both" ] ; then \
+		$(MAKE) --no-print-directory $(basename $@) ARCH=$(ARCH) ;\
+	else \
+		for a in $(ARCHES) ; do \
+			$(MAKE) --no-print-directory $(basename $@) ARCH=$${a} ;\
+		done; \
+	fi
+
+# We group by architecture to reduce the number of times that asterisk
+# needs to be reconfigured and libraries need to be rebuilt
+
+.PHONY: tarballs
+tarballs:
+	@for a in $(ARCHES) ; do \
+		for v in $(VARIANTS) ; do \
+			$(MAKE) --no-print-directory $${v}.$${a} ;\
+		done ;\
+	done
+
+_ATB:=$(addprefix tarballs.,$(DEFAULT_ARCHES))
+.PHONY: $(_ATB)
+$(_ATB): ARCHES=$(call suffixnodot,$@)
+$(_ATB):
+	@$(MAKE) --no-print-directory ARCHES="$(ARCHES)" tarballs
+
+#
+# ############# copy tarballs to svn directories
+#
+
+ifeq ($(MAKELEVEL),0)
+# If called from the command line, we loop through arches and variants
+# and call submakes.
+    copy2svn:
+		@for a in $(ARCHES) ; do \
+			for v in $(VARIANTS) ; do \
+				tv=-$${v} ;\
+				[ $${v} = base ] && tv="" ;\
+				tarfile=$(MODULE_NAME)$${tv}-$(PRODUCT_VERSION)-$${a}.tar.gz ;\
+				if [ -f $${tarfile} ] ; then \
+				$(MAKE) --no-print-directory \
+					V=$${v} ARCH=$${a} SKIP_CHECKS=$(SKIP_CHECKS) NO_COMMIT=$(NO_COMMIT) LOCAL_DIR=$(LOCAL_DIR) REPO=$(REPO) IGNORE_EXTERNALS=$(IGNORE_EXTERNALS) \
+					copy2svn ;\
+				else \
+					echo " [COPY2SVN] No tarball found for $(MODULE_NAME)$${tv}-$(PRODUCT_VERSION)-$${a}" ;\
+				fi ;\
+			done ;\
+		done
+else
+# Otherwise, we do the actual copy.
+    copy2svn: TAR_VARIANT=$(if $(findstring base,$(V)),,$(V))
+    copy2svn:
+		$(ECHO_PREFIX) echo " [COPY2SVN] $(MODULE_NAME): $(V) $(PRODUCT_VERSION) $(ARCH) -> $(LOCAL_DIR)"
+		@if [ -z "$(REPO)" ] ; then echo -e "Missing REPO=<repository>" ; exit 1 ; fi
+		@if [ -z "$(LOCAL_DIR)" ] ; then echo -e "Missing LOCAL_DIR=<local directory>" ; exit 1 ; fi
+		$(CMD_PREFIX)repotools/build_tools/copy2svn --version=$(PRODUCT_VERSION) --arch=$(ARCH) --package-name=$(MODULE_NAME) \
+			--variant=$(TAR_VARIANT) --svn-subdir=$(SVN_SUBDIR) --local-dir=$(LOCAL_DIR) \
+			$(call setflag,$(SKIP_CHECKS),--skip-checks) \
+			$(call setflag,$(IGNORE_EXTERNALS),--ignore-externals) \
+			$(call setflag,$(NO_COMMIT),--no-commit) \
+			--repo=$(REPO)
+endif
+
+$(addprefix copy2svn.,$(DEFAULT_ARCHES)): ARCHES=$(call suffixnodot,$@)
+$(addprefix copy2svn.,$(DEFAULT_ARCHES)):
+	@$(MAKE) --no-print-directory \
+		ARCHES="$(ARCHES)" SKIP_CHECKS=$(SKIP_CHECKS) NO_COMMIT=$(NO_COMMIT) LOCAL_DIR=$(LOCAL_DIR) REPO=$(REPO) IGNORE_EXTERNALS=$(IGNORE_EXTERNALS) \
+		copy2svn
+
+web-staging: LOCAL_DIR=web-staging
+web-staging: copy2svn
+$(addprefix web-staging.,$(ARCHES)): LOCAL_DIR=web-staging
+$(addprefix web-staging.,$(ARCHES)): copy2svn.$(call suffixnodot,$@)
+
+web-public: LOCAL_DIR=web-public
+web-public: copy2svn
+$(addprefix web-public.,$(ARCHES)): LOCAL_DIR=web-public
+ $(addprefix web-public.,$(ARCHES)): copy2svn.$(call suffixnodot,$@)
+
+# Utils
+
+printit: SORTED_VARS=$(sort $(filter-out .VARIABLES,$(.VARIABLES)))
+printit: XXX=$(foreach v,$(SORTED_VARS),$(v)=$($(v))\n)
+printit:
+	@echo -e " $(XXX)"
+
+.PHONY: clean distclean superclean
 clean::
-	@rm -f *.o *.so manifest.xml
+	$(ECHO_PREFIX) echo " [CLEAN]"
+	@rm -f *.o *.so manifest*.xml *~
 
 distclean:: clean
+	$(ECHO_PREFIX) echo " [DISTCLEAN]"
 	- at rm -f optarch.h version.h
 
 superclean:: distclean
-	- at rm -rf *.o $(MODULE_SDK_OBJS) $(MODULE_SDK_LIB) &>/dev/null
+	$(ECHO_PREFIX) echo " [SUPERCLEAN]"
+	- at rm -rf *.o $(MODULE_SDK_OBJS) $(MODULE_SDK_LIB) last*~ &>/dev/null
 	@if [ -d libcp ] ; then $(MAKE) --quiet --no-print-directory  -C libcp clean &>/dev/null ; fi
 	-@$(MAKE) --quiet --no-print-directory -C asterisk distclean &>/dev/null
 
+.PHONY: install everything
 install:: $(MODULE_NAME).so $(MODULE_EXTRA_LIBRARIES)
-	$(INSTALL) -m 755 -t $(DESTDIR)$(FLAVOR_ASTLIBDIR)/modules/ $^
+	$(INSTALL) -m 755 -t $(DESTDIR)$(ASTLIBDIR)/modules/ $^
 
-$(MODULE_NAME)-%.tar.gz: PRODUCT_DIR=$(MODULE_NAME)$(if $(VARIANT),-$(VARIANT))-$(PRODUCT_VERSION)-$(ARCH)
-$(MODULE_NAME)-%.tar.gz: $(MODULE_NAME).so $(MODULE_EXTRA_LIBRARIES)
-	$(ECHO_PREFIX) echo " [TAR] $(PRODUCT_DIR).tar.gz"
-	$(CMD_PREFIX)repotools/build_tools/make_tarball --nostrip=$(or $(NOSTRIP),no) --version=$(PRODUCT_VERSION) \
-		--arch=$(ARCH) --package-name=$(MODULE_NAME) --variant=$(VARIANT) --manifest-in=$(MANIFEST_IN) --manifest-out=$(MANIFEST) $(PRODUCT_DIR).tar.gz $^
-
-clean_tarball: COPYPROTECT=yes
-clean_tarball:: distclean $(PRODUCT_DIR).tar.gz
-
-debug: DEBUG=yes
-debug: NOSTRIP=yes
-debug: VARIANT=debug
-debug: distclean $(PRODUCT_DIR).tar.gz
-
-nocp: COPYPROTECT=
-nocp: VARIANT=nocp
-nocp: distclean $(PRODUCT_DIR).tar.gz
-
-tarballs_64: export ARCH=x86_64
-tarballs_64: PRODUCTS+=clean_tarball
-tarballs_64:
-	@echo "[TARGET] $@: $(PRODUCTS)"
-	@for p in $(PRODUCTS) ; do \
-		echo " [TARGET] $$p $(ARCH) " ;\
-		$(MAKE) --no-print-directory $$p || exit 1 ;\
-		echo " [TARGET] $$p $(ARCH) COMPLETE" ;\
-	done
-	@echo "[TARGET] $@: $(PRODUCTS) COMPLETE"
-	@echo
-
-tarballs_32: export ARCH=x86_32
-tarballs_32: PRODUCTS+=clean_tarball
-tarballs_32:
-	@echo "[TARGET] $@: $(PRODUCTS)"
-	@for p in $(PRODUCTS) ; do \
-		echo " [TARGET] $$p $(ARCH) " ;\
-		$(MAKE) --no-print-directory $$p || exit 1 ;\
-		echo " [TARGET] $$p $(ARCH) COMPLETE" ;\
-	done
-	@echo "[TARGET] $@: $(PRODUCTS) COMPLETE"
-	@echo
-
-everything: superclean tarballs_64 tarballs_32
-
-stage_32: export ARCH:=x86_32
-stage_32: export REPO:=$(REPO)
-stage_32: export VARIANT:=$(VARIANT)
-stage_32:
-	$(ECHO_PREFIX) echo " [STAGE] $@"
-	@if [ -z "$(REPO)" ] ; then echo -e "Missing REPO=<repository>.\nExample: make stage REPO=https://origsvn.digium.com/svn/sites/downloads.digium.com/staging/telephony\n\n" ; exit 1 ; fi
-	$(CMD_PREFIX)repotools/build_tools/make_stage --version=$(PRODUCT_VERSION) --arch=$(ARCH) --package-name=$(MODULE_NAME) \
-		--variant=$(VARIANT) --stage-subdir=$(STAGE_SUBDIR) --skip-checks=$(SKIP_CHECKS) --repo=$(REPO)
-
-stage_64: export ARCH=x86_64
-stage_64: export REPO:=$(REPO)
-stage_64: export VARIANT:=$(VARIANT)
-stage_64:
-	$(ECHO_PREFIX) echo " [STAGE] $<"
-	@if [ -z "$(REPO)" ] ; then echo -e "Missing REPO=<repository>.\nExample: make stage REPO=https://origsvn.digium.com/svn/sites/downloads.digium.com/staging/telephony\n\n" ; exit 1 ; fi
-	$(CMD_PREFIX)repotools/build_tools/make_stage --version=$(PRODUCT_VERSION) --arch=$(ARCH) --package-name=$(MODULE_NAME) \
-		--variant=$(VARIANT) --stage-subdir=$(STAGE_SUBDIR) --skip-checks=$(SKIP_CHECKS) --repo=$(REPO)
-
-stage: stage_32 stage_64
-
-printit:
-	@echo ------------------
-	@echo ARCH=$(ARCH)
-	@echo ARCH_BITS=$(ARCH_BITS)
-	@echo BUILD_ARCH=$(BUILD_ARCH)
-	@echo FLAVOR_LDEMUL=$(FLAVOR_LDEMUL)
-	@echo FLAVOR_LIBDIR=$(FLAVOR_LIBDIR)
-	@echo FLAVOR_MODE=$(FLAVOR_MODE)
-	@echo FLAVOR_CFLAGS=$(FLAVOR_CFLAGS)
-	@echo FLAVOR_ASTLIBDIR=$(FLAVOR_ASTLIBDIR)
-	@echo COPYPROTECT_BITS=$(COPYPROTECT_BITS)
-	@echo COPYPROTECT_BUILD_NEEDED=$(COPYPROTECT_BUILD_NEEDED)
-	@echo COPYPROTECT_CFLAGS=$(COPYPROTECT_CFLAGS)
-	@echo COPYPROTECT_LIBS=$(COPYPROTECT_LIBS)
-	@echo PJPROJECT_BUNDLED=$(PJPROJECT_BUNDLED)
-	@echo PJPROJECT_BUNDLED_NEEDED=$(PJPROJECT_BUNDLED_NEEDED)
-	@echo PJPROJECT_INCLUDES=$(PJPROJECT_INCLUDES)
-	@echo ASTERISK_ARCH=$(ASTERISK_ARCH)
-	@echo ASTERISK_ARCH_MISMATCH=$(ASTERISK_ARCH_MISMATCH)
-	@echo ASTERISK_PJPROJECT_BUNDLED=$(ASTERISK_PJPROJECT_BUNDLED?no)
-	@echo ASTERISK_PJPROJECT_MISMATCH=$(ASTERISK_PJPROJECT_MISMATCH)
-	@echo ASTERISK_CONFIGURE_NEEDED=$(ASTERISK_CONFIGURE_NEEDED)
-	@echo ASTERISK_CONFIGURE_FLAGS=$(ASTERISK_CONFIGURE_FLAGS)
+everything: superclean tarballs
 
 FORCE:
-
-.PHONY: all buildver clean install distclean superclean
-.PHONY: tarballs_64 tarballs_32 everything stage_32 stage_64 stage
-
diff --git a/build_tools/copy2svn b/build_tools/copy2svn
new file mode 100755
index 0000000..1add381
--- /dev/null
+++ b/build_tools/copy2svn
@@ -0,0 +1,114 @@
+#!/bin/bash
+if [[ ( ${BASH_VERSINFO[0]} == 4 && ${BASH_VERSINFO[1]} > 1 ) || ${BASH_VERSINFO[0]} > 4 ]] ; then
+	shopt -s compat41
+fi
+set -e
+
+PUSHD() {
+	&>/dev/null pushd $1
+}
+POPD() {
+	&>/dev/null popd
+}
+
+script_path=$(readlink -f ${0})
+script_dir=$(dirname ${script_path})
+
+skip_checks=0
+no_commit=0
+include_externals=
+
+while [ ${#@} -gt 0 ] ; do
+	case ${1} in
+	--package-name=*)
+		package_name=${1#*=}
+		;;
+	--version=*)
+		version=${1#*=}
+		;;
+	--arch=*)
+		arch=${1#*=}
+		;;
+	--repo=*)
+		repo=${1#*=}
+		;;
+	--variant=*)
+		variant=${1#*=}
+		;;
+	--svn-subdir=*)
+		svn_subdir=${1#*=}
+		;;
+	--local-dir=*)
+		local_dir=${1#*=}
+		;;
+	--skip-checks)
+		skip_checks=1
+		;;
+	--no-commit)
+		no_commit=1
+		;;
+	--include-externals)
+		include_externals="--include-externals"
+		;;
+	esac
+	shift
+done
+
+git_status=$(git status --porcelain)
+
+if [ -n "${git_status}" -a ${skip_checks} = 0 ] ; then
+	echo -e "This directory has uncommitted changes.\n${git_status}\n"
+	exit 1
+fi
+
+if [[ ! "${version}" =~ ^([0-9]+\.[0-9]+(\.[0-9]+)?)_([0-9]+\.[0-9]+\.[0-9]+)(-(rc[0-9]+))?$ && "${skip_checks}" != "yes" ]] ; then
+	echo "version(${version}) isn't a valid tag.\n"
+	exit 1
+fi
+is_rc=${BASH_REMATCH[5]}
+
+ignore_externals="--ignore-externals"
+if [ -n "${include_externals}" ] ; then
+	ignore_externals=""
+fi
+
+astversion=${version%_*}
+prodversion=${version#*_}
+subdir=asterisk-${astversion}/${arch/_/-}
+svndir=${repo}/${subdir}
+package_dir=${package_name}${variant:+-${variant}}-${version}-${arch}
+tarball=${package_dir}.tar.gz
+svn ls ${svndir} &> /dev/null || svn mkdir --parents ${svndir} -m "Create svn subdir directory"
+
+if [ -d ${local_dir}/.svn ] ; then
+	actreporoot=`svn info ${local_dir} | sed -n -r -e "s/URL: //gp"`
+	if [ x${actreporoot} != x${repo} ] ; then
+		rm -rf ${local_dir} &>/dev/null || :
+		svn co ${ignore_externals} ${reporoot} ${local_dir}
+	else
+		PUSHD ${local_dir}
+		svn update ${ignore_externals} >/dev/null 
+		POPD
+	fi
+else
+	rm -rf ${local_dir} &>/dev/null || :
+	svn co ${ignore_externals} ${repo} ${local_dir}
+fi
+
+cp ${tarball} ${local_dir}/${subdir}
+tar --strip-components=1 -xzf ${tarball} -O ${package_dir}/manifest.xml > ${local_dir}/${subdir}/manifest${variant:+-${variant}}.xml
+tar --strip-components=1 -xzf ${tarball} -C ${local_dir}/${subdir} ${package_dir}/README &>/dev/null || :
+tar --strip-components=1 -xzf ${tarball} -C ${local_dir}/${subdir} ${package_dir}/LICENSE &>/dev/null || :
+PUSHD ${local_dir}/${subdir}
+if [ -z "$is_rc" ] ; then
+	ln -sf ${tarball} ${package_name}${variant:+-${variant}}-${astversion}_current-${arch}.tar.gz
+fi
+
+for file in * ; do
+	svn add $file 2>/dev/null || :
+done
+POPD
+
+if [ ${no_commit} = no ] ; then
+	svn commit ${local_dir} ${include_externals} -m "commit ${package_name}${variant:+-${variant}}-${version}-${arch} builds to staging"
+fi
diff --git a/build_tools/make_stage b/build_tools/make_stage
deleted file mode 100755
index 29fc2ed..0000000
--- a/build_tools/make_stage
+++ /dev/null
@@ -1,83 +0,0 @@
-#!/bin/bash
-if [[ ( ${BASH_VERSINFO[0]} == 4 && ${BASH_VERSINFO[1]} > 1 ) || ${BASH_VERSINFO[0]} > 4 ]] ; then
-	shopt -s compat41
-fi
-set -e
-
-script_path=$(readlink -f ${0})
-script_dir=$(dirname ${script_path})
-
-skip_checks=no
-
-while [ ${#@} -gt 0 ] ; do
-	case ${1} in
-	--package-name=*)
-		package_name=${1#*=}
-		;;
-	--version=*)
-		version=${1#*=}
-		;;
-	--arch=*)
-		arch=${1#*=}
-		;;
-	--repo=*)
-		repo=${1#*=}
-		;;
-	--variant=*)
-		variant=${1#*=}
-		;;
-	--stage-subdir=*)
-		stage_subdir=${1#*=}
-		;;
-	--skip-checks=*)
-		skip_checks=${1#*=}
-		;;
-	esac
-	shift
-done
-
-git_status=$(git status --porcelain)
-
-if [ -n "${git_status}" -a "${skip_checks}" != "yes" ] ; then
-	echo -e "This directory has uncommitted changes.\n${git_status}\n"
-	exit 1
-fi
-
-if [[ ! "${version}" =~ ^([0-9]+\.[0-9]+(\.[0-9]+)?)_([0-9]+\.[0-9]+\.[0-9]+)(-(rc[0-9]+))?$ && "${skip_checks}" != "yes" ]] ; then
-	echo "version(${version}) isn't a valid tag.\n"
-	exit 1
-fi
-isrc=${BASH_REMATCH[5]}
-
-directory_name=$(sed -n -r -e "/MODULEINFO/,/[*]{3}\// s/.*\s+directory_name=\"([^\"]+)\".*/\1/gp" ${package_name}.c )
-
-astversion=${version%_*}
-prodversion=${version#*_}
-stagedir=${repo}/${directory_name:-${package_name}}/${stage_subdir:+${stage_subdir}/}asterisk-${astversion}/${arch/_/-}
-package_dir=${package_name}${variant:+-${variant}}-${version}-${arch}
-tarball=${package_dir}.tar.gz
-
-svn ls ${stagedir} &> /dev/null || svn mkdir --parents ${stagedir} -m "Create staging directory"
-if [ -d staging/.svn ] ; then
-	pushd staging
-	svn update
-	popd
-else
-	rm -rf staging &>/dev/null || :
-	svn co ${stagedir} staging
-fi
-
-cp ${tarball} staging/
-tar --strip-components=1 -xzf ${tarball} -O ${package_dir}/manifest.xml > staging/manifest${variant:+-${variant}}.xml
-tar --strip-components=1 -xzf ${tarball} -C staging ${package_dir}/README &>/dev/null || :
-tar --strip-components=1 -xzf ${tarball} -C staging ${package_dir}/LICENSE &>/dev/null || :
-pushd staging &>/dev/null
-if [ -z "$isrc" ] ; then
-	ln -sf ${tarball} ${package_name}${variant:+-${variant}}-${astversion}_current-${arch}.tar.gz
-fi
-for file in * ; do
-	svn add $file 2>/dev/null || :
-done
-popd &>/dev/null
-
-svn commit staging -m "commit ${package_name}${variant:+-${variant}}-${version}-${arch} builds to staging"
diff --git a/build_tools/make_tarball b/build_tools/make_tarball
index 4c9f893..500fe61 100755
--- a/build_tools/make_tarball
+++ b/build_tools/make_tarball
@@ -12,7 +12,7 @@
 script_path=$(readlink -f ${0})
 script_dir=$(dirname ${script_path})
 
-nostrip=no
+no_strip=
 declare -a module_list
 
 while [ ${#@} -gt 0 ] ; do
@@ -29,8 +29,8 @@
 	--manifest-out=*)
 		manifest_out=${1#*=}
 		;;
-	--nostrip=*)
-		nostrip=${1#*=}
+	--no_strip)
+		nostrip=1
 		;;
 	--version=*)
 		version=${1#*=}
@@ -49,7 +49,7 @@
 done
 
 if [[ ( -z "${package_name}" ) || ( -z "${module_list[@]}" ) ]] ; then
-	echo "Usage ${0} --package-name=<package name> [ --variant=<variant> ] [ --manifest-in=<manifest.xml.in> ] [ --arch=(x86_32 | x86_64) ] [ --nostrip=(yes|no) ] [ --version=<x.x_y.y.y> ] <module list>"
+	echo "Usage ${0} --package-name=<package name> [ --variant=<variant> ] [ --manifest-in=<manifest.xml.in> ] [ --arch=(x86_32 | x86_64) ] [ --no_strip ] [ --version=<x.x_y.y.y> ] <module list>"
 	exit 1
 fi
 
@@ -93,7 +93,7 @@
 	mkdir -p ${tardir}/$(dirname ${tfile:-${file}})
 	cp ${file} ${tardir}/${tfile:-${file}}
 
-	if [[ "${nostrip}" != "yes" && "${executable}" == "yes" ]] ; then
+	if [[ -z "${no_strip}" && "${executable}" == "yes" ]] ; then
 		strip ${tardir}/${tfile:-${file}}
 	fi
 done

-- 
To view, visit https://gerrit.asterisk.org/8937
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: repotools
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I6dd7cea2dc83c3d2e1c7ba4b64a38154598f719c
Gerrit-Change-Number: 8937
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180507/88294b03/attachment-0001.html>


More information about the asterisk-code-review mailing list