Makefile 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # The toolchain definitions
  2. CC = gcc
  3. LEX = flex
  4. YACC = bison
  5. SPARSE = sparse
  6. V = @ # Verbose build: make V=1
  7. C = 0 # Sparsechecker build: make C=1
  8. Q = $(V:1=)
  9. QUIET_CC = $(Q:@=@echo ' CC '$@;)$(CC)
  10. QUIET_DEPEND = $(Q:@=@echo ' DEPEND '$@;)$(CC)
  11. QUIET_LEX = $(Q:@=@echo ' LEX '$@;)$(LEX)
  12. QUIET_YACC = $(Q:@=@echo ' YACC '$@;)$(YACC)
  13. ifeq ($(C),1)
  14. QUIET_SPARSE = $(Q:@=@echo ' SPARSE '$@;)$(SPARSE)
  15. else
  16. QUIET_SPARSE = @/bin/true
  17. endif
  18. PREFIX ?= /usr/local
  19. CFLAGS ?= -O2 -fomit-frame-pointer -pipe
  20. CFLAGS += -std=gnu99 -D_GNU_SOURCE \
  21. -Wall -Wextra -Wformat=2 -Wundef -Wno-unused-parameter \
  22. -Wshadow -Wpointer-arith
  23. SPARSEFLAGS = $(CFLAGS) -D__transparent_union__=__unused__ -D_STRING_ARCH_unaligned=1 \
  24. -D__builtin_stpcpy=stpcpy
  25. LDFLAGS += -lfl
  26. BIN = b43-asm.bin
  27. SRCS = parser.c scanner.c main.c initvals.c util.c args.c
  28. # YACC related CFLAGS
  29. CFLAGS += -DYYSTYPE="void *" -DYYERROR_VERBOSE -DYYDEBUG=1 -DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=0 -Wno-unused
  30. .SUFFIXES:
  31. .PHONY: all install clean distclean
  32. .DEFAULT_GOAL := all
  33. DEPS = $(sort $(patsubst %.c,dep/%.d,$(1)))
  34. OBJS = $(sort $(patsubst %.c,obj/%.o,$(1)))
  35. # Generate dependencies
  36. $(call DEPS,$(SRCS)): dep/%.d: %.c
  37. @mkdir -p $(dir $@)
  38. $(QUIET_DEPEND) -o $@.tmp -MM -MG -MT "$@ $(patsubst dep/%.d,obj/%.o,$@)" $(CFLAGS) $< && mv -f $@.tmp $@
  39. -include $(call DEPS,$(SRCS))
  40. # Generate object files
  41. $(call OBJS,$(SRCS)): obj/%.o:
  42. @mkdir -p $(dir $@)
  43. $(QUIET_SPARSE) $(SPARSEFLAGS) $<
  44. $(QUIET_CC) -o $@ -c $(CFLAGS) $<
  45. all: $(BIN)
  46. scanner.c: scanner.l parser.h main.h util.h
  47. $(QUIET_LEX) -o scanner.c --header-file=scanner.h scanner.l
  48. scanner.h: scanner.c
  49. scanner.o: scanner.c
  50. $(QUIET_CC) $(CFLAGS) -c -o scanner.o scanner.c
  51. parser.c: parser.y main.h util.h
  52. $(QUIET_YACC) --defines -o parser.c parser.y
  53. parser.h: parser.c
  54. parser.o: parser.c
  55. $(QUIET_CC) $(CFLAGS) -c -o parser.o parser.c
  56. $(BIN): $(call OBJS,$(SRCS))
  57. $(QUIET_CC) $(CFLAGS) -o $(BIN) $(call OBJS,$(SRCS)) $(LDFLAGS)
  58. install: all
  59. install -m 755 $(BIN) $(PREFIX)/bin/
  60. cp b43-asm b43-asm.inst
  61. sed -i -e 's/installed=0/installed=1/' b43-asm.inst
  62. install -m 755 b43-asm.inst $(PREFIX)/bin/b43-asm
  63. rm -f b43-asm.inst
  64. clean:
  65. -rm -Rf dep obj *~ *.orig *.rej scanner.c scanner.h parser.c parser.h
  66. distclean: clean
  67. -rm -f $(BIN)