sync: 2026-10-01 14:45
This commit is contained in:
1 parent
aa6b343b93
commit
bb0683715c
2 files changed
+117
-2
No files matched your search
+1
-1
Submodule DEV1.1/TP updated: 70a3078428...dde9993ca1.
@@ -0,0 +1,116 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
import getpass
|
||||||
|
import os, subprocess
|
||||||
|
|
||||||
|
|
||||||
|
class Colors:
|
||||||
|
RED = "\033[0;31m"
|
||||||
|
GREEN = "\033[0;32m"
|
||||||
|
YELLOW = "\033[1;33m"
|
||||||
|
ORANGE = "\033[38;5;208m"
|
||||||
|
END = "\033[0m"
|
||||||
|
|
||||||
|
|
||||||
|
def ask(question: str, default=None, required=False, confidential=False):
|
||||||
|
"""Ask a question to the user and check if the result is good"""
|
||||||
|
while True:
|
||||||
|
if confidential:
|
||||||
|
n = getpass.getpass(question, echo_char="*") or default
|
||||||
|
if n == getpass.getpass("confirm : ", echo_char="*") or default:
|
||||||
|
if (not required) or (required and n != None):
|
||||||
|
return n
|
||||||
|
else:
|
||||||
|
print(f"{Colors.RED}this field is required !{Colors.END}")
|
||||||
|
else:
|
||||||
|
print(f"{Colors.END}the 2 results mismatch !{Colors.END}")
|
||||||
|
else:
|
||||||
|
n = input(question) or default
|
||||||
|
if not "n" in input(f"{n} is correct ? "):
|
||||||
|
if (not required) or (required and n != None):
|
||||||
|
return n
|
||||||
|
else:
|
||||||
|
print(f"{Colors.RED}this field is required !{Colors.END}")
|
||||||
|
|
||||||
|
|
||||||
|
project_name = ask("enter your project filename > ", required=True)
|
||||||
|
libs = ask("enter your libs flags press (let the field blank if None) > ", default="")
|
||||||
|
|
||||||
|
template = f"""# tool macros
|
||||||
|
CC ?= gcc
|
||||||
|
#CXX ?=
|
||||||
|
CFLAGS := -ansi -pedantic {libs}
|
||||||
|
#CXXFLAGS := # FILL: compile flags
|
||||||
|
DBGFLAGS := -g
|
||||||
|
COBJFLAGS := $(CFLAGS) -c
|
||||||
|
|
||||||
|
# path macros
|
||||||
|
BIN_PATH := bin
|
||||||
|
OBJ_PATH := obj
|
||||||
|
SRC_PATH := src
|
||||||
|
DBG_PATH := debug
|
||||||
|
|
||||||
|
# compile macros
|
||||||
|
TARGET_NAME := {project_name}
|
||||||
|
ifeq ($(OS),Windows_NT)
|
||||||
|
TARGET_NAME := $(addsuffix .exe,$(TARGET_NAME))
|
||||||
|
endif
|
||||||
|
TARGET := $(BIN_PATH)/$(TARGET_NAME)
|
||||||
|
TARGET_DEBUG := $(DBG_PATH)/$(TARGET_NAME)
|
||||||
|
|
||||||
|
# src files & obj files
|
||||||
|
SRC := $(foreach x, $(SRC_PATH), $(wildcard $(addprefix $(x)/*,.c*)))
|
||||||
|
OBJ := $(addprefix $(OBJ_PATH)/, $(addsuffix .o, $(notdir $(basename $(SRC)))))
|
||||||
|
OBJ_DEBUG := $(addprefix $(DBG_PATH)/, $(addsuffix .o, $(notdir $(basename $(SRC)))))
|
||||||
|
|
||||||
|
# clean files list
|
||||||
|
DISTCLEAN_LIST := $(OBJ) \
|
||||||
|
$(OBJ_DEBUG)
|
||||||
|
CLEAN_LIST := $(TARGET) \
|
||||||
|
$(TARGET_DEBUG) \
|
||||||
|
$(DISTCLEAN_LIST)
|
||||||
|
|
||||||
|
# default rule
|
||||||
|
default: makedir all
|
||||||
|
|
||||||
|
# non-phony targets
|
||||||
|
$(TARGET): $(OBJ)
|
||||||
|
$(CC) -o $@ $(OBJ) $(CFLAGS)
|
||||||
|
|
||||||
|
$(OBJ_PATH)/%.o: $(SRC_PATH)/%.c*
|
||||||
|
$(CC) $(COBJFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
$(DBG_PATH)/%.o: $(SRC_PATH)/%.c*
|
||||||
|
$(CC) $(COBJFLAGS) $(DBGFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
$(TARGET_DEBUG): $(OBJ_DEBUG)
|
||||||
|
$(CC) $(CFLAGS) $(DBGFLAGS) $(OBJ_DEBUG) -o $@
|
||||||
|
|
||||||
|
# phony rules
|
||||||
|
.PHONY: makedir
|
||||||
|
makedir:
|
||||||
|
@mkdir -p $(BIN_PATH) $(OBJ_PATH) $(DBG_PATH) $(SRC_PATH)
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
all: $(TARGET)
|
||||||
|
|
||||||
|
.PHONY: debug
|
||||||
|
debug: $(TARGET_DEBUG)
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
@echo CLEAN $(CLEAN_LIST)
|
||||||
|
@rm -f $(CLEAN_LIST)
|
||||||
|
|
||||||
|
.PHONY: distclean
|
||||||
|
distclean:
|
||||||
|
@echo CLEAN $(DISTCLEAN_LIST)
|
||||||
|
@rm -f $(DISTCLEAN_LIST)"""
|
||||||
|
|
||||||
|
with open("Makefile", "w", encoding="utf-8", errors="ignore") as f:
|
||||||
|
f.write(template)
|
||||||
|
print(f"{Colors.GREEN}Makefile build successfully !{Colors.END}")
|
||||||
|
f.close()
|
||||||
|
os.system("make makedir")
|
||||||
|
open("src/main.c", "w").write(
|
||||||
|
"""#include <stdio.h>\n#include <stdlib.h>\n\nint main(void) {\n\n\treturn EXIT_SUCCESS;\n}"""
|
||||||
|
)
|
||||||
Reference in new issue
Block a user