src-ed/openmp-c/Makefile
Ed Braaten e213617d4e Updated Makefile for openmp-c to add build date and commit author
to embedded version info in the binary.
2015-04-24 13:31:55 -07:00

42 lines
1.3 KiB
Makefile

# Sample makefile to add version/compiler info via an extra
# object module linked to final binary.
#
COMPILER_VER:=$(shell gcc --version)
COMPILER_OPTS=-fopenmp
GIT_DESCRIBE:=$(shell git describe --abbrev=7 --dirty --always --tags --long)
GIT_AUTHOR:=$(shell git --no-pager log -1 --pretty=format:"%an <%ae>")
BUILD_DATE:=$(shell date +"%F %H:%M:%S")
.PHONY: all
all: hello-omp
versioninfo.txt:
@echo "@(#) Build date: ${BUILD_DATE}." >versioninfo.txt
@echo "@(#) Compiler version: ${COMPILER_VER}." >>versioninfo.txt
@echo "@(#) Compiler options: ${COMPILER_OPTS}." >>versioninfo.txt
@echo "@(#) Git info: ${GIT_DESCRIBE}" >>versioninfo.txt
@echo "@(#) Commit author: ${GIT_AUTHOR}" >>versioninfo.txt
versioninfo.o: versioninfo.txt
objcopy --input binary \
--output elf64-x86-64 \
--binary-architecture i386 \
--add-section versioninfo=versioninfo.txt \
--set-section-flags versioninfo=contents,noload \
versioninfo.txt versioninfo.o
hello-omp: hello-omp.c Makefile versioninfo.o
gcc $(COMPILER_OPTS) -DVERSIONINFO="\"$(GIT_DESCRIBE)\"" hello-omp.c \
versioninfo.o -o hello-omp
.PHONY: test
test:
(export OMP_NUM_THREADS=2; ./hello-omp)
sleep 5
(export OMP_NUM_THREADS=24; ./hello-omp)
sleep 5
(export OMP_NUM_THREADS=500; ./hello-omp)
.PHONY: clean
clean:
rm -f hello-omp versioninfo.*