remove old build system

This commit is contained in:
Lephenixnoir 2021-05-09 14:57:00 +02:00
parent ad9f92873b
commit a543bfcb7c
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495
2 changed files with 0 additions and 521 deletions

237
configure vendored
View file

@ -1,237 +0,0 @@
#! /bin/bash
# Fx C standard library configuration script
# output file
confile='fxlibc.cfg'
# Build options
toolchain=sh-elf
prefix=
cflags=
# wanted Makefile
makefile='Makefile.default'
# configuration
debug=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
#---
help()
{
cat << EOF
Configuration script for the fx calculator standard C library.
Usage: $0 [OPTION]...
You should build out-of-tree by creating a build directory and configuring from
there.
Debug the fxlibc
--debug Enable valgrind flags (-g3)
--unit-test Check C-functoon validity with Criterion
Build options:
--toolchain=TRIPLET Build with a different toolchain
[sh-elf-gcc] (or [gcc] when the '--unit_test' flag is set)
--cflags=FLAGS Additional compiler flags at end of command
--prefix=PREFIX Install prefix (PREFIX/lib and PREFIX/include are used)
ABI support:
--support=<target>,<target>, ...
Support all <target> ABI if supported by the library.
target-list:
* vhex
Enable the Vhex kernel support
* fx9860g, fxcg50
Enable the support of the Casio' ABI
fx9860 covers all fx-9860G II-like monochromes models that support
addins or can be flashed with an OS that does. This includes SH3 and
SH4 machines.
fxcg50 covers just the fx-CG 50; there is some unofficial compatibility
with fx-CG 10/20. All of these are SH4-only.
The 'ABI support' is used to allow some part of the code, in particular the
'unistd' part, I/O management and additionals feature. (like process, fs, ...).
Format:
--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
need to create manually an archive that can be used like a shared library.
To do this we need to do several steps:
1) build the sources with the PIE mode as if it were a executable without entry point.
2) manually extract symbols defined as 'global' from the generated ELF.
3) we create "stubs": functions that will have the same name than the wanted shared
libraries and will call internal VHEX loader primitives with the libraries
name, function address and size, etc....Then the loader will load the shared
function and override the "user function (stub)" to force it to jump into
the "real" function (trampoline).
4) all generated stubs will be compiled and linked through a static lib that SHOULD
be used in the user program which uses the "dynamic library"
EOF
exit 0
}
#---
# Check early help options
#---
if [[ $# -eq 1 ]] && [[ "$1" = "-h" ]] || [[ "$1" = "--help" ]]; then
help
fi
#---
# 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
exit 1
fi
#---
# Parsing arguments
#---
for arg; do case "$arg" in
# Help options
--help | -h)
help;;
# debug options
--debug)
debug=true;;
--unit-test)
makefile='Malefile.unitest';;
# build options
--toolchain=*)
toolchain=${arg#*=};;
--prefix=*)
prefix=${arg#*=};;
--cflags=*)
cflags=${arg#*=};;
# ABI support
--support=*)
IFS=',' read -ra target_abi <<< "${arg#*=}"
for abi in "${target_abi[@]}"; do case "$abi" in
all)
support_vhex_kernel=true
support_casio_abi_fx9860=true
support_casio_abi_fxcg50=true;;
vhex)
support_vhex_kernel=true;;
fx9860g)
support_casio_abi_fx9860=true;;
fxcg50)
support_casio_abi_fxcg50=true;;
*)
echo "error: unreconized target '$abi', giving up." >&2
exit 1
esac; done;;
# format options
--static)
format_static=true;;
--dynamic)
format_dynamic=true;;
# error part
*)
echo "error: unreconized argument '$arg', giving up." >&2
exit 1
esac; done
#---
# Check error
#---
# If no prefix is specified, install to the GCC's build folder
if [[ -z "$prefix" ]]
then
# ask the toolchain where is his installation path
echo "No prefix specified, let's ask the compiler:"
echo " Call: \"$toolchain-gcc --print-search-dirs | grep install | sed 's/install: //'\""
if ! inst=$("$toolchain"-gcc --print-search-dirs | grep install | sed 's/install: //'); then
echo " Call: returned $?, giving up." >&2
exit 1
fi
echo " Got '$inst'".
# check if the directory exist
if [[ ! -d $inst ]]; then
echo "Directory does not exist (or is not a directory), giving up." >&2
exit 1
fi
prefix=$inst
fi
# TODO
# TODO: check if the wanted lib exist (check lib verion too)!
# TODO
#---
# Dump appropriate Makefile
# @note:
# * We have 3 makefile: normal, dynlib, unit_test
#---
dst='Makefile'
src="../make/$makefile"
if ! [ -e $src ] ; then
echo "error: target makefile ($src) does not exist !" >&2
exit 1
fi
[ -e "$dst" ] && [ "$(readlink $dst)" = "$src" ] && rm $dst
ln -s $src $dst
#---
# Generate the configuration file
#---
generate_config()
{
# build information
echo "CONFIG.TOOLCHAIN := $toolchain"
[ "$prefix" ] && echo "CONFIG.PREFIX := $prefix"
# extra flags
echo 'CONFIG.CFLAGS := '
[ "$cflags" ] && echo "CONFIG.CFLAGS += $cflags"
[ $debug = true ] && echo 'CONFIG.CFLAGS += -g3'
# ABI support
echo 'CONFIG.TARGET := fxlibc'
[ $support_vhex_kernel = true ] && echo 'CONFIG.TARGET += fxlibc-vhex'
[ $support_casio_abi_fx9860 = true ] && echo 'CONFIG.TARGET += fxlibc-fx9860g'
[ $support_casio_abi_fxcg50 = true ] && echo 'CONFIG.TARGET += fxlibc-fxcg50'
# formats
echo 'CONFIG.FORMAT := '
[ $format_static = true ] && echo 'CONFIG.FORMAT += static'
[ $format_dynamic = true ] && echo 'CONFIG.FORMAT += dynamic'
}
generate_config > $confile
echo "Configuration saved in $confile, ready to make!"
exit 0

