Last active
March 29, 2022 17:28
-
-
Save neverkas/f9f0773b6357a8fa53b4667976a6ac90 to your computer and use it in GitHub Desktop.
Redirect error message from gcc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| BIN=test | |
| LOG_FILE=log.txt | |
| SOURCE_FILE=test.c | |
| #################################################### | |
| GNU_MAKE_PRINT_RECIPE=true | |
| GCC_REDIRECT_LOGS=true | |
| GCC_PRINT_LOGS=false | |
| # con undefine tendra como valor una cadena vacia | |
| undefine LOGS_REDIRECT | |
| undefine AT | |
| # | |
| ifeq (false,$(GNU_MAKE_PRINT_RECIPE)) | |
| AT:=@ | |
| endif | |
| ifeq (true,$(GCC_REDIRECT_LOGS)) | |
| ifeq (false,$(GCC_PRINT_LOGS)) | |
| LOGS_REDIRECT=1>>log.txt 2>&1 | |
| else | |
| # la -a en `tee` actua como el operador >> para hacer append, caso contrario se borra el contenido anterior | |
| LOGS_REDIRECT=2>&1 | tee -a $(LOG_FILE) | |
| endif | |
| endif | |
| all: clean compile exec | |
| create-file: | |
| $(AT)echo "#include <stdio.h>\n int main(){ printf(\"hola\"); 1+1; return 0; }" >> $(SOURCE_FILE) | |
| compile: create-file | |
| $(AT)$(CC) $(SOURCE_FILE) -g -Wall -Wextra -o $(BIN) $(LOGS_REDIRECT) | |
| exec: | |
| $(AT)./$(BIN) | |
| clean: | |
| $(AT)rm -rf $(SOURCE_FILE) $(LOG_FILE) $(BIN) | |
| .PHONY: all create-file compile clean exec |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment