diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..08d4a40 --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +#set environment variable RM_INCLUDE_DIR to the location of redismodule.h +ifndef RM_INCLUDE_DIR + RM_INCLUDE_DIR=./ +endif + +ifndef RMUTIL_LIBDIR + RMUTIL_LIBDIR=rmutil +endif + +ifndef SRC_DIR + SRC_DIR=example +endif + + +all: module.so + +module.so: + $(MAKE) -C ./$(SRC_DIR) + cp ./$(SRC_DIR)/module.so . + +clean: FORCE + rm -rf *.xo *.so *.o + rm -rf ./$(SRC_DIR)/*.xo ./$(SRC_DIR)/*.so ./$(SRC_DIR)/*.o + rm -rf ./$(RMUTIL_LIBDIR)/*.so ./$(RMUTIL_LIBDIR)/*.o ./$(RMUTIL_LIBDIR)/*.a + +FORCE: diff --git a/README.md b/README.md index eeb4eb5..df2366e 100644 --- a/README.md +++ b/README.md @@ -52,9 +52,8 @@ copied from the Redis repo. Here's what you need to do to build your first module: 0. Build Redis in a build supporting modules. -1. Build librmutil: `cd rmutil && make` -2. Build the example module: `cd example && make` -3. Run redis loading the module: `/path/to/redis-server --loadmodule ./example/module.so` +1. Build librmutil and the module by running `make`. (you can also build them seperatly by running `make` in their respective dirs) +2. Run redis loading the module: `/path/to/redis-server --loadmodule ./module.so` Now run `redis-cli` and try the commands: diff --git a/example/Makefile b/example/Makefile index 88f4700..c731b16 100644 --- a/example/Makefile +++ b/example/Makefile @@ -21,7 +21,10 @@ endif CFLAGS = -I$(RM_INCLUDE_DIR) -Wall -g -fPIC -lc -lm -Og -std=gnu99 CC=gcc -all: module.so +all: rmutil module.so + +rmutil: FORCE + $(MAKE) -C $(RMUTIL_LIBDIR) module.so: module.o $(LD) -o $@ module.o $(SHOBJ_LDFLAGS) $(LIBS) -L$(RMUTIL_LIBDIR) -lrmutil -lc @@ -29,3 +32,4 @@ module.so: module.o clean: rm -rf *.xo *.so *.o +FORCE: