Makefile: export helpers, improve install target

This commit is contained in:
xinyangli 2024-12-11 12:41:55 +08:00
parent f0bac361e6
commit 8c6f9bb716
Signed by: xin
SSH key fingerprint: SHA256:UU5pRTl7NiLFJbWJZa+snLylZSXIz5rgHmwjzv8v4oE
2 changed files with 26 additions and 11 deletions

View file

@ -60,7 +60,6 @@ OBJCOPY ?= $(CROSS_COMPILE)objcopy
READELF ?= $(CROSS_COMPILE)readelf READELF ?= $(CROSS_COMPILE)readelf
CXXFLAGS += $(CFLAGS) -ffreestanding -fno-rtti -fno-exceptions CXXFLAGS += $(CFLAGS) -ffreestanding -fno-rtti -fno-exceptions
ASFLAGS += $(INCFLAGS)
LDFLAGS += -z noexecstack LDFLAGS += -z noexecstack
INTERFACE_LDFLAGS += -z noexecstack INTERFACE_LDFLAGS += -z noexecstack
@ -122,7 +121,7 @@ image: image-dep
archive: $(ARCHIVE) archive: $(ARCHIVE)
image-dep: $(OBJS) $(LIBS) image-dep: $(OBJS) $(LIBS)
@echo \# Creating image [$(ARCH)] @echo \# Creating image [$(ARCH)]
.PHONY: image image-dep archive run $(LIBS) install .PHONY: image image-dep archive run libs $(LIBS) install
### Install rules ### Install rules
@ -130,16 +129,28 @@ INTERFACE_INCPATH += $(sort $(KLIB_INTERFACE_INCPATH) $(AM_INTERFACE_INCPATH))
INTERFACE_CFLAGS += $(sort $(KLIB_INTERFACE_CFLAGS) $(AM_INTERFACE_CFLAGS)) INTERFACE_CFLAGS += $(sort $(KLIB_INTERFACE_CFLAGS) $(AM_INTERFACE_CFLAGS))
INTERFACE_LDFLAGS += $(sort $(KLIB_LDFLAGS) $(AM_LDFLAGS)) INTERFACE_LDFLAGS += $(sort $(KLIB_LDFLAGS) $(AM_LDFLAGS))
EXPORT_FLAGS_FILE := $(INSTALLDIR)/flags-$(ARCH).mk EXPORT_FLAGS_FILE := $(LIB_INSTALLDIR)/make/flags-$(ARCH).mk
$(EXPORT_FLAGS_FILE): EXPORT_FLAGS_TEMPLATE := $(file < $(AM_HOME)/scripts/templates/flags.tmpl)
@mkdir -p $(INSTALLDIR) HELPERS := $(wildcard find scripts/helpers/*.mk)
@echo "CFLAGS += " $(INTERFACE_CFLAGS) > $(EXPORT_FLAGS_FILE) EXPORT_HELPERS := $(HELPERS:scripts/helpers/%=$(LIB_INSTALLDIR)/make/%)
@echo "LDFLAGS += " $(INTERFACE_LDFLAGS) >> $(EXPORT_FLAGS_FILE)
install: $(EXPORT_FLAGS_FILE) $(LIBS) test:
@mkdir -p $(LIB_INSTALLDIR) $(INC_INSTALLDIR) @echo $(EXPORT_HELPERS)
@cp $(addsuffix -$(ARCH).a, $(addprefix $(LIB_BUILDDIR)/lib, $(LIBS))) $(LIB_INSTALLDIR) @echo $(LIB_INSTALLDIR)
@cp -r $(addsuffix /*, $(INTERFACE_INCPATH)) $(INC_INSTALLDIR)/
EXPORTS := $(EXPORT_FLAGS_FILE) $(EXPORT_HELPERS)
$(EXPORT_HELPERS): $(LIB_INSTALLDIR)/make/%: scripts/helpers/%
@install -Dm644 $< $(dir $@)
export INTERFACE_CFLAGS INTERFACE_INCPATH INTERFACE_LDFLAGS
$(EXPORT_FLAGS_FILE):
@install -Dm644 <(printf $(EXPORT_FLAGS_TEMPLATE)) $(EXPORT_FLAGS_FILE)
install: $(EXPORTS) $(LIBS)
@install -dm755 $(LIB_INSTALLDIR) $(INC_INSTALLDIR)
@install -Dm644 $(addsuffix -$(ARCH).a, $(addprefix $(LIB_BUILDDIR)/lib, $(LIBS))) $(LIB_INSTALLDIR)
@install -Dm644 $(shell find $(INTERFACE_INCPATH) -name '*.h') $(INC_INSTALLDIR)/
### Clean a single project (remove `build/`) ### Clean a single project (remove `build/`)
clean: clean:

View file

@ -0,0 +1,4 @@
"CFLAGS += %s \n\
LDFLAGS += %s" \
"$INTERFACE_CFLAGS" \
"$INTERFACE_LDFLAGS"