Commit 26d4aa37 authored by Anthony Mallet's avatar Anthony Mallet
Browse files

[mk] Add a 'clean-build' toplevel target, for 'checkout' packages

This runs a `make clean` inside the package source. This is probably only
useful for packages that are 'checkout', where `make clean` can't run.

While here, let `make cleaner` invoke this target for a checkout package,
instead of doing nothing.

The clean-build target can be customized through CLEAN_TARGET (or
CLEAN_TARGET.<build dir>) and CLEAN_MAKE_CMD. CLEAN_MAKE_FLAGS is also
available, defaulting to BUILD_MAKE_FLAGS.
parent 2930af11
#
# Copyright (c) 2006-2011,2013 LAAS/CNRS
# Copyright (c) 2006-2011,2013,2018 LAAS/CNRS
# Copyright (c) 1994-2006 The NetBSD Foundation, Inc.
# All rights reserved.
#
......@@ -101,7 +101,17 @@ BUILD_MAKE_CMD?=\
${BUILD_MAKE_FLAGS} -f ${MAKE_FILE} ${BUILD_TARGET.$1}
# The filter for the {pre,post,}-build targets
# Clean build variables
CLEAN_TARGET?= clean
$(foreach _,${BUILD_DIRS},$(eval CLEAN_TARGET.$_?= ${CLEAN_TARGET}))
CLEAN_MAKE_FLAGS?=${BUILD_MAKE_FLAGS}
CLEAN_MAKE_CMD?=\
${SETENV} ${MAKE_ENV} ${MAKE_PROGRAM} ${MAKE_FLAGS} \
${CLEAN_MAKE_FLAGS} -f ${MAKE_FILE} ${CLEAN_TARGET.$1}
# The filter for the {pre,post,}-{,clean}-build targets
#
BUILD_LOGFILE?= ${WRKDIR}/build.log
BUILD_LOGFILTER?=\
......
#
# Copyright (c) 2018 LAAS/CNRS
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice and this list of conditions.
# 2. Redistributions in binary form must reproduce the above copyright
# notice and this list of conditions in the documentation and/or
# other materials provided with the distribution.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
# IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# Anthony Mallet on Wed Apr 11 2018
#
# This file defines how to clear the build phase.
#
# Package-settable variables:
#
# CLEAN_MAKE_FLAGS is the list of arguments that is passed to the make
# process, in addition to the usual MAKE_FLAGS.
#
# CLEAN_TARGET is the target from ${MAKE_FILE} that should be invoked
# to clean the sources.
#
# Variables defined in this file:
#
# CLEAN_MAKE_CMD
# This command sets the proper environment for the build phase
# and runs make(1) on it. It takes a list of make targets and
# flags as argument.
#
$(call require, ${ROBOTPKG_DIR}/mk/build/build-vars.mk)
# --- clean-build (PRIVATE) ------------------------------------------------
#
# clean-build is a target to clean the built sources of the package.
#
$(call require, ${ROBOTPKG_DIR}/mk/depends/depends-vars.mk)
_CLEAN_BUILD_TARGETS+= $(call add-barrier, depends, clean-build)
_CLEAN_BUILD_TARGETS+= configure
_CLEAN_BUILD_TARGETS+= acquire-clean-build-lock
_CLEAN_BUILD_TARGETS+= clean-build-message
_CLEAN_BUILD_TARGETS+= do-clean-build
_CLEAN_BUILD_TARGETS+= clean-build-cookie
_CLEAN_BUILD_TARGETS+= release-clean-build-lock
.PHONY: clean-build
ifeq (yes,$(call exists,${_COOKIE.build}))
$(call require, ${ROBOTPKG_DIR}/mk/configure/configure.mk)
cleaner: $(call add-barrier, depends, cleaner) clean-build
clean-build: ${_CLEAN_BUILD_TARGETS};
else
cleaner clean-build:
@${DO_NADA}
endif
.PHONY: acquire-clean-build-lock release-clean-build-lock
acquire-clean-build-lock: acquire-lock
release-clean-build-lock: release-lock
.PHONY: clean-build-message
clean-build-message:
@${PHASE_MSG} "Running clean for ${PKGNAME}"
${RUN} \
${ECHO} "--- Environment ---" >${BUILD_LOGFILE}; \
${SETENV} >>${BUILD_LOGFILE}; \
${ECHO} "---" >>${BUILD_LOGFILE}
# --- clean-build-cookie (PRIVATE) -----------------------------------------
#
# clean-build-cookie removes the ${_COOKIE.build} cookie file.
#
.PHONY: clean-build-cookie
clean-build-cookie:
${RUN}${RM} -f ${_COOKIE.build}
# --- do-clean-build (PUBLIC, override) ------------------------------------
#
# do-clean-build is the heart of the package-customizable clean target
#
do-clean-build: SHELL=${BUILD_LOGFILTER}
do-clean-build: .SHELLFLAGS=--
do%clean-build: .FORCE
${_OVERRIDE_TARGET}
${RUN} \
$(foreach _dir_,${BUILD_DIRS}, \
cd ${WRKSRC} && cd ${_dir_} && $(call CLEAN_MAKE_CMD,${_dir_}); \
)
#
# Copyright (c) 2006,2009-2011,2013 LAAS/CNRS
# Copyright (c) 2006,2009-2011,2013,2018 LAAS/CNRS
# All rights reserved.
#
# This project includes software developed by the NetBSD Foundation, Inc.
......@@ -82,14 +82,19 @@ $(call require,${ROBOTPKG_DIR}/mk/extract/extract-vars.mk)
ifneq (,$(call isyes,${_EXTRACT_IS_CHECKOUT}))
.PHONY: clean-confirm-checkout
clean-confirm-checkout:
@${ERROR_MSG} ${hline}; \
${ERROR_MSG} "$${bf}A checkout is present in the build directory$${rm}" \
"of ${PKGBASE}."; \
${ERROR_MSG} ""; \
${ERROR_MSG} "You must confirm the cleaning action by doing"; \
${ERROR_MSG} " \`$${bf}${MAKE} clean confirm$${rm}' in" \
"${PKGPATH}"; \
${ERROR_MSG} ${hline}; \
@${ERROR_MSG} ${hline}; \
${ERROR_MSG} "$${bf}A checkout is present in the build" \
"directory$${rm} of ${PKGBASE}."; \
${ERROR_MSG} ""; \
${ERROR_MSG} "You must confirm the cleaning action by doing"; \
${ERROR_MSG} " \`$${bf}${MAKE} clean confirm$${rm}' in"\
"${PKGPATH}"; \
${ERROR_MSG} ""; \
${ERROR_MSG} "Alternatively, you can clean the built sources" \
"by running"; \
${ERROR_MSG} " \`$${bf}${MAKE} cleaner$${rm}' in" \
"${PKGPATH}"; \
${ERROR_MSG} ${hline}; \
${FALSE}
ifeq (,$(filter confirm,${MAKECMDGOALS}))
......@@ -164,9 +169,7 @@ clean: ${_CLEAN_TARGETS}
.PHONY: cleaner
ifneq (,$(call isyes,${_EXTRACT_IS_CHECKOUT}))
$(call require, ${ROBOTPKG_DIR}/mk/depends/depends-vars.mk)
cleaner: clean-message pre-clean post-clean
$(call require, ${ROBOTPKG_DIR}/mk/build/clean.mk)
else
cleaner: clean
endif
......
......@@ -114,6 +114,8 @@ $(call require-for, configure, \
# Build
$(call require-for, all build, \
${ROBOTPKG_DIR}/mk/build/build.mk)
$(call require-for, clean-build, \
${ROBOTPKG_DIR}/mk/build/clean.mk)
# Install
$(call require-for, install install-failsafe su-install-all \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment