Better githash.h generation on Makefile from @martinwhitaker

This commit is contained in:
Sam Demeulemeester 2022-04-08 03:34:15 +02:00 committed by Sam Demeulemeester
parent 1afcd08951
commit 8f0437c579
3 changed files with 50 additions and 14 deletions

6
.gitignore vendored
View File

@ -7,6 +7,9 @@
# Object files
*.o
# Generated file
githash.h
# Binaries
memtest_shared
memtest_shared.bin
@ -21,5 +24,4 @@ grub-iso
html
latex
# hash file
githash.h

View File

@ -1,10 +1,18 @@
AS = as -32
CC = gcc
GIT = git
ifeq ($(GIT),none)
GIT_AVAILABLE = false
else
GIT_AVAILABLE = true
endif
CFLAGS = -std=c11 -Wall -Wextra -Wshadow -m32 -march=i586 -fpic -fno-builtin \
-ffreestanding -fomit-frame-pointer -fno-stack-protector
INC_DIRS = -I../boot -I../system -I../lib -I../tests -I../app
INC_DIRS = -I../boot -I../system -I../lib -I../tests -I../app -Iapp
SYS_OBJS = system/cpuid.o \
system/cpuinfo.o \
@ -95,14 +103,23 @@ tests/%.o: ../tests/%.c
@mkdir -p tests
$(CC) -c $(CFLAGS) -O3 $(INC_DIRS) -o $@ $< -MMD -MP -MT $@ -MF $(@:.o=.d)
app/%.o: ../app/%.c githash.h
app/%.o: ../app/%.c app/githash.h
@mkdir -p app
$(CC) -c $(CFLAGS) -Os $(INC_DIRS) -o $@ $< -MMD -MP -MT $@ -MF $(@:.o=.d)
githash.h:
echo -n '#ifndef GIT_HASH\n#define GIT_HASH "' > ../app/$@ && \
git rev-parse HEAD | cut -c1-7 | tr -d "\n" >> ../app/$@ && \
echo '"\n#endif' >> ../app/$@
app/githash.h: FORCE
@mkdir -p app
@( \
if $(GIT_AVAILABLE) && test -d ../.git ; then \
hash=`git rev-parse HEAD | cut -c1-7`; \
else \
hash="unknown"; \
fi; \
define=`echo "#define GIT_HASH \"$$hash\""`; \
echo $$define | diff - $@ > /dev/null 2>&1 || echo $$define > $@; \
)
FORCE:
# Link it statically once so I know I don't have undefined symbols and
# then link it dynamically so I have full relocation information.

View File

@ -1,10 +1,18 @@
AS = as -64
CC = gcc
GIT = git
ifeq ($(GIT),none)
GIT_AVAILABLE = false
else
GIT_AVAILABLE = true
endif
CFLAGS = -std=c11 -Wall -Wextra -Wshadow -m64 -march=x86-64 -mno-mmx -mno-sse -mno-sse2 \
-fpic -fno-builtin -ffreestanding -fomit-frame-pointer -fno-stack-protector
INC_DIRS = -I../boot -I../system -I../lib -I../tests -I../app
INC_DIRS = -I../boot -I../system -I../lib -I../tests -I../app -Iapp
SYS_OBJS = system/cpuid.o \
system/cpuinfo.o \
@ -94,14 +102,23 @@ tests/%.o: ../tests/%.c
@mkdir -p tests
$(CC) -c $(CFLAGS) -O3 $(INC_DIRS) -o $@ $< -MMD -MP -MT $@ -MF $(@:.o=.d)
app/%.o: ../app/%.c githash.h
app/%.o: ../app/%.c app/githash.h
@mkdir -p app
$(CC) -c $(CFLAGS) -Os $(INC_DIRS) -o $@ $< -MMD -MP -MT $@ -MF $(@:.o=.d)
githash.h:
echo -n '#ifndef GIT_HASH\n#define GIT_HASH "' > ../app/$@ && \
git rev-parse HEAD | cut -c1-7 | tr -d "\n" >> ../app/$@ && \
echo '"\n#endif' >> ../app/$@
app/githash.h: FORCE
@mkdir -p app
@( \
if $(GIT_AVAILABLE) && test -d ../.git ; then \
hash=`git rev-parse HEAD | cut -c1-7`; \
else \
hash="unknown"; \
fi; \
define=`echo "#define GIT_HASH \"$$hash\""`; \
echo $$define | diff - $@ > /dev/null 2>&1 || echo $$define > $@; \
)
FORCE:
# Link it statically once so I know I don't have undefined symbols and
# then link it dynamically so I have full relocation information.