# Generic GNU Makefile # Version 2.1 # # Mark Allman (mallman@ir.bbn.com) # BBN Technologies/NASA GRC # # Last Updated: Fri Feb 23, 2001 # General variables... CC := gcc CFLAGS := -g CCC := g++ CCFLAGS := $(CFLAGS) YACC := yacc YFLAGS := LEX := lex LFLAGS := PC := pc PFLAGS := -g FC := f77 FFLAGS := -g AS := $(CC) ASFLAGS := -g -c JAVACC := javac JAVAFLAGS := -g LD := $(CC) EXE := a.out # Find all source files... CSRCS := $(notdir $(wildcard *.[cs])) CCSRCS := $(notdir $(wildcard *.cc)) PSRCS := $(notdir $(wildcard *.p)) FSRCS := $(notdir $(wildcard *.f)) JSRCS := $(notdir $(wildcard *.java)) YSRCS := $(notdir $(wildcard *.y)) ifneq ($(strip $(YSRCS)),) ODD_OBJS += y.tab.o endif LSRCS := $(notdir $(wildcard *.l)) ifneq ($(strip $(LSRCS)),) ODD_OBJS += lex.yy.o endif SOURCES := $(CSRCS) $(CCSRCS) $(PSRCS) $(FSRCS) OBJECTS := $(ODD_OBJS) $(addsuffix .o, $(basename $(SOURCES))) JCLASS := $(addsuffix .class, $(basename $(JSRCS))) # Include needed libraries... LIBS := -lm ifneq ($(strip $(PSRCS)),) LIBS += -lp endif ifneq ($(strip $(FSRCS)),) LIBS += -lf2c endif ifneq ($(strip $(CCSRCS)),) LIBS += -lg++ endif ifneq ($(strip $(LSRCS)),) LIBS += -ll endif ARCH := $(shell uname) ifeq ($(ARCH),SunOS) VERS := $(shell uname -r) ifeq ($(basename $(VERS)),5) LIBS += -L/usr/ucblib -lsocket -lnsl -lelf -lucb endif endif # Determine what output we need to generate... TODO := ifneq ($(strip $(OBJECTS)),) TODO += machcompile endif ifneq ($(strip $(JCLASS)),) TODO += bytecompile endif default: $(TODO) # Compile to binary... machcompile: $(OBJECTS) $(LD) $(CFLAGS) $(OBJECTS) -o $(EXE) $(LIBS) # Compile to byte-code... bytecompile: $(JCLASS) %.class: %.java $(JAVACC) $(JAVAFLAGS) $< # Lex/Yacc Rules... y.tab.o: y.tab.c $(CC) -c y.tab.c y.tab.c: $(YSRCS) $(YACC) -dvt $(YFLAGS) $< lex.yy.c: $(LSRCS) $(LEX) $(LFLAGS) $< # Cleaning rules... clean: rm -f $(OBJECTS) $(JCLASS) lex.yy.c y.tab.c y.tab.h y.output core clobber: clean rm -f $(EXE)