feat(c): add hello source
This commit is contained in:
parent
af8d3f5deb
commit
aff83a7bf1
35
c/Makefile
Normal file
35
c/Makefile
Normal file
|
@ -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
|
18
c/compile_flags.txt
Normal file
18
c/compile_flags.txt
Normal file
|
@ -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
|
16
c/main.c
Normal file
16
c/main.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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;
|
||||
}
|
Loading…
Reference in a new issue