summaryrefslogtreecommitdiffstats
path: root/build_all.mk
blob: 9f213d00421ce12257f075027f47f386a01bcce5 (plain)
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
#!/usr/bin/make
# -- Makefile to build all ptxconfigs
# -- Carsten Schlote <c.schlote@konzeptpark.de>

# -- start this fragment with 'make -f build_all.mk' or the supplied wrapper script!
SHELL=/bin/bash

# -- Defines and Lists --------------------------------------------------------

builddate = $(shell date +%y%m%d-%H%M)
subversionrev = $(strip $(shell svnversion))

configdir = ptxconfigs
configfiles = $(wildcard $(configdir)/*.ptxconfig) $(wildcard $(configdir)/*/*.ptxconfig)
configs = $(basename $(notdir $(configfiles)))

gstatedir = gstate
suffix_buildtime = .buildtag
suffix_buildstatus = .status
suffix_buildrevision = .svnrev
gstatefiles = $(addprefix $(gstatedir)/,$(addsuffix $(suffix_buildtime),$(configs)))

instdirs = $(foreach i,$(configfiles),$(shell . $i && echo $${PTXCONF_SYSROOT_CROSS} ))

distdir = dists
suffix_distarc = .tar.bz2
distfiles = $(addprefix $(distdir)/,$(addsuffix $(suffix_distarc),$(configs)))

statuspagefile = $(gstatedir)/OSELAS-BuildAll-Status.txt

# -- Macros -------------------------------------------------------------------

define PrintHeaderMsg
	@echo -en "\n\n---------------------------------------------------------------------\n"
	@echo -en "-- $(1)"
	@echo -en "\n---------------------------------------------------------------------\n\n"
endef

define UpdateStatusPage
	@echo -e "# OSELAS Toolchain Build All Status " > $(statuspagefile).tmp
	@echo -en "# Last build run was $(if $(shell cat $(gstatedir)/lastbuilddate),$(shell cat $(gstatedir)/lastbuilddate),$(builddate)) - " >> $(statuspagefile).tmp
	@echo -e "$(if $(shell cat $(gstatedir)/laststatus),$(shell cat $(gstatedir)/laststatus),$(builddate)) on SVN $(subversionrev)" >> $(statuspagefile).tmp
	@echo -e "# Status page updated : `date` " >> $(statuspagefile).tmp
	@if [ -e build_all.lock ]; then bldpid=$$(cat build_all.lock); if [ -n "$$bldpid" ]; then echo "# Build process running ($$bldpid)"; fi; fi >> $(statuspagefile).tmp
	@echo -e "# Build date\tSVNRev\tStatus\tToolchain" >> $(statuspagefile).tmp
	@for i in $(configs); do \
	   if test -e $(gstatedir)/$$i$(suffix_buildtime); then cat $(gstatedir)/$$i$(suffix_buildtime); else echo -n "000000-0000"; fi; \
	   echo -en "\t"; \
	   if test -e $(gstatedir)/$$i$(suffix_buildrevision); then cat $(gstatedir)/$$i$(suffix_buildrevision); else echo -n "n.a."; fi; \
	   echo -en "\t"; \
	   if test -e $(gstatedir)/$$i$(suffix_buildstatus); then cat $(gstatedir)/$$i$(suffix_buildstatus); else echo -n "n.a."; fi; \
	   echo -en "\t"; \
	   echo "$$i"; \
	done >> $(statuspagefile).tmp
	@mv $(statuspagefile).tmp $(statuspagefile)
endef

define SetupInstallDirs
	@dirs=""; for i in $(instdirs); do \
	  if [ ! -d "$$i" ]; then \
	    echo "Creating install dir : $$i"; \
	    sudo mkdir -p $$i; \
	    sudo chown $(USER) $$i; \
	  fi; \
	done
endef

