Blame project/clbuild.sh

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