Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
Merge pull request #91 from dennwc/cpp_helpers
Browse files Browse the repository at this point in the history
Implement C++ wrappers for libuast
  • Loading branch information
juanjux authored Oct 17, 2018
2 parents e5e66e0 + 0893411 commit e8ad92e
Show file tree
Hide file tree
Showing 14 changed files with 767 additions and 176 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ os:
- osx

before_install:
- if [[ $TRAVIS_OS_NAME = linux ]]; then sudo apt-get update -qq && sudo apt-get install -qq libcunit1 libcunit1-doc libcunit1-dev gcc-mingw-w64-x86-64; fi
- if [[ $TRAVIS_OS_NAME = linux ]]; then sudo apt-get update -y && sudo apt-get install -y libcunit1 libcunit1-doc libcunit1-dev gcc-mingw-w64-x86-64; fi
- if [[ $TRAVIS_OS_NAME = osx ]]; then brew install cunit lcov ; fi
- mkdir -p $GOPATH/bin && curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh

Expand Down
30 changes: 21 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
HOSTOS:=$(shell go env GOHOSTOS)

SRC_DIR=./src
DEPS_C = $(SRC_DIR)/*.h $(SRC_DIR)/*.c
DEPS_C = $(SRC_DIR)/*.h $(SRC_DIR)/*.hpp $(SRC_DIR)/*.c
DEPS_GO = $(SRC_DIR)/*.go gen_header.go vendor

BUILD_MODE=-buildmode=c-shared
Expand All @@ -11,13 +11,21 @@ CC_WIN32=i686-w64-mingw32-gcc

GEN_HEADER=go run gen_header.go -o

ifeq ("$(HOSTOS)", 'windows')
CP_HEADERS=copy $(SRC_DIR)/libuast.hpp

else
CP_HEADERS=cp $(SRC_DIR)/libuast.hpp

endif

OUT_NAME=libuast
OUT_HEADER=$(OUT_NAME).h
OUT_DIR=build

DIR_LINUX=linux_amd64
DIR_OSX=darwin_amd64
DIR_WINDOWS=windows_amd64
DIR_LINUX=linux-amd64
DIR_OSX=darwin-amd64
DIR_WINDOWS=windows-amd64

OUT_LINUX=$(OUT_DIR)/$(DIR_LINUX)
OUT_OSX=$(OUT_DIR)/$(DIR_OSX)
Expand Down Expand Up @@ -48,19 +56,22 @@ build: build-$(HOSTOS)
build-linux: $(DEPS_C) $(DEPS_GO)
mkdir -p $(OUT_LINUX) && \
GOOS=linux GOARCH=amd64 $(GO_BUILD) $(BUILD_MODE) -o=$(OUT_LINUX)/$(OUT_NAME).so $(SRC_DIR)/ && \
$(GEN_HEADER) $(OUT_LINUX)/$(OUT_HEADER)
$(GEN_HEADER) $(OUT_LINUX)/$(OUT_HEADER) && \
$(CP_HEADERS) $(OUT_LINUX)/

build-darwin: $(DEPS_C) $(DEPS_GO)
mkdir -p $(OUT_OSX) && \
GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 $(GO_BUILD) $(BUILD_MODE) -o=$(OUT_OSX)/$(OUT_NAME).so $(SRC_DIR)/ && \
$(GEN_HEADER) $(OUT_OSX)/$(OUT_HEADER)
$(GEN_HEADER) $(OUT_OSX)/$(OUT_HEADER) && \
$(CP_HEADERS) $(OUT_OSX)/


ifneq ("$(HOSTOS)", "windows")
build-windows: $(DEPS_C) $(DEPS_GO)
mkdir -p $(OUT_WINDOWS)
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=$(CC_WIN64) $(GO_BUILD) $(BUILD_MODE) -o=$(OUT_WINDOWS)/$(OUT_NAME).dll $(SRC_DIR)/
$(GEN_HEADER) $(OUT_WINDOWS)/$(OUT_HEADER)
$(CP_HEADERS) $(OUT_WINDOWS)/

else
build-windows: $(DEPS_C) $(DEPS_GO)
Expand All @@ -69,6 +80,7 @@ build-windows: $(DEPS_C) $(DEPS_GO)
set GOARCH=amd64
$(GO_BUILD) $(BUILD_MODE) -o=$(OUT_WINDOWS)\\$(OUT_NAME).dll $(SRC_DIR)/
$(GEN_HEADER) $(OUT_WINDOWS)\\$(OUT_HEADER)
$(CP_HEADERS) $(OUT_WINDOWS)\\

endif

Expand All @@ -87,15 +99,15 @@ endif

package-linux: build-linux
cd $(OUT_DIR) && \
tar -czf linux_amd64.tar.gz $(DIR_LINUX)
tar -czf libuast-linux-amd64.tar.gz $(DIR_LINUX)

package-darwin: build-darwin
cd $(OUT_DIR) && \
tar -czf darwin_amd64.tar.gz $(DIR_OSX)
tar -czf libuast-darwin-amd64.tar.gz $(DIR_OSX)

package-windows: build-windows
cd $(OUT_DIR) && \
tar -czf windows_amd64.tar.gz $(DIR_WINDOWS)
tar -czf libuast-windows-amd64.tar.gz $(DIR_WINDOWS)

.PHONY: gotest
gotest: $(DEPS_GO)
Expand Down
4 changes: 2 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ set (CMAKE_CXX_STANDARD 11)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
find_package(Uast)

include_directories(. ../src/ ${CHECK_INCLUDE_DIRS} ${UAST_INCLUDE_DIRS})
include_directories(. ${CHECK_INCLUDE_DIRS} ${UAST_INCLUDE_DIRS})

add_executable(example example.cc ${libsrc})
add_executable(example example.cpp ${libsrc})
target_link_libraries(example ${UAST_LIBRARIES})
target_link_libraries(example ${libshared})
2 changes: 1 addition & 1 deletion examples/cmake/FindUast.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ find_package(PkgConfig QUIET)
pkg_check_modules(PC_UAST QUIET uast)

find_path(UAST_INCLUDE_DIR
NAMES libuast.h uast.h
NAMES libuast.h libuast.hpp
HINTS ../build/*
)
find_library(UAST_LIBRARY
Expand Down
Loading

0 comments on commit e8ad92e

Please sign in to comment.