|
|
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=
|
|
|
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 |
;;
|
|
|
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 |
|
|
|
81d5d5 |
for d in $dirs; do
|
|
|
81d5d5 |
printf 'if not exist %-20smkdir %s\n' "$d" "$d"
|
|
|
81d5d5 |
done
|
|
|
81d5d5 |
|
|
|
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 version.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' \
|
|
|
81d5d5 |
-e 's@'"$mb_sysroot "'@ @' \
|
|
|
81d5d5 |
-e 's,$, -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 |
|
|
|
81d5d5 |
# eight: link shared library
|
|
|
81d5d5 |
make LDFLAGS_IMPLIB= LDFLAGS_SONAME= shared-lib \
|
|
|
81d5d5 |
| grep -v 'make\[1\]:' \
|
|
|
81d5d5 |
| sed \
|
|
|
81d5d5 |
-e 's@'"$mb_cc"' -shared @link /dll /nologo @' \
|
|
|
81d5d5 |
-e 's@-o @/out:@g' \
|
|
|
81d5d5 |
-e 's@ -L@ /libpath:@g' \
|
|
|
81d5d5 |
-e 's, -l\([^ ]\+\), %sysroot%/lib/lib\1.lib,g' \
|
|
|
81d5d5 |
-e 's@-nostdlib @/nodefaultlib @g' \
|
|
|
81d5d5 |
-e 's@-Wl,--subsystem=@/subsystem:@g' \
|
|
|
81d5d5 |
-e 's@-Wl,--entry -Wl,'"''"'@/entry:@g' \
|
|
|
81d5d5 |
-e 's@-Wl,--entry -Wl,@/entry:@g' \
|
|
|
81d5d5 |
-e 's@-Wl,--no-undefined@@g' \
|
|
|
81d5d5 |
-e 's@-Wl,--exclude-all-symbols@@g' \
|
|
|
81d5d5 |
-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
|