CC = gcc
CFLAGS = -Wall -O2
LIBNAME = libselfcriu.a

all: $(LIBNAME) user_prog

# Step 1: Compile the C file into an object file
self_criu.o: self_criu.c self_criu.h
	$(CC) $(CFLAGS) -c self_criu.c

# Step 2: Bundle the object file into a static archive (.a)
$(LIBNAME): self_criu.o
	ar rcs $(LIBNAME) self_criu.o

# Step 3: Link the test program using the static archive
# -L. tells gcc to look for libraries in the current directory
# -lselfcriu links against libselfcriu.a
user_prog: user_prog.c $(LIBNAME)
	$(CC) $(CFLAGS) user_prog.c -L. -lselfcriu -o user_prog

clean:
	rm -f *.o *.a user_prog

upload:
	ssh gtoal@gtoal.com mkdir -p gtoal.com/src/libcriu
	scp *.[hc] Makefile README.txt gtoal@gtoal.com:gtoal.com/src/libcriu/
