Simplify configure script
This commit is contained in:
102
configure
vendored
102
configure
vendored
@@ -13,21 +13,21 @@ enable_lfs="no"
|
|||||||
enable_tests="no"
|
enable_tests="no"
|
||||||
use_clock_gettime="no"
|
use_clock_gettime="no"
|
||||||
|
|
||||||
if [ -z "$cc" ]; then cc=gcc; fi
|
if [ -z "$cc" ]; then cc="gcc"; fi
|
||||||
if [ -z "$ld" ]; then ld=gcc; fi
|
if [ -z "$ld" ]; then ld="gcc"; fi
|
||||||
if [ -z "$ar" ]; then ar=ar; fi
|
if [ -z "$ar" ]; then ar="ar"; fi
|
||||||
|
|
||||||
# Internal functions
|
# Internal functions
|
||||||
assign_option() {
|
assign_option() {
|
||||||
set -- ${1#--} $2
|
set -- "${1#--}" "$2"
|
||||||
set -- ${2:-${1%%=*}} ${1#*=}
|
set -- "${2:-${1%%=*}}" "${1#*=}"
|
||||||
eval "$1=$2"
|
eval "$1=$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
assign_toggle() {
|
assign_toggle() {
|
||||||
set -- ${1#--} $2 $3
|
set -- "${1#--}" "$2" "$3"
|
||||||
set -- ${2:-${1%%=*}} ${1#*=} $3 $1
|
set -- "${2:-${1%%=*}}" "${1#*=}" "$3" "$1"
|
||||||
if test $4 = $2; then set -- $1 $3; fi
|
if test "$4" = "$2"; then set -- "$1" "$3"; fi
|
||||||
eval "$1=$2"
|
eval "$1=$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,15 +159,15 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Platform independant sources
|
# Platform independant sources
|
||||||
for file in ${source_path}src/*.c; do
|
for file in "${source_path}src"/*.c; do
|
||||||
sources="$sources:$file"
|
sources="$sources:$file"
|
||||||
done
|
done
|
||||||
|
|
||||||
for file in ${source_path}src/Math/*.c; do
|
for file in "${source_path}src/Math"/*.c; do
|
||||||
sources="$sources:$file"
|
sources="$sources:$file"
|
||||||
done
|
done
|
||||||
|
|
||||||
for file in ${source_path}src/String/*.c; do
|
for file in "${source_path}src/String"/*.c; do
|
||||||
sources="$sources:$file"
|
sources="$sources:$file"
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -175,50 +175,52 @@ done
|
|||||||
if [ "$enable_tests" = "yes" ]; then
|
if [ "$enable_tests" = "yes" ]; then
|
||||||
tests=""
|
tests=""
|
||||||
mkdir test test/src 2> /dev/null
|
mkdir test test/src 2> /dev/null
|
||||||
for file in "${source_path}test/src/*.c"; do
|
for file in "${source_path}test/src"/*.c; do
|
||||||
if [ -n "$tests" ]; then tests="$tests:$file"
|
if [ -n "$tests" ]; then tests="$tests:$file"
|
||||||
else tests="$file"; fi
|
else tests="$file"; fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Makefile generation
|
||||||
|
{
|
||||||
# Generate variables
|
# Generate variables
|
||||||
echo "CC=$cc" > Makefile
|
echo "CC=$cc"
|
||||||
echo "AR=$ar" >> Makefile
|
echo "AR=$ar"
|
||||||
echo "CFLAGS=$cflags" >> Makefile
|
echo "CFLAGS=$cflags"
|
||||||
echo "LDFLAGS=$ldflags" >> Makefile
|
echo "LDFLAGS=$ldflags"
|
||||||
echo "STATICLIB=$staticlib" >> Makefile
|
echo "STATICLIB=$staticlib"
|
||||||
|
|
||||||
if [ "$enable_dynamic" = "yes" ]; then
|
if [ "$enable_dynamic" = "yes" ]; then
|
||||||
echo "DYNAMICLIB=$dynamiclib" >> Makefile
|
echo "DYNAMICLIB=$dynamiclib"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Set a list of objects
|
# Set a list of objects
|
||||||
printf "OBJS=" >> Makefile
|
printf "\nOBJS="
|
||||||
(
|
(
|
||||||
IFS=":"
|
IFS=":"
|
||||||
for source in $sources; do
|
for source in $sources; do
|
||||||
object=${source%%.c}.o
|
object=${source%%.c}.o
|
||||||
object=${object#${source_path}}
|
object=${object#${source_path}}
|
||||||
echo " \\" >> Makefile
|
echo " \\"
|
||||||
printf " %s" "$object" >> Makefile
|
printf " %s" "$object"
|
||||||
done
|
done
|
||||||
)
|
)
|
||||||
printf "\n\n" >> Makefile
|
printf "\n\n"
|
||||||
|
|
||||||
# Check if dynamic linking is enabled and add rules
|
# Check if dynamic linking is enabled and add rules
|
||||||
if [ "$enable_dynamic" = "yes" ]; then
|
if [ "$enable_dynamic" = "yes" ]; then
|
||||||
printf "all: static dynamic\n\n" >> Makefile
|
printf "all: static dynamic\n\n"
|
||||||
printf "dynamic: \$(DYNAMICLIB)\n\n" >> Makefile
|
printf "dynamic: \$(DYNAMICLIB)\n\n"
|
||||||
printf "\$(DYNAMICLIB): \$(OBJS)\n" >> Makefile
|
printf "\$(DYNAMICLIB): \$(OBJS)\n"
|
||||||
printf "\t\$(CC) \$(LDFLAGS) \$(OBJS) -o \$(DYNAMICLIB)\n\n" >> Makefile
|
printf "\t\$(CC) \$(LDFLAGS) \$(OBJS) -o \$(DYNAMICLIB)\n\n"
|
||||||
else
|
else
|
||||||
printf "all: static\n\n" >> Makefile
|
printf "all: static\n\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Add rules for static linking
|
# Add rules for static linking
|
||||||
printf "static: \$(STATICLIB)\n\n" >> Makefile
|
printf "static: \$(STATICLIB)\n\n"
|
||||||
printf "\$(STATICLIB): \$(OBJS)\n" >> Makefile
|
printf "\$(STATICLIB): \$(OBJS)\n"
|
||||||
printf "\t\$(AR) r \$(STATICLIB) \$(OBJS)\n\n" >> Makefile
|
printf "\t\$(AR) r \$(STATICLIB) \$(OBJS)\n\n"
|
||||||
|
|
||||||
# Generate rules for tests
|
# Generate rules for tests
|
||||||
if [ "$enable_tests" = "yes" ]; then
|
if [ "$enable_tests" = "yes" ]; then
|
||||||
@@ -227,22 +229,21 @@ if [ "$enable_tests" = "yes" ]; then
|
|||||||
for source in $tests; do
|
for source in $tests; do
|
||||||
object=${source%%.c}${exe}
|
object=${source%%.c}${exe}
|
||||||
object=${object#${source_path}}
|
object=${object#${source_path}}
|
||||||
printf "%s: %s \$(STATICLIB)\n" $object $source >> Makefile
|
printf "%s: %s \$(STATICLIB)\n" $object $source
|
||||||
printf "\t\$(CC) \$(CFLAGS) -I${source_path}unit/include %s %s \$(STATICLIB) -o %s\n\n" "$source" "${source_path}unit/src/Unit.c" "$object" >> Makefile
|
printf "\t\$(CC) \$(CFLAGS) -I${source_path}unit/include %s %s \$(STATICLIB) -o %s\n\n" "$source" "${source_path}unit/src/Unit.c" "$object"
|
||||||
done
|
done
|
||||||
)
|
)
|
||||||
|
printf "tests: "
|
||||||
printf "tests: " >> Makefile
|
|
||||||
(
|
(
|
||||||
IFS=":"
|
IFS=":"
|
||||||
for source in $tests; do
|
for source in $tests; do
|
||||||
object=${source%%.c}${exe}
|
object=${source%%.c}${exe}
|
||||||
object=${object#${source_path}}
|
object=${object#${source_path}}
|
||||||
echo " \\" >> Makefile
|
echo " \\"
|
||||||
printf " %s" "$object" >> Makefile
|
printf " %s" "$object"
|
||||||
done
|
done
|
||||||
)
|
)
|
||||||
printf "\n\n" >> Makefile
|
printf "\n\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Generate rules for main objects
|
# Generate rules for main objects
|
||||||
@@ -251,17 +252,17 @@ fi
|
|||||||
for source in $sources; do
|
for source in $sources; do
|
||||||
object=${source%%.c}.o
|
object=${source%%.c}.o
|
||||||
object=${object#${source_path}}
|
object=${object#${source_path}}
|
||||||
printf "$object: $source\n" >> Makefile
|
printf "$object: $source\n"
|
||||||
printf "\t\$(CC) -c \$(CFLAGS) \$< -o \$@\n\n" >> Makefile
|
printf "\t\$(CC) -c \$(CFLAGS) \$< -o \$@\n\n"
|
||||||
done
|
done
|
||||||
)
|
)
|
||||||
printf "\n\n" >> Makefile
|
printf "\n\n"
|
||||||
|
|
||||||
# Generate clean rules
|
# Generate clean rules
|
||||||
printf "clean:\n" >> Makefile
|
printf "clean:\n"
|
||||||
printf "\t-rm -f \$(OBJS) \$(STATICLIB)" >> Makefile
|
printf "\t-rm -f \$(OBJS) \$(STATICLIB)"
|
||||||
if [ "$enable_dynamic" = "yes" ]; then
|
if [ "$enable_dynamic" = "yes" ]; then
|
||||||
printf " \$(DYNAMICLIB)" >> Makefile
|
printf " \$(DYNAMICLIB)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$enable_tests" = "yes" ]; then
|
if [ "$enable_tests" = "yes" ]; then
|
||||||
@@ -270,14 +271,17 @@ if [ "$enable_tests" = "yes" ]; then
|
|||||||
for source in $tests; do
|
for source in $tests; do
|
||||||
object=${source%%.c}${exe}
|
object=${source%%.c}${exe}
|
||||||
object=${object#${source_path}}
|
object=${object#${source_path}}
|
||||||
printf " %s" "$object" >> Makefile
|
printf " %s" "$object"
|
||||||
done
|
done
|
||||||
)
|
)
|
||||||
fi
|
fi
|
||||||
printf "\n\n" >> Makefile
|
printf "\n\n"
|
||||||
|
} > Makefile
|
||||||
|
|
||||||
# Generate internal config.h
|
# Generate internal config.h
|
||||||
printf "#ifndef BH_SRC_CONFIG_H\n#define BH_SRC_CONFIG_H\n\n" > Config.h
|
{
|
||||||
if [ "$use_clock_gettime" ]; then printf "#define BH_USE_CLOCK_GETTIME\n" >> Config.h; fi
|
printf "#ifndef BH_SRC_CONFIG_H\n#define BH_SRC_CONFIG_H\n\n"
|
||||||
if [ "$enable_lfs" ]; then printf "#define BH_ENABLE_LFS\n" >> Config.h; fi
|
if [ "$use_clock_gettime" ]; then printf "#define BH_USE_CLOCK_GETTIME\n"; fi
|
||||||
printf "\n#endif /* BH_SRC_CONFIG_H */\n" >> Config.h
|
if [ "$enable_lfs" ]; then printf "#define BH_ENABLE_LFS\n"; fi
|
||||||
|
printf "\n#endif /* BH_SRC_CONFIG_H */\n"
|
||||||
|
} > Config.h
|
||||||
|
|||||||
Reference in New Issue
Block a user