-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
63 lines (45 loc) · 1.52 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
CC=gcc
CFLAGS=-ansi -std=c99 -pedantic -Wall -Werror -Iinclude -I $(HOME)/include -fPIC -O3 -L $(HOME)/lib
SRCS=$(shell find src -name \*.c)
OBJS=$(addprefix obj/, $(addsuffix .o, $(notdir $(basename $(SRCS)))))
INCLUDES=$(shell find include -name \*.h)
# shared library version:
VERSION=1
# List of all files that should be pushed to remote nodes (with the path they
# should use on the remote node; not the local path)
REL_DEPS=bin/pcap-print lib/libpktparse.so.$(VERSION) lib/libpktparse.so $(INCLUDES)
# boilerplate:
DEPS=$(foreach file, $(REL_DEPS), $(DEPLOY)/$(file))
DEPDIRS=$(foreach file, $(REL_DEPS), $(DEPLOY)/$(dir $(file)))
.PHONY: all clean deployment dirs init install
.SECONDARY:
# phony targets:
all: lib/libpktparse.so bin/pcap-print
clean:
rm -f bin/* lib/* obj/* src/*~ include/*~
deployment: init dirs $(DEPS) install
dirs:
@mkdir -p $(DEPDIRS)
init: all
ifndef DEPLOY
$(error DEPLOY not specified)
endif
install: all
mkdir -p ~/lib ~/bin ~/include
cp -R -P lib/lib* ~/lib
cp bin/pcap-print ~/bin
cp include/* ~/include
# real targets:
$(DEPLOY)/%: %
cp -R -P $< $@
lib/libpktparse.so.%: obj/pktparse.o obj/pktparse-print.o
@mkdir -p lib
$(CC) $(CFLAGS) -shared -Wl,-soname,$(shell basename $@) -o $@ $^
lib/libpktparse.so: lib/libpktparse.so.$(VERSION)
ln -fs $(shell basename $^) $@
bin/pcap-print: obj/pcap-print.o lib/libpktparse.so
@mkdir -p bin
$(CC) $(CFLAGS) -o $@ $< -rpath $(HOME)/lib -Llib -lpcap -lpktparse
obj/%.o: src/%.c $(INCLUDES) Makefile
@mkdir -p obj
$(CC) $(CFLAGS) -c -o $@ $<