define RemoveInstallDirs
	@dirs=""; for i in $(instdirs); do \
	  if [ -d "$$i" ]; then \
	    echo "Remove install dir contents : $$i"; \
	    rm -rf $$i/*; \
	  else \
	    echo "Skipping non-existing install dir : $$i"; \
	  fi; \
	done
endef

define BuildChain
	$(call PrintHeaderMsg, Rebuild toolchain $(1) )
	ptxdist distclean
	sed -e "s:\(PTXCONF_PREFIX\)=\"\(.*\)\":\1=\"\$\${PWD}/inst\2\":" $$< > selected_ptxconfig

	@instdir=source ./selected_ptxconfig && echo $${PTXCONF_SYSROOT_CROSS}; \
	if [ -d $$instdir ]; then \
	   echo "Removing existing toolchain files in $$instdir"; echo rm -rf "$$instdir/*"; \
	fi;

# -- Intentionally fix make target, we don't want to rebuild broken chains over and oover again
# -- Update status output
	echo -n "$(builddate)" > $$@
	echo -n "?????" > $(gstatedir)/$(1)$(suffix_buildstatus)
	echo -n "$(subversionrev)" > $(gstatedir)/$(1)$(suffix_buildrevision)

	@echo "ptxdist go" ; \
	if ptxdist go; then echo -n "Success" > $(gstatedir)/$(1)$(suffix_buildstatus); \
	else echo -n "Failed" > $(gstatedir)/$(1)$(suffix_buildstatus); fi

	$(call PrintHeaderMsg, Saving logs for toolchain $(1))
	@if test -e logfile; then cp -v logfile $(distdir)/$(1)-logfile; else echo "No logfile?";  fi
	@if test -e deptree.ps; then cp -v deptree.ps $(distdir)/$(1)-deptree.ps; else echo "No deptree.ps?";  fi

	$(call PrintHeaderMsg, Create archive for toolchain $(1))
	@if test -L state/toolchain-install-dir; then \
	  echo tar cjf $(distdir)/$(1).tar.bz2 -C `readlink state/toolchain-install-dir`; \
	else \
	  echo "No symbolic link to install dir found - no archive created."; \
	fi
endef


# -- Targets ------------------------------------------------------------------

.PHONY : all dist mkgstatedir mkdistdir updatestatpage updatestatpage_forced mkblddatetag clean distclean

all : updatestatpage

dist :  $(distfiles)

mkgstatedir :
	@mkdir -p $(gstatedir)

mkdistdir :
	@mkdir -p $(distdir)

mkinstdirs :
	$(call SetupInstallDirs)

rminstdirs :
	$(call RemoveInstallDirs)

$(gstatedir)/laststatus : $(gstatefiles) | mkblddatetag mkinstdirs mkgstatedir
	@echo "Toolchain Status Changed - Status Page updated"
	@date +%y%m%d-%H%M > $@
	$(call UpdateStatusPage)

updatestatpage: $(gstatedir)/laststatus

updatestatpage_forced: mkgstatedir
	$(call UpdateStatusPage)

$(gstatedir)/lastbuilddate :  $(configfiles) | mkgstatedir
	@echo -n "$(builddate)" > $(gstatedir)/lastbuilddate

mkblddatetag: $(gstatedir)/lastbuilddate

clean :
	-rm -rf $(gstatedir)

distclean : clean
	-rm -rf $(distdir)

# -- Rules --------------------------------------------------------------------

define BuildChainRules
$(gstatedir)/$(1).buildtag : $(configdir)/$(1).ptxconfig | mkgstatedir mkdistdir updatestatpage_forced
	$(call BuildChain,$(1))

$(distdir)/$(1)$(suffix_distarc) : $(gstatedir)/$(1).buildtag
	@echo "BROKEN FIXME - needs some way to derive install location from ptxconfig"

build_$(1) : $(gstatedir)/$(1).buildtag updatestatpage

endef

$(foreach CFG,$(configs),$(eval $(call BuildChainRules,$(CFG))))