view Makefile @ 19:ef0807d0e202

Set RPM_ARCH to value of rpm %{_arch} macro.
author Thomas Fitzsimmons <fitzsim@redhat.com>
date Thu, 12 Jul 2007 17:54:01 -0400
parents 2022edf22abc
children
line wrap: on
line source

# -*- Makefile -*-
#
# Common Makefile for building RPMs
# Licensed under the new-BSD license (http://www.opensource.org/licenses/bsd-license.php)
# Copyright (C) 2004-2005 Red Hat, Inc.
# Copyright (C) 2005 Fedora Foundation
#
# $Id: Makefile.common,v 1.68 2007/07/02 13:00:55 ausil Exp $

NAME := java-1.7.0-icedtea
SPECFILE = $(firstword $(wildcard *.spec))

DIST_DEFINES = --define "dist %{nil}"

## a base directory where we'll put as much temporary working stuff as we can
ifndef WORKDIR
WORKDIR := $(shell pwd)
endif
## of course all this can also be overridden in your RPM macros file,
## but this way you can separate your normal RPM setup from your CVS
## setup. Override RPM_WITH_DIRS in ~/.cvspkgsrc to avoid the usage of
## these variables.
SRCRPMDIR ?= $(WORKDIR)
BUILDDIR ?= $(WORKDIR)
RPMDIR ?= $(WORKDIR)

## SOURCEDIR is special; it has to match the CVS checkout directory, 
## because the CVS checkout directory contains the patch files. So it basically 
## can't be overridden without breaking things. But we leave it a variable
## for consistency, and in hopes of convincing it to work sometime.
ifndef SOURCEDIR
SOURCEDIR := $(shell pwd)
endif

ifndef RPM_DEFINES
RPM_DEFINES = --define "_sourcedir $(SOURCEDIR)" \
		--define "_builddir $(BUILDDIR)" \
		--define "_srcrpmdir $(SRCRPMDIR)" \
		--define "_rpmdir $(RPMDIR)" \
                $(DIST_DEFINES)
endif

# Initialize the variables that we need, but are not defined
# the version of the package
ifndef NAME
$(error "You can not run this Makefile without having NAME defined")
endif
ifndef VERSION
VERSION := $(shell rpm $(RPM_DEFINES) $(DIST_DEFINES) -q --qf "%{VERSION}\n" --specfile $(SPECFILE)| head -1)
endif
# the release of the package
ifndef RELEASE
RELEASE := $(shell rpm $(RPM_DEFINES) $(DIST_DEFINES) -q --qf "%{RELEASE}\n" --specfile $(SPECFILE)| head -1)
endif
# this is used in make patch, maybe make clean eventually.
# would be nicer to autodetermine from the spec file...
RPM_BUILD_DIR ?= $(BUILDDIR)/$(NAME)-$(VERSION)

ARCH = $(shell uname -m | sed 's/i.86/i586/')
RPM_ARCH = $(shell rpm --eval "%{_arch}")

all: sources $(ARCH)

# The repository and the clients we use for the files
REPOSITORY ?= http://cvs.fedora.redhat.com/repo/pkgs
UPLOAD_REPOSITORY ?= https://cvs.fedora.redhat.com/repo/pkgs/upload.cgi

# RPM with all the overrides in place; you can override this in your
# .cvspkgsrc also, to use a default rpm setup
# the rpm build command line
ifndef RPM
RPM := $(shell if test -f /usr/bin/rpmbuild ; then echo rpmbuild ; else echo rpm ; fi)
endif
ifndef RPM_WITH_DIRS
RPM_WITH_DIRS = $(RPM) $(RPM_DEFINES)
endif

# source file basenames
SOURCEFILES := $(shell cat sources 2>/dev/null | awk '{ print $$2 }')
# full path to source files
FULLSOURCEFILES := $(addprefix $(SOURCEDIR)/,$(SOURCEFILES))

# list the possible targets for valid arches
ARCHES = i586 x86_64

# for the modules that do different "make prep" depending on what arch we build for
PREP_ARCHES	= $(addprefix prep-,$(ARCHES))

