Skip to content

Instantly share code, notes, and snippets.

@dvirsky
Last active Jun 15, 2017
Embed
What would you like to do?
Minimal makefile for a redis module
DEBUGFLAGS = -g -ggdb -O2
ifeq ($(DEBUG), 1)
DEBUGFLAGS = -g -ggdb -O0
endif
# find the OS
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
CFLAGS = -Wall -Wno-unused-function $(DEBUGFLAGS) -fPIC -std=gnu99 -D_GNU_SOURCE
CC:=$(shell sh -c 'type $(CC) >/dev/null 2>/dev/null && echo $(CC) || echo gcc')
# Compile flags for linux / osx
ifeq ($(uname_S),Linux)
SHOBJ_CFLAGS ?= -fno-common -g -ggdb
SHOBJ_LDFLAGS ?= -shared -Bsymbolic -Bsymbolic-functions
else
CFLAGS += -mmacosx-version-min=10.6
SHOBJ_CFLAGS ?= -dynamic -fno-common -g -ggdb
SHOBJ_LDFLAGS ?= -dylib -exported_symbol _RedisModule_OnLoad -macosx_version_min 10.6
endif
SOURCEDIR=$(shell pwd -P)
CC_SOURCES = $(wildcard $(SOURCEDIR)/*.c)
CC_OBJECTS = $(patsubst $(SOURCEDIR)/%.c, $(SOURCEDIR)/%.o, $(CC_SOURCES))
all: module.so
module.so: $(CC_OBJECTS)
$(LD) -o $@ $(CC_OBJECTS) $(SHOBJ_LDFLAGS) -lc
clean:
rm -rvf *.xo *.so *.o *.a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment