|
|
e16d3b |
#!/bin/sh
|
|
|
e16d3b |
# a poor man's universal driver (but stay tuned...)
|
|
|
e16d3b |
|
|
|
e16d3b |
error_msg()
|
|
|
e16d3b |
{
|
|
|
e16d3b |
echo $@ >&2
|
|
|
e16d3b |
}
|
|
|
e16d3b |
|
|
|
e16d3b |
mb_cc=
|
|
|
e16d3b |
mb_ar=
|
|
|
e16d3b |
mb_source_dir=
|
|
|
e16d3b |
mb_project_dir=
|
|
|
e16d3b |
mb_sysroot=
|
|
|
e16d3b |
version_header=
|
|
|
e16d3b |
version_macro=
|
|
|
e16d3b |
link_target=
|
|
|
e16d3b |
|
|
|
e16d3b |
# one: args
|
|
|
e16d3b |
for arg ; do
|
|
|
e16d3b |
case "$arg" in
|
|
|
e16d3b |
--help) usage
|
|
|
e16d3b |
;;
|
|
|
e16d3b |
--cc=*)
|
|
|
e16d3b |
mb_cc=${arg#*=}
|
|
|
e16d3b |
;;
|
|
|
e16d3b |
--ar=*)
|
|
|
e16d3b |
mb_ar=${arg#*=}
|
|
|
e16d3b |
;;
|
|
|
e16d3b |
--source-dir=*)
|
|
|
e16d3b |
mb_source_dir=${arg#*=}
|
|
|
e16d3b |
;;
|
|
|
e16d3b |
--project-dir=*)
|
|
|
e16d3b |
mb_project_dir=${arg#*=}
|
|
|
e16d3b |
;;
|
|
|
e16d3b |
--sysroot=*)
|
|
|
e16d3b |
mb_sysroot=${arg#*=}
|
|
|
e16d3b |
;;
|
|
|
e16d3b |
--version-header=*)
|
|
|
e16d3b |
version_header=${arg#*=}
|
|
|
e16d3b |
;;
|
|
|
e16d3b |
--version-macro=*)
|
|
|
e16d3b |
version_macro='-D'${arg#*=}'=\\\"unknown\\\"'
|
|
|
e16d3b |
;;
|
|
|
e16d3b |
--link-target=*)
|
|
|
e16d3b |
link_target=${arg#*=}
|
|
|
e16d3b |
;;
|
|
|
e16d3b |
*)
|
|
|
e16d3b |
error_msg ${arg#}: "unsupported config argument."
|
|
|
e16d3b |
exit 2
|
|
|
e16d3b |
;;
|
|
|
e16d3b |
esac
|
|
|
e16d3b |
done
|
|
|
e16d3b |
|
|
|
e16d3b |
if [ -z "$mb_cc" ] || [ -z "$mb_ar" ] \
|
|
|
e16d3b |
|| [ -z "$mb_source_dir" ] \
|
|
|
e16d3b |
|| [ -z "$mb_project_dir" ]; then
|
|
|
e16d3b |
usage
|
|
|
e16d3b |
fi
|
|
|
e16d3b |
|
|
|
e16d3b |
# two: clean
|
|
|
e16d3b |
make -s clean || exit 1
|
|
|
e16d3b |
|
|
|
e16d3b |
# three: init
|
|
|
e16d3b |
echo '@echo on'
|
|
|
e16d3b |
echo '@dir . > nul'
|
|
|
e16d3b |
echo
|
|
|
e16d3b |
echo
|
|
|
e16d3b |
echo 'REM override variables either here or from the shell'
|
|
|
e16d3b |
echo 'set source_dir=%source_dir%'
|
|
|
e16d3b |
echo 'set sysroot=%sysroot%'
|
|
|
e16d3b |
echo
|
|
|
e16d3b |
echo
|
|
|
e16d3b |
|
|
|
e16d3b |
# four: build tree
|
|
|
e16d3b |
cmd_abort_on_error='@if %errorlevel% neq 0 exit /b %errorlevel%'
|
|
|
e16d3b |
sysroot_include_arg='-I%sysroot%/include'
|
|
|
e16d3b |
|
|
|
e16d3b |
dirs=`make dirs.tag tree.tag \
|
|
|
e16d3b |
| grep -v 'make\[1\]:' \
|
|
|
e16d3b |
| grep -v 'touch dirs.tag' \
|
|
|
e16d3b |
| grep -v 'touch tree.tag' \
|
|
|
e16d3b |
| sed \
|
|
|
e16d3b |
-e 's/mkdir -p//g' \
|
|
|
e16d3b |
-e 's@/@\\\\@g'`
|
|
|
e16d3b |
|
|
|
e16d3b |
for d in build $dirs; do
|
|
|
e16d3b |
printf 'if not exist %-20smkdir %s\n' "$d" "$d"
|
|
|
e16d3b |
done
|
|
|
e16d3b |
|
|
|
e16d3b |
# version.tag
|
|
|
e16d3b |
make version.tag > /dev/null
|
|
|
e16d3b |
|
|
|
e16d3b |
echo
|
|
|
e16d3b |
echo "type nul > build/$version_header"
|
|
|
e16d3b |
echo
|
|
|
e16d3b |
echo "$cmd_abort_on_error"
|
|
|
e16d3b |
echo
|
|
|
e16d3b |
|
|
|
e16d3b |
echo
|
|
|
e16d3b |
echo "$cmd_abort_on_error"
|
|
|
e16d3b |
echo
|
|
|
e16d3b |
|
|
|
e16d3b |
# five: compile assembly sources
|
|
|
e16d3b |
make shared-objs-asm static-objs-asm \
|
|
|
e16d3b |
| grep -v 'make\[1\]:' \
|
|
|
e16d3b |
| grep -v "$mb_project_dir/sysinfo/host" \
|
|
|
e16d3b |
| grep -v 'touch dirs.tag' \
|
|
|
e16d3b |
| grep -v 'touch host.tag' \
|
|
|
e16d3b |
| grep -v 'touch app.tag' \
|
|
|
e16d3b |
| sed \
|
|
|
e16d3b |
-e 's@'"$mb_cc -c "'@ml64 /nologo @' \
|
|
|
e16d3b |
-e 's@ '"$mb_source_dir"'@ /c %source_dir%@' \
|
|
|
e16d3b |
-e 's@-o @/Fo @g' \
|
|
|
e16d3b |
-e 's@\.s@\.asm@g' \
|
|
|
e16d3b |
-e 's,$,\n\n'"$cmd_abort_on_error"'\n,g'
|
|
|
e16d3b |
|
|
|
e16d3b |
# six: compile C sources
|
|
|
e16d3b |
make shared-objs static-objs app-objs \
|
|
|
e16d3b |
| grep -v 'make\[1\]:' \
|
|
|
e16d3b |
| grep -v "$mb_project_dir/sysinfo/host" \
|
|
|
e16d3b |
| grep -v 'touch dirs.tag' \
|
|
|
e16d3b |
| grep -v 'touch host.tag' \
|
|
|
e16d3b |
| grep -v 'touch version.tag' \
|
|
|
e16d3b |
| grep -v 'touch app.tag' \
|
|
|
e16d3b |
| sed \
|
|
|
e16d3b |
-e 's@'"$mb_cc -c "'@cl /nologo -c @' \
|
|
|
e16d3b |
-e 's@ '"$mb_source_dir"'@ %source_dir%@' \
|
|
|
e16d3b |
-e 's@-I'"$mb_source_dir"'@-I%source_dir%@g' \
|
|
|
e16d3b |
-e 's@-ffreestanding@/X /GS-@g' \
|
|
|
e16d3b |
-e 's@-o @/Fo:@g' \
|
|
|
e16d3b |
-e 's@-std=c99 @@g' \
|
|
|
e16d3b |
-e 's@-fPIC@@g' \
|
|
|
e16d3b |
-e 's@-fpic@@g' \
|
|
|
e16d3b |
-e 's@-g @/Zi @g' \
|
|
|
e16d3b |
-e 's@-g0 @/Zi @g' \
|
|
|
e16d3b |
-e 's@-g1 @/Zi @g' \
|
|
|
e16d3b |
-e 's@-g2 @/Zi @g' \
|
|
|
e16d3b |
-e 's@-g3 @/Zi @g' \
|
|
|
e16d3b |
-e 's@-O @/O2 @g' \
|
|
|
e16d3b |
-e 's@-Os @/O1 @g' \
|
|
|
e16d3b |
-e 's@-O0 @/Od @g' \
|
|
|
e16d3b |
-e 's@-O1 @/O2 @g' \
|
|
|
e16d3b |
-e 's@-O2 @/O2 @g' \
|
|
|
e16d3b |
-e 's@-O3 @/O2 @g' \
|
|
|
e16d3b |
-e 's@-Wall @/Wall @g' \
|
|
|
e16d3b |
-e 's@-Werror @/WX @g' \
|
|
|
e16d3b |
-e 's@-Wextra @@g' \
|
|
|
e16d3b |
-e 's@-Wundef @/Wall @g' \
|
|
|
e16d3b |
-e 's@-Wno-missing-field-initializers @ @g' \
|
|
|
e16d3b |
-e 's@-Wno-unused-parameter @/wd4100 @g' \
|
|
|
e16d3b |
-e 's@-mno-stack-arg-probe @/Gs65536 @g' \
|
|
|
e16d3b |
-e 's@'"$mb_sysroot "'@ @' \
|
|
|
e16d3b |
-e 's,$, '"$version_macro"' -I%sysroot%/include\n\n'"$cmd_abort_on_error"'\n,g'
|
|
|
e16d3b |
|
|
|
e16d3b |
echo
|
|
|
e16d3b |
echo '@echo.'
|
|
|
e16d3b |
echo '@echo clbuild: successfully built: shared-objs static-objs app-objs.'
|
|
|
e16d3b |
echo '@echo.'
|
|
|
e16d3b |
echo
|
|
|
e16d3b |
|
|
|
e16d3b |
# seven: create static archive
|
|
|
e16d3b |
make static \
|
|
|
e16d3b |
| grep -v 'make\[1\]:' \
|
|
|
e16d3b |
| grep -v "rm -f " \
|
|
|
e16d3b |
| sed \
|
|
|
e16d3b |
-e 's@'"$mb_ar"' rcs @lib /out:@' \
|
|
|
e16d3b |
-e 's,$, /nologo\n,g'
|
|
|
e16d3b |
|
|
|
e16d3b |
echo
|
|
|
e16d3b |
echo "$cmd_abort_on_error"
|
|
|
e16d3b |
echo
|
|
|
e16d3b |
|
|
|
e16d3b |
echo
|
|
|
e16d3b |
echo '@echo.'
|
|
|
e16d3b |
echo '@echo clbuild: successfully created: static archive.'
|
|
|
e16d3b |
echo '@echo.'
|
|
|
e16d3b |
echo
|
|
|
e16d3b |
|
|
|
e16d3b |
# eight: link
|
|
|
e16d3b |
make LDFLAGS_IMPLIB= LDFLAGS_SONAME= $link_target \
|
|
|
e16d3b |
| grep -v 'make\[1\]:' \
|
|
|
e16d3b |
| grep -v 'rm -f app\.tag' \
|
|
|
e16d3b |
| sed \
|
|
|
e16d3b |
-e 's@'"$mb_cc"' -shared @link /dll /nologo @' \
|
|
|
e16d3b |
-e 's@'"$mb_cc"' -static @link /nologo @' \
|
|
|
e16d3b |
-e 's@'"$mb_cc"' @link /nologo @' \
|
|
|
e16d3b |
-e 's@-o @/out:@g' \
|
|
|
e16d3b |
-e 's@ -L@ /libpath:@g' \
|
|
|
e16d3b |
-e 's,-static -l\([^ ]\+\), %sysroot%/lib/lib\1.a,g' \
|
|
|
e16d3b |
-e 's, -l\([^ ]\+\), %sysroot%/lib/lib\1.lib,g' \
|
|
|
e16d3b |
-e 's@-nostdlib @/nodefaultlib @g' \
|
|
|
e16d3b |
-e 's@-Wl,--subsystem=@/subsystem:@g' \
|
|
|
e16d3b |
-e 's@-Wl,--entry -Wl,'"''"'@/entry:@g' \
|
|
|
e16d3b |
-e 's@-Wl,--entry -Wl,@/entry:@g' \
|
|
|
e16d3b |
-e 's@-Wl,--no-undefined@@g' \
|
|
|
e16d3b |
-e 's@-Wl,--exclude-all-symbols@@g' \
|
|
|
e16d3b |
-e 's@'"$mb_sysroot "'@ @' \
|
|
|
e16d3b |
|
|
|
e16d3b |
echo
|
|
|
e16d3b |
echo "$cmd_abort_on_error"
|
|
|
e16d3b |
echo
|
|
|
e16d3b |
|
|
|
e16d3b |
echo
|
|
|
e16d3b |
echo '@echo.'
|
|
|
e16d3b |
echo '@echo clbuild: successfully linked: shared library.'
|
|
|
e16d3b |
echo '@echo.'
|
|
|
e16d3b |
echo
|
|
|
e16d3b |
|
|
|
e16d3b |
echo
|
|
|
e16d3b |
echo '@echo.'
|
|
|
e16d3b |
echo '@echo yay.'
|
|
|
e16d3b |
echo '@echo.'
|
|
|
e16d3b |
echo
|
|
|
e16d3b |
|
|
|
e16d3b |
# all done
|
|
|
e16d3b |
exit 0
|