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# DESCR - 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 ***
40ifeq ($(shell uname),Darwin)
41MD5SUM=md5
42else
43MD5SUM=md5sum
44endif
45
46GAWK=awk
47PACKAGE_DIR?=$(shell pwd)
48ifeq (${PACKAGE_DIR},)
49all:
50	@echo Invalid package directory
51	false
52endif
53CONTROL_EXTRAS ?= ${wildcard preinst postinst prerm postrm}
54
55${PACKAGE_DIR}/control: ${PACKAGE_DIR}/data ${CONTROL_EXTRAS} DESCR \
56			${ICON_SOURCE}
57	#rm -rf $@
58	mkdir -p $@
59ifneq (${CONTROL_EXTRAS},)
60	cp ${CONTROL_EXTRAS} $@
61endif
62#       Make control file.
63	echo "Package: ${PACKAGE}" > $@/control
64	echo "Version: ${VERSION}" >> $@/control
65	echo "Section: ${SECTION}" >> $@/control
66	echo "Priority: ${PRIORITY}" >> $@/control
67	echo "Architecture: ${ARCH}" >> $@/control
68ifneq (${DEPENDS},)
69	echo "Depends: ${DEPENDS}" >> $@/control
70endif
71	echo "Installed-Size: ${shell du -s ${PACKAGE_DIR}/data|cut -f1}" \
72		>> $@/control
73	echo "Maintainer: ${MAINTAINER}" >> $@/control
74	printf "Description:" >> $@/control
75	cat DESCR | ${GAWK} '{print " "$$0;}' >> $@/control
76#ifneq (${ICON_SOURCE},)
77#	echo "Maemo-Icon-26:" >> $@/control
78#	base64 ${ICON_SOURCE} | ${GAWK} '{print " "$$0;}' >> $@/control
79#endif
80#       Make md5sums.
81	cd ${PACKAGE_DIR}/data && find . -type f -exec ${MD5SUM} {} \; \
82		| sed -e 's| \./| |' \
83		> $@/md5sums
84
85${PACKAGE_DIR}/debian-binary:
86	echo "2.0" > $@
87
88${PACKAGE_DIR}/clean:
89	rm -rf ${PACKAGE_DIR}/data ${PACKAGE_DIR}/control ${PACKAGE_DIR}/build *.deb
90
91${PACKAGE_DIR}/build: ${PACKAGE_DIR}/debian-binary ${PACKAGE_DIR}/control \
92			${PACKAGE_DIR}/data
93	rm -rf $@
94	mkdir $@
95	cp ${PACKAGE_DIR}/debian-binary $@/
96	cd ${PACKAGE_DIR}/control && tar cJvf $@/control.tar.xz *
97	cd ${PACKAGE_DIR}/data && \
98		COPY_EXTENDED_ATTRIBUTES_DISABLE=true \
99		COPYFILE_DISABLE=true \
100		tar cpJvf $@/data.tar.xz ./*
101
102# Convert GNU ar to BSD ar that debian requires.
103# Note: Order of files within ar archive is important!
104${PACKAGE_DIR}/${PACKAGE}_${VERSION}_${ARCH}.deb: ${PACKAGE_DIR}/build
105	${AR} -rc $@ $</debian-binary $</control.tar.xz $</data.tar.xz
106	#sed -e 's|^\([^/]\+\)/ \(.*\)|\1  \2|g' $@tmp > $@fail
107	#rm -f $@tmp
108	#mv $@fail $@
109
110.PHONY: data
111data: ${PACKAGE_DIR}/data
112
113.PHONY: control
114control: ${PACKAGE_DIR}/control
115
116.PHONY: build
117build: ${PACKAGE_DIR}/build
118
119.PHONY: clean
120clean: ${PACKAGE_DIR}/clean
121	rm -f debian-binary
122
123.PHONY: mrproper
124mrproper: clean
125	echo ${PACKAGE_DIR}
126	rm -rf root
127
128.PHONY: deb
129deb: ${PACKAGE_DIR}/${PACKAGE}_${VERSION}_${ARCH}.deb
130
131
132clobber::
133	rm -rf ${PACKAGE_DIR}/debian_binary ${PACKAGE_DIR}/control \
134		${PACKAGE_DIR}/data ${PACKAGE_DIR}/build
135
136push:
137	scp *.deb radare.org:/srv/http/radareorg/cydia/debs
138