Browse Source

[Makefile] Use generated header dependencies

Fixes #189.
Simon Gaiser 4 years ago
parent
commit
64e46adcc0

+ 1 - 0
.gitignore

@@ -15,6 +15,7 @@
 *.i
 *.s
 *.e
+*.d
 
 # object file/libraries
 *.a

+ 11 - 11
LibOS/shim/src/Makefile

@@ -51,10 +51,10 @@ objs	= $(addprefix bookkeep/shim_,handle vma thread signal) \
 	  async parser debug object) syscallas start \
 	  $(patsubst %.c,%,$(wildcard sys/*.c)) \
 	  vdso/vdso-data
+all_objs = $(objs) vdso/vdso-note vdso/vdso
 
 graphene_lib = .lib/graphene-lib.a
 pal_lib = $(RUNTIME_DIR)/libpal-$(PAL_HOST).so
-headers = ../include/*.h ../../../Pal/lib/*.h ../../../Pal/include/pal/*.h
 
 all: $(files_to_build) $(files_to_install)
 
@@ -99,23 +99,19 @@ else
 $(shim_target):
 endif
 
-$(addsuffix .o,$(addprefix ipc/shim_ipc_,$(ipcns))): $(wildcard ipc/*.h)
-elf/shim_rtld.o: $(wildcard elf/*.h)
-
-
-%.o: %.c $(headers)
+%.o: %.c
 	$(call cmd,cc_o_c)
 
-%.i: %.c $(headers)
+%.i: %.c
 	$(call cmd,cpp_i_c)
 
-%.s: %.c $(headers)
+%.s: %.c
 	$(call cmd,cc_s_c)
 
-%.o: %.S $(headers)
+%.o: %.S
 	$(call cmd,as_o_S)
 
-%.s: %.S $(headers)
+%.s: %.S
 	$(call cmd,cpp_s_S)
 
 syscallas.S shim_checkpoint.c: asm-offsets.h
@@ -152,4 +148,8 @@ vdso/vdso-data.o: vdso/vdso.so
 CLEAN_FILES += vdso/vdso.so.dbg vdso/vdso.so vdso/.vdso.so
 
 clean:
-	rm -rf $(addsuffix .o,$(objs)) $(shim_target) $(files_to_build) .lib $(CLEAN_FILES)
+	rm -rf $(addsuffix .o,$(all_objs)) $(addsuffix .d,$(all_objs)) \
+	       $(addsuffix .i.d,$(all_objs)) $(addsuffix .s.d,$(all_objs)) \
+	       $(shim_target) $(files_to_build) .lib $(CLEAN_FILES)
+
+-include $(addsuffix .d,$(all_objs)) $(addsuffix .i.d,$(all_objs)) $(addsuffix .s.d,$(all_objs))

+ 1 - 1
LibOS/shim/test/Makefile

@@ -77,7 +77,7 @@ manifest: manifest.template
 
 .PHONY: clean
 clean: $(clean-extra) $(if $(level),,clean-subdirs)
-	rm -rf pal_loader $(call expand_target,$(exec_target)) $(target)
+	rm -rf pal_loader $(call expand_target,$(exec_target)) $(target) $(wildcard *.d)
 
 .PHONY: build-subdirs
 build-subdirs:

+ 6 - 4
LibOS/shim/test/native/Makefile

@@ -12,23 +12,25 @@ include ../Makefile
 ifeq ($(findstring x86_64,$(SYS))$(findstring linux,$(SYS)),x86_64linux)
 $(c_executables): %: %.c
 	@echo [ $@ ]
-	@$(CC) $(CFLAGS) $(if $(findstring .libos,$@),$(CFLAGS-libos),) -o $@ $< \
+	@$(CC) -MD -MP $(CFLAGS) $(if $(findstring .libos,$@),$(CFLAGS-libos),) -o $@ $< \
 	$(shell echo $@ | sed 's/^[^\.]*//g' | sed 's/\./ -l/g')
 
 $(cxx_executables): %: %.cpp
 	@echo [ $@ ]
-	@$(CXX) $(CXXFLAGS) $(if $(findstring .libos,$@),$(CFLAGS-libos),) -o $@ $< \
+	@$(CXX) -MD -MP $(CXXFLAGS) $(if $(findstring .libos,$@),$(CFLAGS-libos),) -o $@ $< \
 	$(shell echo $@ | sed 's/^[^\.]*//g' | sed 's/\./ -l/g')
 
 static: %: %.c
 	@echo [ $@ ]
-	@$(CC) $(CFLAGS) -o $@ -static $< \
+	@$(CC) -MD -MP $(CFLAGS) -o $@ -static $< \
 	$(shell echo $@ | sed 's/^[^\.]*//g' | sed 's/\./ -l/g')
 
 pie: %: %.c
 	@echo [ $@ ]
-	@$(CC) $(CFLAGS) -fPIC --pie -o $@ $< \
+	@$(CC) -MD -MP $(CFLAGS) -fPIC --pie -o $@ $< \
 	$(shell echo $@ | sed 's/^[^\.]*//g' | sed 's/\./ -l/g')
+
+include $(wildcard *.d)
 else
 .IGNORE: $(special_executables) $(c_executables) $(cxx_executables)
 $(special_executables) $(c_executables) $(cxx_executables):

+ 5 - 5
Makefile.rules

@@ -76,20 +76,20 @@ cc-option = $(shell set -e; \
 
 # .c
 quiet_cmd_cc_o_c = [ $@ ]
-      cmd_cc_o_c = $(CC) $(CFLAGS) $(CFLAGS-$@) -c -o $@ $<
+      cmd_cc_o_c = $(CC) -MD -MP $(CFLAGS) $(CFLAGS-$@) -c -o $@ $<
 
 quiet_cmd_cpp_i_c = [ $@ ]
-      cmd_cpp_i_c = $(CC) $(CFLAGS) $(CFLAGS-$@) -E -o $@ $<
+      cmd_cpp_i_c = $(CC) -MD -MP -MF $@.d $(CFLAGS) $(CFLAGS-$@) -E -o $@ $<
 
 quiet_cmd_cc_s_c = [ $@ ]
-      cmd_cc_s_c = $(CC) $(CFLAGS) $(CFLAGS-$@) -S -o $@ $<
+      cmd_cc_s_c = $(CC) -MD -MP -MF $@.d $(CFLAGS) $(CFLAGS-$@) -S -o $@ $<
 
 # .S
 quiet_cmd_as_o_S = [ $@ ]
-      cmd_as_o_S = $(CC) $(ASFLAGS) $(ASFLAGS-$@) -c -o $@ $<
+      cmd_as_o_S = $(CC) -MD -MP $(ASFLAGS) $(ASFLAGS-$@) -c -o $@ $<
 
 quiet_cmd_cpp_s_S = [ $@ ]
-      cmd_cpp_s_S = $(CC) $(ASFLAGS) $(ASFLAGS-$@) -E -o $@ $<
+      cmd_cpp_s_S = $(CC) -MD -MP -MF $@.d $(ASFLAGS) $(ASFLAGS-$@) -E -o $@ $<
 
 # LD
 quiet_cmd_ld_so_o = [ $@ ]

+ 3 - 4
Pal/lib/Makefile

@@ -21,7 +21,6 @@ CFLAGS += -I$(target)
 endif
 
 subdirs = string stdlib network graphene util crypto
-headers = api.h pal_crypto.h
 
 # Choose Crypto provider among (mbedtls|wolfssl)
 CRYPTO_PROVIDER ?= mbedtls
@@ -36,11 +35,9 @@ CRYPTO_PROVIDER ?= mbedtls
 # symbols.
 ifeq ($(CRYPTO_PROVIDER),mbedtls)
 subdirs += crypto/mbedtls
-headers += $(wildcard crypto/mbedtls/mbedtls/*.h)
 endif
 ifeq ($(CRYPTO_PROVIDER),wolfssl)
 subdirs += crypto/wolfssl
-headers += $(wildcard crypto/wolfssl/*.h)
 endif
 
 objs	= $(foreach dir,$(subdirs),$(patsubst %.c,%.o,$(wildcard $(dir)/*.c)))
@@ -68,10 +65,12 @@ $(target)graphene-lib.a: $(addprefix $(target),$(objs))
 	@mkdir -p $(dir $@)
 	$(call cmd,ar_a_o)
 
-$(target)%.o: %.c $(headers)
+$(target)%.o: %.c
 	@mkdir -p $(dir $@)
 	$(call cmd,cc_o_c)
 
+-include $(patsubst %.o,%.d,$(addprefix $(target),$(objs)))
+
 .PHONY: clean
 clean:
 	rm -f $(objs) graphene-lib.a

+ 7 - 6
Pal/regression/Makefile

@@ -12,7 +12,6 @@ target = $(executables) $(manifests)
 
 graphene_lib = .lib/graphene-lib.a
 pal_lib = ../../Runtime/libpal-$(PAL_HOST).so
-headers = $(wildcard ../include/pal/*.h)
 
 .PHONY: default
 default: all
@@ -51,14 +50,16 @@ manifest: manifest.template
 
 ifeq ($(findstring x86_64,$(SYS))$(findstring linux,$(SYS)),x86_64linux)
 $(preloads): %.so: %.so.c ../src/user_shared_start.o \
-	$(graphene_lib) $(pal_lib) ../include/pal/pal.h
+	$(graphene_lib) $(pal_lib)
 	@echo [ $@ ]
-	@$(CC) -shared -fPIC $(filter-out -no-pie,$(CFLAGS)) $^ -o $@
+	@$(CC) -MD -MP -shared -fPIC $(filter-out -no-pie,$(CFLAGS)) $(filter-out %.h,$^) -o $@
 
 $(executables): %: %.c ../src/user_start.o \
-	$(graphene_lib) $(pal_lib) $(preloads) ../include/pal/pal.h
+	$(graphene_lib) $(pal_lib) $(preloads)
 	@echo [ $@ ]
-	@$(CC) $(CFLAGS) $^ -o $@
+	@$(CC) -MD -MP $(CFLAGS) $(filter-out %.h,$^) -o $@
+
+include $(wildcard *.d)
 
 .lib/host_endian.h: ../src/host/$(PAL_HOST)/host_endian.h
 	@mkdir -p .lib
@@ -86,4 +87,4 @@ pal-regression.xml: test_pal.py $(call expand_target,$(target))
 
 .PHONY: clean
 clean:
-	rm -rf $(call expand_target,$(target)) $(preloads) *.tmp .lib *.cached *.sig
+	rm -rf $(call expand_target,$(target)) $(preloads) *.tmp .lib *.cached *.sig *.d

+ 4 - 3
Pal/src/Makefile

@@ -43,7 +43,6 @@ objs	= $(addprefix db_,streams memory threading mutex events process \
 
 graphene_lib = $(LIB_DIR)/graphene-lib.a
 host_lib = $(HOST_DIR)/libpal-$(PAL_HOST).a
-headers	= $(wildcard *.h) $(wildcard ../lib/*.h) $(HOST_DIR)/pal_host.h
 
 ifeq ($(findstring x86_64,$(SYS))$(findstring linux,$(SYS)),x86_64linux)
 files_to_build += user_start.o user_shared_start.o
@@ -128,7 +127,7 @@ user_shared_start.o: ASFLAGS = -DSHARED -fPIC
 user_shared_start.o: user_start.S
 	$(call cmd,as_o_S)
 
-$(OBJ_DIR)/%.o: %.c $(headers)
+$(OBJ_DIR)/%.o: %.c
 	@mkdir -p $(OBJ_DIR)
 	$(call cmd,cc_o_c)
 
@@ -140,9 +139,11 @@ $(OBJ_DIR)/%.s: %.c $(headers)
 	@mkdir -p $(OBJ_DIR)
 	$(call cmd,cc_s_c)
 
+include $(wildcard *.d)
+
 .PHONY: clean
 clean:
-	rm -rf $(LIB_DIR) $(OBJ_DIR) $(files_to_build)
+	rm -rf $(LIB_DIR) $(OBJ_DIR) $(files_to_build) *.d
 	@[ ! -d $(HOST_DIR) ] || $(MAKE) -C $(HOST_DIR) clean
 
 .PHONY: test

+ 14 - 14
Pal/src/host/Linux-SGX/Makefile

@@ -17,8 +17,6 @@ enclave-asm-objs = enclave_entry
 urts-objs = $(addprefix sgx_,enclave framework main rtld thread process exception graphene)
 urts-asm-objs = sgx_entry
 graphene_lib = .lib/graphene-lib.a
-headers	= $(wildcard *.h) $(wildcard ../../*.h) $(wildcard ../../../lib/*.h) \
-	  $(addprefix sgx-driver/,graphene-sgx.h isgx_version.h)
 
 .PHONY: all
 all: $(host_files)
@@ -37,38 +35,38 @@ libpal-Linux-SGX.a: $(addsuffix .o,$(enclave-objs) $(enclave-asm-objs))
 	$(call cmd,ar_a_o)
 
 $(addsuffix .o,$(enclave-objs)): CFLAGS += -DIN_ENCLAVE
-$(addsuffix .o,$(enclave-objs)): %.o: %.c $(headers)
+$(addsuffix .o,$(enclave-objs)): %.o: %.c
 	$(call cmd,cc_o_c)
 
 $(addsuffix .i,$(enclave-objs)): CFLAGS += -DIN_ENCLAVE
-$(addsuffix .i,$(enclave-objs)): %.i: %.c $(headers)
+$(addsuffix .i,$(enclave-objs)): %.i: %.c
 	$(call cmd,cpp_i_c)
 
 $(addsuffix .s,$(enclave-objs)): CFLAGS += -DIN_ENCLAVE
-$(addsuffix .s,$(enclave-objs)): %.s: %.c $(headers)
+$(addsuffix .s,$(enclave-objs)): %.s: %.c
 	$(call cmd,cc_s_c)
 
 $(addsuffix .o,$(enclave-asm-objs)): ASFLAGS += -DIN_ENCLAVE
-$(addsuffix .o,$(enclave-asm-objs)): %.o: %.S $(headers)
+$(addsuffix .o,$(enclave-asm-objs)): %.o: %.S
 	$(call cmd,as_o_S)
 
 $(addsuffix .s,$(enclave-asm-objs)): ASFLAGS += -DIN_ENCLAVE
-$(addsuffix .s,$(enclave-asm-objs)): %.s: %.S $(headers)
+$(addsuffix .s,$(enclave-asm-objs)): %.s: %.S
 	$(call cmd,cpp_s_S)
 
-$(addsuffix .o,$(urts-objs)): %.o: %.c $(headers)
+$(addsuffix .o,$(urts-objs)): %.o: %.c
 	$(call cmd,cc_o_c)
 
-$(addsuffix .i,$(urts-objs)): %.i: %.c $(headers)
+$(addsuffix .i,$(urts-objs)): %.i: %.c
 	$(call cmd,cpp_i_c)
 
-$(addsuffix .s,$(urts-objs)): %.s: %.c $(headers)
+$(addsuffix .s,$(urts-objs)): %.s: %.c
 	$(call cmd,cc_s_c)
 
-$(addsuffix .s,$(urts-asm-objs)): %.s: %.S $(headers)
+$(addsuffix .s,$(urts-asm-objs)): %.s: %.S
 	$(call cmd,cpp_s_S)
 
-$(addsuffix .o,$(urts-asm-objs)): %.o: %.S $(headers)
+$(addsuffix .o,$(urts-asm-objs)): %.o: %.S
 	$(call cmd,as_o_S)
 
 pal-sgx: $(addsuffix .o,$(urts-objs) $(urts-asm-objs)) $(graphene_lib)
@@ -77,7 +75,7 @@ pal-sgx: $(addsuffix .o,$(urts-objs) $(urts-asm-objs)) $(graphene_lib)
 
 debugger/sgx_gdb.so: debugger/sgx_gdb.c debugger/sgx_gdb.h sgx_arch.h
 	@echo [ host/Linux-SGX/$@ ]
-	$(CC) -Wall -fPIC -O2 -std=c11 -c debugger/sgx_gdb.c -o debugger/sgx_gdb.o
+	$(CC) -MD -MP -Wall -fPIC -O2 -std=c11 -c debugger/sgx_gdb.c -o debugger/sgx_gdb.o
 	$(LD) -shared debugger/sgx_gdb.o -o debugger/sgx_gdb.so -lc
 
 enclave_entry.o sgx_entry.o: asm-offsets.h
@@ -85,6 +83,8 @@ enclave_entry.o sgx_entry.o: asm-offsets.h
 sgx-driver/isgx_version.h:
 	$(MAKE) -C sgx-driver $(notdir $<)
 
+include $(wildcard *.d) $(wildcard debugger/*.d)
+
 include ../../../../Makefile.rules
 
 CLEAN_FILES += $(notdir $(pal_static) $(pal_lib) $(pal_loader))
@@ -92,7 +92,7 @@ CLEAN_FILES += debugger/sgx_gdb.o
 
 .PHONY: clean
 clean:
-	rm -f *.o *.e *.i *.s $(host_files) $(CLEAN_FILES)
+	rm -f *.o *.e *.i *.s $(host_files) $(CLEAN_FILES) *.d debugger/*.d
 
 .PHONY: test
 test:

+ 10 - 7
Pal/src/host/Linux/Makefile

@@ -19,7 +19,6 @@ objs	= $(addprefix db_,files devices pipes sockets streams memory threading \
 	    mutex events process object main rtld misc ipc \
 	    exception) clone-x86_64 gettimeofday-x86_64
 graphene_lib = .lib/graphene-lib.a
-headers	= $(wildcard *.h) $(wildcard ../../*.h) $(wildcard ../../../lib/*.h)
 
 .PHONY: all
 all: $(host_files)
@@ -33,28 +32,32 @@ endif
 libpal-Linux.a: $(addsuffix .o,$(objs)) $(graphene_lib)
 	$(call cmd,ar_a_o)
 
-%.o: %.c $(headers)
+%.o: %.c
 	$(call cmd,cc_o_c)
 
-%.i: %.c $(headers)
+%.i: %.c
 	$(call cmd,cpp_i_c)
 
-%.s: %.c $(headers)
+%.s: %.c
 	$(call cmd,cc_s_c)
 
-%.o: %.S $(headers)
+%.o: %.S
 	$(call cmd,as_o_S)
 
-%.s: %.S $(headers)
+%.s: %.S
 	$(call cmd,cpp_s_S)
 
 include ../../../../Makefile.rules
 
+-include $(addsuffix .d,$(objs)) $(addsuffix .i.d,$(objs)) $(addsuffix .s.d,$(objs))
+
 CLEAN_FILES += $(notdir $(pal_static) $(pal_lib) $(pal_loader))
 
 .PHONY: clean
 clean:
-	rm -f $(addsuffix .o,$(objs)) $(host_files) $(CLEAN_FILES)
+	rm -f $(addsuffix .o,$(objs)) $(host_files) $(CLEAN_FILES) \
+	      $(addsuffix .d,$(objs)) $(addsuffix .i.d,$(objs)) \
+	      $(addsuffix .s.d,$(objs))
 
 .PHONY: test
 test:

+ 6 - 3
Pal/test/Makefile

@@ -17,7 +17,6 @@ target = $(executables) $(manifests)
 
 graphene_lib = .lib/graphene-lib.a
 pal_lib = ../../Runtime/libpal-$(PAL_HOST).so
-headers = $(wildcard ../include/pal/*.h)
 
 .PHONY: all
 all:	pal_loader $(call expand_target,$(target))
@@ -43,7 +42,7 @@ manifest: manifest.template
 ifeq ($(findstring x86_64,$(SYS))$(findstring linux,$(SYS)),x86_64linux)
 $(executables): %: %.c $(graphene_lib) $(pal_lib) ../src/user_start.o
 	@echo [ $@ ]
-	@$(CC) $(CFLAGS) $(if $(filter Pie,$@),-fPIC -pie,) $^ -o $@
+	@$(CC) -MD -MP $(CFLAGS) $(if $(filter Pie,$@),-fPIC -pie,) $^ -o $@
 
 .lib/host_endian.h: ../src/host/$(PAL_HOST)/host_endian.h
 	@mkdir -p .lib
@@ -56,6 +55,10 @@ else
 $(executables):
 endif
 
+-include $(addsuffix .d, $(executables)) $(addsuffix .i.d, $(executables)) $(addsuffix .s.d, $(executables))
+
 .PHONY: clean
 clean:
-	rm -rf pal_loader $(call expand_target,$(target)) .lib *.cached
+	rm -rf pal_loader $(call expand_target,$(target)) .lib *.cached \
+	       $(addsuffix .d, $(executables)) $(addsuffix .i.d, $(executables)) \
+	       $(addsuffix .s.d, $(executables))