1#!/usr/bin/make 2 3DEFAULT_VERSION := $(shell grep 'define NXT_VERSION' ../../src/nxt_main.h \ 4 | sed -e 's/^.*"\(.*\)".*/\1/') 5 6DEFAULT_RELEASE := 1 7 8VERSION ?= $(DEFAULT_VERSION) 9RELEASE ?= $(DEFAULT_RELEASE) 10 11BUILD_DEPENDS_unit = libxml2 libxslt rpm-build rpmlint 12BUILD_DEPENDS = $(BUILD_DEPENDS_unit) 13 14ifeq ($(shell rpm --eval "%{?rhel}"), 6) 15OSVER = centos6 16else ifeq ($(shell rpm --eval "%{?rhel}"), 7) 17OSVER = centos7 18else ifeq ($(shell rpm --eval "%{?amzn}"), 1) 19OSVER = amazonlinux1 20BUILD_DEPENDS += system-rpm-config 21else ifeq ($(shell rpm --eval "%{?amzn}"), 2) 22OSVER = amazonlinux2 23endif 24 25MODULES= 26 27ifneq (,$(findstring $(OSVER),centos6 centos7 amazonlinux2)) 28include Makefile.php 29include Makefile.python 30include Makefile.go 31endif 32 33ifeq ($(OSVER), amazonlinux1) 34include Makefile.php 35include Makefile.python27 36include Makefile.python34 37include Makefile.python35 38include Makefile.python36 39include Makefile.go 40endif 41 42CONFIGURE_ARGS=\ 43 --prefix=/usr \ 44 --state=%{_sharedstatedir}/unit \ 45 --control="unix:/var/run/control.unit.sock" \ 46 --pid=/var/run/unit.pid \ 47 --log=/var/log/unit.log \ 48 --tests 49 50export CR=\\n 51 52default: 53 @echo "valid targets: all modules unit $(addprefix unit-, $(MODULES)) rpmlint specs clean" 54 55all: check-build-depends unit modules 56 57modules: $(addprefix unit-, $(MODULES)) 58 59specs: $(addsuffix .spec, $(addprefix rpmbuild/SPECS/unit-, $(MODULES))) 60 61check-build-depends: 62 @{ \ 63 not_installed= ; \ 64 for pkg in $(BUILD_DEPENDS); do \ 65 rpm -qi $${pkg} >/dev/null 2>&1 ; \ 66 if [ $$? -ne 0 ]; then \ 67 not_installed="$${not_installed} $${pkg}" ; \ 68 fi ; \ 69 done ; \ 70 if test -n "$${not_installed}" ; then \ 71 echo "" >&2 ; \ 72 echo "The following packages are required in order to proceed:" >&2 ; \ 73 echo "" >&2 ; \ 74 echo $${not_installed} >&2 ; \ 75 echo "" >&2 ; \ 76 exit 1 ; \ 77 fi \ 78 } 79 80check-build-depends-%: 81 @{ \ 82 not_installed= ; \ 83 for pkg in $(BUILD_DEPENDS_unit) $(BUILD_DEPENDS_$*); do \ 84 rpm -qi $${pkg} >/dev/null 2>&1 ; \ 85 if [ $$? -ne 0 ]; then \ 86 not_installed="$${not_installed} $${pkg}" ; \ 87 fi ; \ 88 done ; \ 89 if test -n "$${not_installed}" ; then \ 90 echo "" >&2 ; \ 91 echo "The following packages are required in order to proceed:" >&2 ; \ 92 echo "" >&2 ; \ 93 echo $${not_installed} >&2 ; \ 94 echo "" >&2 ; \ 95 exit 1 ; \ 96 fi \ 97 } 98 99rpmbuild/SPECS: 100 mkdir -p rpmbuild/SPECS 101 102rpmbuild/SPECS/unit.spec: unit.spec.in ../../docs/changes.xml | rpmbuild/SPECS 103 cat unit.spec.in | \ 104 sed -e "s#%%VERSION%%#$(VERSION)#g" \ 105 -e "s#%%RELEASE%%#$(RELEASE)#g" \ 106 -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \ 107 > rpmbuild/SPECS/unit.spec 108 cd ../../docs && make ../build/unit.rpm-changelog 109ifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE)) 110 cat ../../build/unit.rpm-changelog | sed -e \ 111 "s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(VERSION)-$(RELEASE)/" \ 112 >> rpmbuild/SPECS/unit.spec 113else 114 cat ../../build/unit.rpm-changelog >> rpmbuild/SPECS/unit.spec 115endif 116 117rpmbuild/SOURCES/unit-$(VERSION).tar.gz: 118 cd ../.. && tar -czf pkg/rpm/rpmbuild/SOURCES/unit-$(VERSION).tar.gz \ 119 --transform "s#^#unit-$(VERSION)/#" \ 120 LICENSE NOTICE CHANGES README configure auto src test 121 122unit: check-build-depends-unit rpmbuild/SPECS/unit.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz 123 @echo "===> Building $@ package" ; \ 124 rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/unit.spec && \ 125 ln -s rpmbuild/BUILD/$@-$(VERSION)/build $@ 126 127rpmlint: 128 find rpmbuild/ -name "*.rpm" -print -exec rpmlint {} \; 129 130rpmbuild/SPECS/unit-%.spec: unit.module.spec.in ../../docs/changes.xml | rpmbuild/SPECS 131 @echo "===> Creating $@" 132 @{ \ 133 set -e ; \ 134 i=100 ; \ 135 sources= ; \ 136 for src in $(MODULE_SOURCES_$*); do \ 137 s="`printf "Source%d: %s\n" $${i} $${src}`" ; \ 138 sources="$${sources}\n$${s}" ; \ 139 i=$$(($${i}+1)) ; \ 140 done ; \ 141 pkgname=$(shell echo $@ | cut -d '/' -f 3 | cut -d '.' -f 1) ; \ 142 definitions=`echo "$$MODULE_DEFINITIONS_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \ 143 preinstall=`echo "$$MODULE_PREINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \ 144 files=`echo "$$MODULE_FILES_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \ 145 post=`echo "$$MODULE_POST_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \ 146 cat unit.module.spec.in | sed \ 147 -e "s#%%NAME%%#$${pkgname}#g" \ 148 -e "s#%%SUMMARY%%#$(MODULE_SUMMARY_$*)#g" \ 149 -e "s#%%VERSION%%#$(MODULE_VERSION_$*)#g" \ 150 -e "s#%%RELEASE%%#$(MODULE_RELEASE_$*)#g" \ 151 -e "s#%%UNIT_VERSION%%#$(VERSION)#g" \ 152 -e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \ 153 -e "s#%%MODULE_SOURCES%%#$${sources}#g" \ 154 -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \ 155 -e "s#%%MODULE_CONFARGS%%#$(MODULE_CONFARGS_$*)#g" \ 156 -e "s#%%MODULE_MAKEARGS%%#$(MODULE_MAKEARGS_$*)#g" \ 157 -e "s#%%MODULE_INSTARGS%%#$(MODULE_INSTARGS_$*)#g" \ 158 -e "s#%%MODULE_DEFINITIONS%%#$${definitions}#g" \ 159 -e "s#%%MODULE_PREINSTALL%%#$${preinstall}#g" \ 160 -e "s#%%MODULE_FILES%%#$${files}#g" \ 161 -e "s#%%MODULE_POST%%#$${post}#g" \ 162 > $@.tmp ; \ 163 } 164 cd ../../docs && make ../build/unit-$*.rpm-changelog 165 cat ../../build/unit-$*.rpm-changelog | sed -e \ 166 "s/> - $(DEFAULT_VERSION)-$(DEFAULT_RELEASE)/> - $(MODULE_VERSION_$*)-$(MODULE_RELEASE_$*)/" \ 167 >> $@.tmp 168 mv $@.tmp $@ 169 170unit-%: check-build-depends-% rpmbuild/SPECS/unit-%.spec rpmbuild/SOURCES/unit-$(VERSION).tar.gz 171 @echo "===> Building $@ package" ; \ 172 rpmbuild -D "_topdir `pwd`/rpmbuild" -ba rpmbuild/SPECS/$@.spec && \ 173 ln -s rpmbuild/BUILD/$@-$(VERSION)/build $@ 174 175clean: 176 rm -rf rpmbuild/SPECS rpmbuild/BUILD rpmbuild/BUILDROOT rpmbuild/RPMS rpmbuild/SRPMS ../../build 177 rm -f rpmbuild/SOURCES/unit-*.tar.gz unit 178 find . -maxdepth 1 -type l -delete 179 180.PHONY: default all modules specs check-build-depends rpmlint clean 181 182.SECONDARY: 183