forked from DaveAckley/ULAM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
224 lines (180 loc) · 7.52 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
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
219
220
221
222
223
224
####
# 'Almost' top-level Makefile driver for ULAM
#
# (This is <ROOT>/ULAM/Makefile. It is the top-level Makefile for the
# ulam compiler iself. But there is an even-more top-level Makefile
# for the ulam _package_, which also includes the MFM simulation,
# located in <ROOT>/Makefile. But _that_ Makefile is not explicitly
# respresented in the ulam repo (or the mfm repo), because it is
# auto-generated by ./share/perl/extractDistro.pl during Ubuntu
# package construction. Among minor other things, that autogenerated
# Makefile exports DEBIAN_PACKAGE_NAME, which we default if unset.)
ifndef DEBIAN_PACKAGE_NAME
export DEBIAN_PACKAGE_NAME:=ulam
export MAGIC_DEBIAN_PACKAGE_VERSION:=
endif
$(info Building ULAM for Debian package name: $(DEBIAN_PACKAGE_NAME))
# Root of source tree
ULAM_ROOT_DIR := $(shell pwd)
export ULAM_ROOT_DIR
include VERSION.mk
####
# TOP_TARGETS: Targets that are handled at this level
TOP_TARGETS:=
TOP_TARGETS+=doc # Build documentation in doc/ref
TOP_TARGETS+=dist # Export as tar file
TOP_TARGETS+=topclean # Light cleaning in top dir only
TOP_TARGETS+=realclean # Deep cleaning: Nuke build, bin, doc/ref, also clean
TOP_TARGETS+=projini # Initialize CWD as an ULAM project, if it isn't already
####
# SRC_TARGETS: Targets that are passed to src/
SRC_TARGETS:=
SRC_TARGETS+=all # Build everything that needs it
SRC_TARGETS+=clean # Light cleaning: ~'s .o's and such
# Default target
all:
####
# Targets handled at top level
doc: FORCE
mkdir -p doc/ref
echo doxygen
REALCLEAN_DIRS:=build bin doc/ref
realclean: topclean
rm -rf $(REALCLEAN_DIRS)
mkdir -p $(REALCLEAN_DIRS)
make clean
testclean: FORCE
rm -f bin/test
# rm -f build/test/test.inc
rm -f build/drivers/test/main*
$(MAKE) -C src/test all
$(MAKE) -C src/drivers
topclean: FORCE
@rm -f *~
BASENAME=$(shell basename `pwd`)
dist: realclean
cd ..;tar cfz ulam${ULAM_LANGUAGE_VERSION}-$(BUILD_DATE_TIME).tgz $(BASENAME)
####
# Variables exported to submakes
export SRC_TARGETS
export ULAM_VERSION_MAJOR
export ULAM_VERSION_MINOR
export ULAM_VERSION_REV
export ULAM_LANGUAGE_VERSION
ULAM_LANGUAGE_VERSION:=1
# Defines from top level
export DEFINES
export ULAM_BUILD_DATE := $(shell date -u +%Y%m%d)
export ULAM_BUILD_TIME := $(shell date -u +%H%M%S)
export ULAM_BUILD_TIMESTAMP := $(ULAM_BUILD_DATE)$(ULAM_BUILD_TIME)
export ULAM_BUILD_WHO:=$(shell whoami)
export ULAM_BUILD_WHERE:=$(shell hostname)
DEFINES+=-DBUILD_DATE="0x$(ULAM_BUILD_DATE)" -DBUILD_TIME="0x$(ULAM_BUILD_TIME)" -DBUILD_DATE_TIME="$(ULAM_BUILD_TIMESTAMP)"
DEFINES+=-DULAM_VERSION_MAJOR=$(ULAM_VERSION_MAJOR) -DULAM_VERSION_MINOR=$(ULAM_VERSION_MINOR) -DULAM_VERSION_REV=$(ULAM_VERSION_REV)
DEFINES+=-DULAM_TREE_VERSION="$(ULAM_TREE_VERSION)"
DEFINES+=-DDEBIAN_PACKAGE_NAME="$(DEBIAN_PACKAGE_NAME)"
DEFINES+=-DMAGIC_DEBIAN_PACKAGE_VERSION="$(MAGIC_DEBIAN_PACKAGE_VERSION)"
export DEFINES
# Compilation flags from top level
export CFLAGS
CFLAGS+=-g2 -ansi -Wall -pedantic -Werror -Wformat
#CFLAGS+=-DNDEBUG
# Libs from top level
export LIBS
# Root of shared files tree.
ifeq ($(ULAM_SHARE_DIR),)
ULAM_SHARE_DIR:=$(ULAM_ROOT_DIR)/share
endif
export ULAM_SHARE_DIR
# Root of MFM simulator tree (configure in Makefile.local.mk if known)
export MFM_ROOT_DIR
# MFM version we're built on
export MFM_VERSION_NUMBER
# MFM git rev we're built on
export MFM_TREE_VERSION
# Things that all builds should depend on
export ALLDEP
ALLDEP += $(shell find $(ULAM_ROOT_DIR) -name 'Makefile')
# Allow local configuration, if any, to override us:
-include Makefile.local.mk
ifeq ($(MFM_ROOT_DIR),)
# check installed location
ifeq ("$(wildcard ../MFM)","")
${warning MFM_ROOT_DIR not configured}
${info =>Consider creating '$(ULAM_ROOT_DIR)/Makefile.local.mk', containing something like}
${info => MFM_ROOT_DIR := /path/to/source/dir/of/MFMv2}
${info =>to avoid this message}
else
MFM_ROOT_DIR:=$(realpath ../MFM)
endif
endif
#${info Local configuration: MFM_ROOT_DIR=$(MFM_ROOT_DIR)}
## This wants to be rethought and refactored!
COMPONENTNAME:=ulamic
BASEDIR:=$(MFM_ROOT_DIR)
include $(BASEDIR)/config/Makeplatform.mk
MFM_TARGET:=$(PLATFORM)
include $(BASEDIR)/config/Makecommon.mk
override CFLAGS += -I $(BASEDIR)/src/core/include
override CFLAGS += -D ULAM_SHARE_DIR=$(ULAM_SHARE_DIR)
override LIBS := -L $(BASEDIR)/build/core $(LIBS)
####
# Top level rules
$(SRC_TARGETS): src
# src rule just passes the make goals down to src
src: FORCE
@$(MAKE) -k -C $@ $(MAKECMDGOALS)
# pattern rule to build shared libs of ulam elements destined to live
# inside the MFM tree. NOTE: MAKE BOTH TREES FIRST!
ULAMDIR:=share/ulam
ULAMWORKDIR:=.gen
ULAMDEMODATE:=$(shell date +%Y%m%d%H%M%S)
ULAMDEMOVERSION:=$(shell if [ -x ./bin/ulam ] ; then ./bin/ulam -V 2>&1 ; else echo --unknown version-- ; fi)
ULAMDEMOWHO:=$(shell whoami)
ULAMDEMOKEY:="MFM-DEMOS-$(ULAMDEMODATE)-$(ULAMDEMOVERSION)-$(ULAMDEMOWHO)"
MFZMAKEPATH:=$(MFM_ROOT_DIR)/bin/mfzmake
TMP_KEY_DIR:=$(shell mktemp -d)
makedemokey: FORCE
KEYPATH=`$(MFZMAKEPATH) -kd $(TMP_KEY_DIR) keygen $(ULAMDEMOKEY) | awk -F ' "[^"]+" | ' '{print $$4}'` && \
mkdir -p $(MFM_ROOT_DIR)/res/public_keys/ && \
cp $$KEYPATH $(MFM_ROOT_DIR)/res/public_keys/
burndemokey: FORCE
$(MFZMAKEPATH) -kd $(TMP_KEY_DIR) burn $(ULAMDEMOKEY)
havedemokey: FORCE
$(MFZMAKEPATH) -kd $(TMP_KEY_DIR) cansign $(ULAMDEMOKEY)
donothavedemokey: FORCE
$(MFZMAKEPATH) -kd $(TMP_KEY_DIR) keygen $(ULAMDEMOKEY)
$(MFZMAKEPATH) -kd $(TMP_KEY_DIR) cansign $(ULAMDEMOKEY) 2>/dev/null || exit 0
$(MFM_ROOT_DIR)/res/elements/libue%.so: $(ULAMDIR)/%/*.ulam
## ./bin/ulam -lo --sd $(ULAMDIR)/core --sd $(ULAMDIR)/$* $(^:$(ULAMDIR)/$*/%=%)
./bin/ulam -lo --sa --sd $(ULAMDIR)/core --sd $(ULAMDIR)/$* $(^:$(ULAMDIR)/$*/%=%)
mv -f $(ULAMWORKDIR)/bin/libcue.so "$@"
rm -rf $(ULAMWORKDIR)
$(MFM_ROOT_DIR)/res/elements/demos/libue%.so: $(ULAMDIR)/demos/%/*.ulam
mkdir -p $(MFM_ROOT_DIR)/res/elements/demos
./bin/ulam -lo --sd $(ULAMDIR)/core --sd $(ULAMDIR)/demos/$* $(^:$(ULAMDIR)/demos/$*/%=%)
mv -f $(ULAMWORKDIR)/bin/libcue.so "$@"
rm -rf $(ULAMWORKDIR)
ULAM_DEMO_LIST_FILE:=$(MFM_ROOT_DIR)/res/elements/demos.dat
$(MFM_ROOT_DIR)/res/elements/demos/%.mfz: $(ULAMDIR)/demos/%/*.ulam
mkdir -p $(MFM_ROOT_DIR)/res/elements/demos
## ./bin/ulam -kd $(TMP_KEY_DIR) -z $(ULAMDEMOKEY) -o --sc --sd $(ULAMDIR)/core --sd $(ULAMDIR)/demos/$* $(^:$(ULAMDIR)/demos/$*/%.ulam=%.ulam) $@ $(wildcard $(ULAMDIR)/demos/$*/*.mfs) $(wildcard $(ULAMDIR)/demos/$*/args.txt)
./bin/ulam -kd $(TMP_KEY_DIR) -z $(ULAMDEMOKEY) -o --sa --sc --sd $(ULAMDIR)/core --sd $(ULAMDIR)/demos/$* $(^:$(ULAMDIR)/demos/$*/%.ulam=%.ulam) $@ $(wildcard $(ULAMDIR)/demos/$*/*.mfs) $(wildcard $(ULAMDIR)/demos/$*/args.txt)
mv -f $(ULAMWORKDIR)/bin/libcue.so "$(MFM_ROOT_DIR)/res/elements/demos/libue$*.so"
printf "$*\0elements/demos/$*.mfz\0elements/demos/libue$*.so\0$(^:$(ULAMDIR)/demos/$*/%.ulam=%)\0\0\n" >> $(ULAM_DEMO_LIST_FILE)
rm -rf $(ULAMWORKDIR)
ULAM_MFM_TARGETS+=$(MFM_ROOT_DIR)/res/elements/libuecore.so
ULAM_DEMO_PATHS:=$(wildcard $(ULAMDIR)/demos/*/.)
ULAM_DEMO_DIRS:=$(patsubst %/.,%,$(ULAM_DEMO_PATHS))
ULAM_DEMO_NAMES:=$(patsubst $(ULAMDIR)/demos/%,%,$(ULAM_DEMO_DIRS))
ULAM_DEMO_LIBS:=$(patsubst %,$(MFM_ROOT_DIR)/res/elements/demos/libue%.so,$(ULAM_DEMO_NAMES))
#ULAM_MFM_TARGETS+=$(ULAM_DEMO_LIBS)
ULAM_DEMO_MFZS:=$(patsubst %,$(MFM_ROOT_DIR)/res/elements/demos/%.mfz,$(ULAM_DEMO_NAMES))
ulamexports: $(ULAM_MFM_TARGETS) | makedemokey $(ULAM_DEMO_MFZS) burndemokey
cleanulamexports: FORCE
rm -f $(ULAM_DEMO_LIST_FILE)
rm -f $(ULAM_MFM_TARGETS) $(ULAM_DEMO_MFZS)
# Shortcut to ulam template build
ulam: FORCE
@$(MAKE) -C src/drivers/ulam
.PHONY: $(TOP_TARGETS) $(SRC_TARGETS) FORCE