Update configure and makefile

This commit is contained in:
Yatis 2020-10-11 10:15:34 +02:00
parent 9c59763ad7
commit ac36fce54d
2 changed files with 87 additions and 156 deletions

74
configure vendored
View File

@ -17,12 +17,17 @@ cflags=
makefile='Makefile.default'
# configuration
declare -A config
config[__DEBUG]=false
config[__ENABLE_VALGRIND]=false
config[__SUPPORT_VHEX_KERNEL]=false
config[__SUPPORT_CASIO_FX9860]=false
config[__SUPPORT_CASIO_FXCG50]=false
debug=false
valgrind=false
# ABI support
support_vhex_kernel=false
support_casio_abi_fx9860=false
support_casio_abi_fxcg50=false
# format
format_static=false
format_dynamic=false
#---
# Help screen
@ -63,7 +68,8 @@ The 'ABI support' is used to allow some part of the code, in particular the 'uni
part, I/O management and additionals feature. (like process, fs, ...).
Format:
--dyn-lib Generate dynamic librairies (Vhex kernel dependant)
--static Generate static libraries (default)
--dynamic Generate dynamic libraries (Vhex kernel dependant)
Little note for the generation of dynamic libraries. The superH toolchain currently
used (GCC) does not support the '--shared' flags when the archive is build. So we
@ -84,12 +90,12 @@ EOF
}
#
#---
# Check mandatory build location
# @note:
# * You should build out-of-tree by creating a build directory and configuring
# from there.
#
#---
if [ -f 'make/Makefile.default' ]; then
echo 'error: you should configure from a build directory, like this:' >&2
echo ' mkdir build && cd build && ../configure [options..]' >&2
@ -97,16 +103,16 @@ if [ -f 'make/Makefile.default' ]; then
fi
#
#---
# Parsing arguments
#
#---
for arg; do case "$arg" in
--help | -h)
help;;
# debug options
--debug)
config[__DEBUG]=true;;
debug=true;;
--unit-test)
makefile='Malefile.unitest';;
@ -120,15 +126,17 @@ for arg; do case "$arg" in
# ABI support
--support-vhex)
config[__SUPPORT_VHEX_KERNEL]=true;;
support_vhex_kernel=true;;
--support-casio-abi-fx9860)
config[__SUPPORT_CASIO_ABI_FX9860]=true;;
support_casio_abi_fx9860=true;;
--support-casio-abi-fxcg50)
config[__SUPPORT_CASIO_ABI_FXCG50]=true;;
support_casio_abi_fxcg50=true;;
# format options
--dyn-lib)
makefile='Makefile.dynlib';;
--static)
format_static=true;;
--dynamic)
format_dynamic=true;;
# error part
*)
@ -140,14 +148,6 @@ esac; done
#---
# Check error
#---
# Check ABI support error
if [ ${config[__SUPPORT_CASIO_ABI_FX9860]} = true ] && [ ${config[__SUPPORT_CASIO_ABI_FXCG50]} = true ] ||
[ ${config[__SUPPORT_VHEX_KERNEL]} = true ] && [ ${config[__SUPPORT_CASIO_ABI_FXCG50]} = true ] ||
[ ${config[__SUPPORT_VHEX_KERNEL]} = true ] && [ ${config[__SUPPORT_CASIO_ABI_FX9860]} = true ]; then
echo "error: too many ABI target" >&2
exit 1
fi
# If no prefix is specified, install to the GCC's build folder
if [[ -z "$prefix" ]]
then
@ -169,9 +169,9 @@ then
fi
#
# TODO
# TODO: check if the wanted lib exist (check lib verion too)!
#
# TODO
#---
# Dump appropriate Makefile
@ -193,16 +193,24 @@ ln -s $src $dst
#---
generate_config()
{
echo "CONFIG.CFLAGS := "
echo "CONFIG.TARGET := "
echo 'CONFIG.CFLAGS := '
echo 'CONFIG.TARGET := '
echo 'CONFIG.FORMAT := '
echo "CONFIG.TOOLCHAIN := $toolchain"
[ "$prefix" ] && echo "CONFIG.PREFIX := $prefix"
[ "$cflags" ] && echo "CONFIG.CFLAGS += $cflags"
#[ ${config[__DEBUG]} = true ] && echo "CONFIG.CFLAGS += -g3"
[ ${config[__SUPPORT_VHEX_KERNEL]} = true ] && echo "CONFIG.TARGET += fxlibc-vhex"
[ ${config[__SUPPORT_CASIO_ABI_FX9860]} = true ] && echo "CONFIG.TARGET += fxlibc-fx9860"
[ ${config[__SUPPORT_CASIO_ABI_FXCG50]} = true ] && echo "CONFIG.TARGET += fxlibc-fxcg50"
# debug / unit tests
[ $debug = true ] && echo 'CONFIG.CFLAGS += -g3'
# ABI support
[ $support_vhex_kernel = true ] && echo 'CONFIG.TARGET += fxlibc-vhex'
[ $support_casio_abi_fx9860 = true ] && echo 'CONFIG.TARGET += fxlibc-fx9860'
[ $support_casio_abi_fxcg50 = true ] && echo 'CONFIG.TARGET += fxlibc-fxcg50'
# formats
[ $format_static = true ] && echo 'CONFIG.FORMAT += static'
[ $format_dynamic = true ] && echo 'CONFIG.FORMAT += dynamic'
}
generate_config > $confile

