Blame project/clbuild.sh

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