Skip to content

Instantly share code, notes, and snippets.

@sheutettz
Created April 29, 2014 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sheutettz/11399743 to your computer and use it in GitHub Desktop.
Save sheutettz/11399743 to your computer and use it in GitHub Desktop.
INCDIR := inc
SRCDIR := src
STUBDIR := test/src
LIBNAME := libxxx.a
EXENAME := xxxt.exe
PREFIX := /opt
#CC := gcc -O3
CC := gcc -g -O0
#CC := gcc -ffreestanding
#CC := gcc -pg
#CC := gcc -g -fprofile-arcs -ftest-coverage
LIBS :=
LIBS += -nostartfiles
LIBS += -nostdlib
LIBS += -L/opt/lib
LIBS += -lcrypto
LIBS += -lz
LIBS += -lgcc
CFLAGS :=
CFLAGS += -nostdinc
CFLAGS += -I$(INCDIR)
CFLAGS += -I/opt/include
CFLAGS += -std=gnu99
CFLAGS += -Wall
CFLAGS += -march=pentium4
#CFLAGS += -fomit-frame-pointer
CFLAGS += -fno-common
CFLAGS += -fno-builtin
CFLAGS += -DNDEBUG
SRCS := $(shell find $(SRCDIR) -follow -type f -name "*.c")
OBJS := $(SRCS:.c=.o)
SRCS := $(shell find $(SRCDIR) -follow -type f -name "*.S")
OBJS += $(SRCS:.S=.o)
SRCS := $(shell find $(STUBDIR) -follow -type f -name "*.c")
ST_OBJS := $(SRCS:.c=.o)
SRCS := $(shell find $(STUBDIR) -follow -type f -name "*.S")
ST_OBJS += $(SRCS:.S=.o)
empty :=
colon := $(empty):$(empty)
space := $(empty) $(empty)
#vpath %.c $(subst $(space),$(colon),$(strip $(shell find $(SRCDIR) -follow -type d -not -name CVS)))
#vpath %.S $(subst $(space),$(colon),$(strip $(shell find $(SRCDIR) -follow -type d -not -name CVS)))
.PHONY : all lib exe clean install uninstall
.SUFFIXES:
%.o : %.c
%.o : %.S
%.s : %.c
all : lib exe
lib : $(LIBNAME)
exe : $(EXENAME)
$(LIBNAME) : $(OBJS)
\ar -rs $(LIBNAME) $(OBJS)
$(EXENAME) : $(OBJS) $(ST_OBJS)
$(CC) -o $(EXENAME) $(OBJS) $(ST_OBJS) $(LIBS)
%.o : %.c
$(CC) -I$(dir $@) -I- $(CFLAGS) -c -o $@ $<
%.o : %.S
$(CC) -I$(dir $@) -I- $(CFLAGS) -c -o $@ $<
%.s : %.c
$(CC) -fverbose-asm -I$(dir $@) -I- $(CFLAGS) -S -o $@ $<
%.gcov : %.gcda
\gcov -lf -o $(<:.gcda=.o) $(<:.gcda=.c)
clean :
@\rm -fv $(LIBNAME) $(EXENAME) $(shell find $(SRCDIR) -follow -type f -name "*.o" -or -name "*.gcno" -or -name "*.gcda") \
$(shell find $(STUBDIR) -follow -type f -name "*.o" -or -name "*.gcno" -or -name "*.gcda")
install : uninstall $(LIBNAME)
@if [ ! -d $(PREFIX) ]; then \mkdir -p $(PREFIX)/ ; fi
@if [ ! -d $(PREFIX)/lib ]; then \mkdir -p $(PREFIX)/lib ; fi
@\cp -fv $(LIBNAME) $(PREFIX)/lib/
@\cp -rfv $(INCDIR)/ $(PREFIX)/include
uninstall :
@\rm -rfv $(PREFIX)/include/
@\rm -rfv $(PREFIX)/lib/
#cov :
# \gcov -lf -o $(SRCDIR) $(shell find $(SRCDIR) -follow -type f -name "*.c") > summary.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment