-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMakefile
54 lines (40 loc) · 1.14 KB
/
Makefile
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
43
44
45
46
47
48
49
50
51
52
53
54
ifeq ($(CC),cc)
CC=$(lastword $(subst /, ,$(shell readlink -f `which cc`)))
endif
ifeq ($(findstring gcc,$(CC)),gcc)
CFLAGS += -Wno-stringop-truncation
LDFLAGS += -s
else
CFLAGS += -fno-temp-file
endif
PLATFORM ?= $(firstword $(subst -, ,$(CC)))
HOST ?= $(word 2, $(subst -, ,$(CC)))
SRC = .
CORE = bin/climdnssd-$(HOST)
BUILDDIR = $(dir $(CORE))$(HOST)/$(PLATFORM)
LIB = lib/$(HOST)/$(PLATFORM)/libmdnssd.a
EXECUTABLE = $(CORE)-$(PLATFORM)
CFLAGS += -Wall -fPIC -ggdb -O2 $(DEFINES) -fdata-sections -ffunction-sections
vpath %.c $(SRC)
INCLUDE = -I$(SRC)
SOURCES = mdnssd.c
OBJECTS = $(SOURCES:%.c=$(BUILDDIR)/%.o)
all: lib $(EXECUTABLE)
lib: directory $(LIB)
directory:
@mkdir -p lib/$(HOST)/$(PLATFORM)
@mkdir -p $(BUILDDIR)
$(EXECUTABLE): $(BUILDDIR)/climdnssd.o $(LIB)
$(CC) $^ $(CFLAGS) $(LDFLAGS) -o $@
ifeq ($(HOST),macos)
rm -f $(CORE)
lipo -create -output $(CORE) $$(ls $(CORE)* | grep -v '\-static')
endif
$(LIB): $(OBJECTS)
$(AR) -rcs $@ $^
$(BUILDDIR)/%.o : %.c
$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDE) $< -c -o $@
cleanlib:
rm -f $(BUILDDIR)/*.o $(LIB)
clean: cleanlib
rm -f $(EXECUTABLE) $(CORE)