Skip to content

Commit

Permalink
Added support in Makefile for RHEL
Browse files Browse the repository at this point in the history
  • Loading branch information
lpsantil committed Jun 26, 2017
1 parent 02a3fb2 commit 7ba93de
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
26 changes: 18 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ DESTDIR ?= /usr/local
CORES ?= 1

# Basic feature detection
OS = $(shell uname)
OS = $(shell cat /etc/os-release | grep "rhel\|fedora\|centos" && echo "rhel" || cat /etc/os-release | grep "debian\|ubuntu" && echo "debian" || uname)
ARCH ?= $(shell uname -m)

ifeq ($(ARCH), i686)
Expand All @@ -27,6 +27,7 @@ endif
# Comment next line if you want System Default/GNU BFD LD instead
#LD = gold
CFLAGS ?= -Os -Wall -ansi -pedantic -nostdlib -fomit-frame-pointer -fno-stack-protector -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-unroll-loops -fmerge-all-constants -fno-ident -mfpmath=sse -mfancy-math-387 -ffunction-sections -fdata-sections -Wl,--gc-sections -flto
#CFLAGS ?= -Os -Wall -std=gnu99 -pedantic -nostdlib -fomit-frame-pointer -fno-stack-protector -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-unroll-loops -fmerge-all-constants -fno-ident -mfpmath=sse -mfancy-math-387 -ffunction-sections -fdata-sections -Wl,--gc-sections -flto
LDFLAGS ?= -s -static -nostdlib -z norelro --hash-style=sysv --build-id=none --gc-sections -flto
#LDFLAGS ?= -g -nostdlib
#LDFLAGS ?= -s -nostdlib -Wl,--gc-sections
Expand Down Expand Up @@ -56,9 +57,9 @@ TOBJ = $(TSRC:.c=.o)
TSDEPS = $(TSRC:.c=.d)
TEXE = $(TOBJ:.o=.exe)

TMPCI = $(shell cat tmp.ci.pid)
TMPCT = $(shell cat tmp.ct.pid)
TMPCD = $(shell cat tmp.cd.pid)
TMPCI = $(shell cat tmp.ci.pid 2>/dev/null)
TMPCT = $(shell cat tmp.ct.pid 2>/dev/null)
TMPCD = $(shell cat tmp.cd.pid 2>/dev/null)

CILOG ?= tmp.ci.log

Expand Down Expand Up @@ -87,6 +88,14 @@ ifeq ($(OS), Freebsd)
LDFLAGS += -Wl,-u_start
endif

# Fix up the unistd_$(MSIZE) on rhel/fedora/centos vs. debian/ubuntu
ifeq ($(OS), rhel)
UNISTD_PATH =
endif
ifeq ($(OS), debian)
UNISTD_PATH = $(ARCH)-linux-gnu/
endif

######################################################################
######################## DO NOT MODIFY BELOW #########################
######################################################################
Expand All @@ -103,13 +112,13 @@ t/%.exe: t/%.o $(LIB) Makefile

all: $(LIB)

$(SYSINC): /usr/include/$(ARCH)-linux-gnu/asm/unistd_$(MSIZE).h
echo "\n#define __SYSCALL(x,y)\n" >> $@
$(SYSINC): /usr/include/$(UNISTD_PATH)/asm/unistd_$(MSIZE).h
echo -e "\n#define __SYSCALL(x,y)\n" >> $@
grep __NR_ $< | sed -e s/__NR_/SYS_/g >> $@
ifeq ($(WITH_FAST_SYSCALL), 1)
echo "\n#define __RT0_WITH_FASTER_SYSCALL__ 1\n" >> $@
echo -e "\n#define __RT0_WITH_FASTER_SYSCALL__ 1\n" >> $@
endif
echo "\n#undef __SYSCALL\n" >> $@
echo -e "\n#undef __SYSCALL\n" >> $@

$(LIB): $(LOBJ)
$(AR) -rcs $@ $^
Expand Down Expand Up @@ -165,6 +174,7 @@ showconfig:
@echo "DESTDIR="$(DESTDIR)
@echo "CFLAGS="$(CFLAGS)
@echo "LDFLAGS="$(LDFLAGS)
@echo "UNISTD_PATH="$(UNISTD_PATH)
@echo "DDIR="$(DDIR)
@echo "DSRC="$(DSRC)
@echo "SRC="$(SRC)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ A minimal C runtime for Linux on i386 &amp; x86_64
* Can be used with [gold][19] (Google LD, part of GNU Binutils)
* Hello World in just 608 bytes (i386) or 792 bytes (x86_64)
* Small binary sizes vs. other libc's
* Tested with RHEL 7, Ubuntu 14.04+, i386, i686, x86_64

See [STATS.md][20] to see how rt0 fares.
See the [musl libc comparison][0] to see how other libc's fare.
Expand Down
3 changes: 2 additions & 1 deletion STATS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
| t/null.exe | i386 | 552 | Empty main |
| t/null.exe | x86_64 | 752 | Empty main |

Compiler: GCC 4.8.5, GNU LD linker 2.25.1, ld/binutils 2.25.1, OS: RHEL 7.3, Source: Author
Compiler: GCC 4.8.4, gold linker 1.11, ld/binutils 2.24, OS: Ubuntu 14.04.3, Source: Author

Compile Flags: `-Os -nostdlib -fomit-frame-pointer -fno-stack-protector -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-unroll-loops -fmerge-all-constants -fno-ident -mfpmath=387 -mfancy-math-387 -ffunction-sections -fdata-sections -Wl,--gc-sections`

Link Flags: `-s -nostdlib -z norelro --hash-style=sysv --build-id=none --gc-sections`
Link Flags: `-s -static -nostdlib -z norelro --hash-style=sysv --build-id=none --gc-sections`

---

Expand Down

0 comments on commit 7ba93de

Please sign in to comment.