CXXFLAGS = -O2 -g

all: run

S.o: S.cpp S.h
	g++ $(CXXFLAGS) -fPIC -c -o S.o S.cpp

libS.so: S.o
	g++ -shared -o libS.so S.o

main.o: main.cpp S.h
	g++ $(CXXFLAGS) -c -o main.o main.cpp

main: main.o libS.so
	g++ -o main main.o -L. -lS

altmain: main.o S.o
	g++ -o altmain main.o S.o

run: main altmain
	@echo "-- Running using shared library"
	LD_LIBRARY_PATH=. ./main
	@echo "-- Running using static build"
	./altmain

clean:
	rm -f *.o *.so main altmain
