Update Makefile Andrin

This commit is contained in:
romanschenk37 2022-03-23 16:28:20 +01:00 committed by GitHub Enterprise
parent 04b3b86afb
commit 4627d6994a
1 changed files with 56 additions and 14 deletions

View File

@ -1,25 +1,67 @@
SNP_SHARED_MAKEFILE := $(if $(SNP_SHARED_MAKEFILE),$(SNP_SHARED_MAKEFILE),"~/snp/shared.mk") SNP_SHARED_MAKEFILE := $(if $(SNP_SHARED_MAKEFILE),$(SNP_SHARED_MAKEFILE),"~/snp/shared.mk")
TARGET := bin/triangle TARGET := bin/dep2dot
SOURCES := src/triangle.c src/read.c src/rectang.c # Add all additional c-files to the SOURCES variable
# BEGIN-STUDENTS-TO-ADD-CODE
SOURCES := src/main.c src/data.c src/output.c
# END-STUDENTS-TO-ADD-CODE
TSTSOURCES := tests/tests.c TSTSOURCES := tests/tests.c
LIBS := -lm
include $(SNP_SHARED_MAKEFILE) include $(SNP_SHARED_MAKEFILE)
all: modul
modul: triangle.o read.o rectang.o # DEPFILES := ... define a list of png file names: %.c -> %.c.png
gcc -o modul src/triangle.o src/read.o src/rectang.o # BEGIN-STUDENTS-TO-ADD-CODE
DEPFILES := $(SOURCES:%.c=%.c.png)
clean: # END-STUDENTS-TO-ADD-CODE
rm -f *.o modul
triangle.o: src/triangle.c Makefile
gcc -c src/triangle.c
read.o: src/read.c src/read.h Makefile
gcc -c src/read.c
rectang.o: src/rectang.c src/rectang.h Makefile # define dep target as .PHONEY
gcc -c src/rectang.c # BEGIN-STUDENTS-TO-ADD-CODE
.PHONEY: dep
# BEGIN-STUDENTS-TO-ADD-CODE
# define dep target depending on FULLTARGET and DEPFILES above
# action: echo some text telling that the target is done using $@ - the echo command shall not be echoed before execution
# BEGIN-STUDENTS-TO-ADD-CODE
dep: $(DEPFILES) $(FULLTARGET)
echo $@
# BEGIN-STUDENTS-TO-ADD-CODE
# define new suffix rule for %.png depending on %.dot
# action: dot -Tpng $< >$@ || $(RM) $@
# BEGIN-STUDENTS-TO-ADD-CODE
%.png: %.dot
dot -Tpng $< >$@ || $(RM) $@
# BEGIN-STUDENTS-TO-ADD-CODE
# define new suffix rule for %.dot depending on %.dep
# action: call $(TARGET) $(@:.dot=) <$< >$@ || $(RM) $@
# BEGIN-STUDENTS-TO-ADD-CODE
%.dot: %.dep
call $(TARGET) $(@:.dot=) <$< >$@ || $(RM) $@
# BEGIN-STUDENTS-TO-ADD-CODE
# converts any .c file into a .c.dep file by means of GCC -H switch
# note: it removes intermediate files which were created as side effect
%.c.dep: %.c
$(COMPILE.c) -H -o $@.x $< 2>$@ && $(RM) $@.x $@.d
# cleanup all results, including the ones od creating the dependencies
dep-clean: clean
$(RM) $(DEPFILES) $(wildcard src/*.dep src/*.dot)