Blame project/clbuild.sh

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