-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
111 lines (90 loc) · 3.27 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
##############################################################
# PUFlib Makefile
# Description: Compiles PUFlib
#
# Author: Jacob I. Torrey
# Author: Chris Pavlina
# Date: 2016-08-09
##############################################################
SHELL:=/bin/bash
# Variables used by the Makefile
CC = $(shell command -v colorgcc 2>&1 || echo gcc)
INSTALL = install
DESTDIR ?=
PREFIX ?= /usr
SONAME = libpuf.so
SO_MAJ = 1
SO_MIN = 0.1
SOFILE = ${SONAME}.${SO_MAJ}.${SO_MIN}
CFLAGS = -I${CURDIR}/include -g -Og -Wall -Wextra -Werror -fPIC -std=c99
LDFLAGS = -shared -Wl,-soname,${SONAME}.${SO_MAJ}
MODULES := puflibtest # sxc
MODULES_SUPPORTED := $(shell bash ./scripts/test_module_support ${MODULES})
MODULE_DIRS = $(foreach mod,${MODULES_SUPPORTED},modules/${mod})
MODULE_PACKAGES = $(foreach mod,${MODULES_SUPPORTED},modules/${mod}/${mod}.mod.o)
define module_mf
make -C modules/$(1) $(2) PUFLIB_MF=${CURDIR}/Makefile.inc MODNAME=$(1) \
PUFLIB_CFLAGS="${CFLAGS}" PUFLIB_LDFLAGS="${LDFLAGS}" \
CC="${CC}"
endef
# List all the objects needed here
OBJECTS = puflib/puflib.o puflib/misc.o puflib/platform-posix.o module_list.o
.PHONY: all docs deb install clean distclean pufctl puf ${MODULE_DIRS}
all: ${SOFILE} pufctl puf
pufctl:
${MAKE} -C tools pufctl
puf:
${MAKE} -C tools puf
docs:
doxygen doxyfile
install: ${SOFILE} pufctl puf
${INSTALL} -m 0755 -d ${DESTDIR}/${PREFIX}/lib
${INSTALL} -m 0755 -d ${DESTDIR}/${PREFIX}/bin
${INSTALL} -m 0755 -d ${DESTDIR}/${PREFIX}/include
${INSTALL} -m 0644 ${SOFILE} ${DESTDIR}/${PREFIX}/lib/${SOFILE}
ln -fs ${SOFILE} ${DESTDIR}/${PREFIX}/lib/${SONAME}.${SO_MAJ}
ln -fs ${SONAME}.${SO_MAJ} ${DESTDIR}/${PREFIX}/lib/${SONAME}
${INSTALL} -m 0755 tools/puf ${DESTDIR}/${PREFIX}/bin/puf
${INSTALL} -m 0755 tools/pufctl ${DESTDIR}/${PREFIX}/bin/pufctl
${INSTALL} -m 0644 include/puflib.h ${DESTDIR}/${PREFIX}/include/puflib.h
${INSTALL} -m 0644 include/puflib_internal.h ${DESTDIR}/${PREFIX}/include/puflib_internal.h
${INSTALL} -m 0644 include/puflib_module.h ${DESTDIR}/${PREFIX}/include/puflib_module.h
deb: distclean
tar -cz . -f ../puflib_1.0.orig.tar.gz
dpkg-buildpackage -uc -us
dpkg-buildpackage -Tclean
# Include calculated dependencies
-include ${OBJECTS:.o=.d}
-include $(patsubst %,modules/%/Makefile.inc,${MODULES_SUPPORTED})
# Custom rule that calculates dependencies
%.o: %.c
${CC} -c ${CFLAGS} $*.c -o $*.o
${CC} -MM ${CFLAGS} $*.c -o $*.d
# Module package
# This links together all the .o files in a module and only exports the module
# info struct, ensuring no symbol collisions between modules.
THIS_MODULE_NAME = $(patsubst modules/%,%,$@)
${MODULE_DIRS}:
$(call module_mf,${THIS_MODULE_NAME},all)
${SOFILE}: ${OBJECTS} ${MODULE_DIRS}
${CC} ${LDFLAGS} ${OBJECTS} ${MODULE_PACKAGES} -o ${SOFILE}
ln -fs ${SOFILE} ${SONAME}.${SO_MAJ}
ln -fs ${SONAME}.${SO_MAJ} ${SONAME}
module_list.c:
bash ./scripts/get_submodules
bash ./scripts/gen_module_list ${MODULES_SUPPORTED} > $@
distclean: clean
rm -f ${SONAME}.${SO_MAJ}.${SO_MIN} ${SONAME}.${SO_MAJ} ${SONAME}
rm -rf docs/html
make -C tools distclean
for mod in ${MODULES}; do \
$(call module_mf,$${mod},distclean); \
done
clean:
rm -f ${OBJECTS}
rm -f ${OBJECTS:.o=.d}
rm -f module_list.c
for mod in ${MODULES}; do \
$(call module_mf,$${mod},clean); \
done
make -C tools clean