View File

@ -5,7 +5,7 @@
#
# This makefile is grandly inspired by the Gint unikernel
# projet, many thanks to Lephenixnoir !
#
#
# Build architecture:
# build/
# |-- objects/
@ -19,15 +19,24 @@
# | `-- otherinfo.txt
# |-- Makefile
# |-- fxlibc.cfg
# `-- bin/
# |-- fxlibc_stubs.a (workaround for the shared librairie, see documentation note)
# |-- fxlibc.so (shared librairy)
# `-- fxlibc.a (static librairy)
# `-- ouptut/
# |-- static/
# | |--- libfxlibc.a
# | |--- libfxlibc-casio-abi-fx9860.a
# | `--- libfxlibc-casio-abi-fxcg50.a
# `--- dynamic/
# |--- libfxlibc.so
# |--- libfxlibc-casio-abi-fx9860.so
# `--- libfxlibc-casio-abi-fxcg50.so
#
# TODO:
# * generate all libraries for all ABI by default ?
# * handle versionning
#---
MAJOR := 0
MINOR := 1
PATCH := 1
EXTRAVERSION := -alpha
#---
# Build configuration
@ -52,7 +61,7 @@ blue := \033[1;34m
white := \033[1;37m
nocolor := \033[1;0m
# This is a workaround to force a newline when the "eval" keyword is involved
# This is a workaround to force a newline when the "eval" keyword is involved
define n
# Force newline character
@ -61,11 +70,9 @@ endef
# Define all directory used to stored informations
dir_object := object
dir_output := output
dir_bin := bin
# Output configurations
name := fxlibc
target := $(dir_bin)/$(name).a
# automated variable
directory := $(shell find ../src -not -path "*/\.*" -type d)
@ -77,7 +84,6 @@ src := $(foreach path,$(directory), \
#---
# Toolchain
#---
@ -90,14 +96,6 @@ objcopy = $(CONFIG.TOOLCHAIN)-objcopy
#---
# Version management
#---
# TODO
#---
# Build rules
#---
@ -114,6 +112,7 @@ first: all
#---
# Automated rules
#---
@ -125,10 +124,9 @@ first: all
# * handle custom cflags (format, abi management)
# * handle verbose option
define compile-src
$(patsubst .._src_%,$2/%.o,$(subst /,_,$(basename $1))): $1 | $2/
@ printf "compiling $(white)$$@$(nocolor)..."
$(patsubst .._src_%,$2%.o,$(subst /,_,$(basename $1))): $1 | $2/
@ printf "$(green)>$(nocolor) $(white)$$@$(nocolor)\n"
@ $(gcc) $(cflags) -o $$@ -c $$< -lgcc
@ printf "$(green)[ok]$(nocolor)\n"
endef
# common part used by all library geneation
@ -141,35 +139,44 @@ define generate-target
lib-output-dir := $(dir_output)/$2/
lib-build-dir := $(dir_object)/$2/$1/
ifeq ($2,dynamic)
lib-name := $$(lib-output-dir)/lib$1.so
lib-cflags := -pic $(cflags)
lib-name := $$(lib-output-dir)lib$1.so.$$(lib-version)
lib-cflags := -fPIC $(cflags)
else
lib-name := $$(lib-output-dir)/lib$1.a
lib-name := $$(lib-output-dir)lib$1.a
lib-cflags := $(cflags)
endif
# indicate the new lib that will be ouputed
generated-libs += $$(lib-name)
# add custom flags based on the target ABI
ifeq ($1,fxlibc-vhex)
lib-cflags += -D __SUPPORT_VHEX_KERNEL
else ifeq ($1,fxlibc-casio-abi-fx9860)
lib-cflags += -D __SUPPORT_CASIO_ABI_FX9860G
else ifeq ($1,fxlibc-casio-abi-fxcf50)
lib-cflags += -D __SUPPORT_CASIO_ABI_FXCG50
endif
# generate all file object name
$$(foreach source,$3,$$(eval \
$$(call compile-src,$$(source),$$(lib-build-dir)) \
))
# link the library
# @note: based on the wanted format
ifeq ($2,shared)
$$(lib-name): $$(patsubst .._src_%,$$(lib-build-dir)/%.o,$$(subst /,_,$$(basename $3))) | $$(lib-output-dir)
$(gcc) -shared -o $$@ $$^ -nostdlib -lgcc
# @note: we need to generate the library verion information manually
# TODO: find a better way to generate the version symbols
$$(lib-name): $$(patsubst .._src_%,$$(lib-build-dir)%.o,$$(subst /,_,$$(basename $3))) | $$(lib-output-dir)
ifeq ($2,dynamic)
$(gcc) -shared -Wl,-soname=$$@ -o $$@ $$^ -nostdlib -lgcc
else
$$(lib-name): $$(patsubst .._src_%,$$(lib-build-dir)/%.o,$$(subst /,_,$$(basename $3))) | $$(lib-output-dir)
$(ar) crs $$@ $$^
endif
endef
# create all "target" variable used to determine which format
# and which libraries will be generated.
# @note:
# @note:
# * we force default variable if nothing is set
target-formats := $(if $(CONFIG.FORMAT),$(CONFIG.FORMAT),static)
target-libs := $(if $(CONFIG.TARGET),$(CONFIG.TARGET),fxlibc)
@ -178,6 +185,9 @@ target-libs := $(if $(CONFIG.TARGET),$(CONFIG.TARGET),fxlibc)
# the dynamic make code generation (generated by the "foreach")
generated-libs :=
# generate the library version
lib-version := $(MAJOR).$(MINOR).$(PATCH)$(EXTRAVERSION)
# Generate all targets
$(foreach format,$(target-formats), \
$(foreach lib,$(target-libs),$(eval \
@ -187,11 +197,15 @@ $(foreach format,$(target-formats), \
#---
# Build rule
#---
all: $(generated-libs)
version:
@ echo "$(lib-version)"
DEBUG=$(call generate-target,fxlibc,static,$(dir_objects),$(src))
export DEBUG
debug:
@ -205,99 +219,8 @@ debug:
# clean rules
#---
clean:
rm -rf $(dir_objects)
rm -rf $(dir_object)
fclean: clean
rm -rf $(dir_bin)
rm -rf $(dir_output)
re: fclean clean
.PHONY: clean fclean re
#---
# Build rules
#---
#all: $(target)
#
## linker part
#$(target): $(obj) | $(dir_bin)
# $(ar) crs $@ $^
#
## installation part
#install: $(target)
# install -d $(CONFIG.PREFIX)
# install $(target) -m 644 $(CONFIG.PREFIX)
# cp -r $(header) $(CONFIG.PREFIX)/include/fxlibc
#uninstall:
# rm -f $(CONFIG.PREFIX)/$(target)
# rm -rf $(CONFIG.PREFIX)/include/fxlibc
#
## Directory management
#$(dir_bin) $(dir_objects):
# @ printf "Create $(blue)$@$(nocolor) directory\n"
# @ mkdir -p $@
#
#.PHONY: all install uninstall
#
#
#
##define rule-src
##$(patsubst .._src_%,$(dir_objects)/%.o,$(subst /,_,$(basename $1))): $1 | $(dir_objects)
## @ printf "compiling $(white)$$<$(nocolor)..."
## @ $(gcc) $(cflags) -o $$@ -c $$< -lgcc
## @ printf "$(green)[ok]$(nocolor)\n"
##endef
##
##$(foreach source,$(src),$(eval \
## $(call rule-src,$(source))) \
##)
#
#
##---
## Debugging rules
##---
#help:
# @ echo 'make [options]...'
# @ echo ''
# @ echo 'Options:'
# @ echo ' * install install the library and headers to the PREFIX'
# @ echo ' * uninstall uninstall the library and headers of the PREFIX'
# @ echo ' * disasm use objdump to display the content of the archive'
# @ echo ' * debug display source files name and objects name'
# @ echo ' * elf_sec display ELF section of the archive'
#__debug:
# @ echo 'src: $(src)'
# @ echo ''
# @ echo 'obj: $(obj)'
# @ echo ''
# @ echo 'directory: $(dir_bin) $(dir_output) $(dir_objects)'
#
#disasm:
# @ $(objdump) -D $(target) | less
#
#elf_sec:
# @ $(objdump) -h $(target) | less
#
#.PHONY: help __debug disasm elf_sec
#
#
##---
## clean rules
##---
#clean:
# rm -rf $(dir_objects)
#
#fclean: clean
# rm -rf $(dir_bin)
#
#re: fclean clean
#
#.PHONY: clean fclean re