File: Makefile

package info (click to toggle)
imx-code-signing-tool 3.4.1%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 4,912 kB
  • sloc: ansic: 10,258; sh: 2,558; python: 391; yacc: 245; makefile: 203; lex: 59
file content (218 lines) | stat: -rw-r--r-- 6,456 bytes parent folder | download
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
# SPDX-License-Identifier: BSD-3-Clause
#
# Freescale Semiconductor
# (c) Freescale Semiconductor, Inc. 2011-2015. All rights reserved.
# Copyright 2017-2019, 2022-2024 NXP
#
#==============================================================================
#
#    File Name:  Makefile
#
#    General Description:  CST Makefile that builds the CST libraries and
#                          executable.
#
#==============================================================================

# Define CST version number
export VERSION := 3.4.1

# Common Makefile variables
OSTYPES := linux64 linux32 mingw32 osx
OSTYPES_BUILD_ALL := $(filter-out osx,$(OSTYPES))

# Get operating system name and machine hardware name
UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m)

# Set SYSTEM_TYPE based on the detected operating system
ifeq ($(UNAME_S),Linux)
    ifeq ($(UNAME_M),x86_64)
        SYSTEM_TYPE := linux64
    else
        SYSTEM_TYPE := linux32
    endif
endif
ifeq ($(UNAME_S),Darwin)
    SYSTEM_TYPE := osx
endif
ifeq ($(UNAME_S),MINGW32_NT-*)
    SYSTEM_TYPE := mingw32
endif

export OSTYPE ?= $(SYSTEM_TYPE)

ifeq ($(filter-out $(OSTYPE),$(OSTYPES)),$(OSTYPES))
$(error OSTYPE is not correct (expected values: $(OSTYPES)))
endif

include code/build/make/$(OSTYPE).mk

# Before including init.mk we need to set relative path to root
ROOTPATH := $(CURDIR)
include code/build/make/init.mk

# Build specific variable definitions
export O ?= $(ROOTPATH)/build

# Define the release package name with the version number
RELEASE_PACKAGE := cst-$(VERSION)

