summaryrefslogtreecommitdiff
path: root/plugins/Makefile
blob: cace09b0606fbcba28b0ac6b6d4429c8f4291570 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
CC = gcc
CFLAGS = -Wall -Wextra -std=c11 -fwrapv -I.. -fPIC
ifneq ($(DEBUG),)
	CFLAGS += -g
else
	CFLAGS += -O2
endif

ifeq ($(shell uname),Darwin)
	SO_EXT = dylib
	SO_FLAGS = -dynamiclib
else
	SO_EXT = so
	SO_FLAGS = -shared
endif
SO_FLAGS += -fPIC

TARGET = $(PLUGINNAME)/$(PLUGINNAME).$(SO_EXT)


.PHONY: all clean remake warning

all: warning $(TARGET)

clean:
	rm -rf $(TARGET) $(PLUGINNAME)/*.{o,dSYM,$(SO_EXT)}

remake: clean all

warning:
ifndef PLUGINNAME
	$(error "PLUGINNAME not set! Please run root Makefile instead.")
endif


.SECONDARY:

$(PLUGINNAME)/%.$(SO_EXT): $(patsubst %.c,%.o,$(wildcard $(PLUGINNAME)/*.c)) $(wildcard ../*.o)
	$(CC) $(SO_FLAGS) -o $@ $(filter %.o,$^)

$(PLUGINNAME)/%.o: $(PLUGINNAME)/%.c $(wildcard $(PLUGINNAME)/*.h) $(wildcard ../*.h)
	$(CC) $(CFLAGS) -c -o $@ $<