stargazing/notwa-util/ofc

12 lines
620 B
Bash
Executable file

#!/usr/bin/env sh
: "${CC:=cc}" "${LDFLAGS=-Wl,--gc-sections}" "${CFLAGS=-Os -g -Wall -Wextra \
-Wwrite-strings -Wformat=2 -Wno-unused -ffunction-sections -fdata-sections}" \
&& compile() { "$CC" $CFLAGS $CPPFLAGS -c -o "$n$obj" "$c" ;} \
&& link() { "$CC" $LDFLAGS -o "$n$dbg" "$n$obj" $LIBS ;} \
&& finish() { "${STRIP:-strip}" "$n$dbg" -o "$n$exe" ;} \
&& obj=.o dbg=.dbg exe= \
&& if [ cosmocc = "${CC##*/}" ]; then dbg=.com.dbg exe=.com \
&& finish() { "${OBJCOPY:-objcopy}" -S -O binary "$n$dbg" "$n$exe" ;} \
;fi \
&& for c in "$@"; do n="${c%.*}" && compile && link && finish || exit; done \
;