ADDONS     := $(wildcard $(ROOTPATH)/add-ons/*)
ADDONS_OUT := $(ROOTPATH)/add-ons/hab_log_parser
ADDONS_REL := $(filter-out $(ADDONS_OUT),$(ADDONS))

CSTSRC     := $(wildcard $(ROOTPATH)/code/*)
CSTSRC_OBJ := $(addprefix obj.,$(OSTYPES))
CSTSRC_OUT := $(addprefix $(ROOTPATH)/code/,$(CSTSRC_OBJ))
CSTSRC_REL := $(filter-out $(CSTSRC_OUT),$(CSTSRC))

# Build CST binary for target OS
$(O)/$(OSTYPE)/bin: openssl
	$(MAKE) -C $(CST_CODE_PATH)/obj.$(OSTYPE) install

# OpenSSL source and custom build paths
export OPENSSL_VERSION ?= 3.2.0
OPENSSL_TAR := openssl-$(OPENSSL_VERSION).tar.gz
OPENSSL_URL := https://www.openssl.org/source/$(OPENSSL_TAR)
OPENSSL_SRC_DIR := openssl-$(OSTYPE)
OPENSSL_BUILD_DIR := /opt/cst
OPENSSL_CONFIG += no-tests no-threads no-shared no-idea no-hw no-idea

# Check if OPENSSL_PATH is provided and valid
ifdef OPENSSL_PATH
ifeq ($(wildcard $(OPENSSL_PATH)/*),)
$(error OPENSSL_PATH is not valid)
endif
OPENSSL_LIB_DIR := $(OPENSSL_PATH)
openssl:
	@echo "Using provided OpenSSL library."
else
# Default behavior: download and build OpenSSL
OPENSSL_LIB_DIR := $(OPENSSL_SRC_DIR)

# Download and unpack OpenSSL
$(OPENSSL_TAR):
	curl --proxy-insecure --insecure -O $(OPENSSL_URL)

$(OPENSSL_SRC_DIR): $(OPENSSL_TAR)
	tar xzf $(OPENSSL_TAR)
	mv openssl-$(OPENSSL_VERSION) $(OPENSSL_SRC_DIR)

# Build OpenSSL
openssl: $(OPENSSL_SRC_DIR)
	cd $(OPENSSL_SRC_DIR) && ./Configure \
	--prefix=$(OPENSSL_BUILD_DIR) \
	--openssldir=$(OPENSSL_BUILD_DIR) $(OPENSSL_CONFIG)
	$(MAKE) -C $(OPENSSL_SRC_DIR)
	$(CP) $(OPENSSL_SRC_DIR)/ms/applink.c \
	$(OPENSSL_SRC_DIR)/include/openssl/
endif

# OPENSSL_LIB_DIR depends on conditions
$(eval export _OPENSSL_PATH := $(ROOTPATH)/$(OPENSSL_LIB_DIR))

# Make build directories
$(O)%:
	$(MKDIR) $@

# Build binaries
build: $(O)/$(OSTYPE)/bin

# Install binaries, scripts, docs and sources
install: build scripts docs sources

# Helper function to install scripts and configuration files
define install_scripts
	@for dir in scripts $(2); do \
		if [ -d $$dir ]; then \
			find $$dir -name $(1) -type f | while IFS= read -r f; do \
				echo "Installing $$f to $(O)/$(2)"; \
				case $$f in \
				*.sh|*.bat) \
					$(INSTALL) -D -m 0755 "$$f" $(O)/$(2) ;; \
					*) \
					$(CP) "$$f" $(O)/$(2) ;; \
				esac; \
			done; \
		fi; \
	done
endef

# Copy key and certificate generation scripts
scripts: $(O)/ca $(O)/keys $(O)/crts
	@echo "Copy scripts and configuration files"
	$(call install_scripts,*.cnf,ca)
	$(call install_scripts,*.sh,keys)
	$(call install_scripts,*.bat,keys)

# Clean-up after build
clean:
	@echo "Clean-up build objects"
	$(MAKE) -C $(CST_CODE_PATH)/obj.$(OSTYPE) OSTYPE=$(OSTYPE) clean

# Clean-up removing all build output files
clobber:
	@echo "Clean OS objects"
	$(foreach OSTYPE, $(OSTYPES), $(MAKE) OSTYPE=$(OSTYPE) clean ;)
	@echo "Clean build"
	$(RMDIR) $(O)/

# Clean-up the repository by removing untracked files and directories
distclean:
	git clean -dfx

# Copy documentation to output folder
docs: $(O)/docs
	@echo "Copy documentations"
	$(CP_REC) $(shell find docs -name '*.pdf' -o -name '*.md') $(O)/docs
	$(CP_REC) ./Release_Notes.txt  $(O)/
	$(CP_REC) ./BUILD.md           $(O)/
	$(CP_REC) ./LICENSE.openssl    $(O)/
	$(CP_REC) ./LICENSE.bsd3       $(O)/
	@if [ -d "$(ROOTPATH)/add-ons/hab_log_parser" ]; then \
		$(CP_REC) $(ROOTPATH)/add-ons/hab_log_parser/README \
					$(O)/docs/README.hab_log_parser; \
		$(CP_REC) $(ROOTPATH)/add-ons/hab_log_parser/LICENSE.hidapi $(O)/; \
	else \
		echo "Skipping hab_log_parser."; \
	fi
	$(CP_REC) ./Software_Content_Register_CST.txt $(O)/

# Copy source and header directories to output folder
sources: $(addprefix $(O)/code/,$(CSTSRC_OBJ))
	@echo "Copy sources"
	$(CP_REC) Makefile \
	          $(O)/
	$(CP_REC) Dockerfile \
	          $(O)/
	$(CP_REC) Dockerfile.hsm \
	          $(O)/
	$(CP_REC) $(CSTSRC_REL) \
	          $(O)/code/
	$(MKDIR)  $(O)/add-ons/
	$(CP_REC) $(ADDONS_REL) \
	          $(O)/add-ons/
	$(foreach objdir,$(CSTSRC_OBJ), $(MKDIR) $(O)/code/$(objdir); \
		$(CP_REC) $(CST_CODE_PATH)/$(objdir)/Makefile $(O)/code/$(objdir)/ ;)

# Build and the images for all OS targets except OSX. The Docker build
# environment doesn't include cross compile tools for OSX.
build-all:
	$(foreach ostype,$(OSTYPES_BUILD_ALL),$(MAKE) OSTYPE=$(ostype) ;)

install-all:
	$(foreach ostype,$(OSTYPES_BUILD_ALL),$(MAKE) OSTYPE=$(ostype) install ;)

# Sequentially execute build and install for all supported systems,
# then install scripts documentation and source code.
all: build-all install-all scripts docs sources

# Create a package of the build directory
package: all
	@echo "Creating package version $(VERSION)"
	ln -sfn $(O) $(RELEASE_PACKAGE)
	tar -czvf $(RELEASE_PACKAGE).tgz \
	--transform='s,^$(notdir $(O)),$(RELEASE_PACKAGE),' $(notdir $(O))
	@echo "Package file $(RELEASE_PACKAGE).tgz created."

.PHONY: all build-all install-all scripts docs sources package