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