Skip to content

Commit

Permalink
Improve compiling for static binaries.
Browse files Browse the repository at this point in the history
Have "#ifdef STATIC" in config.c, and the 'rmconf' target
was a mess.
Instead, create 'pwgr.c' with stub routines for those unavailable
when statically compiled, and include that in STATICOBJ

Signed-off-by: Neil Brown <[email protected]>
  • Loading branch information
neilbrown committed May 29, 2006
1 parent 0c239ef commit c97be4d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
23 changes: 10 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ endif
SYSCONFDIR = /etc
CONFFILE = $(SYSCONFDIR)/mdadm.conf
MAILCMD =/usr/sbin/sendmail -t
CFLAGS = $(CWFLAGS) $(STATIC) $(CPPFLAGS) -DCONFFILE=\"$(CONFFILE)\" $(CXFLAGS) -DSendmail=\""$(MAILCMD)"\"
CFLAGS = $(CWFLAGS) $(CPPFLAGS) -DCONFFILE=\"$(CONFFILE)\" $(CXFLAGS) -DSendmail=\""$(MAILCMD)"\"

# If you want a static binary, you might uncomment these
# LDFLAGS = -static
Expand All @@ -72,7 +72,8 @@ SRCS = mdadm.c config.c mdstat.c ReadMe.c util.c Manage.c Assemble.c Build.c \
Create.c Detail.c Examine.c Grow.c Monitor.c dlink.c Kill.c Query.c \
mdopen.c super0.c super1.c bitmap.c restripe.c sysfs.c

STATICOBJS = SHA1.o sha1.o
STATICSRC = SHA1.c sha1.c pwgr.c
STATICOBJS = SHA1.o sha1.o pwgr.o

ASSEMBLE_SRCS := mdassemble.c Assemble.c config.c dlink.c util.c super0.c super1.c
ASSEMBLE_FLAGS:= $(CFLAGS) -DMDASSEMBLE
Expand All @@ -86,21 +87,17 @@ all : mdadm mdadm.man md.man mdadm.conf.man
everything: all mdadm.static mdadm.uclibc swap_super test_stripe mdassemble mdassemble.uclibc mdassemble.static mdassemble.man
# mdadm.tcc doesn't work..

mdadm : rmconf $(OBJS)
mdadm : $(OBJS)
$(CC) $(LDFLAGS) -o mdadm $(OBJS) $(LDLIBS)

mdadm.static : STATIC=-DSTATIC
mdadm.static : rmconf $(OBJS) $(STATICOBJS)
$(CC) $(LDFLAGS) -DSTATIC -static -o mdadm.static $(OBJS) $(STATICOBJS)

rmconf:
rm -f config.o
mdadm.static : $(OBJS) $(STATICOBJS)
$(CC) $(LDFLAGS) -static -o mdadm.static $(OBJS) $(STATICOBJS)

mdadm.tcc : $(SRCS) mdadm.h
$(TCC) -o mdadm.tcc $(SRCS)

mdadm.uclibc : $(SRCS) mdadm.h
$(UCLIBC_GCC) -DUCLIBC -DHAVE_STDINT_H -o mdadm.uclibc $(SRCS) SHA1.c sha1.c
$(UCLIBC_GCC) -DUCLIBC -DHAVE_STDINT_H -o mdadm.uclibc $(SRCS) $(STATICSRC)

mdadm.klibc : $(SRCS) mdadm.h
rm -f $(OBJS)
Expand All @@ -111,15 +108,15 @@ test_stripe : restripe.c mdadm.h

mdassemble : $(ASSEMBLE_SRCS) mdadm.h
rm -f $(OBJS)
$(DIET_GCC) $(ASSEMBLE_FLAGS) -o mdassemble $(ASSEMBLE_SRCS) SHA1.c sha1.c
$(DIET_GCC) $(ASSEMBLE_FLAGS) -o mdassemble $(ASSEMBLE_SRCS) $(STATICSRC)

mdassemble.static : $(ASSEMBLE_SRCS) mdadm.h
rm -f $(OBJS)
$(CC) $(LDFLAGS) $(ASSEMBLE_FLAGS) -static -DSTATIC -DHAVE_STDINT_H -o mdassemble.static $(ASSEMBLE_SRCS) SHA1.c sha1.c
$(CC) $(LDFLAGS) $(ASSEMBLE_FLAGS) -static -DHAVE_STDINT_H -o mdassemble.static $(ASSEMBLE_SRCS) $(STATICSRC)

mdassemble.uclibc : $(ASSEMBLE_SRCS) mdadm.h
rm -f $(OJS)
$(UCLIBC_GCC) $(ASSEMBLE_FLAGS) -DSTATIC -DUCLIBC -DHAVE_STDINT_H -static -o mdassemble.uclibc $(ASSEMBLE_SRCS) SHA1.c sha1.c
$(UCLIBC_GCC) $(ASSEMBLE_FLAGS) -DUCLIBC -DHAVE_STDINT_H -static -o mdassemble.uclibc $(ASSEMBLE_SRCS) $(STATICSRC)

# This doesn't work
mdassemble.klibc : $(ASSEMBLE_SRCS) mdadm.h
Expand Down
4 changes: 0 additions & 4 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,12 @@ static void createline(char *line)
}
createinfo.uid = strtoul(w+6, &ep, 10);
if (*ep != 0) {
#ifndef STATIC
struct passwd *pw;
/* must be a name */
pw = getpwnam(w+6);
if (pw)
createinfo.uid = pw->pw_uid;
else
#endif /* STATIC */
fprintf(stderr, Name ": CREATE user %s not found\n", w+6);
}
} else if (strncasecmp(w, "group=", 6) == 0) {
Expand All @@ -337,14 +335,12 @@ static void createline(char *line)
}
createinfo.gid = strtoul(w+6, &ep, 10);
if (*ep != 0) {
#ifndef STATIC
struct group *gr;
/* must be a name */
gr = getgrnam(w+6);
if (gr)
createinfo.gid = gr->gr_gid;
else
#endif /* STATIC */
fprintf(stderr, Name ": CREATE group %s not found\n", w+6);
}
} else if (strncasecmp(w, "mode=", 5) == 0) {
Expand Down
17 changes: 17 additions & 0 deletions pwgr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

/*
* We cannot link a static binary with passwd/group support, so
* just do without
*/
#include <stdlib.h>
#include <pwd.h>
#include <grp.h>

struct passwd *getpwnam(const char *name)
{
return NULL;
}
struct group *getgrnam(const char *name)
{
return NULL;
}

0 comments on commit c97be4d

Please sign in to comment.