summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-05-01 19:30:03 -0400
committerRich Felker <dalias@aerifal.cx>2012-05-01 19:30:03 -0400
commitd76eafcbdc099abfc1b6d09829349f01c0bfcacf (patch)
tree71d2f0f4fd295ddd2b6fdeab4991bf65065b7d3e /Makefile
parentd86d2829abc116c3e8741aa92727a5c55023088a (diff)
downloadmusl-d76eafcbdc099abfc1b6d09829349f01c0bfcacf.tar.gz
reorganize Makefile to support "least surprise" config/make semantics
the major change here is that CFLAGS is now a variable that can be changed entirely under user control, without causing essential flags to be lost. previously, "CFLAGS += ..." was valid in config.mak, but using "CFLAGS = ..." in config.mak would have badly broken the build process unless the user took care to copy the necessary flags out of the main Makefile. I have also added a distclean target that removes config.mak.
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile34
1 files changed, 23 insertions, 11 deletions
diff --git a/Makefile b/Makefile
index b4195544..2265fce4 100644
--- a/Makefile
+++ b/Makefile
@@ -21,10 +21,17 @@ OBJS = $(SRCS:.c=.o)
LOBJS = $(OBJS:.o=.lo)
GENH = include/bits/alltypes.h
-CFLAGS = -Os -nostdinc -ffreestanding -std=c99 -D_XOPEN_SOURCE=700 -pipe
-LDFLAGS = -nostdlib -shared -fPIC -Wl,-e,_start -Wl,-Bsymbolic-functions
-INC = -I./src/internal -I./include -I./arch/$(ARCH)
-PIC = -fPIC -O3
+LDFLAGS =
+CPPFLAGS =
+CFLAGS = -Os -pipe
+CFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc
+
+CFLAGS_ALL = $(CFLAGS_C99FSE)
+CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I./src/internal -I./include -I./arch/$(ARCH)
+CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS)
+CFLAGS_ALL_STATIC = $(CFLAGS_ALL)
+CFLAGS_ALL_SHARED = $(CFLAGS_ALL) -fPIC -DSHARED -O3
+
AR = $(CROSS_COMPILE)ar
RANLIB = $(CROSS_COMPILE)ranlib
@@ -33,10 +40,10 @@ ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH))
EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
CRT_LIBS = lib/crt1.o lib/crti.o lib/crtn.o
-STATIC_LIBS = lib/libc.a $(EMPTY_LIBS)
+STATIC_LIBS = lib/libc.a
SHARED_LIBS = lib/libc.so
TOOL_LIBS = lib/musl-gcc.specs
-ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(TOOL_LIBS)
+ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS)
ALL_TOOLS = tools/musl-gcc
LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH).so.1
@@ -56,6 +63,9 @@ clean:
rm -f $(GENH)
rm -f include/bits
+distclean: clean
+ rm -f config.mak
+
include/bits:
@test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
ln -sf ../arch/$(ARCH)/bits $@
@@ -66,19 +76,21 @@ include/bits/alltypes.h: include/bits/alltypes.h.sh
sh $< > $@
%.o: $(ARCH)/%.s
- $(CC) $(CFLAGS) $(INC) -c -o $@ $<
+ $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
%.o: %.c $(GENH)
- $(CC) $(CFLAGS) $(INC) -c -o $@ $<
+ $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
%.lo: $(ARCH)/%.s
- $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<
+ $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
%.lo: %.c $(GENH)
- $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<
+ $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
lib/libc.so: $(LOBJS)
- $(CC) $(LDFLAGS) -Wl,-soname=libc.so -o $@ $(LOBJS) -lgcc
+ $(CC) $(CFLAGS_ALL_SHARED) $(LDFLAGS) -nostdlib -shared \
+ -Wl,-e,_start -Wl,-Bsymbolic-functions \
+ -Wl,-soname=libc.so -o $@ $(LOBJS) -lgcc
lib/libc.a: $(OBJS)
rm -f $@