added makefile and basics
This commit is contained in:
1 parent
93f9c0f252
commit
ef7b09cbeb
4 files changed
+159
No files matched your search
@@ -0,0 +1,111 @@
|
|||||||
|
SHELL := /usr/bin/env bash
|
||||||
|
|
||||||
|
PREFIX :=
|
||||||
|
CC := $(PREFIX)gcc
|
||||||
|
COPY := $(PREFIX)objcopy
|
||||||
|
SIZE := $(PREFIX)size
|
||||||
|
GDB := $(PREFIX)gdb
|
||||||
|
|
||||||
|
SRC_DIR := ./src
|
||||||
|
INC_DIR := ./inc
|
||||||
|
OBJ_DIR := ./obj
|
||||||
|
BIN_DIR := ./bin
|
||||||
|
|
||||||
|
MK_DIR := $(OBJ_DIR) \
|
||||||
|
$(BIN_DIR)
|
||||||
|
|
||||||
|
NAME := scan
|
||||||
|
|
||||||
|
WG := -Wall \
|
||||||
|
-Wextra \
|
||||||
|
-Wpedantic \
|
||||||
|
-Werror
|
||||||
|
|
||||||
|
WCC := -Wconversion \
|
||||||
|
-Wsign-conversion \
|
||||||
|
-Wsign-compare \
|
||||||
|
-Wcast-align=strict \
|
||||||
|
-Wfloat-equal \
|
||||||
|
-Wlogical-op \
|
||||||
|
-Wshadow \
|
||||||
|
-Wpointer-arith
|
||||||
|
|
||||||
|
C_DEF :=
|
||||||
|
|
||||||
|
C_SRC := main.c \
|
||||||
|
log.c
|
||||||
|
|
||||||
|
C_FLAGS := -std=c11 \
|
||||||
|
$(WG) \
|
||||||
|
$(WCC) \
|
||||||
|
$(addprefix -I, $(INC_DIR)) \
|
||||||
|
$(addprefix -D, $(C_DEF))
|
||||||
|
|
||||||
|
LIB := m
|
||||||
|
|
||||||
|
LD_FLAGS := $(addprefix -l, $(LIB)) \
|
||||||
|
-Wl,--gc-sections
|
||||||
|
|
||||||
|
OBJ := $(addprefix $(OBJ_DIR)/, $(C_SRC:.c=.o))
|
||||||
|
BIN := $(BIN_DIR)/$(NAME)
|
||||||
|
|
||||||
|
# the flags file is required for `clangd` (lsp client)
|
||||||
|
FLAGS_FILE := ./compile_flags.txt
|
||||||
|
|
||||||
|
VPATH := $(SRC_DIR)
|
||||||
|
|
||||||
|
|
||||||
|
.PHONY: all build clean install rebuild run test
|
||||||
|
|
||||||
|
|
||||||
|
all: build
|
||||||
|
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(MK_DIR) $(FLAGS_FILE)
|
||||||
|
|
||||||
|
|
||||||
|
build: $(MK_DIR) $(FLAGS_FILE) $(BIN)
|
||||||
|
|
||||||
|
|
||||||
|
rebuild: clean build
|
||||||
|
|
||||||
|
|
||||||
|
install: $(BIN)
|
||||||
|
sudo cp $(BIN) /usr/bin/
|
||||||
|
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
sudo rm -f /usr/bin/$(notdir $(BIN))
|
||||||
|
|
||||||
|
|
||||||
|
run: $(BIN)
|
||||||
|
@./$(BIN)
|
||||||
|
|
||||||
|
|
||||||
|
$(MK_DIR):
|
||||||
|
@mkdir -p $@
|
||||||
|
|
||||||
|
|
||||||
|
$(BIN): $(MK_DIR) $(OBJ)
|
||||||
|
$(CC) \
|
||||||
|
$(C_FLAGS) \
|
||||||
|
$(LD_FLAGS) \
|
||||||
|
-o $@ \
|
||||||
|
$(OBJ)
|
||||||
|
$(SIZE) $(BIN)
|
||||||
|
|
||||||
|
|
||||||
|
$(OBJ_DIR)/%.o: %.c
|
||||||
|
$(CC) \
|
||||||
|
$(C_FLAGS) \
|
||||||
|
-c $< \
|
||||||
|
-o $@
|
||||||
|
|
||||||
|
|
||||||
|
$(FLAGS_FILE):
|
||||||
|
@echo "$(C_FLAGS) $(LD_FLAGS)" | sed 's/ /\n/g' > $@
|
||||||
|
|
||||||
|
|
||||||
|
test: $(BIN)
|
||||||
|
$@ .
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#ifndef __LOG_H
|
||||||
|
#define __LOG_H
|
||||||
|
|
||||||
|
int log_info( const char* format, ... );
|
||||||
|
int log_error( const char* format, ... );
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int log_info( const char* format, ... )
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
va_list args;
|
||||||
|
|
||||||
|
va_start( args, format );
|
||||||
|
result = fprintf( stdout, format, args );
|
||||||
|
va_end( args );
|
||||||
|
|
||||||
|
( void )fputc('\n', stdout);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int log_error( const char* format, ... )
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
va_list args;
|
||||||
|
|
||||||
|
va_start( args, format );
|
||||||
|
result = fprintf( stderr, format, args );
|
||||||
|
va_end( args );
|
||||||
|
|
||||||
|
( void )fputc('\n', stderr);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
int main( int argc, char** argv )
|
||||||
|
{
|
||||||
|
( void )argc;
|
||||||
|
( void )argv;
|
||||||
|
|
||||||
|
log_info( "kuckuck!" );
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user