View file

@ -1,284 +0,0 @@
#! /usr/bin/make -f
#---
#
# fxlibc project Makefile
#
# This makefile is grandly inspired by the one used for the Gint (unikernel)
# project, many thanks to Lephenixnoir !
#
# Build architecture:
# build/
# |-- objects/
# | |-- string_strlen.o
# | |-- string_strcmp.o
# | ...
# | `-- signal_kill.o
# |-- debug/
# | |-- fxlibc.map (ELF link map informations)
# | ...
# | `-- otherinfo.txt
# |-- Makefile
# |-- fxlibc.cfg
# `-- 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:
# * handle dynamic versioning
# * handle verbose option
#---
MAJOR := 0
MINOR := 3
PATCH := 6
EXTRAVERSION :=
#---
# Build configuration
#---
# Require configuration file (if you want to clean up and lost the file, you
# can either reconfigure or just delete the build directory)
CONFIG := fxlibc.cfg
ifeq "$(wildcard $(CONFIG))" ""
$(error "config file $(CONFIG) does not exist (reconfigure or wipe directory)")
endif
include $(CONFIG)
# Compiler flags, assembler flags, dependency generation, archiving
header := ../include
cflags := -ffreestanding -nostdlib -Wall -Wextra -std=c11 -Os \
-fstrict-volatile-bitfields -I$(header) $(CONFIG.CFLAGS)
# color definition
red := \033[1;31m
green := \033[1;32m
blue := \033[1;34m
white := \033[1;37m
nocolor := \033[1;0m
# Define all directories used to stored information
dir_object := object
dir_output := output
# Output configurations
name := fxlibc
# Automated variables
directory := $(shell find ../src -not -path "*/\.*" -type d)
src := $(foreach path,$(directory), \
$(wildcard $(path)/*.c) \
$(wildcard $(path)/*.S) \
$(wildcard $(path)/*.s))
# Toolchain
gcc = $(CONFIG.TOOLCHAIN)-gcc
as = $(CONFIG.TOOLCHAIN)-as
ld = $(CONFIG.TOOLCHAIN)-ld
ar = $(CONFIG.TOOLCHAIN)-ar
objcopy = $(CONFIG.TOOLCHAIN)-objcopy
#---
# Build rules
#---
# (Make selects the first rule when you type "make" and I don't want the first
# rule to be "%/" so here's a placeholder)
first: all
# Create directory helper
# @note: Just use "$*" and "$@" to refer to the directory being created.
%/:
@ printf "Create $(blue)$*$(nocolor) directory\n"
@ mkdir -p $@
.PRECIOUS: %/
#---
# Generate building rules
#---
# This function will generate compilation rule for each source.
# @params:
# *1 - source file path
# *2 - build directory path (output)
# *3 - build flags
# TODO:
# * handle verbose option
define generate-compilation-rule
$(patsubst .._src_%,$2%.o,$(subst /,_,$(basename $1))): $1 | $2/
@ printf "$(green)>$(nocolor) $(white)$$@$(nocolor)\n"
@ $(gcc) $3 -o $$@ -c $$< -lgcc
endef
# Function that will generate all rules for building each library.
# @params:
# * 1 - library name
# * 2 - format (dynamic/static)
# * 3 - source file list
define generate-target
# Generate all variables (library name based on the wanted formats, output
# directory, ...) used by each rule that will be generated.
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-version)
lib-cflags := -fPIC $(cflags)
else
lib-name := $$(lib-output-dir)lib$1.a
lib-cflags := $(cflags)
endif
# add custom project-specific flags based on the target ABI
ifeq ($1,fxlibc-vhex)
lib-cflags += -D __SUPPORT_VHEX_KERNEL
else ifeq ($1,fxlibc-fx9860g)
lib-cflags += -D __SUPPORT_CASIO_ABI_FX9860G
else ifeq ($1,fxlibc-fxcf50)
lib-cflags += -D __SUPPORT_CASIO_ABI_FXCG50
endif
# Generate all file compilation rules
$$(foreach source,$3,$$(eval \
$$(call generate-compilation-rule,$$(source),$$(lib-build-dir),$$(lib-cflags)) \
))
# Register the library building rule name
# @note:
# This rule list (lib-generation-rules) is used by the main compiling rule like
# a dependency. And it's this dependency that will involve all generated rules
# for building each library.
lib-generation-rules += $$(lib-name)
# Generate the linking library rule
# TODO
# * Find better way to generate binary files name dependency
$$(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
$(ar) crs $$@ $$^
endif
endef
# Create all "target" variable used to determine which format and which
# libraries will be generated.
# @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)
# Create a variable that will be updated during the dynamic makecode generation
# (generated by the "foreach"). This variable will list all rules generated for
# building each library and used like a dependency by the main rule.
lib-generation-rules :=
# Generate the library version (used only by the dynamic library format).
lib-version := $(MAJOR).$(MINOR).$(PATCH)$(EXTRAVERSION)
# Generate all building rules
$(foreach format,$(target-formats), \
$(foreach lib,$(target-libs),$(eval \
$(call generate-target,$(lib),$(format),$(src)) \
)) \
)
#---
# Build rules
#---
all: $(lib-generation-rules)
version:
@ echo "$(lib-version)"
#---
# Generate installation rules
#---
# Common rules generated for the installation of each libraries.
# Basically, it will generate <libname>-install and <libname>-uninstall rules
# @note:
# *1 - library pathname
define generate-install-rule
# Generate the installation rule
$(basename $(notdir $1))-install:
install -d $(CONFIG.PREFIX)
install $1 -m 644 $(CONFIG.PREFIX)
# Generate the uninstallation rule
$(basename $(notdir $1))-uninstall:
rm -f $(CONFIG.PREFIX)$(notdir $1)
# Register generated rules into their appropriate list
lib-installation-rules += $(basename $(notdir $1))-install
lib-uninstallation-rules += $(basename $(notdir $1))-uninstall
endef
# Internal variable used to store all rules about installation/uninstallation
lib-installation-rules :=
lib-uninstallation-rules :=
# Generate all installation/unstallation rules
$(foreach libs,$(lib-generation-rules),$(eval \
$(call generate-install-rule,$(libs)) \
))
# Generate the path where include directory will be installed.
lib-install-header-dir := $(CONFIG.PREFIX)include/
ifeq ($(wildcard $(lib-install-header-dir)fxlibc/.*),)
lib-install-header-dir := $(lib-install-header-dir)fxlibc
endif
#---
# Installation rules
#---
install: $(lib-generation-rules) $(lib-installation-rules)
cp -r ../include/fxlibc/ $(lib-install-header-dir)
uninstall: $(lib-uninstallation-rules)
rm -rf $(CONFIG.PREFIX)include/fxlibc
#---
# (internal ) debug rule
#---
#DEBUG=$(call generate-target,fxlibc-vhex,static,$(dir_objects),$(src))
DEBUG=$(call generate-install-rule,/output/static/fxlibc.a)
export DEBUG
debug:
@ echo "$$DEBUG"
@ echo "target-lib: $(target-libs)"
@ echo "generated lib: $(lib-generation-rules)"
@ echo "target format: $(target-formats)"
@ echo "install-rules: $(lib-installation-rules)"
@ echo "uninstall-rules: $(lib-uninstallation-rules)"
#---
# cleaning rules
#---
clean:
rm -rf $(dir_object)
fclean: clean
rm -rf $(dir_output)
re: fclean all
.PHONY: clean fclean re