kirill-refactor
This commit is contained in:
52
mine/lab_2/vlad/Makefile
Normal file
52
mine/lab_2/vlad/Makefile
Normal file
@@ -0,0 +1,52 @@
|
||||
# Makefile
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wextra -O2
|
||||
PICFLAGS = -fPIC
|
||||
|
||||
.PHONY: all dynamic static test-dynamic test-static clean
|
||||
|
||||
all: dynamic static
|
||||
|
||||
# --- Dynamic (shared) build ---
|
||||
dynamic: libtext.so main_d
|
||||
|
||||
libtext.so: lib_d.o
|
||||
$(CC) -shared -o $@ $^
|
||||
|
||||
main_d: main_d.o
|
||||
$(CC) -o $@ $^ -ldl
|
||||
|
||||
lib_d.o: lib_d.c
|
||||
$(CC) $(CFLAGS) $(PICFLAGS) -c $< -o $@
|
||||
|
||||
# --- Static build ---
|
||||
static: libtext.a main_s
|
||||
|
||||
libtext.a: lib_s.o
|
||||
ar rcs $@ $^
|
||||
|
||||
main_s: main_s.o libtext.a
|
||||
$(CC) -o $@ main_s.o libtext.a
|
||||
|
||||
# Generic rule for other .o files
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
# --- Test targets ---
|
||||
# Creates a small `test_input.txt`, runs the program, and shows `out.txt`
|
||||
test-dynamic: dynamic
|
||||
printf "Hello123456789\n!!@@2211122\n" > test_input.txt
|
||||
./main_d test_input.txt out.txt 100 ./libtext.so
|
||||
@echo "---- out.txt ----"
|
||||
cat out.txt
|
||||
|
||||
test-static: static
|
||||
printf "Hello123456789\n!!@@2211122\n" > test_input.txt
|
||||
./main_s test_input.txt out.txt 100
|
||||
@echo "---- out.txt ----"
|
||||
cat out.txt
|
||||
|
||||
# --- Cleanup ---
|
||||
clean:
|
||||
rm -f *.o *.so *.a main_d main_s test_input.txt out.txt
|
||||
Reference in New Issue
Block a user