forked from facebookincubator/nvdtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
157 lines (133 loc) · 4.08 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
145
146
147
148
149
150
151
152
153
154
155
156
157
# Copyright (c) Facebook, Inc. and its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
NAME = nvdtools
VERSION = tip
TOOLS = \
cpe2cve \
csv2cpe \
fireeye2nvd \
flexera2nvd \
idefense2nvd \
nvdsync \
rpm2cpe \
rustsec2nvd \
lininfosec \
vulndb
DOCS = \
CODE_OF_CONDUCT.md \
CONTRIBUTING.md \
HOWTO.md \
LICENSE \
README.md
GO = go
GOOS = $(shell $(GO) env GOOS)
GOARCH = $(shell $(GO) env GOARCH)
TAR = tar
ZIP = zip
INSTALL = install
# Compile all tools.
all: $(TOOLS)
# Compile TOOLS to ./build/bin/$tool using GOOS and GOARCH.
$(TOOLS):
GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO) build $(GOFLAGS) -o ./build/bin/$@ ./cmd/$@
# Check/fetch all dependencies.
deps:
GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO) get -v -d ./...
# install installs tools and documentation.
# The install target is used by rpm and deb builders.
install:
# tools
$(INSTALL) -d $(DESTDIR)/usr/bin
for tool in $(TOOLS); do $(INSTALL) -p -m 0755 ./build/bin/$$tool $(DESTDIR)/usr/bin/$$tool; done
# docs
$(INSTALL) -d $(DESTDIR)/usr/share/doc/nvdtools
for doc in $(DOCS); do $(INSTALL) -p -m 0644 $$doc $(DESTDIR)/usr/share/doc/nvdtools/$$doc; done
DIST_NAME = $(NAME)-$(VERSION)
DIST_DIR = build/$(DIST_NAME)
# binary_dist creates a local binary distribution in DIST_DIR.
binary_dist: $(TOOLS)
mkdir -p $(DIST_DIR)/doc
cp $(DOCS) $(DIST_DIR)/doc
mv build/bin $(DIST_DIR)/bin
# binary_tar creates tarball of binary distribution.
binary_tar: binary_dist
mkdir -p build/tgz
cd build && $(TAR) czf tgz/$(DIST_NAME)-$(GOOS)-$(GOARCH).tar.gz $(DIST_NAME)
rm -rf $(DIST_DIR)
# binary_zip creates zip of binary distribution.
binary_zip: binary_dist
mkdir -p build/zip
cd build && $(ZIP) -r zip/$(DIST_NAME)-$(GOOS)-$(GOARCH).zip $(DIST_NAME)
rm -rf $(DIST_DIR)
# binary_deb creates debian package.
#
# Requires GOPATH and dependencies available to compile nvdtools.
# Must set version to build: make binary_deb VERSION=1.0
binary_deb:
VERSION=$(VERSION) dpkg-buildpackage -rfakeroot -uc -us
mkdir -p build/deb
mv ../$(NAME)*.deb build/deb/
# archive_tar creates tarball of the source code.
archive_tar:
mkdir -p build/tgz
$(TAR) czf build/tgz/$(DIST_NAME).tar.gz \
--exclude=build \
--exclude=release \
--exclude=.git \
--exclude=.travis.yml \
--transform s/./$(DIST_NAME)/ \
.
# binary_rpm creates rpm package.
#
# Requires GOPATH and dependencies available to compile nvdtools.
# Must set version to build: make binary_rpm VERSION=1.0
binary_rpm: archive_tar
mkdir -p build/rpm/SOURCES
mv build/tgz/$(DIST_NAME).tar.gz build/rpm/SOURCES/
rpmbuild -ba \
--define="_topdir $(PWD)/build/rpm" \
--define="_version $(VERSION)" \
nvdtools.spec
# release_tar creates tarball releases.
release_tar:
mkdir -p release
make deps binary_tar GOOS=darwin GOARCH=amd64
make deps binary_tar GOOS=freebsd GOARCH=amd64
make deps binary_tar GOOS=freebsd GOARCH=arm
make deps binary_tar GOOS=linux GOARCH=amd64
make deps binary_tar GOOS=linux GOARCH=arm64
mv build/tgz/*.tar.gz release
# release_zip creates zip releases.
release_zip:
mkdir -p release
make deps binary_zip GOOS=windows GOARCH=386
make deps binary_zip GOOS=windows GOARCH=amd64
mv build/zip/*.zip release
# release_deb creates debian releases.
release_deb: binary_deb
mkdir -p release
mv build/deb/*.deb release
# release_rpm creates rpm releases.
release_rpm: binary_rpm
mkdir -p release
mv build/rpm/RPMS/*/*.rpm release
# release creates all release packages.
# Example: make distclean release VERSION=1.0
release: release_deb release_rpm release_tar release_zip
# Removes build related files.
clean:
rm -rf build
distclean: clean
rm -rf release
.PHONY: $(TOOLS)