## list all our bogus targets
.PHONY :: $(ARCHES) sources tag test-srpm srpm verrel clean patch mockbuild prep compile install-short compile-short FORCE local

# build for a particular arch
$(ARCHES) : sources $(TARGETS)
	$(RPM_WITH_DIRS) --target $@ -ba $(SPECFILE) 2>&1 | tee .build-$(VERSION)-$(RELEASE).log
	@exit ${PIPESTATUS[0]}

# empty target to force checking of md5sums in FULLSOURCEFILES
FORCE:

# build whatever's appropriate for the local architecture
local: $(ARCH)

tag:
	hg tag $(NAME)-$(VERSION)-$(RELEASE)

mockbuild: srpm
	mock -r fedora-devel-$(RPM_ARCH) --arch=$(ARCH) $(NAME)-$(VERSION)-$(RELEASE).src.rpm

prep: sources $(TARGETS)
	$(RPM_WITH_DIRS) --nodeps -bp --target $(ARCH) $(SPECFILE)

compile: sources $(TARGETS)
	$(RPM_WITH_DIRS) -bc $(SPECFILE)

compile-short: sources $(TARGETS)
	$(RPM_WITH_DIRS) --nodeps --short-circuit -bc $(SPECFILE)

install-short: sources $(TARGETS)
	$(RPM_WITH_DIRS) --nodeps --short-circuit -bi $(SPECFILE)

## use this to build an srpm locally
srpm: sources $(TARGETS)
	$(RPM_WITH_DIRS) $(DIST_DEFINES) --nodeps -bs $(SPECFILE)

test-srpm: srpm

verrel:
	@echo $(NAME)-$(VERSION)-$(RELEASE)

# mop up, printing out exactly what was mopped.
clean ::
	@echo "Running the %clean script of the rpmbuild..."
	-@$(RPM_WITH_DIRS) --clean --nodeps $(SPECFILE)
	@for F in $(FULLSOURCEFILES); do \
                if test -e $$F ; then \
                        echo "Deleting $$F" ; /bin/rm -f $$F ; \
                fi; \
        done
	@if test -d $(TMPCVS); then \
		echo "Deleting CVS dir $(TMPCVS)" ; \
		/bin/rm -rf $(TMPCVS); \
	fi
	@if test -e $(SRCRPMDIR)/$(NAME)-$(VERSION)-$(RELEASE).src.rpm ; then \
		echo "Deleting $(SRCRPMDIR)/$(NAME)-$(VERSION)-$(RELEASE).src.rpm" ; \
		/bin/rm -f $(SRCRPMDIR)/$(NAME)-$(VERSION)-$(RELEASE).src.rpm ; \
        fi
	@rm -fv *~ clog
	@echo "Fully clean!"

clog: $(SPECFILE)
	@sed -n '/^%changelog/,/^$$/{/^%/d;/^$$/d;s/%%/%/g;p}' $(SPECFILE) | tee $@

help:
	@echo "Usage: make <target>"
	@echo "Available targets are:"
	@echo "	help			Show this text"
	@echo "	sources			Download source files [default]"
	@echo "	<arch>			Local test rpmbuild binary"
	@echo "	local			Local test rpmbuild binary"
	@echo "	prep			Local test rpmbuild prep"
	@echo "	compile			Local test rpmbuild compile"
	@echo "	compile-short		Local test rpmbuild short-circuit compile"
	@echo "	install-short		Local test rpmbuild short-circuit install"
	@echo "	srpm			Create a srpm"
	@echo "	verrel			Echo \"$(NAME)-$(VERSION)-$(RELEASE)\""
	@echo "	clog			Make a clog file containing top changelog entry"
	@echo "	clean			Remove srcs ($(SOURCEFILES)), export dir (cvs-$(TAG)) and srpm ($(NAME)-$(VERSION)-$(RELEASE).src.rpm)"
	@echo "	unused-patches		Print list of patches not referenced by name in specfile"
	@echo "	gimmespec		Print the name of the specfile"

gimmespec:
	@echo "$(SPECFILE)"

unused-patches:
	@for f in *.patch; do if [ -e $$f ]; then grep -q $$f $(SPECFILE) || echo $$f; fi; done