# Makefile for mergemem
#
# This file is part of mergemem by Philipp Richter & Philipp Reisner
#
# mergemem is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# mergemem is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with mergemem; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#

include ../Makefile.vars
CFLAGS=-O -ansi -pedantic -Wall -I.

it: updates mergetwo updatemmlib.3 mergetwo test updates

all: mmlib.so

mmlib.so: mmlib.o
	$(CC) -shared -o mmlib.so mmlib.o


mmlib.o: mmlib.c mmlib.h kern.h
	$(CC) -ansi -pedantic $(USERFLAGS) -DMOD_VERSION=$(MOD_VERSION) -DVERSION=\"$(VERSION)\" -fPIC -DPIC -c -o mmlib.o mmlib.c

kern.o: kern.c kern.h
	$(CC) -ansi -pedantic $(USERFLAGS) -DMOD_VERSION=$(MOD_VERSION) -DVERSION=\"$(VERSION)\" -fPIC -DPIC -c -o kern.o kern.c



mergetwo.o: mmlib.h mergetwo.c
	cc $(CFLAGS) -I. -c mergetwo.c

mergetwo2.o: mmlib.h mergetwo2.c
	cc $(CFLAGS) -I. -c mergetwo2.c

mergecompletely.o: mmlib.h mergecompletely.c
	cc $(CFLAGS) -I. -c mergecompletely.c


mergetwo: mmlib.o kern.o mergetwo.o
	cc mmlib.o kern.o -o mergetwo mergetwo.o

mergetwo2: mmlib.o kern.o mergetwo2.o
	cc mmlib.o kern.o -o mergetwo2 mergetwo2.o

mergecompletely: mmlib.o kern.o mergecompletely.o
	cc mmlib.o kern.o -o mergecompletely mergecompletely.o



test:	mergecompletely mergetwo 
	./mergetwo 350 40087000-401bc000 `ps a|awk '/[/]memtest[.]gupu/{print $$1}'`
	./mergecompletely 4096 40000000 2000000
#	./mergecompletely 4096 40000000 20000000
#	./mergetwo 5 40087000-401bc000 `ps|awk '/mergemem[/]memtest/{print $$1}'`

updates: updatemmlib.3 mmlib.[ch] mergetwo.c mergecompletely.c kern.[ch] Makefile
	tar cf - $? | ( cd /usr/ftp/pub/ulrich/mergemem/pre0.14; tar xvf - )
	touch updates

updatemmlib.3: mmlib.3
	tar cf - $? | ( cd /usr/ftp/pub/ulrich/mergemem/; tar xvf - )
	touch updatemmlib.3

print_docu:
	groff -Tps -mandoc mmlib.3 | lpr

clean:
	rm -f *.o
	rm -f mmlib.o mmlib.so
	rm -f *~

install:
	install -m 0755 mmlib.so /usr/lib/mmlib.so
	install -m 0644 mmlib.3 /usr/man/man3/mergemem.3	