# Make sure to set the DYNINST_ROOT environment variable to the directory where
# Dyninst is installed. The directory should contain the include and
# $(PLATFORM)/lib directories

# Or uncomment the following line and change the path accordingly
DYNINST_ROOT = /usr/local

export LD_LIBRARY_PATH := /usr/lib:$(DYNINST_ROOT)/lib:./test1
export DYNINSTAPI_RT_LIB := $(DYNINST_ROOT)/lib/libdyninstAPI_RT.so

DYNINST_INCLUDE = $(DYNINST_ROOT)/include
DYNINST_LIB = $(DYNINST_ROOT)/lib

# These should point to where libelf and libdwarf are installed
LOCAL_INC_DIR = /usr/local/include
LOCAL_LIBS_DIR = /usr/local/lib

CXX = g++
CXXFLAGS = -Wall -g

CC = gcc
CFLAGS = -Wall -pedantic -g

RESULT = onetimecode
TEST = mytest

.PHONY: all clean clean_all

all: $(TEST).out 

$(RESULT): $(RESULT).o Makefile
	$(CXX) $(CXXFLAGS) \
		-L$(DYNINST_LIB) \
		-L$(LOCAL_LIBS_DIR) \
		$< \
		-ldyninstAPI \
		-o $@

%.o: %.cpp
	$(CXX) $(CXXFLAGS) -I$(LOCAL_INC_DIR) -I$(DYNINST_INCLUDE) -c $^

$(TEST).out: $(TEST) $(RESULT)
	./$(RESULT) ./$< 2>&1 | tee $@ 
	
$(TEST): $(TEST).c
	$(CC) $(CFLAGS) $< -o $@

clean_all: clean
	rm -f $(TEST)

clean:
	rm -f *.o *.out $(RESULT)
