"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 CFLAGS += -D_GNU_SOURCE
LDFLAGS = LDFLAGS =
SRC = modfetch.c semver.c NAME = modfetch
OBJ = $(SRC:.c=.o)
PROG = modfetch.c
LIB = semver.c
OBJ = $(PROG:.c=.o) $(LIB:.c=.o)
BIN = target BIN = target
TEMPMOD = $(wildcard modules/*.c) TEMPMOD = $(wildcard modules/*.c)
MOD = $(TEMPMOD:modules/%=%) MOD = $(TEMPMOD:modules/%=%)
PROGRAM = modfetch
.PHONY: all clean .PHONY: all clean
all: dirs modules $(PROGRAM) all: dirs modules $(NAME)
modules: dirs $(MOD:.c=.so) modules: dirs $(MOD:.c=.so)
dirs: dirs:
mkdir -p ./$(BIN) mkdir -p $(BIN)
$(PROGRAM): $(addprefix $(BIN)/, $(OBJ)) $(NAME): $(OBJ)
$(CC) -o $(BIN)/$(PROGRAM) $^ $(LDFLAGS) $(CC) -o $(BIN)/$(NAME) $(addprefix $(BIN)/, $^) $(LDFLAGS)
%.so: modules/%.c $(LIB)
$(CC) -o $(BIN)/$@ $^ -shared -fPIC $(CFLAGS) $(LDFLAGS)
%.o: %.c %.o: %.c
$(CC) -o $(BIN)/$@ -c $< $(CFLAGS) $(CC) -o $(BIN)/$@ -c $< $(CFLAGS)
%.so: modules/%.c
$(CC) -o $(BIN)/$@ $^ -shared -fPIC $(CFLAGS)
clean: clean_modules clean: clean_modules
rm -rf $(OBJ) rm -rf $(addprefix $(BIN)/, $(OBJ))
rm -rf $(PROGRAM) rm -rf $(BIN)/$(NAME)
clean_modules: clean_modules:
rm -rf $(wildcard $(BIN)/*.so) rm -rf $(wildcard $(BIN)/*.so)