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