Skip to content

Instantly share code, notes, and snippets.

@fdavidcl
Last active August 29, 2015 14:09
Show Gist options
  • Save fdavidcl/7ee2e6da7120ef318116 to your computer and use it in GitHub Desktop.
Save fdavidcl/7ee2e6da7120ef318116 to your computer and use it in GitHub Desktop.
Makefile for Lex programs
/*************************************************
Extremely helpful bit of C++ code stolen from:
http://cs.gmu.edu/~white/CS440/usingC++.html
(necessary for compilation)
*************************************************/
#include <iostream>
#include <stdio.h>
extern FILE *yyin;
extern char *yytext;
extern int yylex(void);
###############################################################################
# Makefile
# Compiles Lex programs in C++
###############################################################################
SHELL = /bin/bash
BIN = .
SRC = $(wildcard *.l)
EXE = $(basename $(BIN)/$(SRC))
CFLAGS = -Wall -Wl,--no-as-needed
CXXFLAGS = $(CFLAGS) -std=c++0x
LDFLAGS = -ll -I/usr/include
###############################################################################
default: $(EXE)
$(BIN)/%: %.o help.o
$(CXX) -o $@ $^ $(LDFLAGS)
%.o: %.c
$(CXX) -c -x c++ $(CXXFLAGS) $<
%.c: %.l
$(LEX) -o $@ $<
clean:
$(RM) -fv $(EXE) core.* *~ *.o
###############################################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment