1OCAMLOPT		= ocamlopt
2OCAMLOPTFLAGS	= -thread -w s
3OCAMLOPTLIBS	= str.cmxa unix.cmxa threads.cmxa
4OCAMLINCS		=
5XOBJS			= pdfsandwich_version.cmx
6
7SOURCE = pdfsandwich.ml
8TARGET = pdfsandwich
9MANUAL =	$(TARGET).1.gz
10
11VERSION :=	$(shell cat pdfsandwich_version)
12
13all: $(TARGET) $(MANUAL)
14
15$(TARGET): $(XOBJS) $(SOURCE)
16	$(OCAMLOPT) $(OCAMLOPTFLAGS) $(OCAMLINCS) $(OCAMLOPTLIBS) -o $@ $^
17
18
19%.cmx: %.ml
20	$(OCAMLOPT) $(OCAMLOPTFLAGS) $(OCAMLINCS) $(OCAMLOPTLIBS) -c $<
21
22pdfsandwich_version.ml: pdfsandwich_version
23	echo "let pdfsandwich_version=\"$(VERSION)\";; (*automatically generated from file pdfsandwich_version*)" > $@
24
25$(MANUAL):	manual.txt
26	# you need gawk for this:
27	./txt2man -t PDFSANDWICH manual.txt | gzip -9 > $(MANUAL)
28
29# Canceling pathological implicit rule:
30%: %.o
31
32##############
33### install
34##############
35
36DOCFILES = 	copyright changelog
37
38PREFIX = 		/usr/local
39# this may overwrite PREFIX:
40include makefile.installprefix
41
42PREF = $(DESTDIR)$(PREFIX)
43INSTALL = 	install -s
44CP = 		cp
45INSTALLBINDIR =	$(PREF)/bin
46INSTALLMANDIR = $(PREF)/man/man1
47INSTALLDOCDIR = $(PREF)/share/doc/$(TARGET)
48
49install: $(DOCFILES) $(ADDITIONAL)
50	(umask 0022; mkdir -p $(INSTALLBINDIR) $(INSTALLMANDIR))
51	$(INSTALL) $(TARGET) $(INSTALLBINDIR)
52	#$(CP) $(DOCFILES) $(INSTALLDOCDIR)
53	#gzip -9 $(INSTALLDOCDIR)/changelog
54	$(CP) $(MANUAL) $(INSTALLMANDIR)
55	#chmod 644 $(INSTALLDOCDIR)/* $(INSTALLMANDIR)/*
56
57uninstall:
58	rm -rf $(INSTALLBINDIR)/$(TARGET) $(INSTALLDOCDIR) $(INSTALLMANDIR)/$(MANUAL)
59
60
61##########
62# PACKAGES:
63##########
64SVN=svn
65#REMOTESRCDIR = https://pdfsandwich.svn.sourceforge.net/svnroot/pdfsandwich/trunk/src
66REMOTESRCDIR = https://svn.code.sf.net/p/pdfsandwich/code/trunk/src
67PACKAGE :=	$(TARGET)-$(VERSION)
68bz2: $(PACKAGE).tar.bz2
69
70# source package:
71$(PACKAGE).tar.bz2:
72	# "clean" checkout (unversioned):
73	$(SVN) export $(REMOTESRCDIR) $(PACKAGE)
74	tar -cjf $@ $(PACKAGE)
75	rm -rf $(PACKAGE)
76
77# MacOS X Macport:
78Portfile: $(PACKAGE).tar.bz2 pdfsandwich_version
79	./make_portfile.pl $< > $@
80
81###### deb (Ubuntu)
82
83ARCHITECTURE := $(shell uname -a|perl -e 'while(<>) {print /x86_64/ ? "amd64" : "i386";}')
84DEBPACKAGE :=	$(TARGET)_$(VERSION)_$(ARCHITECTURE)
85DEBDOCDIR = 	$(DEBPACKAGE)/usr/share/doc/$(TARGET)
86
87deb: control md5sums
88	mkdir -p $(DEBPACKAGE)/DEBIAN
89	cp $^ $(DEBPACKAGE)/DEBIAN
90	fakeroot dpkg -b $(DEBPACKAGE)/ .
91
92$(DEBPACKAGE): all
93	$(MAKE) PREFIX=$@/usr install
94	./changelog2deb.pl changelog | gzip -9 > $(DEBDOCDIR)/changelog.Debian.gz
95	chmod 644 $(DEBDOCDIR)/changelog.Debian.gz
96
97md5sums: $(DEBPACKAGE)
98	cd $< && find * -type f -exec md5sum {} \; > ../md5sums
99	chmod 644 md5sums
100
101control: $(DEBPACKAGE)
102	./make_control.pl $< > $@
103
104clean:
105	rm -f *.cmi *.cmo *.cmx *.cma *.cmxa *.o *.a *.so depend $(TARGET)
106	rm -f pdfsandwich_version.ml $(MANUAL)
107	rm -rf $(PACKAGE) $(PACKAGE).tar.bz2 $(DEBPACKAGE) $(DEBPACKAGE).deb
108
109