-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
468 lines (390 loc) · 17.6 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
CC = gcc
CFLAGS = -Wall -pedantic -std=c99 -D_GNU_SOURCE
DEBUG_CFLAGS = -ggdb -DDEBUG -ftrapv
# Add -DDBG to the KERN_DEBUG_CFLAGS to output extra debug information from IXGBE
KERN_DEBUG_CFLAGS = -DDEBUG -DDBG
KERN_DEBUG_ENVVARS = CONFIG_DEBUG_INFO=1
RELEASE_CFLAGS = -O3 -march=native
KERN_RELEASE_CFLAGS = -O3
KERN_RELEASE_ENVVARS =
LDFLAGS = -lhpcap -lpcap -lpthread -lm -lmgmon
DEBUG_LDFLAGS = -Llib/debug
RELEASE_LDFLAGS = -Llib/release
LATEXFLAGS = -pdf -silent -synctex=1 -shell-escape
VERBOSE = 0
# Uncomment to build the driver for a specific kernel version
# BUILD_KERNEL=4.8.0-32-generic
# Directory variables
BINDIR = bin
OBJDIR = obj
DOCDIR = doc
LIBDIR = lib
KOBJDIR = $(OBJDIR)/kernel
LIBSRCDIR = srclib
SAMPLEDIR = samples
INCDIR = include
SCRIPTDIR = scripts
INCLUDEDIRS = . $(INCDIR)
DRIVDIR = driver
COMMON_DIR = $(DRIVDIR)/common
IXGBE_DIR = $(DRIVDIR)/hpcap_ixgbe-3.7.17_buffer/driver
IXGBEVF_DIR = $(DRIVDIR)/hpcap_ixgbevf-2.14.2/driver
PDF_DOCS = HPCAP_DevGuide.pdf HPCAP_UserGuide.pdf
PDF_PATHS = $(addprefix $(DOCDIR)/, $(PDF_DOCS))
DRIVERVARS = Makefile-driver-vars.mk
DRIVERVARS_KBUILD = $(abspath $(DRIVERVARS))
# Some automatic variables
INCLUDES := $(addprefix -I, $(addsuffix /, $(INCLUDEDIRS)))
INCLUDES_ABS := $(addprefix -I, $(abspath $(addsuffix /, $(INCLUDEDIRS))))
SAMPLE_DIRS := $(notdir $(wildcard $(SAMPLEDIR)/*))
SAMPLE_SRCS := $(wildcard $(SAMPLEDIR)/**/*.c)
# Avoid adding to our list of sample applications directories that do not comply
# with our expected directory structure. That is, we only include samples where the
# file $(SAMPLEDIR)/samplename/samplename.c exists.
SAMPLES := $(foreach sample, $(SAMPLE_DIRS), $(shell [ -z "$(wildcard $(SAMPLEDIR)/$(sample)/$(sample).c)" ] || echo $(sample)))
COMMON_SRCS := $(wildcard $(COMMON_DIR)/*.c)
COMMON_HDRS := $(wildcard $(COMMON_DIR)/*.h)
IXGBE_SRCS := $(wildcard $(IXGBE_DIR)/*.c)
IXGBE_HDRS := $(wildcard $(IXGBE_DIR)/*.h)
IXGBEVF_SRCS := $(wildcard $(IXGBEVF_DIR)/*.c)
IXGBEVF_HDRS := $(wildcard $(IXGBEVF_DIR)/*.h)
DRIV_NAMES := $(filter-out common, $(notdir $(wildcard $(DRIVDIR)/*)))
LIB_SRCS := $(wildcard $(LIBSRCDIR)/**/*.c)
LIB_OBJS := $(addprefix $(OBJDIR)/, $(patsubst %.c,%.o, $(LIB_SRCS)))
LIB_NAMES := $(notdir $(wildcard $(LIBSRCDIR)/*))
LIBS := $(addsuffix .a, $(LIB_NAMES))
ALL_SRCS = $(LIB_SRCS) $(SAMPLE_SRCS) include/*
ALL_SRCS += $(COMMON_SRCS) $(COMMON_HDRS) $(IXGBE_SRCS) $(IXGBE_HDRS) $(IXGBEVF_SRCS) $(IXGBEVF_HDRS)
# Formatting
FMT_BOLD := $(shell tput bold)
FMT_NORM := $(shell tput sgr0)
.PHONY: config dirs depend hpcap hpcapvf libs samples drivers version-info changes .FORCE driverclean
ALL_TARGETS = libs samples drivers
# Basic rules
all: $(ALL_TARGETS)
libs: $(LIB_NAMES)
samples: $(SAMPLES)
# For debugging
print-%: ; @echo $*=$($*)
####################################
## Help ##
####################################
help:
@echo "HPCAP Makefile help. Available targets: "
@echo
@echo "- all: build all targets (libraries, samples and drivers)"
@echo "- $(ALL_TARGETS): build libraries, samples or drivers respectively."
@echo "- $(CONFS): build all the targets in the given configuration."
@echo "- $(addprefix drivers-, $(CONFS)): build the drivers for the given configuration."
@echo "- clean: Clean the intermediate files and binaries."
@echo "- docs: Build the documentation."
@echo "- doxydoc: Build the doxygen documentation (included in the docs target)."
@echo "- cscope: Build the cscope database."
@echo "- install: Install the driver in this system. Accepts INSTALL_PATH=prefix to set the installation prefix."
@echo "- install-libs: Install only the HPCAP libraries and headers. Useful for development."
@echo "- uninstall: Uninstall the driver from the system."
@echo "- pack: Pack the source code in a .tar.gz file in the current directory."
@echo "- dist: Pack the source code and binaries in a ready-to-install package."
@echo "- format: Run the astyle formatter"
@echo "- check: Check the folder structure is correct and output readable errors"
@echo ""
@echo "Apart from those generic rules, you can use specific rules, such as bin/[conf]/[binary]"
@echo "or lib/[conf]/[library] to build just one file in one given configuration. Drivers are"
@echo "stored in the bin directory. Also, 'make [object]' will build the given object in the default"
@echo "configuration ($(DEFAULT_CONF)). E.g., 'make libhpcap' will build lib/$(DEFAULT_CONF)/libhpcap.a,"
@echo "and 'make bin/debug/hpcapdd' will build hpcapdd with the debug configuration."
@echo ""
@echo "Files that can be built:"
@echo "Drivers: $(DRIV_TARGETS)"
@echo "Sample applications: $(SAMPLES)"
@echo "Libraries: $(LIB_NAMES)"
@echo ""
@echo "Note: If some target gives Makefile errors, first try to run make clean, rm -rf obj, and/or run make check"
@echo " to see if it is some common error (like not having the correct folder structure)."
####################################
## Build configuration management ##
####################################
CONFS = debug release
DEFAULT_CONF = release
SAMPLE_CONFS := $(addsuffix -conf.mk, $(addprefix $(OBJDIR)/.sample-, $(SAMPLES)))
SAMPLE_DEPS = $(addsuffix -deps.mk, $(addprefix $(OBJDIR)/.sample-, $(SAMPLES)))
LIB_CONFS := $(addsuffix -conf.mk, $(addprefix $(OBJDIR)/.lib-, $(LIB_NAMES)))
LIB_DEPS := $(addsuffix -deps.mk, $(addprefix $(OBJDIR)/.lib-, $(LIB_NAMES)))
DRIV_CONFS := $(addsuffix -conf.mk, $(addprefix $(OBJDIR)/.driver-, $(DRIV_NAMES)))
DRIV_OBJDIRS := $(foreach conf, $(CONFS), $(addprefix $(OBJDIR)/kernel/$(conf)/, $(DRIV_NAMES)))
LIB_OBJDIRS := $(foreach conf, $(CONFS), $(addprefix $(OBJDIR)/$(conf)/$(LIBSRCDIR)/, $(LIB_NAMES)))
LIB_OUTDIRS := $(addprefix $(LIBDIR)/, $(CONFS))
SAMPLE_OBJDIRS := $(foreach conf, $(CONFS), $(addprefix $(OBJDIR)/$(conf)/samples/, $(SAMPLES)))
ALL_CONFS = $(SAMPLE_CONFS) $(LIB_CONFS) $(DRIV_CONFS)
ALL_DEPS = $(SAMPLE_DEPS) $(LIB_DEPS)
config: $(ALL_CONFS)
depend: $(ALL_DEPS)
check:
@for driver in $(DRIV_NAMES); do \
if [ ! -d $(DRIVDIR)/$$driver/driver ]; then \
echo "Error: Cannot build $$driver: folder $(DRIVDIR)/$$driver/driver does not exist"; \
fi; \
done; \
# If the kernel version is fixed, we have to add it to the kernel environment variables
ifneq (,$(BUILD_KERNEL))
KERN_DEBUG_ENVVARS += BUILD_KERNEL=$(BUILD_KERNEL)
KERN_RELEASE_ENVVARS += BUILD_KERNEL=$(BUILD_KERNEL)
endif
# This function generates a new file that will be automatically included in this Makefile,
# containing dynamically generated rules and flags for each configuration of a given target.
# Arguments:
# 1: File where the new rules will be stored
# 2: Root for the sources (e.g., SAMPLEDIR or LIBSRCDIR)
# 3: Target directory (e.g., bin or lib)
# 4: Target name
# 5: Target
generate_config = \
-rm -f $(1); \
echo "SRCS_$(4) := \$$(wildcard $(2)/$(4)/*.c)" >> $(1); \
for c in $(CONFS); do \
cnf=$$(echo $$c | tr '[:lower:]' '[:upper:]'); \
echo "OBJS_$${c}_$(4) := \$$(addprefix $(OBJDIR)/$$c/, \$$(patsubst %.c, %.o, \$$(SRCS_$(4))))" >> $(1); \
echo "$(3)/$$c/$(5): CFLAGS += \$$(""$$cnf""_CFLAGS)" >> $(1); \
echo "$(3)/$$c/$(5): LDFLAGS += \$$(""$$cnf""_LDFLAGS)" >> $(1); \
echo "$(3)/$$c/$(5): \$$(OBJS_$${c}_$(4))" >> $(1); \
done; \
echo "$(4): $(3)/$(DEFAULT_CONF)/$(5)" >> $(1); \
echo "" >> $(1); \
for c in $(CONFS); do \
echo "$$c: $(3)/$$c/$(5)" >> $(1); \
done
# This function generates a new file that will be included automatically in this Makefile,
# containing dynamically generated dependencies for each configuration of a given target.
# Arguments:
# 1: File where the new rules will be stored
# 2: Root for the sources (e.g., SAMPLEDIR or LIBSRCDIR)
# 3: Target directory (e.g., bin or lib)
# 4: Source files
# 5: Target name (e.g., libhpcap or hpcapdd)
# 6: Final file name
generate_deps = \
-rm -f $(1); \
$(CC) $(CFLAGS) $(INCLUDES) -MM $(4) >> $(1) || exit 1; \
awk '{if (sub(/\\$$/,"")) printf "%s", $$0; else print $$0}' $(1) > "$(1).0"; \
mv "$(1).0" $(1) && \
for c in $(CONFS); do \
awk '{printf("$(OBJDIR)/%s/$(2)/$(5)/%s\n", conf, $$0)}' conf=$$c $(1) >> "$(1).0"; \
echo "$(3)/$$c/$(6): $(patsubst %.c, $(OBJDIR)/$$c/%.o, $(4))" >> "$(1).0"; \
done; \
mv "$(1).0" $(1)
# This function is just a regex that constructs the hpcap driver name from the folder name
# E.g., hpcap_i40e-1.4.25 is converted to hpcapi, hpcap_ixgbevf-2.14.2 is converted to
# hpcapvf, etc.
drivname = $(shell echo $(1) | sed -E 's/hpcap_(ixgbe)?([a-zA-Z]*)[0-9e]*(vf)?.*/hpcap\2\3/')
DRIV_TARGETS := $(foreach driver, $(DRIV_NAMES), $(call drivname, $(driver)))
DRIV_BINARIES := $(foreach conf, $(CONFS), $(wildcard $(BINDIR)/$(conf)/*.ko))
ifeq (Linux,$(shell uname))
-include $(ALL_CONFS)
-include $(ALL_DEPS)
-include $(DRIVERVARS)
endif
# Generate the configuration for the given output sample. Include
# dependencies on the libraries.
$(OBJDIR)/.sample-%-conf.mk: Makefile | $(OBJDIR)
@$(call generate_config,$@,$(SAMPLEDIR),$(BINDIR),$*,$*)
@for c in $(CONFS); do \
for s in $(SAMPLES); do \
echo "$(BINDIR)/$$c/$$s: $(addprefix $(LIBDIR)/$$c/, $(LIBS))" >> $@; \
done; \
done; \
$(OBJDIR)/.lib-%-conf.mk: Makefile | $(OBJDIR)
@$(call generate_config,$@,$(LIBSRCDIR),$(LIBDIR),$*,$*.a)
# This weird rule is actually pretty simple. I'd comment it between the lines but that would
# mess up with the shell long line.
#
# What we want with all of this is to be able to generate driver modules with different
# configurations, and to be able to control the output of the objects in order to avoid filling
# the code trees with temporary files, which is really ugly (although this rule is probably uglier).
# The reasoning behind this is explained in the developer documentation guide.
#
# To achieve that, we automatically generate some rules for each driver. You can take a look
# at the generated files in the obj directory and see that it's actually fairly simple.
#
# First, we generate the user-friendly name ($fname) with the regex, based on directory names.
# The names will be either hpcap or hpcapvf.
#
# The module (*.ko) is placed in the bin/confname directory. It is a simple cp command.
# Its prerequisite is the actual driver file, generated in the duplicated source tree
# in the obj/kernel/confname/drivername directory. Make will automatically copy out of date
# files.
#
# To build the files, we call the kernel build system. We have to copy the whole source tree
# for each configuration because it's impossible to change the output directory of the kernel
# build system. This is the trick that allows us to maintain different build configurations.
#
# The mkmakefile script generates automatically an script for the configuration.
#
# PS: This would be so much easier if Make had the ability to do multiple matches in one pattern.
$(OBJDIR)/.driver-%-conf.mk: Makefile $(COMMON_FILES) $(DRIVDIR)/%/driver/*.c $(COMMON_DIR)/hpcap_version.h | $(OBJDIR)
@-rm -f $@
@for cnf in $(CONFS); do \
fname="$(call drivname,$*)"; \
cnfcaps=$$(echo $$cnf | tr '[:lower:]' '[:upper:]'); \
echo -n "$(BINDIR)/$$cnf/$$fname.ko"; \
echo ": $(KOBJDIR)/$$cnf/$*/$$fname.ko | dirs"; \
echo " @cp \$$< \$$@"; \
echo ""; \
echo "$${fname}_$${cnf}_orig_files := \$$(wildcard $(DRIVDIR)/$*/driver/*.c) \$$(wildcard $(DRIVDIR)/$*/driver/*.h)"; \
echo "$${fname}_$${cnf}_orig_files += \$$(wildcard $(COMMON_DIR)/*.c) \$$(wildcard $(COMMON_DIR)/*.h)"; \
echo "$${fname}_$${cnf}_files := \$$(patsubst %, $(KOBJDIR)/$$cnf/$*/%, \$$(notdir \$$($${fname}_$${cnf}_orig_files)))"; \
echo "$(KOBJDIR)/$$cnf/$*/$$fname.ko: \$$($${fname}_$${cnf}_files) $(KOBJDIR)/$$cnf/$*/Makefile"; \
echo " \$$(KERN_$${cnfcaps}_ENVVARS) \$$(MAKE) -C \$$(KSRC) \$$(KOBJRULE) SUBDIRS=\$$(shell pwd)/$(KOBJDIR)/$$cnf/$* modules"; \
echo "$(KOBJDIR)/$$cnf/$*/%.c: $(DRIVDIR)/$*/driver/%.c"; \
echo " @cp \$$< \$$@"; \
echo "$(KOBJDIR)/$$cnf/$*/%.c: $(COMMON_DIR)/%.c"; \
echo " @cp \$$< \$$@"; \
echo "$(KOBJDIR)/$$cnf/$*/%.h: $(DRIVDIR)/$*/driver/%.h"; \
echo " @cp \$$< \$$@"; \
echo "$(KOBJDIR)/$$cnf/$*/%.h: $(COMMON_DIR)/%.h"; \
echo " @cp \$$< \$$@"; \
echo "$(KOBJDIR)/$$cnf/$*/Makefile: Makefile scripts/mkmakefile"; \
echo " @scripts/mkmakefile $$fname $$cnf \"\$$(KERN_$${cnfcaps}_CFLAGS) $(INCLUDES_ABS)\" $(DRIVERVARS_KBUILD) > \$$@"; \
echo "$$cnf: $(BINDIR)/$$cnf/$$fname.ko"; \
echo "drivers-$$cnf: $(BINDIR)/$$cnf/$$fname.ko"; \
echo; \
done >> $@
@echo "$(call drivname,$*): $(BINDIR)/$(DEFAULT_CONF)/$(call drivname,$*).ko" >> $@
# Detect file dependencies for each object file.
$(OBJDIR)/.sample-%-deps.mk: Makefile $(SAMPLEDIR)/%/*.c | $(OBJDIR)
@$(call generate_deps,$@,$(SAMPLEDIR),$(BINDIR),$(filter-out Makefile,$^),$*,$*)
$(OBJDIR)/.lib-%-deps.mk: $(LIBSRCDIR)/%/*.c Makefile | $(OBJDIR)
@$(call generate_deps,$@,$(LIBSRCDIR),$(LIBDIR),$(filter-out Makefile,$^),$*,$*.a)
####################################
## Build information ##
####################################
SOURCES_AFFECTING_VERSION := $(filter-out $(COMMON_DIR)/hpcap_version.h, $(ALL_SRCS))
# Use "wildcard" to avoid errors due to unexisting files when not running without the .git
# directory. If the .git directory is not present, GIT_INFO_FILES will be empty.
GIT_INFO_FILES := $(wildcard .git/index) $(wildcard .git/HEAD)
VERSION_FILE = .gitversion
GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "master")
GIT_COMMIT = $(shell git describe --dirty --tags --always --abbrev=7 --match="v*" || cat $(VERSION_FILE) 2>/dev/null || echo "no-git-info")
ifeq (master,$(GIT_BRANCH))
VERSION_BRANCH_INFO =
else
VERSION_BRANCH_INFO = , branch $(GIT_BRANCH)
endif
# Only overwrite the version file if we can extract significant info (that is, the .git directory)
# is present.
$(COMMON_DIR)/hpcap_version.h: $(SOURCES_AFFECTING_VERSION) $(GIT_INFO_FILES)
ifneq (,$(GIT_INFO_FILES))
@echo "#ifndef HPCAP_VERSION_H" > $@
@echo "#define HPCAP_VERSION_H" >> $@
@echo "#define HPCAP_REVISION \"$(GIT_COMMIT)$(VERSION_BRANCH_INFO)\"" >> $@
@echo "#define HPCAP_BUILD_DATE \"$(shell date +"%d %b %Y %R %Z")\"" >> $@
@echo "#define HPCAP_BUILD_INFO HPCAP_REVISION \" built \" HPCAP_BUILD_DATE" >> $@
@echo "#endif" >> $@
else
@touch $@
endif
$(VERSION_FILE): $(GIT_INFO_FILES)
ifneq (,$(GIT_INFO_FILES))
@echo $(shell git describe --dirty --tags --always --abbrev=7) > $@
else
@touch $@
endif
version-info: $(COMMON_DIR)/hpcap_version.h $(VERSION_FILE)
####################################
## Directory management ##
####################################
dirs: $(OBJDIR) $(BINDIR) $(LIBDIR)
$(OBJDIR): Makefile
@for c in $(CONFS); do \
mkdir -p $(OBJDIR)/$$c/$(SRCDIR); \
mkdir -p $(OBJDIR)/$$c/$(LIBSRCDIR); \
mkdir -p $(OBJDIR)/$$c/$(TESTDIR); \
done
@mkdir -p $(SAMPLE_OBJDIRS)
@mkdir -p $(DRIV_OBJDIRS)
@mkdir -p $(KOBJDIR)
$(BINDIR): Makefile
@for c in $(CONFS); do \
mkdir -p $(BINDIR)/$$c; \
done
$(LIBDIR): Makefile
@mkdir -p $(LIB_OUTDIRS)
@mkdir -p $(LIB_OBJDIRS)
####################################
## Compilation rules ##
####################################
$(OBJDIR)/%.o: | $(OBJDIR) depend config
@echo "$< -> $@"
@$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
$(BINDIR)/%: | $(BINDIR) depend config
@echo "$(FMT_BOLD)Building binary $* $(FMT_NORM)"
@$(CC) $(CFLAGS) $(filter-out libs, $^) $(LDFLAGS) -o $@
$(LIBDIR)/%.a: | $(LIBDIR) depend config
@echo "$(FMT_BOLD)Building static library $* $(FMT_NORM)"
@$(AR) -r $@ $^
####################################
## Cleaning rules ##
####################################
clean: codeclean
codeclean:
@-rm -rf $(BINDIR) $(LIBDIR) $(OBJDIR)
distclean:
@-rm -rf $(OBJDIR)
driverclean:
@-rm -rf $(KOBJDIR) $(DRIV_BINARIES)
####################################
## Documentation ##
####################################
docs: $(PDF_PATHS) doxydoc
doxydoc: $(ALL_SRCS)
@doxygen
%.pdf: %.tex
@echo "$(FMT_BOLD)Latexmk: generating $@ $(FMT_NORM)"
@cd $(dir $<); latexmk $(LATEXFLAGS) $(notdir $<)
cscope: cscope.out
cscope.out: $(LIB_SRCS) $(SAMPLE_SRCS)
@cscope -bR -f$@
####################################
## Drivers (for convenience) ##
####################################
drivers: $(DRIV_TARGETS) | dirs
####################################
## Installing ##
####################################
include Makefile-install.mk
####################################
## Packaging ##
####################################
TAR_EXCLUDES_DIST = obj *.tar.gz .git tasks \
cscope.out *.sublime-project *.sublime-workspace \
*.dat callgrind.* gmon.out \
*.blg *.aux *.bbl *.bib *.fdb_latexmk *.fls *.log *.toc \
*.idx *.ilg *.ind *.out *.synctex.gz *.pyg.. \
doc/man doc/html
TAR_EXCLUDES_SRC = $(TAR_EXCLUDES_DIST) bin lib
TAR_EXCLUDES_DIST_ARG = $(addprefix --exclude=, $(TAR_EXCLUDES_DIST))
TAR_EXCLUDES_SRC_ARG = $(addprefix --exclude=, $(TAR_EXCLUDES_SRC))
# Only show the git branch if we're not on master
ifeq (master,$(GIT_BRANCH))
TAR_GITBRANCH =
else
TAR_GITBRANCH = _$(shell echo $(GIT_BRANCH) | tr '/' '-' | sed 's/release/pre-release/')
endif
TAR_TARGET = HPCAP$(TAR_GITBRANCH)_$(shell date +"%F")_$(shell git describe --tags --always --match="v*")
CHANGELOG: $(GIT_INFO_FILES)
@git tag -l -n99 "v*" > CHANGELOG
VERSION.txt: $(GIT_INFO_FILES)
@git tag -l $(shell git describe) -n99 > VERSION.txt
changes: CHANGELOG VERSION.txt version-info
pack: docs changes
@cd ..; COPYFILE_DISABLE=1 tar $(TAR_EXCLUDES_SRC_ARG) -czf $(TAR_TARGET).tar.gz $(lastword $(notdir $(CURDIR)))
@mv ../$(TAR_TARGET).tar.gz .
@echo "Packed $(TAR_TARGET).tar.gz."
dist: release docs changes
@cd ..; COPYFILE_DISABLE=1 tar $(TAR_EXCLUDES_DIST_ARG) -czf $(TAR_TARGET)_dist.tar.gz $(lastword $(notdir $(CURDIR)))
@mv ../$(TAR_TARGET)_dist.tar.gz .
@echo "Packed $(TAR_TARGET).tar.gz."
####################################
## Some misc scripts ##
####################################
format:
astyle --options=.astylerc --recursive "driver/*.c" "driver/*.h" "samples/*.c" "samples/*.h" "include/*.h" "srclib/*.c"