diff --git a/c/Makefile b/c/Makefile new file mode 100644 index 0000000..a7f3da0 --- /dev/null +++ b/c/Makefile @@ -0,0 +1,35 @@ +.POSIX: +.SUFFIXES: .o + +CC ?= gcc +OUT := hello + +SRC += main.c +OBJ := $(SRC:.c=.o) + +CFLAGS += @compile_flags.txt +CFLAGS += -ffunction-sections -fdata-sections + +LDFLAGS := -fwhole-program -flto +LDFLAGS += -Wl,--gc-sections -s + +RM ?= rm -f + +.DEFAULT_GOAL: all +.PHONY: all +all: $(OUT) + +$(OUT): $(OBJ) + $(CC) -o $@ $< + +.PHONY: clean +clean: + $(RM) $(OBJ) + +.PHONY: fclean +fclean: clean + $(RM) -r $(OUT) + +.PHONY: re +.NOTPARALLEL: re +re: fclean all diff --git a/c/compile_flags.txt b/c/compile_flags.txt new file mode 100644 index 0000000..19adf53 --- /dev/null +++ b/c/compile_flags.txt @@ -0,0 +1,18 @@ +-std=c99 +-pedantic +-pipe + +-Wall +-Wcast-qual +-Wconversion +-Werror=return-type +-Werror=vla-larger-than=0 +-Wextra +-Wmissing-prototypes +-Wshadow +-Wstrict-prototypes +-Wwrite-strings + +-O2 +-march=native +-mtune=native diff --git a/c/main.c b/c/main.c new file mode 100644 index 0000000..30a4d72 --- /dev/null +++ b/c/main.c @@ -0,0 +1,16 @@ +#include +#include + +#define lengthof(sstr) (sizeof (sstr) / sizeof *(sstr)) +#define sstr_len(sstr) (lengthof(sstr) - 1) +#define sstr_unpack(sstr) (sstr), (sstr_len(sstr)) + +static const char GREETING[] = "hello, world!\n"; + +int main(void) +{ + return ( + write(STDOUT_FILENO, sstr_unpack(GREETING)) + == sstr_len(GREETING) + ) ? EXIT_SUCCESS : EXIT_FAILURE; +}