File size: 832 Bytes
d664931
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/sh
# setup_compiler_wrappers.sh
# Creates compiler wrapper scripts for reproducible builds by overriding
# __TIME__, __DATE__, and __TIMESTAMP__ macros with constant values.
# This ensures Docker image builds are deterministic regardless of build time.

set -e

WRAPPER_DIR="/usr/local/bin/wrapped-cc"
mkdir -p "$WRAPPER_DIR"

# GCC wrapper
cat > "$WRAPPER_DIR/gcc" << 'WRAPPER'
#!/bin/sh
exec /usr/bin/gcc -D__TIME__="\"0\"" -D__DATE__="\"0\"" -D__TIMESTAMP__="\"0\"" -Wno-builtin-macro-redefined "$@"
WRAPPER
chmod +x "$WRAPPER_DIR/gcc"

# Symlink cc to gcc wrapper
ln -sf "$WRAPPER_DIR/gcc" "$WRAPPER_DIR/cc"

# G++ wrapper
cat > "$WRAPPER_DIR/g++" << 'WRAPPER'
#!/bin/sh
exec /usr/bin/g++ -D__TIME__="\"0\"" -D__DATE__="\"0\"" -D__TIMESTAMP__="\"0\"" -Wno-builtin-macro-redefined "$@"
WRAPPER
chmod +x "$WRAPPER_DIR/g++"