Skip to content

Instantly share code, notes, and snippets.

@Abhiroop
Created December 19, 2022 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Abhiroop/c67815df12bf27ed305158d4118c6ed6 to your computer and use it in GitHub Desktop.
Save Abhiroop/c67815df12bf27ed305158d4118c6ed6 to your computer and use it in GitHub Desktop.
CFLAGS = -Wall -Wextra
ifeq ($(DEBUG),1)
GRAMINE_LOG_LEVEL = debug
CFLAGS += -g
else
GRAMINE_LOG_LEVEL = error
CFLAGS += -O3
endif
.PHONY: all
all: helloworld helloworld.manifest
ifeq ($(SGX),1)
all: helloworld.manifest.sgx helloworld.sig helloworld.token
endif
helloworld: Main.hs
ghc Main.hs -o helloworld
helloworld.manifest: helloworld.manifest.template
gramine-manifest \
-Dlog_level=$(GRAMINE_LOG_LEVEL) \
$< $@
# gramine-sgx-sign generates both a .sig file and a .manifest.sgx file. This is somewhat
# hard to express properly in Make. The simple solution would be to use
# "Rules with Grouped Targets" (`&:`), however make on Ubuntu <= 20.04 doesn't support it.
#
# Simply using a normal rule with "two targets" is equivalent to creating separate rules
# for each of the targets, and when using `make -j`, this might cause two instances
# of gramine-sgx-sign to get launched simultaneously, potentially breaking the build.
#
# As a workaround, we use a dummy intermediate target, and mark both files as depending on it, to
# get the dependency graph we want. We mark this dummy target as .INTERMEDIATE, which means
# that make will consider the source tree up-to-date even if the sgx_sign file doesn't exist,
# as long as the other dependencies check out. This is in contrast to .PHONY, which would
# be rebuilt on every invocation of make.
helloworld.sig helloworld.manifest.sgx: sgx_sign
@:
.INTERMEDIATE: sgx_sign
sgx_sign: helloworld.manifest helloworld
gramine-sgx-sign \
--manifest $< \
--output $<.sgx
helloworld.token: helloworld.sig
gramine-sgx-get-token \
--output $@ --sig $<
ifeq ($(SGX),)
GRAMINE = gramine-direct
else
GRAMINE = gramine-sgx
endif
.PHONY: check
check: all
$(GRAMINE) helloworld > OUTPUT
echo "Hello, world" | diff OUTPUT -
@echo "[ Success ]"
.PHONY: clean
clean:
$(RM) *.token *.sig *.manifest.sgx *.manifest Main.o helloworld Main.hi OUTPUT
.PHONY: distclean
distclean: clean
69,1 Bot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment