aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Romanko <me@blankhex.com>2025-07-30 18:25:33 +0300
committerMikhail Romanko <me@blankhex.com>2025-07-30 18:25:33 +0300
commitda5a4cb4837175523414782935ebd05828bcb3fa (patch)
treec94b80222e5a65618a1de9cb0489e0f197b56299
parent514a17e04d5bc9fe1fd1ac33ff53e309c8d74c48 (diff)
downloadbhlib-da5a4cb4837175523414782935ebd05828bcb3fa.tar.gz
Simplify configure script
-rwxr-xr-xconfigure208
1 files changed, 106 insertions, 102 deletions
diff --git a/configure b/configure
index 63753f9..03b20d7 100755
--- a/configure
+++ b/configure
@@ -13,21 +13,21 @@ enable_lfs="no"
enable_tests="no"
use_clock_gettime="no"
-if [ -z "$cc" ]; then cc=gcc; fi
-if [ -z "$ld" ]; then ld=gcc; fi
-if [ -z "$ar" ]; then ar=ar; fi
+if [ -z "$cc" ]; then cc="gcc"; fi
+if [ -z "$ld" ]; then ld="gcc"; fi
+if [ -z "$ar" ]; then ar="ar"; fi
# Internal functions
assign_option() {
- set -- ${1#--} $2
- set -- ${2:-${1%%=*}} ${1#*=}
+ set -- "${1#--}" "$2"
+ set -- "${2:-${1%%=*}}" "${1#*=}"
eval "$1=$2"
}
assign_toggle() {
- set -- ${1#--} $2 $3
- set -- ${2:-${1%%=*}} ${1#*=} $3 $1
- if test $4 = $2; then set -- $1 $3; fi
+ set -- "${1#--}" "$2" "$3"
+ set -- "${2:-${1%%=*}}" "${1#*=}" "$3" "$1"
+ if test "$4" = "$2"; then set -- "$1" "$3"; fi
eval "$1=$2"
}
@@ -159,15 +159,15 @@ else
fi
# Platform independant sources
-for file in ${source_path}src/*.c; do
+for file in "${source_path}src"/*.c; do
sources="$sources:$file"
done
-for file in ${source_path}src/Math/*.c; do
+for file in "${source_path}src/Math"/*.c; do
sources="$sources:$file"
done
-for file in ${source_path}src/String/*.c; do
+for file in "${source_path}src/String"/*.c; do
sources="$sources:$file"
done
@@ -175,109 +175,113 @@ done
if [ "$enable_tests" = "yes" ]; then
tests=""
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"
else tests="$file"; fi
done
fi
-# Generate variables
-echo "CC=$cc" > Makefile
-echo "AR=$ar" >> Makefile
-echo "CFLAGS=$cflags" >> Makefile
-echo "LDFLAGS=$ldflags" >> Makefile
-echo "STATICLIB=$staticlib" >> Makefile
+# Makefile generation
+{
+ # Generate variables
+ echo "CC=$cc"
+ echo "AR=$ar"
+ echo "CFLAGS=$cflags"
+ echo "LDFLAGS=$ldflags"
+ echo "STATICLIB=$staticlib"
-if [ "$enable_dynamic" = "yes" ]; then
- echo "DYNAMICLIB=$dynamiclib" >> Makefile
-fi
+ if [ "$enable_dynamic" = "yes" ]; then
+ echo "DYNAMICLIB=$dynamiclib"
+ fi
-# Set a list of objects
-printf "OBJS=" >> Makefile
-(
- IFS=":"
- for source in $sources; do
- object=${source%%.c}.o
- object=${object#${source_path}}
- echo " \\" >> Makefile
- printf " %s" "$object" >> Makefile
- done
-)
-printf "\n\n" >> Makefile
+ # Set a list of objects
+ printf "\nOBJS="
+ (
+ IFS=":"
+ for source in $sources; do
+ object=${source%%.c}.o
+ object=${object#${source_path}}
+ echo " \\"
+ printf " %s" "$object"
+ done
+ )
+ printf "\n\n"
-# Check if dynamic linking is enabled and add rules
-if [ "$enable_dynamic" = "yes" ]; then
- printf "all: static dynamic\n\n" >> Makefile
- printf "dynamic: \$(DYNAMICLIB)\n\n" >> Makefile
- printf "\$(DYNAMICLIB): \$(OBJS)\n" >> Makefile
- printf "\t\$(CC) \$(LDFLAGS) \$(OBJS) -o \$(DYNAMICLIB)\n\n" >> Makefile
-else
- printf "all: static\n\n" >> Makefile
-fi
+ # Check if dynamic linking is enabled and add rules
+ if [ "$enable_dynamic" = "yes" ]; then
+ printf "all: static dynamic\n\n"
+ printf "dynamic: \$(DYNAMICLIB)\n\n"
+ printf "\$(DYNAMICLIB): \$(OBJS)\n"
+ printf "\t\$(CC) \$(LDFLAGS) \$(OBJS) -o \$(DYNAMICLIB)\n\n"
+ else
+ printf "all: static\n\n"
+ fi
-# Add rules for static linking
-printf "static: \$(STATICLIB)\n\n" >> Makefile
-printf "\$(STATICLIB): \$(OBJS)\n" >> Makefile
-printf "\t\$(AR) r \$(STATICLIB) \$(OBJS)\n\n" >> Makefile
-
-# Generate rules for tests
-if [ "$enable_tests" = "yes" ]; then
-(
- IFS=":"
- for source in $tests; do
- object=${source%%.c}${exe}
- object=${object#${source_path}}
- printf "%s: %s \$(STATICLIB)\n" $object $source >> 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" >> Makefile
- done
-)
+ # Add rules for static linking
+ printf "static: \$(STATICLIB)\n\n"
+ printf "\$(STATICLIB): \$(OBJS)\n"
+ printf "\t\$(AR) r \$(STATICLIB) \$(OBJS)\n\n"
-printf "tests: " >> Makefile
-(
- IFS=":"
- for source in $tests; do
- object=${source%%.c}${exe}
- object=${object#${source_path}}
- echo " \\" >> Makefile
- printf " %s" "$object" >> Makefile
- done
-)
-printf "\n\n" >> Makefile
-fi
+ # Generate rules for tests
+ if [ "$enable_tests" = "yes" ]; then
+ (
+ IFS=":"
+ for source in $tests; do
+ object=${source%%.c}${exe}
+ object=${object#${source_path}}
+ 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"
+ done
+ )
+ printf "tests: "
+ (
+ IFS=":"
+ for source in $tests; do
+ object=${source%%.c}${exe}
+ object=${object#${source_path}}
+ echo " \\"
+ printf " %s" "$object"
+ done
+ )
+ printf "\n\n"
+ fi
-# Generate rules for main objects
-(
- IFS=":"
- for source in $sources; do
- object=${source%%.c}.o
- object=${object#${source_path}}
- printf "$object: $source\n" >> Makefile
- printf "\t\$(CC) -c \$(CFLAGS) \$< -o \$@\n\n" >> Makefile
- done
-)
-printf "\n\n" >> Makefile
+ # Generate rules for main objects
+ (
+ IFS=":"
+ for source in $sources; do
+ object=${source%%.c}.o
+ object=${object#${source_path}}
+ printf "$object: $source\n"
+ printf "\t\$(CC) -c \$(CFLAGS) \$< -o \$@\n\n"
+ done
+ )
+ printf "\n\n"
-# Generate clean rules
-printf "clean:\n" >> Makefile
-printf "\t-rm -f \$(OBJS) \$(STATICLIB)" >> Makefile
-if [ "$enable_dynamic" = "yes" ]; then
- printf " \$(DYNAMICLIB)" >> Makefile
-fi
+ # Generate clean rules
+ printf "clean:\n"
+ printf "\t-rm -f \$(OBJS) \$(STATICLIB)"
+ if [ "$enable_dynamic" = "yes" ]; then
+ printf " \$(DYNAMICLIB)"
+ fi
-if [ "$enable_tests" = "yes" ]; then
-(
- IFS=":"
- for source in $tests; do
- object=${source%%.c}${exe}
- object=${object#${source_path}}
- printf " %s" "$object" >> Makefile
- done
-)
-fi
-printf "\n\n" >> Makefile
+ if [ "$enable_tests" = "yes" ]; then
+ (
+ IFS=":"
+ for source in $tests; do
+ object=${source%%.c}${exe}
+ object=${object#${source_path}}
+ printf " %s" "$object"
+ done
+ )
+ fi
+ printf "\n\n"
+} > Makefile
# 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
-if [ "$enable_lfs" ]; then printf "#define BH_ENABLE_LFS\n" >> Config.h; fi
-printf "\n#endif /* BH_SRC_CONFIG_H */\n" >> Config.h
+{
+ printf "#ifndef BH_SRC_CONFIG_H\n#define BH_SRC_CONFIG_H\n\n"
+ if [ "$use_clock_gettime" ]; then printf "#define BH_USE_CLOCK_GETTIME\n"; fi
+ if [ "$enable_lfs" ]; then printf "#define BH_ENABLE_LFS\n"; fi
+ printf "\n#endif /* BH_SRC_CONFIG_H */\n"
+} > Config.h