Skip to content

Commit

Permalink
Merge pull request #88 from SymbiFlow/cmdline_tools_improve
Browse files Browse the repository at this point in the history
Improvements to command line tools
  • Loading branch information
gatecat authored Aug 31, 2019
2 parents a673791 + c0d12d6 commit 1c87d30
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 7 deletions.
1 change: 1 addition & 0 deletions libtrellis/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ ecppll
libtrellis.dylib
*~
ecpmulti
generated/
26 changes: 21 additions & 5 deletions libtrellis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ if (BUILD_PYTHON)
target_link_libraries(pytrellis LINK_PUBLIC ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
endif()


find_package(Boost REQUIRED COMPONENTS program_options)

get_property(LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
Expand All @@ -117,22 +116,39 @@ function(setup_rpath name)
endif()
endfunction()

add_executable(ecppack ${INCLUDE_FILES} tools/ecppack.cpp)

# Avoid peturbing build if git version hasn't changed
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/generated")
set(LAST_GIT_VERSION "")
execute_process(COMMAND git describe --tags OUTPUT_VARIABLE CURRENT_GIT_VERSION)
string(STRIP "${CURRENT_GIT_VERSION}" CURRENT_GIT_VERSION)
if (EXISTS "${CMAKE_BINARY_DIR}/generated/last_git_version")
file(READ "${CMAKE_BINARY_DIR}/generated/last_git_version" LAST_GIT_VERSION)
endif()
if (NOT ("${LAST_GIT_VERSION}" STREQUAL "${CURRENT_GIT_VERSION}"))
configure_file(
${CMAKE_SOURCE_DIR}/tools/version.cpp.in
${CMAKE_BINARY_DIR}/generated/version.cpp
)
endif()
file(WRITE "${CMAKE_BINARY_DIR}/generated/last_git_version" CURRENT_GIT_VERSION)

add_executable(ecppack ${INCLUDE_FILES} tools/ecppack.cpp "${CMAKE_BINARY_DIR}/generated/version.cpp")
target_compile_definitions(ecppack PRIVATE TRELLIS_PREFIX="${CMAKE_INSTALL_PREFIX}")
target_link_libraries(ecppack trellis ${Boost_LIBRARIES} ${link_param})
setup_rpath(ecppack)

add_executable(ecpunpack ${INCLUDE_FILES} tools/ecpunpack.cpp)
add_executable(ecpunpack ${INCLUDE_FILES} tools/ecpunpack.cpp "${CMAKE_BINARY_DIR}/generated/version.cpp")
target_compile_definitions(ecpunpack PRIVATE TRELLIS_PREFIX="${CMAKE_INSTALL_PREFIX}")
target_link_libraries(ecpunpack trellis ${Boost_LIBRARIES} ${link_param})
setup_rpath(ecpunpack)

add_executable(ecppll ${INCLUDE_FILES} tools/ecppll.cpp)
add_executable(ecppll ${INCLUDE_FILES} tools/ecppll.cpp "${CMAKE_BINARY_DIR}/generated/version.cpp")
target_compile_definitions(ecppll PRIVATE TRELLIS_PREFIX="${CMAKE_INSTALL_PREFIX}")
target_link_libraries(ecppll trellis ${Boost_LIBRARIES} ${link_param})
setup_rpath(ecppll)

add_executable(ecpmulti ${INCLUDE_FILES} tools/ecpmulti.cpp)
add_executable(ecpmulti ${INCLUDE_FILES} tools/ecpmulti.cpp "${CMAKE_BINARY_DIR}/generated/version.cpp")
target_compile_definitions(ecpmulti PRIVATE TRELLIS_PREFIX="${CMAKE_INSTALL_PREFIX}")
target_link_libraries(ecpmulti trellis ${Boost_LIBRARIES} ${link_param})
setup_rpath(ecpmulti)
Expand Down
2 changes: 2 additions & 0 deletions libtrellis/tools/ecpmulti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Chip.hpp"
#include "Database.hpp"
#include "Tile.hpp"
#include "version.hpp"
#include <iostream>
#include <boost/program_options.hpp>
#include <stdexcept>
Expand Down Expand Up @@ -78,6 +79,7 @@ int main(int argc, char *argv[])
if (vm.count("help")) {
help:
cerr << "Project Trellis - Open Source Tools for ECP5 FPGAs" << endl;
cerr << "Version " << git_describe_str << endl;
cerr << "ecpmulti: ECP5 multiboot bitstream assembler" << endl;
cerr << endl;
cerr << "Copyright (C) 2019 Jens Andersen <[email protected]>" << endl;
Expand Down
9 changes: 8 additions & 1 deletion libtrellis/tools/ecppack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "Bitstream.hpp"
#include "Chip.hpp"
#include "Database.hpp"
#include "version.hpp"
#include <iostream>
#include <boost/program_options.hpp>
#include <stdexcept>
Expand Down Expand Up @@ -49,18 +50,24 @@ int main(int argc, char *argv[])
po::store(parsed, vm);
po::notify(vm);
}
catch (po::required_option &e) {
cerr << "Error: input file is mandatory." << endl << endl;
goto help;
}
catch (std::exception &e) {
cerr << e.what() << endl << endl;
cerr << "Error: " << e.what() << endl << endl;
goto help;
}

if (vm.count("help")) {
help:
cerr << "Project Trellis - Open Source Tools for ECP5 FPGAs" << endl;
cerr << "Version " << git_describe_str << endl;
cerr << "ecppack: ECP5 bitstream packer" << endl;
cerr << endl;
cerr << "Copyright (C) 2018 David Shah <[email protected]>" << endl;
cerr << endl;
cerr << "Usage: ecppack input.config [output.bit] [options]" << endl;
cerr << options << endl;
return vm.count("help") ? 0 : 1;
}
Expand Down
2 changes: 2 additions & 0 deletions libtrellis/tools/ecppll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ f_out = f_vco / output
#include <fstream>
#include <string>
#include <boost/program_options.hpp>
#include "version.hpp"
using namespace std;

enum class pll_mode{
Expand Down Expand Up @@ -113,6 +114,7 @@ int main(int argc, char** argv){
if(vm.count("help")){
cerr << "Project Trellis - Open Source Tools for ECP5 FPGAs" << endl;
cerr << "ecppll: ECP5 PLL Configuration Calculator" << endl;
cerr << "Version " << git_describe_str << endl;
cerr << endl;
cerr << "This tool is experimental! Use at your own risk!" << endl;
cerr << endl;
Expand Down
9 changes: 8 additions & 1 deletion libtrellis/tools/ecpunpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "Bitstream.hpp"
#include "Chip.hpp"
#include "Database.hpp"
#include "version.hpp"
#include <iostream>
#include <boost/optional.hpp>
#include <boost/program_options.hpp>
Expand Down Expand Up @@ -36,18 +37,24 @@ int main(int argc, char *argv[])
po::store(parsed, vm);
po::notify(vm);
}
catch (po::required_option &e) {
cerr << "Error: input file is mandatory." << endl << endl;
goto help;
}
catch (std::exception &e) {
cerr << e.what() << endl << endl;
cerr << "Error: " << e.what() << endl << endl;
goto help;
}

if (vm.count("help")) {
help:
cerr << "Project Trellis - Open Source Tools for ECP5 FPGAs" << endl;
cerr << "Version " << git_describe_str << endl;
cerr << "ecpunpack: ECP5 bitstream to text config converter" << endl;
cerr << endl;
cerr << "Copyright (C) 2018 David Shah <[email protected]>" << endl;
cerr << endl;
cerr << "Usage: ecpunpack input.bit [output.config] [options]" << endl;
cerr << options << endl;
return vm.count("help") ? 0 : 1;
}
Expand Down
2 changes: 2 additions & 0 deletions libtrellis/tools/version.cpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include <string>
std::string git_describe_str = "@CURRENT_GIT_VERSION@";
5 changes: 5 additions & 0 deletions libtrellis/tools/version.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#ifndef VERSION_H
#define VERSION_H
#include <string>
extern const std::string git_describe_str;
#endif

0 comments on commit 1c87d30

Please sign in to comment.