137 lines
4.5 KiB
Makefile
Executable File
137 lines
4.5 KiB
Makefile
Executable File
#!/usr/bin/make -f
|
|
#******************************************************************************#
|
|
# Include variables and message subsystem #
|
|
#******************************************************************************#
|
|
include Makefile.vars Makefile.msg
|
|
|
|
#******************************************************************************#
|
|
# General targets #
|
|
#******************************************************************************#
|
|
# Build everything.
|
|
all: all-bin
|
|
|
|
# Mostly clean everything (remove everything but the end results).
|
|
mostlyclean: mostlyclean-bin
|
|
mclean: mostlyclean
|
|
|
|
# Clean everything.
|
|
clean: clean-bin clean-gint
|
|
fclean: clean
|
|
|
|
# Clean everything with configuration.
|
|
mrproper: clean
|
|
$(call rmsg,Removing configuration.)
|
|
$(call qcmd,$(RM) Makefile.cfg)
|
|
distclean: mrproper
|
|
|
|
# Remake everything (clean and build).
|
|
re: mostlyclean all
|
|
|
|
.PHONY: all mostlyclean mclean clean fclean distclean mrproper re
|
|
#******************************************************************************#
|
|
# Configuration (version) checking dependencies #
|
|
#******************************************************************************#
|
|
# Define the dependencies.
|
|
CHECKCFG := $(if $(shell test -f Makefile.cfg || echo y),check-config, \
|
|
$(if $(shell [ "$(VERSION)" = "$(CONFIG_VERSION)" ] || echo y), \
|
|
check-config-version))
|
|
|
|
# Define the rules.
|
|
check-config:
|
|
@printf "\033[1;31mNo configuration file found!\n"
|
|
@printf "You should configure before re-running this target.\033[0m\n"
|
|
@false
|
|
check-config-version:
|
|
@printf "\033[1;31mConfiguration version is incorrect!\n"
|
|
@printf "You should re-configure before re-running this target.\033[0m\n"
|
|
@false
|
|
|
|
.PHONY: check-config check-config-version
|
|
#******************************************************************************#
|
|
# Information getting from the Makefile variables #
|
|
#******************************************************************************#
|
|
# Get the project name.
|
|
getname:
|
|
@echo $(NAME)
|
|
|
|
# Get the project version.
|
|
getversion:
|
|
@echo $(VERSION)
|
|
|
|
# Get the project maintainer.
|
|
getmaintainer:
|
|
@echo "$(MAINTAINER_NAME) <$(MAINTAINER_MAIL)>"
|
|
|
|
.PHONY: getname getmaintainer getversion
|
|
#******************************************************************************#
|
|
# gint-related targets #
|
|
#******************************************************************************#
|
|
# Main gint target
|
|
all-gint: $(GLIBDIR)/libgint.a
|
|
|
|
# Configure gint libraries.
|
|
$(GLIBDIR)/gcc.cfg:
|
|
-$(call qcmd,test -e .git && ! test -e $(GLIBDIR)/.git && \
|
|
git submodule update --init $(GLIBDIR))
|
|
$(call bmsg,Configuring gint.)
|
|
$(call qcmd,cd $(GLIBDIR) && ./configure --no-syscalls)
|
|
|
|
# Make gint libraries.
|
|
$(GLIBDIR)/libgint.a $(GLIBDIR)/libc.a: $(GLIBDIR)/gcc.cfg
|
|
$(call bmsg,Making gint.)
|
|
$(call bcmd,make,gint,$(MAKE) $(GLIBDIR) libgint.a libc.a | sed 's/^/ /')
|
|
|
|
# Clean gint libraries.
|
|
clean-gint:
|
|
$(call rmsg,Cleaning gint.)
|
|
-$(call qcmd,test -e $(GLIBDIR)/Makefile && \
|
|
$(MAKE) $(GLIBDIR) distclean | sed 's/^/ /')
|
|
|
|
.PHONY: all-gint clean-gint
|
|
#******************************************************************************#
|
|
# Binary-related targets #
|
|
#******************************************************************************#
|
|
# Make the binary.
|
|
all-bin: $(CHECKCFG) $(NAME).bin
|
|
|
|
# Make the object directory.
|
|
$(OBJDIR):
|
|
$(call bcmd,mkdir,$@,$(MD) $@)
|
|
|
|
# Make an object file out of an assembly source file.
|
|
$(OBJDIR)/%.o: $(SRCDIR)/%.s | $(OBJDIR)
|
|
$(call bcmd,as,$@,$(AS) -c -o $@ $<)
|
|
|
|
# Make an object file out of a C source file.
|
|
$(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR)
|
|
$(call bcmd,cc,$@,$(CC) -c -o $@ $< $(CFLAGS))
|
|
|
|
# Make the ELF file.
|
|
$(NAME).elf: all-gint $(SRC:%=$(OBJDIR)/%.o)
|
|
$(call bcmd,ld,$@,$(LD) -o $@ $(SRC:%=$(OBJDIR)/%.o) $(LDFLAGS))
|
|
|
|
# Make the binary file.
|
|
$(NAME).bin: $(NAME).elf
|
|
$(call bcmd,objcopy,$@,$(OBJCOPY) -R .comment -R .bss -O binary $< $@)
|
|
|
|
# Removing the objects directory.
|
|
mostlyclean-bin:
|
|
$(call rmsg,Removing the objects directory.)
|
|
$(call qcmd,$(RM) -r $(OBJDIR))
|
|
$(call rmsg,Removing the ELF file.)
|
|
$(call qcmd,$(RM) *.elf)
|
|
|
|
mclean-bin: mostlyclean-bin
|
|
|
|
# Remove everything that was built.
|
|
clean-bin: mostlyclean-bin
|
|
$(call rmsg,Removing the final binary.)
|
|
$(call qcmd,$(RM) *.bin)
|
|
fclean-bin: clean-bin
|
|
|
|
# Remake the binary.
|
|
re-bin: clean-bin all-bin
|
|
|
|
.PHONY: all-bin mostlyclean-bin mclean-bin clean-bin fclean-bin re-bin
|
|
# End of file.
|