Skip to content

Commit cf59f2d

Browse files
committed
Add Makefile to generate packages and JSON
To produce core and tools packages/json: make or make all To produce core package/json only: make core To produce tools package/json only: make tools Fix stm32duino#13 as Makefile generate tools packages per host OS Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
1 parent 8d2823e commit cf59f2d

File tree

5 files changed

+202
-504
lines changed

5 files changed

+202
-504
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.swp
2+
STM32/src/*.json
3+
STM32/src/*.tar.bz2

STM32/src/Makefile

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
SHELL = /bin/sh
2+
3+
.SUFFIXES: .tar.bz2
4+
5+
ROOT_PATH := .
6+
7+
OS ?=$(shell uname -s)
8+
9+
# -----------------------------------------------------------------------------
10+
ifeq (postpackaging_core,$(findstring $(MAKECMDGOALS),postpackaging_core))
11+
PACKAGE_FILENAME=$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.bz2
12+
PACKAGE_CHKSUM := $(firstword $(shell shasum -a 256 "$(PACKAGE_FILENAME)"))
13+
PACKAGE_SIZE := $(firstword $(shell wc -c "$(PACKAGE_FILENAME)"))
14+
endif
15+
16+
ifeq (postpackaging_tools,$(findstring $(MAKECMDGOALS),postpackaging_tools))
17+
PACKAGE_WIN_FILENAME=$(PACKAGE_NAME)-$(PACKAGE_VERSION)-windows.tar.bz2
18+
PACKAGE_LINUX_FILENAME=$(PACKAGE_NAME)-$(PACKAGE_VERSION)-linux.tar.bz2
19+
PACKAGE_MAC_FILENAME=$(PACKAGE_NAME)-$(PACKAGE_VERSION)-mac.tar.bz2
20+
21+
PACKAGE_WIN_CHKSUM := $(firstword $(shell shasum -a 256 "$(PACKAGE_WIN_FILENAME)"))
22+
PACKAGE_LINUX_CHKSUM := $(firstword $(shell shasum -a 256 "$(PACKAGE_LINUX_FILENAME)"))
23+
PACKAGE_MAC_CHKSUM := $(firstword $(shell shasum -a 256 "$(PACKAGE_MAC_FILENAME)"))
24+
25+
PACKAGE_WIN_SIZE := $(firstword $(shell wc -c "$(PACKAGE_WIN_FILENAME)"))
26+
PACKAGE_LINUX_SIZE := $(firstword $(shell wc -c "$(PACKAGE_LINUX_FILENAME)"))
27+
PACKAGE_MAC_SIZE := $(firstword $(shell wc -c "$(PACKAGE_MAC_FILENAME)"))
28+
endif
29+
# -----------------------------------------------------------------------------
30+
31+
.PHONY: all clean tools print_info postpackaging
32+
33+
all: core tools
34+
35+
core: PACKAGE_NAME := STM32
36+
core: PACKAGE_FOLDER := Arduino_Core_STM32
37+
core: PACKAGE_VERSION := $(shell git --git-dir=$(PACKAGE_FOLDER)/.git describe --tags)
38+
core: PACKAGE_DATE := $(firstword $(shell git --git-dir=$(PACKAGE_FOLDER)/.git log -1 --pretty=format:%ci))
39+
core: clean print_info
40+
@echo ----------------------------------------------------------
41+
@echo "Packaging core."
42+
git --git-dir=$(PACKAGE_FOLDER)/.git show HEAD --pretty=short --no-patch > $(PACKAGE_FOLDER)/package_version.txt
43+
sed -i 's/{runtime.hardware.path}\/tools/{runtime.tools.STM32Tools.path}\/tools/g' $(PACKAGE_FOLDER)/platform.txt
44+
tar --mtime='$(PACKAGE_DATE)' \
45+
--exclude=.git \
46+
--exclude=.gitattributes \
47+
--exclude=.github \
48+
--exclude=.gitignore \
49+
--transform "s|$(PACKAGE_FOLDER)|$(PACKAGE_NAME)|" \
50+
-cjf "$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.bz2" "$(PACKAGE_FOLDER)"
51+
rm -f $(PACKAGE_FOLDER)/package_version.txt
52+
git --git-dir=$(PACKAGE_FOLDER)/.git checkout .
53+
$(MAKE) PACKAGE_NAME=$(PACKAGE_NAME) PACKAGE_VERSION=$(PACKAGE_VERSION) PACKAGE_FOLDER="$(PACKAGE_FOLDER)" --no-builtin-rules postpackaging_core -C .
54+
@echo ----------------------------------------------------------
55+
56+
tools: PACKAGE_NAME := STM32Tools
57+
tools: PACKAGE_FOLDER := Arduino_Tools
58+
tools: PACKAGE_VERSION := $(shell git --git-dir=$(PACKAGE_FOLDER)/.git describe --tags)
59+
tools: PACKAGE_DATE := $(firstword $(shell git --git-dir=$(PACKAGE_FOLDER)/.git log -1 --pretty=format:%ci))
60+
tools: clean print_info
61+
@echo ----------------------------------------------------------
62+
@echo "Packaging tools."
63+
git --git-dir=$(PACKAGE_FOLDER)/.git show HEAD --pretty=short --no-patch > $(PACKAGE_FOLDER)/package_version.txt
64+
tar --mtime='$(PACKAGE_DATE)' \
65+
--exclude=.git \
66+
--exclude=.gitattributes \
67+
--exclude=.github \
68+
--exclude=.gitignore \
69+
--exclude=linux \
70+
--exclude=linux64 \
71+
--exclude=macosx \
72+
--transform "s|$(PACKAGE_FOLDER)|$(PACKAGE_NAME)/tools|" \
73+
-cjf "$(PACKAGE_NAME)-$(PACKAGE_VERSION)-windows.tar.bz2" "$(PACKAGE_FOLDER)"
74+
tar --mtime='$(PACKAGE_DATE)' \
75+
--exclude=.git \
76+
--exclude=.gitattributes \
77+
--exclude=.github \
78+
--exclude=.gitignore \
79+
--exclude=macosx \
80+
--exclude=win \
81+
--transform "s|$(PACKAGE_FOLDER)|$(PACKAGE_NAME)/tools|" \
82+
-cjf "$(PACKAGE_NAME)-$(PACKAGE_VERSION)-linux.tar.bz2" "$(PACKAGE_FOLDER)"
83+
tar --mtime='$(PACKAGE_DATE)' \
84+
--exclude=.git \
85+
--exclude=.gitattributes \
86+
--exclude=.github \
87+
--exclude=.gitignore \
88+
--exclude=linux \
89+
--exclude=linux64 \
90+
--exclude=win \
91+
--transform "s|$(PACKAGE_FOLDER)|$(PACKAGE_NAME)/tools|" \
92+
-cjf "$(PACKAGE_NAME)-$(PACKAGE_VERSION)-mac.tar.bz2" "$(PACKAGE_FOLDER)"
93+
rm -f $(PACKAGE_FOLDER)/package_version.txt
94+
$(MAKE) PACKAGE_NAME=$(PACKAGE_NAME) PACKAGE_VERSION=$(PACKAGE_VERSION) --no-builtin-rules postpackaging_tools -C .
95+
@echo ----------------------------------------------------------
96+
97+
clean:
98+
@echo ----------------------------------------------------------
99+
@echo Cleanup
100+
-$(RM) *.tar.bz2 package_*.json
101+
@echo ----------------------------------------------------------
102+
103+
print_info:
104+
@echo ----------------------------------------------------------
105+
@echo Building $(PACKAGE_NAME) using
106+
@echo "CURDIR = $(CURDIR)"
107+
@echo "OS = $(OS)"
108+
@echo "SHELL = $(SHELL)"
109+
@echo "PACKAGE_NAME = $(PACKAGE_NAME)"
110+
@echo "PACKAGE_FOLDER = $(PACKAGE_FOLDER)"
111+
@echo "PACKAGE_VERSION = $(PACKAGE_VERSION)"
112+
113+
114+
postpackaging_core:
115+
@echo "PACKAGE_CHKSUM = $(PACKAGE_CHKSUM)"
116+
@echo "PACKAGE_SIZE = $(PACKAGE_SIZE)"
117+
@echo "PACKAGE_FILENAME = $(PACKAGE_FILENAME)"
118+
BOARDS_LIST=`grep -E ".+\.menu\.pnum\.[^\.]+=" $(PACKAGE_FOLDER)/boards.txt | cut -d'=' -f2 | awk '{print " {\"name\": \""$$0"\"},"}'`; \
119+
BOARDS_LIST=$${BOARDS_LIST::-1}; \
120+
cat templates/package_core_index.json | sed s/%%VERSION%%/$(PACKAGE_VERSION)/ | sed s/%%FILENAME%%/$(PACKAGE_FILENAME)/ | sed s/%%CHECKSUM%%/$(PACKAGE_CHKSUM)/ | sed s/%%SIZE%%/$(PACKAGE_SIZE)/ | sed -e "s/%%BOARDSLIST%%/$${BOARDS_LIST//$$'\n'/\\n}/" > package_$(PACKAGE_NAME)_$(PACKAGE_VERSION)_index.json
121+
@echo "package_$(PACKAGE_NAME)_$(PACKAGE_VERSION)_index.json created"
122+
123+
postpackaging_tools:
124+
@echo "PACKAGE_WIN_FILENAME = $(PACKAGE_WIN_FILENAME)"
125+
@echo "PACKAGE_WIN_SIZE = $(PACKAGE_WIN_SIZE)"
126+
@echo "PACKAGE_WIN_CHKSUM = $(PACKAGE_WIN_CHKSUM)"
127+
@echo "PACKAGE_LINUX_FILENAME = $(PACKAGE_LINUX_FILENAME)"
128+
@echo "PACKAGE_LINUX_SIZE = $(PACKAGE_LINUX_SIZE)"
129+
@echo "PACKAGE_LINUX_CHKSUM = $(PACKAGE_LINUX_CHKSUM)"
130+
@echo "PACKAGE_MAC_FILENAME = $(PACKAGE_MAC_FILENAME)"
131+
@echo "PACKAGE_MAC_SIZE = $(PACKAGE_MAC_SIZE)"
132+
@echo "PACKAGE_MAC_CHKSUM = $(PACKAGE_MAC_CHKSUM)"
133+
cat templates/package_tools_index.json | sed s/%%PACKAGENAME%%/$(PACKAGE_NAME)/ | sed s/%%VERSION%%/$(PACKAGE_VERSION)/ | sed s/%%FILENAMEWIN%%/$(PACKAGE_WIN_FILENAME)/ | sed s/%%CHECKSUMWIN%%/$(PACKAGE_WIN_CHKSUM)/ | sed s/%%SIZEWIN%%/$(PACKAGE_WIN_SIZE)/ | sed s/%%FILENAMEMAC%%/$(PACKAGE_MAC_FILENAME)/ | sed s/%%CHECKSUMMAC%%/$(PACKAGE_MAC_CHKSUM)/ | sed s/%%SIZEMAC%%/$(PACKAGE_MAC_SIZE)/ | sed s/%%FILENAMELINUX%%/$(PACKAGE_LINUX_FILENAME)/ | sed s/%%CHECKSUMLINUX%%/$(PACKAGE_LINUX_CHKSUM)/ | sed s/%%SIZELINUX%%/$(PACKAGE_LINUX_SIZE)/ > package_$(PACKAGE_NAME)_$(PACKAGE_VERSION)_index.json
134+
@echo "package_$(PACKAGE_NAME)_$(PACKAGE_VERSION)_index.json created"

0 commit comments

Comments
 (0)