-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGNUmakefile
96 lines (76 loc) · 2.25 KB
/
GNUmakefile
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
LIB.NAME = clens
LIB.SRCS = clens.c arc4random_buf.c strlcat.c strlcpy.c strtonum.c fmt_scaled.c
LIB.SRCS += fgetln.c fparseln.c glob.c arc4random_uniform.c
LIB.HEADERS = clens/clens.h
LIB.HDRDIRS = clens
CPPFLAGS +=
INCFLAGS += -I include/clens
WARNFLAGS += -Wall -Werror
DEBUG += -g
CFLAGS += $(INCFLAGS) $(WARNFLAGS) $(DEBUG)
LDFLAGS +=
# Attempt to include platform specific makefile.
# OSNAME may be passed in.
OSNAME ?= $(shell uname -s | sed -e 's/[-_].*//g')
OSNAME := $(shell echo $(OSNAME) | tr A-Z a-z)
-include config/Makefile.$(OSNAME)
# Default paths.
DESTDIR ?=
LOCALBASE ?= /usr/local
BINDIR ?= ${LOCALBASE}/bin
LIBDIR ?= ${LOCALBASE}/lib
INCDIR ?= ${LOCALBASE}/include
BUILDVERSION=$(shell sh ${CURDIR}/buildver.sh)
ifneq ("${BUILDVERSION}", "")
CPPFLAGS+= -DBUILDSTR=\"$(BUILDVERSION)\"
endif
# Use obj directory if it exists.
OBJPREFIX ?= obj/
ifeq "$(wildcard $(OBJPREFIX))" ""
OBJPREFIX =
endif
# System utils.
AR ?= ar
CC ?= gcc
INSTALL ?= install
LN ?= ln
LNFLAGS ?= -sf
MKDIR ?= mkdir
RM ?= rm -f
RMDIR ?= rm -rf
vpath %.c src
vpath %.h include
LIB.OBJS = $(addprefix $(OBJPREFIX), $(LIB.SRCS:.c=.o))
LIB.DEPS = $(addsuffix .depend, $(LIB.OBJS))
all: $(OBJPREFIX)$(LIB.STATIC)
obj:
-$(MKDIR) obj
$(OBJPREFIX)$(LIB.STATIC): $(LIB.OBJS)
$(AR) $(ARFLAGS) $@ $^
$(OBJPREFIX)%.o: %.c
@echo "Generating [email protected]"
@$(CC) $(INCFLAGS) -MM $(CPPFLAGS) $< | \
sed 's,$*\.o[ :]*,$@ [email protected] : ,g' > [email protected]
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
depend:
@echo "Dependencies are automatically generated. This target is not necessary."
install:
$(INSTALL) -m 0755 -d $(DESTDIR)$(LIBDIR)/
$(INSTALL) -m 0644 $(OBJPREFIX)$(LIB.STATIC) $(DESTDIR)$(LIBDIR)/
@for d in $(LIB.HDRDIRS); do \
echo "$(INSTALL) -d -m 0755 $(DESTDIR)$(INCDIR)/$$d"; \
$(INSTALL) -d -m 0755 $(DESTDIR)$(INCDIR)/$$d; \
done
@for hdr in $(LIB.HEADERS); do \
echo "$(INSTALL) -m 0644 include/$$hdr $(DESTDIR)$(INCDIR)/$$hdr"; \
$(INSTALL) -m 0644 include/$$hdr $(DESTDIR)$(INCDIR)/$$hdr; \
done
uninstall:
$(RM) $(DESTDIR)$(LIBDIR)/$(LIB.STATIC)
$(RM) $(addprefix $(DESTDIR)$(INCDIR)/, $(LIB.HEADERS))
$(RMDIR) $(addprefix $(DESTDIR)$(INCDIR)/, $(LIB.HDRDIRS))
clean:
$(RM) $(LIB.OBJS)
$(RM) $(OBJPREFIX)$(LIB.STATIC)
$(RM) $(LIB.DEPS)
.PHONY: clean depend install uninstall