-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
79 lines (69 loc) · 3.25 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
.ONESHELL:
SHELL = /bin/bash
.SHELLFLAGS += -e
ARCH ?= amd64
SRC_PATH = src
RULES_PATH = rules
TARGET_PATH ?= target
ROOT := $(shell pwd)
DEST = $(ROOT)/$(TARGET_PATH)
SYMCRYPT_OPENSSL := target/symcrypt-openssl_0.1_$(ARCH).deb
OPENSSH := target/ssh_8.4p1-5+fips_all.deb
GOLANG := target/golang-1.15-go_1.15.15-1~deb11u2+fips_$(ARCH).deb
PYTHON := target/python3.9_3.9.2-1+fips_$(ARCH).deb
QUILT_REFRESH_ARGS="-p ab --no-timestamps --no-index"
.SECONDEXPANSION:
include $(RULES_PATH)/*.mk
# Export environments
export SYMCRYPT_OPENSSL_VERSION
export QUILT_REFRESH_ARGS
export ARCH
export DEST
DEPNEDS := $(SYMCRYPT_OPENSSL) $(OPENSSH) $(GOLANG) $(PYTHON)
MAIN_TARGET_LIST = $(addprefix $(TARGET_PATH)/, $(MAIN_TARGETS))
all: $(MAIN_TARGET_LIST)
list:
@$(foreach target,$(MAIN_TARGET_LIST),echo $(target);)
symcrypt : $(TARGET_PATH)/$(SYMCRYPT_OPENSSL)
openssl: $(TARGET_PATH)/$(OPENSSL)
$(addprefix $(TARGET_PATH)/, $(MAIN_TARGETS)) : $(TARGET_PATH)/% : $$(addprefix $(TARGET_PATH)/,$$($$*_DEPENDS))
# Remove target to force rebuild
rm -f $(addprefix $(TARGET_PATH)/, $*)
mkdir -p $(TARGET_PATH)
# Run pre script
if [ -n "$($*_PRE_SCRIPT)" ]; then :;$($*_PRE_SCRIPT) fi
# Copy debian folder
if [ -n "$($*_DEBIAN)" ]; then mkdir -p $($*_SRC_PATH)/debian; cp $($*_DEBIAN)/* -rf $($*_SRC_PATH)/debian/; fi
# Apply series of patches if exist
if [ -f $($*_SRC_PATH).patch/series ]; then pushd $($*_SRC_PATH) && QUILT_PATCHES=../$(notdir $($*_SRC_PATH)).patch quilt push -a && mv .pc .pc1; popd; fi
if [ -n "$($*_PATCH_EXT)" ]; then pushd $($*_SRC_PATH); QUILT_PATCHES=$($*_PATCH_EXT) quilt push -a && mv .pc .pc2; popd; fi
# Merge the debian patches if not applied
if [ -f $($*_SRC_PATH).patch/debian.patch/series ]; then
LAST_PATCH=$$(tail -n1 $($*_SRC_PATH).patch/debian.patch/series)
if ! grep -q $$LAST_PATCH $($*_SRC_PATH)/debian/patches/series 2>/dev/null; then
echo "Applying patches for $($*_SRC_PATH)/debian/patches/"
cat $($*_SRC_PATH).patch/debian.patch/series >> $($*_SRC_PATH)/debian/patches/series
cp $($*_SRC_PATH).patch/debian.patch/*.patch $($*_SRC_PATH)/debian/patches/
fi
fi
if [ -n "$($*_MAKEFILE)" ]; then
$($*_BUILD_OPTIONS) make -C $($*_SRC_PATH) -f $($*_MAKEFILE) $(DEST)/$* | tee $(DEST)/$*.log
elif [ -f $($*_SRC_PATH)/debian/control ]; then
pushd $($*_SRC_PATH)
VERSION=$$(dpkg-parsechangelog --show-field Version)
if [[ "$*" == *+fips_* ]] && [[ "$$VERSION" != *+fips ]]; then
sed -i "s/$$VERSION/$$VERSION+fips/" debian/changelog
fi
# Fix Misc/NEWS not found issue for python
if [[ "$*" == python3* ]]; then touch Misc/NEWS; fi
# Fix package overwrite issue, increase the timestamp
export SOURCE_DATE_EPOCH="$$(($$(dpkg-parsechangelog -STimestamp) + 86400))"
$($*_BUILD_OPTIONS) dpkg-buildpackage -b -d -rfakeroot -us -uc | tee $(DEST)/$*.log
popd
mkdir -p $(DEST)
mv -f $(addprefix $($*_SRC_PATH)/../, $* $($*_DERIVED_DEBS)) $(DEST)/
else
error "Do not know how to make $(TARGET_PATH)/$*"
fi
if [ -n "$($*_PATCH_EXT)" ]; then pushd $($*_SRC_PATH) && rm -rf .pc && mv .pc2 .pc && quilt pop -a -f; [ -d .pc ] && rm -rf .pc; popd; fi || true
if [ -f $($*_SRC_PATH).patch/series ]; then pushd $($*_SRC_PATH) && rm -rf .pc && mv .pc1 .pc && quilt pop -a -f; [ -d .pc ] && rm -rf .pc; popd; fi || true