-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
144 lines (122 loc) · 4.25 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# -----------------------------------------------------------------------------
# Makefile for carbon-c-relay
#
# Author: Jose Riguera <[email protected]> based on the work of Fabian Groffen
# Date : 2014-10-12
#
# -----------------------------------------------------------------------------
# creation of initial debian folder:
# dh_make --native -c apache -s -p carbon-c-relay_0.35
CC = gcc
LINKER = gcc -o
RM = rm -f
MD = mkdir -p
GIT = git
INSTALL = install
DEBUILD = debuild
DEBCLEAN = debclean
RPMBUILD = rpmbuild
# project name (generate executable with this name)
DISTDIR = .
DESTDIR = /usr/local/etc/carbon
PREFIX = /usr/local
TARGET = carbon-c-relay
GIT_VERSION := $(shell git describe --abbrev=6 --dirty --always || date +%F)
GVCFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\" -DVERSION=\"3.0\"
# change these to set the proper directories where each files shoould be
SRCDIR = src
OBJDIR = obj
BINDIR = sbin
# compiling flags here
CFLAGS ?= -O3 -Wall -Werror -Wshadow -pipe
override CFLAGS += $(GVCFLAGS) `pkg-config openssl --cflags` -pthread
# linking flags here
override LIBS += `pkg-config openssl --libs` -pthread
ifeq ($(shell uname), SunOS)
override LIBS += -lsocket -lnsl
endif
LFLAGS = -O3 -Wall -Werror -Wshadow -pipe -lm $(LIBS)
SOURCES := $(wildcard $(SRCDIR)/*.c)
INCLUDES := $(wildcard $(SRCDIR)/*.h)
OBJECTS := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
all: folders $(BINDIR)/$(TARGET)
$(BINDIR)/$(TARGET): $(OBJECTS)
$(LINKER) $@ $(OBJECTS) $(LFLAGS)
@echo "Linking complete. Binary file created!"
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
@echo "Compiled "$<" successfully!"
.PHONY: folders
folders:
@$(MD) $(BINDIR)
@$(MD) $(OBJDIR)
.PHONY: install
install: $(BINDIR)/$(TARGET)
$(INSTALL) -m 0755 $< $(PREFIX)/$(BINDIR)/$(TARGET)
$(INSTALL) -d $(DESTDIR)
$(INSTALL) -m 0644 config/* $(DESTDIR)
.PHONY: uninstall
uninstall:
$(RM) $(PREFIX)/$(BINDIR)/$(TARGET)
$(RM) -rf $(DESTDIR)/etc/$(TARGET)
VERSION = $(shell sed -n '/VERSION/s/^.*"\([0-9.]\+\)".*$$/\1/p' $(SRCDIR)/relay.h)
.PHONY: dist
dist:
@$(GIT) archive \
--format=tar \
--prefix=$(TARGET)-$(VERSION)/ HEAD \
| gzip > $(DISTDIR)/$(TARGET)-$(VERSION).tar.gz
@echo "Created $(DISTDIR)/$(TARGET)-$(VERSION).tar.gz successfully!"
# Centos/RH packages
.PHONY: rpmbuild
rpmbuild:
$(RPMBUILD) --define "_topdir ${PWD}/rpm" -ba rpm/SPECS/$(TARGET).spec
# check if the local environment is suitable to generate a package
# we check environment variables and a gpg private key matching
# these variables. this is necessary as we sign our packages.
.PHONY: checkenv
checkenv:
ifndef DEBEMAIL
echo "Missing environment variable DEBEMAIL"
@exit 1
endif
ifndef DEBFULLNAME
echo "Missing environment variable DEBFULLNAME"
@exit 1
endif
#gpg --list-secret-keys "$(DEBFULLNAME) <$(DEBEMAIL)>" >/dev/null
# creates the .deb package and other related files
# all files are placed in ../
.PHONY: debuild
debuild: checkenv
# dpkg-buildpackage + lintian
# -sa Forces the inclusion of the original source.
# -us Do not sign the source package.
# -uc Do not sign the .changes file.
$(DEBUILD) -us -uc -sa -b -rfakeroot -i -I.git -I.gitignore -I$(BINDIR) -I$(OBJDIR) -I$(TARGET)-$(VERSION).tar.gz
# create a new release based on PW_VERSION variable
.PHONY: newrelease
newrelease:
debchange --changelog debian/changelog --urgency high --newversion $(VERSION)-1 "Releasing $(TARGET) $(VERSION)"
sed -i '/%define.*version/s/^%define.* \([0-9.]\+\).*$$/%define version $(VERSION)/g' rpm/SPECS/carbon-c-relay.spec
# creates a new version in debian/changelog (only for debian)
.PHONY: newversion
newversion:
debchange --changelog debian/changelog -i --urgency high
# allow user to enter one or more changelog comment manually
.PHONY: changelog
changelog:
debchange --changelog debian/changelog --force-distribution dist --urgency high -r
debchange --changelog debian/changelog -a
.PHONY: clean
clean:
@$(RM) $(OBJECTS)
@$(RM) -r rpm/SOURCES rpm/BUILD rpm/BUILDROOT
@echo "Cleanup complete!"
.PHONY: dist-clean
distclean: clean
@$(RM) -r $(BINDIR)
@$(RM) -r $(OBJDIR)
@$(RM) -r rpm/SOURCES rpm/BUILD rpm/BUILDROOT rpm/RPMS rpm/SRPMS
@$(RM) $(TARGET).*$(VERSION).*
@echo "Executable removed!"