jniinclude=-I/usr/lib/jvm/java-6-openjdk-amd64/include -I/usr/lib/jvm/java-6-openjdk-i386/include -I/usr/lib/jvm/java-6-openjdk/include
pathdistorm=./distorm3-1.0
pathjdistorm=./jdistorm/jdistorm
pathbuild=./

LINKFLAGS=-pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions 
JDIFLAGS=-c -fPIC -O2 -Wall
DIFLAGS=-c -fPIC -O2 -Wall -DSUPPORT_64BIT_OFFSET -DDISTORM_STATIC -pthread -fno-strict-aliasing -DNDEBUG -fwrapv -Wstrict-prototypes

libjdistorm.so: $(pathbuild)/decoder.o $(pathbuild)/distorm.o $(pathbuild)/instructions.o $(pathbuild)/insts.o $(pathbuild)/mnemonics.o $(pathbuild)/operands.o $(pathbuild)/prefix.o $(pathbuild)/textdefs.o $(pathbuild)/wstring.o $(pathbuild)/x86defs.o $(pathbuild)/jdistorm.o
	gcc $(LINKFLAGS) $^ -o $@
	rm *.o

$(pathbuild)/jdistorm.o: $(pathjdistorm)/jdistorm.c
	gcc $(JDIFLAGS) -I$(pathdistorm)/include $(jniinclude) $^ -o $@

$(pathbuild)/decoder.o: $(pathdistorm)/src/decoder.c
	gcc $(DIFLAGS) -I$(pathdistorm)/include $^ -o $@

$(pathbuild)/distorm.o: $(pathdistorm)/src/distorm.c
	gcc $(DIFLAGS) -I$(pathdistorm)/include $^ -o $@

$(pathbuild)/instructions.o: $(pathdistorm)/src/instructions.c
	gcc $(DIFLAGS) -I$(pathdistorm)/include $^ -o $@

$(pathbuild)/insts.o: $(pathdistorm)/src/insts.c
	gcc $(DIFLAGS) -I$(pathdistorm)/include $^ -o $@

$(pathbuild)/mnemonics.o: $(pathdistorm)/src/mnemonics.c
	gcc $(DIFLAGS) -I$(pathdistorm)/include $^ -o $@

$(pathbuild)/operands.o: $(pathdistorm)/src/operands.c
	gcc $(DIFLAGS) -I$(pathdistorm)/include $^ -o $@

$(pathbuild)/prefix.o: $(pathdistorm)/src/prefix.c
	gcc $(DIFLAGS) -I$(pathdistorm)/include $^ -o $@

$(pathbuild)/textdefs.o: $(pathdistorm)/src/textdefs.c
	gcc $(DIFLAGS) -I$(pathdistorm)/include $^ -o $@

$(pathbuild)/wstring.o: $(pathdistorm)/src/wstring.c
	gcc $(DIFLAGS) -I$(pathdistorm)/include $^ -o $@

$(pathbuild)/x86defs.o: $(pathdistorm)/src/x86defs.c
	gcc $(DIFLAGS) -I$(pathdistorm)/include $^ -o $@

clean:
	rm -f $(pathbuild)/*
	rm -f libjdistorm.so

