diff options
Diffstat (limited to 'configure')
| -rwxr-xr-x | configure | 208 |
1 files changed, 106 insertions, 102 deletions
@@ -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 |
