Debian Codegraph @

Makefile

raw ◀ ▶
2 Debian patches touch this file
1 # SPDX-License-Identifier: GPL-2.0-or-later
2 #
3 # Makefile for Bit-Twist project
4 # Copyright (C) 2006 - 2024 Addy Yeow <[email protected]>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 SHELL = /bin/sh
21
•22 prefix = $(DESTDIR)/usr
23 exec_prefix = ${prefix}
24 bindir = ${exec_prefix}/bin
25 mandir = ${prefix}/share/man/man1
26
27 # Bit-Twist 3.1 and earlier was using /usr instead of /usr/local.
28 # These old paths are defined below to allow `sudo make uninstall` to also
29 # remove any installation of Bit-Twist 3.1 or earlier.
30 old_prefix = /usr
31 old_exec_prefix = ${old_prefix}
32 old_bindir = ${old_exec_prefix}/bin
33 old_mandir = ${old_prefix}/share/man/man1
34
35 CC ?= gcc
36 CFLAGS ?= -std=gnu17
37 CFLAGS += -O3
38 CFLAGS += -Wall
39
40 # Use make ENABLE_DEBUG=0 to disable debug.
41 ENABLE_DEBUG ?= 1
42 DEBUG = -g
43 ifeq ($(ENABLE_DEBUG), 1)
44 CFLAGS += $(DEBUG)
45 endif
46
47 SRC = src
48 DOC = doc
49 BIN = bin
50
51 CPPCHECK ?= cppcheck
52
53 CLANG_FORMAT ?= clang-format
54
55 INSTALL = /usr/bin/install -c
56 INSTALL_PROGRAM = ${INSTALL}
57 INSTALL_DATA = ${INSTALL} -m 644
58
59 UNAME_S := $(shell uname -s)
60
61 # Use static linking to libpcap on Linux.
62 ifeq ($(UNAME_S),Linux)
•63 # don't use static linking to libpcap in Debian
64 # LPCAP = -Wl,-Bstatic -lpcap -Wl,-Bdynamic
65 LPCAP = -lpcap
66 else
67 LPCAP = -lpcap
68 endif
69
70 # MinGW-w64 compiler for Windows cross-compilation.
71 MINGW_CC = x86_64-w64-mingw32-gcc
72
•73 ifneq ("$(shell which $(MINGW_CC) 2>/dev/null)","")
74 WINDOWS_TARGETS = windows
75 endif
•76
77 # To ensure reproducible outputs.
78 export SOURCE_DATE_EPOCH=0
79
80 all: bittwist bittwiste $(WINDOWS_TARGETS)
81
82 bittwist:
83 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(SRC)/bittwist.c $(SRC)/token_bucket.c -o $(BIN)/bittwist -I/usr/local/include -L/usr/local/lib $(LPCAP)
84
85 bittwiste:
86 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(SRC)/bittwiste.c $(SRC)/tinymt/tinymt64.c $(SRC)/template_pcap.c -o $(BIN)/bittwiste -I $(SRC)/tinymt -I/usr/local/include -L/usr/local/lib
87
88 clean:
89 rm -f $(BIN)/bittwist $(BIN)/bittwiste
90
91 check:
92 $(CPPCHECK) --enable=warning $(SRC)
93
94 format:
95 $(CLANG_FORMAT) -i src/windows_utils.h src/def.h src/token_bucket.h src/token_bucket.c src/template_pcap.h src/template_pcap.c src/bittwist.h src/bittwist.c src/bittwiste.h src/bittwiste.c
96
97 install:
98 mkdir -p $(bindir)
99 chmod 755 $(bindir)
100 $(INSTALL_PROGRAM) $(BIN)/bittwist $(BIN)/bittwiste $(bindir)
101 mkdir -p $(mandir)
102 chmod 755 $(mandir)
103 $(INSTALL_DATA) $(DOC)/bittwist.1 $(DOC)/bittwiste.1 $(mandir)
104
105 uninstall:
106 @rm -vf $(wildcard $(bindir)/bittwist)
107 @rm -vf $(wildcard $(bindir)/bittwiste)
108 @rm -vf $(wildcard $(mandir)/bittwist.1)
109 @rm -vf $(wildcard $(mandir)/bittwiste.1)
110 @rm -vf $(wildcard $(old_bindir)/bittwist)
111 @rm -vf $(wildcard $(old_bindir)/bittwiste)
112 @rm -vf $(wildcard $(old_mandir)/bittwist.1)
113 @rm -vf $(wildcard $(old_mandir)/bittwiste.1)
114
115 windows: bittwist_windows bittwiste_windows
116
117 bittwist_windows:
118 $(MINGW_CC) $(CFLAGS) $(SRC)/bittwist.c $(SRC)/token_bucket.c -o $(BIN)/bittwist.exe -I npcap-sdk/Include -L npcap-sdk/Lib/x64 -lwpcap
119
120 bittwiste_windows:
121 $(MINGW_CC) $(CFLAGS) $(SRC)/bittwiste.c $(SRC)/tinymt/tinymt64.c $(SRC)/template_pcap.c -o $(BIN)/bittwiste.exe -I $(SRC)/tinymt -I npcap-sdk/Include -lws2_32