Update the user Makefrag to be more generic
authorKevin Klues <klueska@cs.berkeley.edu>
Fri, 13 Nov 2015 02:51:53 +0000 (18:51 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Fri, 13 Nov 2015 20:44:05 +0000 (15:44 -0500)
This commit updates the makefrag for user libs so that it can handle
libraries that organize their header files using different patterns. As
part of this, we are now able to remove our custom pthread Makefile, as
one of the patterns we now support is the one used by the pthread
library.

Signed-off-by: Kevin Klues <klueska@cs.berkeley.edu>
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
user/Makefrag-user-lib
user/pthread/Makefile

index 8af4829..2ac9d05 100644 (file)
@@ -3,15 +3,14 @@
 # e.g.  LIBNAME = parlib
 
 ARCH ?= none   # catch bugs
+SRCDIR ?=
+INCDIR ?= $(SRCDIR)include
+OBJDIR ?= $(SRCDIR)obj
 CFLAGS_USER += $(CFLAGS_USER_LIBS)
 # DEPLIBS passed in from the top-level Makefile
 DEPLIBS := $(DEPLIBS)
 DEPLIBAS = $(patsubst %, $(XCC_TARGET_LIB)/lib%.a, $(DEPLIBS))
 
-SRCDIR :=
-OBJDIR := $(SRCDIR)obj
-INCDIR = $(SRCDIR)include
-
 INCS = -I$(INCDIR)
 FINALLIB = $(OBJDIR)/lib$(LIBNAME).a
 FINALLIB-INSTALL = $(XCC_TARGET_LIB)/lib$(LIBNAME).a
@@ -44,13 +43,20 @@ $(FINALLIB): $(OBJS)
        @mkdir -p $(@D)
        $(Q)$(AR) rc $@ $(OBJS)
 
-# The last rm is for the symlink
+# Allow three different patterns for installing include files
 $(FINALLIB-INSTALL): $(FINALLIB)
        @cp $(FINALLIB) $@
-       @rm -rf $(XCC_TARGET_INCLUDE)/$(LIBNAME)
-       @mkdir $(XCC_TARGET_INCLUDE)/$(LIBNAME)
-       @cp -r $(INCDIR)/* $(XCC_TARGET_INCLUDE)/$(LIBNAME)/
-       @rm $(XCC_TARGET_INCLUDE)/$(LIBNAME)/$(LIBNAME)
+       @if [ -L "$(INCDIR)/$(LIBNAME)" ]; then \
+               rm -rf $(XCC_TARGET_INCLUDE)/$(LIBNAME) ; \
+               mkdir $(XCC_TARGET_INCLUDE)/$(LIBNAME) ; \
+               cp -r $(INCDIR)/* $(XCC_TARGET_INCLUDE)/$(LIBNAME)/ ; \
+               rm $(XCC_TARGET_INCLUDE)/$(LIBNAME)/$(LIBNAME) ; \
+       elif [ -d "$(INCDIR)/$(LIBNAME)" ]; then \
+               rm -rf $(XCC_TARGET_INCLUDE)/$(LIBNAME) ; \
+               cp -r $(INCDIR)/$(LIBNAME) $(XCC_TARGET_INCLUDE)/ ; \
+       else \
+               cp -r $(INCDIR)/*.h $(XCC_TARGET_INCLUDE)/ ; \
+       fi;
 
 install: $(FINALLIB-INSTALL)
        @echo > /dev/null
index 74df0a3..c3b5fa6 100644 (file)
@@ -1,47 +1,4 @@
-ARCH ?= none # catch bugs
-CFLAGS_USER += $(CFLAGS_USER_LIBS)
 LIBNAME = pthread
-# DEPLIBS passed in from the top-level Makefile
-DEPLIBS := $(DEPLIBS)
-DEPLIBAS = $(patsubst %, $(XCC_TARGET_LIB)/lib%.a, $(DEPLIBS))
+INCDIR = .
+include ../Makefrag-user-lib
 
-SRCDIR := 
-OBJDIR := $(SRCDIR)obj
-INCDIR = $(SRCDIR).
-
-INCS = -I$(INCDIR) 
-FINALLIB = $(OBJDIR)/lib$(LIBNAME).a
-FINALLIB-INSTALL = $(XCC_TARGET_LIB)/lib$(LIBNAME).a
-
-uc = $(shell echo $(1) | tr a-z A-Z)
-
-LIBUCNAME := $(call uc, $(LIBNAME))
-HEADERS := $(shell find $(INCDIR) -name "*.h")
-CFILES  := $(wildcard $(SRCDIR)*.c)
-OBJS    := $(patsubst %.c, $(OBJDIR)/%.o, $(CFILES))
-
-all: $(FINALLIB)
-       @:
-
-$(OBJDIR)/%.o: $(SRCDIR)%.c $(HEADERS) $(DEPLIBAS)
-       @echo + cc [$(LIBUCNAME)] $<
-       @mkdir -p $(@D)
-       $(Q)$(CC) $(CFLAGS_USER) $(INCS) -o $@ -c $<
-
-$(FINALLIB): $(OBJS)
-       @echo + ar [$(LIBUCNAME)] $@
-       @mkdir -p $(@D)
-       $(Q)$(AR) rc $@ $(OBJS)
-
-$(FINALLIB-INSTALL): $(FINALLIB)
-       @cp $(FINALLIB) $@
-       @cp -R $(INCDIR)/*.h $(XCC_TARGET_INCLUDE)/
-
-install: $(FINALLIB-INSTALL)
-       @echo > /dev/null
-
-clean: 
-       @echo + clean [$(LIBUCNAME)]
-       $(Q)rm -rf $(FINALLIB)
-       $(Q)rm -rf $(OBJDIR)
-