1# Create .deb without using dpkg tools.
2#
3# Author: Tim Wegener <twegener@madabar.com>
4#
5# Use 'include deb_hand.mak' after defining the user variables in a local
6# makefile.
7#
8# The 'data' rule must be customised in the local make file.
9# This rule should make a 'data' directory containing the full file
10# layout of the installed package.
11#
12# This makefile will create a debian-binary file a control directory and a
13# a build directory in the current directory.
14# Do 'make clobber' to remove these generated files.
15#
16# Destination:
17# PACKAGE_DIR - directory where package (and support files) will be built
18#               defaults to the current directory
19#
20# Sources:
21# SOURCE_DIR - directory containing files to be packaged
22# ICON_SOURCE - 26x26 icon file for maemo
23# description.txt - description with summary on first line
24# preinst, postinst, prerm, postrm - optional control shell scripts
25
26# These fields are used to build the control file:
27# PACKAGE =
28# VERSION =
29# ARCH =
30# SECTION =
31# PRIORITY =
32# MAINTAINER =
33# DEPENDS =
34#
35# SOURCE_DIR =
36# ICON_SOURCE =
37# (ICON_SOURCE is optional)
38
39# *** NO USER CHANGES REQUIRED BEYOND THIS POINT ***
40
41GAWK=awk
42PACKAGE_DIR ?= .
43CONTROL_EXTRAS ?= ${wildcard preinst postinst prerm postrm}
44
45${PACKAGE_DIR}/control: ${PACKAGE_DIR}/data ${CONTROL_EXTRAS} description.txt \
46			${ICON_SOURCE}
47	#rm -rf $@
48	mkdir -p $@
49ifneq (${CONTROL_EXTRAS},)
50	cp ${CONTROL_EXTRAS} $@
51endif
52#       Make control file.
53	echo "Package: ${PACKAGE}" > $@/control
54	echo "Version: ${VERSION}" >> $@/control
55	echo "Section: ${SECTION}" >> $@/control
56	echo "Priority: ${PRIORITY}" >> $@/control
57	echo "Architecture: ${ARCH}" >> $@/control
58	echo "Depends: ${DEPENDS}" >> $@/control
59	echo "Installed-Size: ${shell du -s ${PACKAGE_DIR}/data|cut -f1}" \
60		>> $@/control
61	echo "Maintainer: ${MAINTAINER}" >> $@/control
62	printf "Description:" >> $@/control
63	cat description.txt | ${GAWK} '{print " "$$0;}' >> $@/control
64#ifneq (${ICON_SOURCE},)
65#	echo "Maemo-Icon-26:" >> $@/control
66#	base64 ${ICON_SOURCE} | ${GAWK} '{print " "$$0;}' >> $@/control
67#endif
68#       Make md5sums.
69	cd ${PACKAGE_DIR}/data && find . -type f -exec md5sum {} \; \
70		| sed -e 's| \./||' \
71		> $@/md5sums
72
73${PACKAGE_DIR}/debian-binary:
74	echo "2.0" > $@
75
76${PACKAGE_DIR}/clean:
77	rm -rf ${PACKAGE_DIR}/data ${PACKAGE_DIR}/control ${PACKAGE_DIR}/build *.deb
78
79${PACKAGE_DIR}/build: ${PACKAGE_DIR}/debian-binary ${PACKAGE_DIR}/control \
80			${PACKAGE_DIR}/data
81	rm -rf $@
82	mkdir $@
83	cp ${PACKAGE_DIR}/debian-binary $@/
84	cd ${PACKAGE_DIR}/control && tar czvf $@/control.tar.gz *
85	cd ${PACKAGE_DIR}/data && tar czvf $@/data.tar.gz ./*
86
87# Convert GNU ar to BSD ar that debian requires.
88# Note: Order of files within ar archive is important!
89${PACKAGE_DIR}/${PACKAGE}_${VERSION}_${ARCH}.deb: ${PACKAGE_DIR}/build
90	${AR} -rc $@ $</debian-binary $</control.tar.gz $</data.tar.gz
91	#sed -e 's|^\([^/]\+\)/ \(.*\)|\1  \2|g' $@tmp > $@fail
92	#rm -f $@tmp
93	#mv $@fail $@
94
95.PHONY: data
96data: ${PACKAGE_DIR}/data
97
98.PHONY: control
99control: ${PACKAGE_DIR}/control
100
101.PHONY: build
102build: ${PACKAGE_DIR}/build
103
104.PHONY: clean
105clean: ${PACKAGE_DIR}/clean
106
107.PHONY: deb
108deb: ${PACKAGE_DIR}/${PACKAGE}_${VERSION}_${ARCH}.deb
109
110
111clobber::
112	rm -rf ${PACKAGE_DIR}/debian_binary ${PACKAGE_DIR}/control \
113		${PACKAGE_DIR}/data ${PACKAGE_DIR}/build
114
115