"clean up" makefile

will need to rework it again later
This commit is contained in:
jacekpoz 2024-02-11 17:44:35 +01:00
parent ac6c61e10a
commit 0e9a7d6bd8
No known key found for this signature in database
GPG key ID: 94E812A8B12AAE3C

View file

@ -8,34 +8,36 @@ CFLAGS += -Wconversion -Wunreachable-code
CFLAGS += -D_GNU_SOURCE
LDFLAGS =
SRC = modfetch.c semver.c
OBJ = $(SRC:.c=.o)
NAME = modfetch
PROG = modfetch.c
LIB = semver.c
OBJ = $(PROG:.c=.o) $(LIB:.c=.o)
BIN = target
TEMPMOD = $(wildcard modules/*.c)
MOD = $(TEMPMOD:modules/%=%)
PROGRAM = modfetch
.PHONY: all clean
all: dirs modules $(PROGRAM)
all: dirs modules $(NAME)
modules: dirs $(MOD:.c=.so)
dirs:
mkdir -p ./$(BIN)
mkdir -p $(BIN)
$(PROGRAM): $(addprefix $(BIN)/, $(OBJ))
$(CC) -o $(BIN)/$(PROGRAM) $^ $(LDFLAGS)
$(NAME): $(OBJ)
$(CC) -o $(BIN)/$(NAME) $(addprefix $(BIN)/, $^) $(LDFLAGS)
%.so: modules/%.c $(LIB)
$(CC) -o $(BIN)/$@ $^ -shared -fPIC $(CFLAGS) $(LDFLAGS)
%.o: %.c
$(CC) -o $(BIN)/$@ -c $< $(CFLAGS)
%.so: modules/%.c
$(CC) -o $(BIN)/$@ $^ -shared -fPIC $(CFLAGS)
clean: clean_modules
rm -rf $(OBJ)
rm -rf $(PROGRAM)
rm -rf $(addprefix $(BIN)/, $(OBJ))
rm -rf $(BIN)/$(NAME)
clean_modules:
rm -rf $(wildcard $(BIN)/*.so)