tweak Makefiles to be noisier and use default rules and be more robust

- be less aggressive about suppressing printing of commands
- invoke subcommands once and save results
  - to make commands shorter
  - to make it easy to see the actual values
  - to be robust against changes like "git commit" during a build
- modularize CFLAGS vs CPPFLAGS
- use default rules where possible
This commit is contained in:
Barak A. Pearlmutter 2014-04-02 12:19:40 +01:00
parent 31bca0d578
commit 5fe92b1b08
4 changed files with 25 additions and 26 deletions

2
.gitignore vendored
View File

@ -3,3 +3,5 @@
/src/base64u.c /src/base64u.c
/src/base64u.h /src/base64u.h
/tests/test /tests/test
/src/iodine
/src/iodined

View File

@ -14,7 +14,7 @@ MKDIR_FLAGS=-p
RM=rm RM=rm
RM_FLAGS=-f RM_FLAGS=-f
TARGETOS = `uname` TARGETOS := $(shell uname)
all: all:
@(cd src; $(MAKE) TARGETOS=$(TARGETOS) all) @(cd src; $(MAKE) TARGETOS=$(TARGETOS) all)

View File

@ -4,45 +4,40 @@ CLIENT = ../bin/iodine
SERVEROBJS = iodined.o user.o fw_query.o SERVEROBJS = iodined.o user.o fw_query.o
SERVER = ../bin/iodined SERVER = ../bin/iodined
OS = `echo $(TARGETOS) | tr "a-z" "A-Z"` OS := $(shell echo $(TARGETOS) | tr "a-z" "A-Z")
ARCH = `uname -m` ARCH := $(shell uname -m)
HEAD_COMMIT = `git rev-parse --short HEAD` HEAD_COMMIT := $(shell git rev-parse --short HEAD)
LIBPATH = -L. LIBPATH = -L.
LDFLAGS += -lz `sh osflags $(TARGETOS) link` $(LIBPATH) OS_CPPFLAGS := $(shell sh osflags $(TARGETOS) cppflags)
CFLAGS += -c -g -Wall -D$(OS) -pedantic `sh osflags $(TARGETOS) cflags` -DGITREVISION=\"$(HEAD_COMMIT)\" OS_CFLAGS := $(shell sh osflags $(TARGETOS) cflags)
OS_LDFLAGS := $(shell sh osflags $(TARGETOS) link)
CPPFLAGS = -D$(OS) -DGITREVISION=\"$(HEAD_COMMIT)\" $(OS_CPPFLAGS)
CFLAGS += -g -Wall -pedantic $(OS_CFLAGS)
LDFLAGS += -lz $(OS_LDFLAGS) $(LIBPATH)
all: stateos $(CLIENT) $(SERVER) all: stateos $(CLIENT) $(SERVER)
stateos: stateos:
@echo OS is $(OS), arch is $(ARCH) @echo OS is $(OS), arch is $(ARCH)
$(CLIENT): $(COMMONOBJS) $(CLIENTOBJS) iodine: $(COMMONOBJS) $(CLIENTOBJS)
@echo LD $@ iodined: $(COMMONOBJS) $(SERVEROBJS)
@mkdir -p ../bin $(CLIENT): iodine; mkdir -p ../bin && cp -a $< $@
@$(CC) $(COMMONOBJS) $(CLIENTOBJS) -o $(CLIENT) $(LDFLAGS) $(SERVER): iodined; mkdir -p ../bin && cp -a $< $@
$(SERVER): $(COMMONOBJS) $(SERVEROBJS)
@echo LD $@
@mkdir -p ../bin
@$(CC) $(COMMONOBJS) $(SERVEROBJS) -o $(SERVER) $(LDFLAGS)
.c.o:
@echo CC $<
@$(CC) $(CFLAGS) $< -o $@
base64u.o client.o iodined.o: base64u.h base64u.o client.o iodined.o: base64u.h
base64u.c: base64.c base64u.c: base64.c
@echo Making $@ @echo Making $@
@echo '/* No use in editing, produced by Makefile! */' > $@ echo '/* No use in editing, produced by Makefile! */' > $@
@sed -e 's/\([Bb][Aa][Ss][Ee]64\)/\1u/g ; s/0123456789+/0123456789_/' < base64.c >> $@ sed -e 's/\([Bb][Aa][Ss][Ee]64\)/\1u/g ; s/0123456789+/0123456789_/' < base64.c >> $@
base64u.h: base64.h base64u.h: base64.h
@echo Making $@ @echo Making $@
@echo '/* No use in editing, produced by Makefile! */' > $@ echo '/* No use in editing, produced by Makefile! */' > $@
@sed -e 's/\([Bb][Aa][Ss][Ee]64\)/\1u/g ; s/0123456789+/0123456789_/' < base64.h >> $@ sed -e 's/\([Bb][Aa][Ss][Ee]64\)/\1u/g ; s/0123456789+/0123456789_/' < base64.h >> $@
clean: clean:
@echo "Cleaning src/" @echo "Cleaning src/"
@rm -f $(CLIENT){,.exe} $(SERVER){,.exe} *~ *.o *.core base64u.* rm -f iodine iodined
@rm -rf obj libs #android stuff rm -f $(CLIENT){,.exe} $(SERVER){,.exe} *~ *.o *.core base64u.*
rm -rf obj libs #android stuff

View File

@ -25,6 +25,8 @@ link)
esac esac
;; ;;
cflags) cflags)
;;
cppflags)
case $1 in case $1 in
windows32) windows32)
echo '-DWINVER=0x0501'; echo '-DWINVER=0x0501';