summaryrefslogtreecommitdiffhomepage
path: root/project/clbuild.sh
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-12-13 21:09:51 -0500
committermidipix <writeonce@midipix.org>2016-12-13 21:09:51 -0500
commit81d45694311b2f44e5a0524465c37ff8421a1f34 (patch)
tree2f748ddd68a1a4a3c7ec06ce767958d9fd5294fa /project/clbuild.sh
parent6d59028454b4823e7f1a2eab12119ddd507d49f0 (diff)
downloaddalist-81d45694311b2f44e5a0524465c37ff8421a1f34.tar.bz2
dalist-81d45694311b2f44e5a0524465c37ff8421a1f34.tar.xz
added clbuild-bat: a poor man's transitional clbuild command translator.
Diffstat (limited to 'project/clbuild.sh')
-rwxr-xr-xproject/clbuild.sh174
1 files changed, 174 insertions, 0 deletions
diff --git a/project/clbuild.sh b/project/clbuild.sh
new file mode 100755
index 0000000..d11c98a
--- /dev/null
+++ b/project/clbuild.sh
@@ -0,0 +1,174 @@
+#!/bin/sh
+# a poor man's universal driver (but stay tuned...)
+
+error_msg()
+{
+ echo $@ >&2
+}
+
+mb_cc=
+mb_ar=
+mb_source_dir=
+mb_project_dir=
+mb_sysroot=
+
+# one: args
+for arg ; do
+ case "$arg" in
+ --help) usage
+ ;;
+ --cc=*)
+ mb_cc=${arg#*=}
+ ;;
+ --ar=*)
+ mb_ar=${arg#*=}
+ ;;
+ --source-dir=*)
+ mb_source_dir=${arg#*=}
+ ;;
+ --project-dir=*)
+ mb_project_dir=${arg#*=}
+ ;;
+ --sysroot=*)
+ mb_sysroot=${arg#*=}
+ ;;
+ *)
+ error_msg ${arg#}: "unsupported config argument."
+ exit 2
+ ;;
+ esac
+done
+
+if [ -z "$mb_cc" ] || [ -z "$mb_ar" ] \
+ || [ -z "$mb_source_dir" ] \
+ || [ -z "$mb_project_dir" ]; then
+ usage
+fi
+
+# two: clean
+make -s clean || exit 1
+
+# three: init
+echo '@echo on'
+echo '@dir . > nul'
+echo
+echo
+echo 'REM override variables either here or from the shell'
+echo 'set source_dir=%source_dir%'
+echo 'set sysroot=%sysroot%'
+echo
+echo
+
+# four: build tree
+cmd_abort_on_error='@if %errorlevel% neq 0 exit /b %errorlevel%'
+sysroot_include_arg='-I%sysroot%/include'
+
+dirs=`make dirs.tag tree.tag \
+ | grep -v 'make\[1\]:' \
+ | grep -v 'touch dirs.tag' \
+ | grep -v 'touch tree.tag' \
+ | sed \
+ -e 's/mkdir -p//g' \
+ -e 's@/@\\\\@g'`
+
+for d in $dirs; do
+ printf 'if not exist %-20smkdir %s\n' "$d" "$d"
+done
+
+echo
+echo "$cmd_abort_on_error"
+echo
+
+# five: build objects
+make shared-objs static-objs app-objs \
+ | grep -v 'make\[1\]:' \
+ | grep -v "$mb_project_dir/sysinfo/host" \
+ | grep -v 'touch dirs.tag' \
+ | grep -v 'touch host.tag' \
+ | grep -v 'touch version.tag' \
+ | grep -v 'touch app.tag' \
+ | sed \
+ -e 's@'"$mb_cc -c "'@cl /nologo -c @' \
+ -e 's@ '"$mb_source_dir"'@ %source_dir%@' \
+ -e 's@-I'"$mb_source_dir"'@-I%source_dir%@g' \
+ -e 's@-ffreestanding@/X /GS-@g' \
+ -e 's@-o @/Fo:@g' \
+ -e 's@-std=c99 @@g' \
+ -e 's@-fPIC@@g' \
+ -e 's@-fpic@@g' \
+ -e 's@-g @/Zi @g' \
+ -e 's@-g0 @/Zi @g' \
+ -e 's@-g1 @/Zi @g' \
+ -e 's@-g2 @/Zi @g' \
+ -e 's@-g3 @/Zi @g' \
+ -e 's@-O @/O2 @g' \
+ -e 's@-Os @/O1 @g' \
+ -e 's@-O0 @/Od @g' \
+ -e 's@-O1 @/O2 @g' \
+ -e 's@-O2 @/O2 @g' \
+ -e 's@-O3 @/O2 @g' \
+ -e 's@-Wall @/Wall @g' \
+ -e 's@-Werror @/WX @g' \
+ -e 's@-Wextra @@g' \
+ -e 's@-Wundef @/Wall @g' \
+ -e 's@'"$mb_sysroot "'@ @' \
+ -e 's,$, -I%sysroot%/include\n\n'"$cmd_abort_on_error"'\n,g'
+
+echo
+echo '@echo.'
+echo '@echo clbuild: successfully built: shared-objs static-objs app-objs.'
+echo '@echo.'
+echo
+
+# six: create static archive
+make static \
+ | grep -v 'make\[1\]:' \
+ | grep -v "rm -f " \
+ | sed \
+ -e 's@'"$mb_ar"' rcs @lib /out:@' \
+ -e 's,$, /nologo\n,g'
+
+echo
+echo "$cmd_abort_on_error"
+echo
+
+echo
+echo '@echo.'
+echo '@echo clbuild: successfully created: static archive.'
+echo '@echo.'
+echo
+
+# seven: link shared library
+make LDFLAGS_IMPLIB= LDFLAGS_SONAME= shared-lib \
+ | grep -v 'make\[1\]:' \
+ | sed \
+ -e 's@'"$mb_cc"' -shared @link /dll /nologo @' \
+ -e 's@-o @/out:@g' \
+ -e 's@ -L@ /libpath:@g' \
+ -e 's/^ -l\(.\+\)$/\1.lib/' \
+ -e 's@-nostdlib @/nodefaultlib @g' \
+ -e 's@-Wl,--subsystem=@/subsystem:@g' \
+ -e 's@-Wl,--entry -Wl,'"''"'@/entry:@g' \
+ -e 's@-Wl,--entry -Wl,@/entry:@g' \
+ -e 's@-Wl,--no-undefined@@g' \
+ -e 's@-Wl,--exclude-all-symbols@@g' \
+ -e 's@'"$mb_sysroot "'@ @' \
+
+echo
+echo "$cmd_abort_on_error"
+echo
+
+echo
+echo '@echo.'
+echo '@echo clbuild: successfully linked: shared library.'
+echo '@echo.'
+echo
+
+echo
+echo '@echo.'
+echo '@echo yay.'
+echo '@echo.'
+echo
+
+# all done
+exit 0