-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGNUmakefile
89 lines (69 loc) · 2.02 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
TARGET := imk
CC ?= cc
BUILD_HOST := build_host.h
SRC := $(wildcard *.c)
OS := $(shell uname -s)
OBJDIR := obj
ifeq ($(OS), Linux)
GRP := root
SRC += compat/poll_linux.c
CFLAGS += -D_DEFAULT_SOURCE
else ifeq ($(OS), $(filter $(OS), NetBSD OpenBSD FreeBSD Darwin))
GRP := wheel
SRC += compat/poll_bsd.c
else
$(error Unrecognized OS)
endif
OBJ := $(addprefix $(OBJDIR)/,$(notdir $(SRC:.c=.o)))
INSTALL := install
INSTALL_ARGS := -o root -g $(GRP) -m 755
INSTALL_DIR := /usr/local/bin/
INCLUDES :=
LIBS :=
CFLAGS += -Werror -Wall $(INCLUDES)
LFLAGS += $(LIBS)
ifeq ($(CC), $(filter $(CC), clang gcc cc musl-gcc))
CFLAGS += -std=c99 -pedantic
endif
# version info from git
REVCNT := $(shell git rev-list --count master 2>/dev/null)
ifeq ($(REVCNT),)
VERSION := devel
else
REVHASH := $(shell git rev-parse --short HEAD 2>/dev/null)
ISCLEAN := $(shell git diff-index --quiet HEAD || echo " [devel]" 2>/dev/null)
VERSION := "$(REVCNT).$(REVHASH)$(ISCLEAN)"
endif
all : debug
debug : CFLAGS += -g -ggdb -DDEBUG
debug : LFLAGS += -g
debug : build
release : CFLAGS += -O3
release : clean build
strip $(TARGET)
static : CFLAGS += -static
static : LFLAGS += -static
static : release
build : $(OBJDIR) $(BUILD_HOST) $(TARGET)
$(BUILD_HOST):
@echo "#define BUILD_HOST \"`hostname`\"" > $(BUILD_HOST)
@echo "#define BUILD_OS \"`uname`\"" >> $(BUILD_HOST)
@echo "#define BUILD_PLATFORM \"`uname -m`\"" >> $(BUILD_HOST)
@echo "#define BUILD_KERNEL \"`uname -r`\"" >> $(BUILD_HOST)
@echo "#define VERSION \"$(VERSION)\"" >> $(BUILD_HOST)
$(TARGET) : $(BUILD_HOST) $(OBJ)
$(CC) $(LFLAGS) -o $@ $(OBJ)
$(OBJDIR) :
@mkdir -p $(OBJDIR)
$(OBJDIR)/%.o : %.c
$(CC) $(CFLAGS) -o $@ -c $<
$(OBJDIR)/%.o : compat/%.c
$(CC) $(CFLAGS) -o $@ -c $<
install :
$(INSTALL) $(INSTALL_ARGS) $(TARGET) $(INSTALL_DIR)
clean :
-rm -f *.core
-rm -f $(BUILD_HOST)
-rm -f $(TARGET)
-rm -rf ./$(OBJDIR)
.PHONY : all build debug release static install install-static clean